dimples 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dimples/site.rb +121 -145
- data/lib/dimples/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c480fd2f7363a7a6072668b2380b2e6962456bf3
|
4
|
+
data.tar.gz: ab0db580748680bd12d31dc34b947ee7d2161c60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d56249e0b2cfaa9d0e4cfe6472503cfaa30d6e17e83da57cdeee62568c643c126492e03a714118d6f6e5023dd3c51b9d870d33bb075336f4494073ed01ab34c4
|
7
|
+
data.tar.gz: 84b2d79bc6f0108196098b91fbb62ba8d533114ef4902164ebf525ae1ad6cd8fc50a5b260a00ccdc0e1327cb7a457a21ccf255b6b110cb8ddf95e64ffda87fbb
|
data/lib/dimples/site.rb
CHANGED
@@ -17,7 +17,7 @@ module Dimples
|
|
17
17
|
@output_paths = {}
|
18
18
|
@templates = {}
|
19
19
|
@categories = {}
|
20
|
-
@archives = {}
|
20
|
+
@archives = {year: {}, month: {}, day: {}}
|
21
21
|
|
22
22
|
@pages = []
|
23
23
|
@posts = []
|
@@ -39,163 +39,117 @@ module Dimples
|
|
39
39
|
@output_paths[:posts] = File.join(@output_paths[:site], @config['paths']['posts'])
|
40
40
|
end
|
41
41
|
|
42
|
+
def generate
|
43
|
+
prepare_site
|
44
|
+
scan_files
|
45
|
+
|
46
|
+
generate_posts
|
47
|
+
generate_pages
|
48
|
+
generate_archives
|
49
|
+
|
50
|
+
generate_categories if @config['generation']['categories']
|
51
|
+
generate_posts_feed if @config['generation']['feed']
|
52
|
+
generate_category_feeds if @config['generation']['category_feeds']
|
53
|
+
|
54
|
+
copy_assets
|
55
|
+
end
|
56
|
+
|
57
|
+
def prepare_site
|
58
|
+
begin
|
59
|
+
FileUtils.remove_dir(@output_paths[:site]) if Dir.exist?(@output_paths[:site])
|
60
|
+
Dir.mkdir(@output_paths[:site])
|
61
|
+
rescue => e
|
62
|
+
raise "Failed to prepare the site directory (#{e})"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
42
66
|
def scan_files
|
67
|
+
scan_templates
|
68
|
+
scan_pages
|
69
|
+
scan_posts
|
70
|
+
end
|
71
|
+
|
72
|
+
def scan_templates
|
43
73
|
Dir.glob(File.join(@source_paths[:templates], '**', '*.*')).each do |path|
|
44
74
|
template = Dimples::Template.new(self, path)
|
45
75
|
@templates[template.slug] = template
|
46
76
|
end
|
77
|
+
end
|
47
78
|
|
79
|
+
def scan_pages
|
48
80
|
Dir.glob(File.join(@source_paths[:pages], '**', '*.*')).each do |path|
|
49
81
|
@pages << @page_class.new(self, path)
|
50
82
|
end
|
83
|
+
end
|
51
84
|
|
52
|
-
|
53
|
-
@posts << @post_class.new(self, path)
|
54
|
-
end
|
55
|
-
|
56
|
-
@posts.reverse!
|
57
|
-
@latest_post = @posts.first
|
58
|
-
|
59
|
-
@posts.each do |post|
|
60
|
-
|
61
|
-
year = post.year.to_s
|
62
|
-
month = post.month.to_s
|
63
|
-
day = post.day.to_s
|
64
|
-
|
65
|
-
@archives[year] ||= {posts: [], months: {}}
|
85
|
+
def scan_posts
|
66
86
|
|
67
|
-
|
68
|
-
|
69
|
-
@archives[year][:months][month][:posts] << post
|
70
|
-
@archives[year][:months][month][:days][day] ||= []
|
71
|
-
@archives[year][:months][month][:days][day] << post
|
87
|
+
Dir.glob(File.join(@source_paths[:posts], '*.*')).reverse.each do |path|
|
88
|
+
post = @post_class.new(self, path)
|
72
89
|
|
73
90
|
post.categories.each do |category|
|
74
91
|
(@categories[category] ||= []) << post
|
75
92
|
end
|
76
|
-
end
|
77
|
-
end
|
78
93
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
begin
|
83
|
-
FileUtils.remove_dir(@output_paths[:site]) if Dir.exist?(@output_paths[:site])
|
84
|
-
Dir.mkdir(@output_paths[:site])
|
85
|
-
rescue => e
|
86
|
-
raise "Failed to prepare the site directory (#{e})"
|
87
|
-
end
|
94
|
+
%w[year month day].each do |date_type|
|
95
|
+
if @config['generation']["#{date_type}_archives"]
|
88
96
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
rescue => e
|
93
|
-
raise "Failed to render post #{File.basename(post.path)} (#{e})"
|
97
|
+
date_key = post.date.strftime(@config['date_formats'][date_type])
|
98
|
+
(@archives[date_type.to_sym][date_key] ||= []) << post
|
99
|
+
end
|
94
100
|
end
|
95
|
-
end
|
96
101
|
|
97
|
-
|
98
|
-
begin
|
99
|
-
page.write(@output_paths[:site])
|
100
|
-
rescue => e
|
101
|
-
raise "Failed to render page from #{page.path.gsub(@source_paths[:root], '')} (#{e})"
|
102
|
-
end
|
102
|
+
@posts << post
|
103
103
|
end
|
104
104
|
|
105
|
-
|
106
|
-
|
107
|
-
paginate(@posts, false, @config['pagination']['per_page'], [@output_paths[:posts]], @config['layouts']['posts'])
|
108
|
-
rescue => e
|
109
|
-
raise "Failed to paginate main posts (#{e})"
|
110
|
-
end
|
111
|
-
end
|
105
|
+
@latest_post = @posts.first
|
106
|
+
end
|
112
107
|
|
113
|
-
|
108
|
+
def generate_posts
|
109
|
+
@posts.each do |post|
|
114
110
|
begin
|
115
|
-
|
111
|
+
post.write(@output_paths[:posts])
|
116
112
|
rescue => e
|
117
|
-
raise "Failed to
|
113
|
+
raise "Failed to render post #{post.path} (#{e})"
|
118
114
|
end
|
119
115
|
end
|
120
116
|
|
121
|
-
if @config['generation']['
|
122
|
-
@
|
123
|
-
if @config['generation']['category_feeds']
|
124
|
-
begin
|
125
|
-
generate_feed(File.join(@output_paths[:posts], slug), {posts: posts[0..@config['pagination']['per_page'] - 1], category: slug})
|
126
|
-
rescue => e
|
127
|
-
raise "Failed to generate category feed for '#{slug}' (#{e})"
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
begin
|
132
|
-
paginate(posts, slug.capitalize, @config['pagination']['per_page'], [@output_paths[:posts], slug], @config['layouts']['category'])
|
133
|
-
rescue => e
|
134
|
-
raise "Failed to generate category pages for '#{slug}' (#{e})"
|
135
|
-
end
|
136
|
-
end
|
117
|
+
if @config['generation']['paginated_posts']
|
118
|
+
paginate(posts: @posts, paths: [@output_paths[:posts]], layout: @config['layouts']['posts'])
|
137
119
|
end
|
120
|
+
end
|
138
121
|
|
139
|
-
|
122
|
+
def generate_pages
|
123
|
+
@pages.each do |page|
|
140
124
|
begin
|
141
|
-
|
125
|
+
page.write(@output_paths[:site])
|
142
126
|
rescue => e
|
143
|
-
raise "Failed to
|
127
|
+
raise "Failed to render page #{page.path.gsub(@source_paths[:root], '')} (#{e})"
|
144
128
|
end
|
145
129
|
end
|
130
|
+
end
|
146
131
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
raise "Failed to copy site assets (#{e})"
|
132
|
+
def generate_categories
|
133
|
+
@categories.each_pair do |slug, posts|
|
134
|
+
paginate(posts: posts, title: slug.capitalize, paths: [@output_paths[:posts], slug], layout: @config['layouts']['category'])
|
151
135
|
end
|
152
136
|
end
|
153
137
|
|
154
138
|
def generate_archives
|
155
|
-
|
156
|
-
year_template = @config['layouts']['year']
|
157
|
-
elsif @config['layouts'].has_key?('archives')
|
158
|
-
year_template = @config['layouts']['archives']
|
159
|
-
else
|
160
|
-
year_template = @config['layouts']['posts']
|
161
|
-
end
|
139
|
+
%w[year month day].each do |date_type|
|
162
140
|
|
163
|
-
|
164
|
-
|
165
|
-
if @config['generation']['month_archives']
|
166
|
-
if @config['layouts'].has_key?('month')
|
167
|
-
month_template = @config['layouts']['month']
|
168
|
-
elsif @config['layouts'].has_key?('archives')
|
169
|
-
month_template = @config['layouts']['archives']
|
170
|
-
else
|
171
|
-
month_template = @config['layouts']['posts']
|
172
|
-
end
|
141
|
+
if @config['generation']["#{date_type}_archives"]
|
173
142
|
|
174
|
-
|
143
|
+
template = @config['layouts'][date_type] || @config['layouts']['archives'] || @config['layouts']['posts']
|
144
|
+
archives[date_type.to_sym].each_pair do |date_title, posts|
|
175
145
|
|
176
|
-
|
146
|
+
paths = [@output_paths[:posts], posts[0].year]
|
147
|
+
paths << posts[0].month if date_type =~ /month|day/
|
148
|
+
paths << posts[0].day if date_type == 'day'
|
177
149
|
|
178
|
-
|
179
|
-
day_template = @config['layouts']['day']
|
180
|
-
elsif @config['layouts'].has_key?('archives')
|
181
|
-
day_template = @config['layouts']['archives']
|
182
|
-
else
|
183
|
-
day_template = @config['layouts']['posts']
|
184
|
-
end
|
185
|
-
|
186
|
-
month_archive[:days].each do |day, posts|
|
187
|
-
day_title = posts[0].date.strftime(@config['date_formats']['day'])
|
188
|
-
paginate(posts, day_title, @config['pagination']['per_page'], [@output_paths[:posts], year.to_s, month.to_s, day.to_s], day_template)
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
month_title = month_archive[:posts][0].date.strftime(@config['date_formats']['month'])
|
193
|
-
paginate(month_archive[:posts], month_title, @config['pagination']['per_page'], [@output_paths[:posts], year.to_s, month.to_s], month_template)
|
150
|
+
paginate(posts: posts, title: date_title, paths: paths, layout: template)
|
194
151
|
end
|
195
152
|
end
|
196
|
-
|
197
|
-
year_title = year_archive[:posts][0].date.strftime(@config['date_formats']['year'])
|
198
|
-
paginate(year_archive[:posts], year_title, @config['pagination']['per_page'], [@output_paths[:posts], year.to_s], year_template)
|
199
153
|
end
|
200
154
|
end
|
201
155
|
|
@@ -206,53 +160,75 @@ module Dimples
|
|
206
160
|
feed.extension = 'atom'
|
207
161
|
feed.layout = 'feed'
|
208
162
|
|
209
|
-
|
163
|
+
begin
|
164
|
+
feed.write(path, options)
|
165
|
+
rescue => e
|
166
|
+
raise "Failed to generate feed #{path} (#{e})"
|
167
|
+
end
|
210
168
|
end
|
211
169
|
|
212
|
-
def
|
213
|
-
|
170
|
+
def generate_posts_feed
|
171
|
+
generate_feed(@output_paths[:site], {posts: @posts[0..@config['pagination']['per_page'] - 1]})
|
172
|
+
end
|
214
173
|
|
215
|
-
|
174
|
+
def generate_category_feeds
|
175
|
+
@categories.each_pair do |slug, posts|
|
176
|
+
generate_feed(File.join(@output_paths[:posts], slug), {posts: posts[0..@config['pagination']['per_page'] - 1], category: slug})
|
177
|
+
end
|
178
|
+
end
|
216
179
|
|
217
|
-
|
218
|
-
|
180
|
+
def copy_assets
|
181
|
+
begin
|
182
|
+
FileUtils.cp_r(File.join(@source_paths[:public], '.'), @output_paths[:site]) if Dir.exists?(@source_paths[:public])
|
183
|
+
rescue => e
|
184
|
+
raise "Failed to copy site assets (#{e})"
|
185
|
+
end
|
186
|
+
end
|
219
187
|
|
220
|
-
|
188
|
+
def pagination_url(page, paths)
|
189
|
+
path = '/'
|
221
190
|
|
222
|
-
|
223
|
-
|
191
|
+
path += File.split(paths[0])[-1] + "/" if paths[0] != @output_paths[:site]
|
192
|
+
path += paths[1..-1].join('/') + "/" if paths.length > 1
|
193
|
+
|
194
|
+
path
|
195
|
+
end
|
224
196
|
|
225
|
-
|
226
|
-
|
227
|
-
else
|
228
|
-
url_path = "/#{File.split(page_paths[0])[-1]}/"
|
229
|
-
end
|
197
|
+
def paginate(posts:, title: nil, paths:, layout: false)
|
198
|
+
fail "'#{layout}' template not found" unless @templates.has_key?(layout)
|
230
199
|
|
231
|
-
|
200
|
+
per_page = @config['pagination']['per_page']
|
201
|
+
page_count = (posts.length.to_f / per_page.to_i).ceil
|
232
202
|
|
233
|
-
|
234
|
-
|
235
|
-
|
203
|
+
for index in 1..page_count
|
204
|
+
range = posts.slice((index - 1) * per_page, per_page)
|
205
|
+
|
206
|
+
page = @page_class.new(self)
|
207
|
+
|
208
|
+
page.layout = layout
|
209
|
+
page.title = title || @templates[layout].title
|
210
|
+
|
211
|
+
page_paths = paths.clone
|
236
212
|
|
237
213
|
pagination = {
|
238
|
-
page: index
|
239
|
-
pages:
|
240
|
-
|
241
|
-
path:
|
214
|
+
page: index,
|
215
|
+
pages: page_count,
|
216
|
+
post_count: posts.length,
|
217
|
+
path: pagination_url(index, page_paths)
|
242
218
|
}
|
243
219
|
|
244
|
-
|
245
|
-
pagination[:previous_page] = pagination[:page] - 1
|
246
|
-
end
|
220
|
+
page_paths << "page#{index}" if index != 1
|
247
221
|
|
248
|
-
|
249
|
-
|
250
|
-
end
|
222
|
+
pagination[:previous_page] = pagination[:page] - 1 if (pagination[:page] - 1) > 0
|
223
|
+
pagination[:next_page] = pagination[:page] + 1 if (pagination[:page] + 1) <= pagination[:pages]
|
251
224
|
|
252
|
-
|
253
|
-
page.title = page_title
|
225
|
+
path = File.join(page_paths)
|
254
226
|
|
255
|
-
|
227
|
+
begin
|
228
|
+
page.write(path, {posts: range, pagination: pagination})
|
229
|
+
rescue => e
|
230
|
+
raise "Failed to generate paginated page #{path} (#{e})"
|
231
|
+
end
|
256
232
|
end
|
257
233
|
end
|
258
234
|
end
|
data/lib/dimples/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dimples
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Bogan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tilt
|