Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Archive subclass of Page #67

Merged
merged 2 commits into from
Aug 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 1 addition & 21 deletions lib/jekyll-archives.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,8 @@ def generate(site)
@site.config['jekyll-archives'] = @config

read
render
write
@site.pages.concat(@archives)

@site.keep_files ||= []
@archives.each do |archive|
@site.keep_files << archive.relative_path
end
@site.config["archives"] = @archives
end

Expand Down Expand Up @@ -97,21 +92,6 @@ def enabled?(archive)
end
end

# Renders the archives into the layouts
def render
payload = @site.site_payload
@archives.each do |archive|
archive.render(@site.layouts, payload)
end
end

# Write archives to their destination
def write
@archives.each do |archive|
archive.write(@site.dest)
end
end

def tags
@site.post_attr_hash('tags')
end
Expand Down
53 changes: 4 additions & 49 deletions lib/jekyll-archives/archive.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
module Jekyll
module Archives
class Archive
include Convertible
class Archive < Jekyll::Page

attr_accessor :posts, :type, :name, :slug
attr_accessor :data, :content, :output
attr_accessor :path, :ext
attr_accessor :site
attr_accessor :posts, :type, :slug

# Attributes for Liquid templates
ATTRIBUTES_FOR_LIQUID = %w[
ATTRIBUTES_FOR_LIQUID = %w(
posts
type
title
date
name
path
url
]
).freeze

# Initialize a new Archive page
#
Expand Down Expand Up @@ -90,31 +86,6 @@ def url
raise ArgumentError.new "Template \"#{template}\" provided is invalid."
end

# Add any necessary layouts to this post
#
# layouts - The Hash of {"name" => "layout"}.
# site_payload - The site payload Hash.
#
# Returns nothing.
def render(layouts, site_payload)
payload = Utils.deep_merge_hashes({
"page" => to_liquid
}, site_payload)

do_layout(payload, layouts)
end

# Convert this Convertible's data to a Hash suitable for use by Liquid.
#
# Returns the Hash representation of this Convertible.
def to_liquid(attrs = nil)
further_data = Hash[(attrs || self.class::ATTRIBUTES_FOR_LIQUID).map { |attribute|
[attribute, send(attribute)]
}]

Utils.deep_merge_hashes(data, further_data)
end

# Produce a title object suitable for Liquid based on type of archive.
#
# Returns a String (for tag and category archives) and nil for
Expand All @@ -135,17 +106,6 @@ def date
end
end

# Obtain destination path.
#
# dest - The String path to the destination dir.
#
# Returns the destination file path String.
def destination(dest)
path = Jekyll.sanitized_path(dest, URL.unescape_path(url))
path = File.join(path, "index.html") if url =~ /\/$/
path
end

# Obtain the write path relative to the destination directory
#
# Returns the destination relative path String.
Expand All @@ -159,11 +119,6 @@ def relative_path
def inspect
"#<Jekyll:Archive @type=#{@type.to_s} @title=#{@title} @data=#{@data.inspect}>"
end

# Returns the Boolean of whether this Page is HTML or not.
def html?
true
end
end
end
end