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 dependencies for incremental mode
@@ -107,17 +105,15 @@ def add_dependencies
107105 # Returns a String (for tag and category archives) and nil for
108106 # date-based archives.
109107 def title
110- if @title . is_a? String
111- @title
112- end
108+ @title if @title . is_a? String
113109 end
114110
115111 # Produce a date object if a date-based archive
116112 #
117113 # Returns a Date.
118114 def date
119115 if @title . is_a? Hash
120- args = @title . values . map { | s | s . to_i }
116+ args = @title . values . map ( & : to_i)
121117 Date . new ( *args )
122118 end
123119 end
@@ -126,8 +122,8 @@ def date
126122 #
127123 # Returns the destination relative path String.
128124 def relative_path
129- path = URL . unescape_path ( url ) . gsub ( / ^\/ / , '' )
130- path = File . join ( path , "index.html" ) if url =~ / \/ $/
125+ path = URL . unescape_path ( url ) . gsub ( %r! ^\/ ! , "" )
126+ path = File . join ( path , "index.html" ) if url =~ %r! \/ $!
131127 path
132128 end
133129
@@ -141,7 +137,7 @@ def regenerate?
141137
142138 # Returns the object as a debug String.
143139 def inspect
144- "#<Jekyll:Archive @type=#{ @type . to_s } @title=#{ @title } @data=#{ @data . inspect } >"
140+ "#<Jekyll:Archive @type=#{ @type } @title=#{ @title } @data=#{ @data . inspect } >"
145141 end
146142 end
147143 end
0 commit comments