Class: Jekyll::Archive
- Inherits:
-
Object
- Object
- Jekyll::Archive
- Includes:
- Convertible
- Defined in:
- lib/jekyll-archives/archive.rb
Constant Summary collapse
- ATTRIBUTES_FOR_LIQUID =
Attributes for Liquid templates
%w[ posts type name ]
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#data ⇒ Object
Returns the value of attribute data.
-
#ext ⇒ Object
Returns the value of attribute ext.
-
#name ⇒ Object
Returns the value of attribute name.
-
#output ⇒ Object
Returns the value of attribute output.
-
#path ⇒ Object
Returns the value of attribute path.
-
#posts ⇒ Object
Returns the value of attribute posts.
-
#site ⇒ Object
Returns the value of attribute site.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#destination(dest) ⇒ Object
Obtain destination path.
-
#html? ⇒ Boolean
Returns the Boolean of whether this Page is HTML or not.
-
#initialize(site, posts, type, name) ⇒ Archive
constructor
Initialize a new Archive page.
-
#inspect ⇒ Object
Returns the object as a debug String.
-
#render(layouts, site_payload) ⇒ Object
Add any necessary layouts to this post.
-
#template ⇒ Object
The template of the permalink.
-
#to_liquid(attrs = nil) ⇒ Object
Convert this Convertible’s data to a Hash suitable for use by Liquid.
-
#url ⇒ Object
The generated relative url of this page.
-
#url_placeholders ⇒ Object
Returns a hash of URL placeholder names (as symbols) mapping to the desired placeholder replacements.
Constructor Details
#initialize(site, posts, type, name) ⇒ Archive
Initialize a new Archive page
site - The Site object. posts - The array of posts that belong in this archive. type - The type of archive. Can be one of “year”, “category”, or “tag” name - The name of the archive (e.g. “2014” or “my-category” or “my-tag”).
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/jekyll-archives/archive.rb', line 23 def initialize(site, posts, type, name) @site = site @posts = posts @type = type @name = name # Use ".html" for file extension and url for path @ext = ".html" @path = url @data = { "layout" => site.config['jekyll-archives']['layout'] } @content = "" end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
6 7 8 |
# File 'lib/jekyll-archives/archive.rb', line 6 def content @content end |
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/jekyll-archives/archive.rb', line 6 def data @data end |
#ext ⇒ Object
Returns the value of attribute ext.
7 8 9 |
# File 'lib/jekyll-archives/archive.rb', line 7 def ext @ext end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/jekyll-archives/archive.rb', line 5 def name @name end |
#output ⇒ Object
Returns the value of attribute output.
6 7 8 |
# File 'lib/jekyll-archives/archive.rb', line 6 def output @output end |
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'lib/jekyll-archives/archive.rb', line 7 def path @path end |
#posts ⇒ Object
Returns the value of attribute posts.
5 6 7 |
# File 'lib/jekyll-archives/archive.rb', line 5 def posts @posts end |
#site ⇒ Object
Returns the value of attribute site.
8 9 10 |
# File 'lib/jekyll-archives/archive.rb', line 8 def site @site end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/jekyll-archives/archive.rb', line 5 def type @type end |
Instance Method Details
#destination(dest) ⇒ Object
Obtain destination path.
dest - The String path to the destination dir.
Returns the destination file path String.
95 96 97 98 99 |
# File 'lib/jekyll-archives/archive.rb', line 95 def destination(dest) path = Jekyll.sanitized_path(dest, URL.unescape_path(url)) path = File.join(path, "index.html") if url =~ /\/$/ path end |
#html? ⇒ Boolean
Returns the Boolean of whether this Page is HTML or not.
107 108 109 |
# File 'lib/jekyll-archives/archive.rb', line 107 def html? true end |
#inspect ⇒ Object
Returns the object as a debug String.
102 103 104 |
# File 'lib/jekyll-archives/archive.rb', line 102 def inspect "#<Jekyll:Archive @type=#{@type.to_s} @name=#{@name}>" end |
#render(layouts, site_payload) ⇒ Object
Add any necessary layouts to this post
layouts - The Hash of => “layout”. site_payload - The site payload Hash.
Returns nothing.
71 72 73 74 75 76 77 |
# File 'lib/jekyll-archives/archive.rb', line 71 def render(layouts, site_payload) payload = Utils.deep_merge_hashes({ "page" => to_liquid }, site_payload) do_layout(payload, layouts) end |
#template ⇒ Object
The template of the permalink.
Returns the template String.
42 43 44 |
# File 'lib/jekyll-archives/archive.rb', line 42 def template site.config['jekyll-archives']['permalinks'][type] end |
#to_liquid(attrs = nil) ⇒ Object
Convert this Convertible’s data to a Hash suitable for use by Liquid.
Returns the Hash representation of this Convertible.
82 83 84 85 86 87 88 |
# File 'lib/jekyll-archives/archive.rb', line 82 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 |
#url ⇒ Object
The generated relative url of this page. e.g. /about.html.
Returns the String url.
55 56 57 58 59 60 61 62 63 |
# File 'lib/jekyll-archives/archive.rb', line 55 def url @url ||= URL.new({ :template => template, :placeholders => url_placeholders, :permalink => nil }).to_s rescue ArgumentError raise ArgumentError.new "Template \"#{template}\" provided is invalid." end |
#url_placeholders ⇒ Object
Returns a hash of URL placeholder names (as symbols) mapping to the desired placeholder replacements. For details see “url.rb”.
48 49 50 |
# File 'lib/jekyll-archives/archive.rb', line 48 def url_placeholders { :name => @name, :type => @type.to_s } end |