11module Jekyll
22 module Archives
33 class Archive < Jekyll ::Page
4-
54 attr_accessor :posts , :type , :slug
65
76 # Attributes for Liquid templates
@@ -28,12 +27,11 @@ def initialize(site, title, type, posts)
2827 @posts = posts
2928 @type = type
3029 @title = title
31- @config = site . config [ ' jekyll-archives' ]
30+ @config = site . config [ " jekyll-archives" ]
3231
33- # Generate slug if tag or category (taken from jekyll/jekyll/features/support/env.rb)
34- if title . is_a? String
35- @slug = Utils . slugify ( title )
36- end
32+ # Generate slug if tag or category
33+ # (taken from jekyll/jekyll/features/support/env.rb)
34+ @slug = Utils . slugify ( title ) if title . is_a? String
3735
3836 # Use ".html" for file extension and url for path
3937 @ext = File . extname ( relative_path )
@@ -50,25 +48,25 @@ def initialize(site, title, type, posts)
5048 #
5149 # Returns the template String.
5250 def template
53- @config [ ' permalinks' ] [ type ]
51+ @config [ " permalinks" ] [ type ]
5452 end
5553
5654 # The layout to use for rendering
5755 #
5856 # Returns the layout as a String
5957 def layout
60- if @config [ ' layouts' ] && @config [ ' layouts' ] [ type ]
61- @config [ ' layouts' ] [ type ]
58+ if @config [ " layouts" ] && @config [ " layouts" ] [ type ]
59+ @config [ " layouts" ] [ type ]
6260 else
63- @config [ ' layout' ]
61+ @config [ " layout" ]
6462 end
6563 end
6664
6765 # Returns a hash of URL placeholder names (as symbols) mapping to the
6866 # desired placeholder replacements. For details see "url.rb".
6967 def url_placeholders
7068 if @title . is_a? Hash
71- @title . merge ( { :type => @type } )
69+ @title . merge ( :type => @type )
7270 else
7371 { :name => @slug , :type => @type }
7472 end
@@ -79,16 +77,16 @@ def url_placeholders
7977 # Returns the String url.
8078 def url
8179 @url ||= URL . new ( {
82- :template => template ,
80+ :template => template ,
8381 :placeholders => url_placeholders ,
84- :permalink => nil
82+ :permalink => nil
8583 } ) . to_s
8684 rescue ArgumentError
87- raise ArgumentError . new "Template \" #{ template } \" provided is invalid."
85+ raise ArgumentError , "Template \" #{ template } \" provided is invalid."
8886 end
8987
9088 def permalink
91- data && data . is_a? ( Hash ) && data [ ' permalink' ]
89+ data && data . is_a? ( Hash ) && data [ " permalink" ]
9290 end
9391
9492 # Add any necessary layouts to this post
@@ -115,14 +113,14 @@ def add_dependencies
115113 end
116114 end
117115 end
118-
116+
119117 # Convert this Convertible's data to a Hash suitable for use by Liquid.
120118 #
121119 # Returns the Hash representation of this Convertible.
122120 def to_liquid ( attrs = nil )
123- further_data = Hash [ ( attrs || self . class ::ATTRIBUTES_FOR_LIQUID ) . map { |attribute |
121+ further_data = Hash [ ( attrs || self . class ::ATTRIBUTES_FOR_LIQUID ) . map do |attribute |
124122 [ attribute , send ( attribute ) ]
125- } ]
123+ end ]
126124
127125 Utils . deep_merge_hashes ( data , further_data )
128126 end
@@ -132,17 +130,15 @@ def to_liquid(attrs = nil)
132130 # Returns a String (for tag and category archives) and nil for
133131 # date-based archives.
134132 def title
135- if @title . is_a? String
136- @title
137- end
133+ @title if @title . is_a? String
138134 end
139135
140136 # Produce a date object if a date-based archive
141137 #
142138 # Returns a Date.
143139 def date
144140 if @title . is_a? Hash
145- args = @title . values . map { | s | s . to_i }
141+ args = @title . values . map ( & : to_i)
146142 Date . new ( *args )
147143 end
148144 end
@@ -151,8 +147,8 @@ def date
151147 #
152148 # Returns the destination relative path String.
153149 def relative_path
154- path = URL . unescape_path ( url ) . gsub ( / ^\/ / , '' )
155- path = File . join ( path , "index.html" ) if url =~ / \/ $/
150+ path = URL . unescape_path ( url ) . gsub ( %r! ^\/ ! , "" )
151+ path = File . join ( path , "index.html" ) if url =~ %r! \/ $!
156152 path
157153 end
158154
@@ -166,7 +162,7 @@ def regenerate?
166162
167163 # Returns the object as a debug String.
168164 def inspect
169- "#<Jekyll:Archive @type=#{ @type . to_s } @title=#{ @title } @data=#{ @data . inspect } >"
165+ "#<Jekyll:Archive @type=#{ @type } @title=#{ @title } @data=#{ @data . inspect } >"
170166 end
171167 end
172168 end
0 commit comments