dimples 3.0.7 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/dimples +16 -12
- data/lib/dimples/category.rb +1 -1
- data/lib/dimples/configuration.rb +31 -44
- data/lib/dimples/page.rb +1 -1
- data/lib/dimples/pagination.rb +2 -2
- data/lib/dimples/post.rb +1 -1
- data/lib/dimples/renderable.rb +2 -2
- data/lib/dimples/site.rb +34 -27
- data/lib/dimples/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e347e41fcd6d975535e6acb93dae09e600b0b8aa
|
4
|
+
data.tar.gz: 4de9555a39ed438e94f76c4caef2ac79b0407914
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c76600d5243dd598286c17d36f177391cd2f7d1bb820f7c4281599f5b98937479462cf5cf1a5e5860a5f6c31910d9dbfd822030f9e18be9fda2c81c31105fa7
|
7
|
+
data.tar.gz: f502ff18da072fe8d6c0844b2691de1a72ecbdbe137c4fb68c37801cfbb437588ba6b837e97d005e989a3ba17d186da7e7f667d21660e2c98cdcdd93e379d64d
|
data/bin/dimples
CHANGED
@@ -5,6 +5,7 @@ $LOAD_PATH.unshift(File.join(__dir__, '..', 'lib'))
|
|
5
5
|
|
6
6
|
require 'dimples'
|
7
7
|
require 'dimples/version'
|
8
|
+
require 'json'
|
8
9
|
require 'trollop'
|
9
10
|
|
10
11
|
trap('SIGINT') do
|
@@ -37,30 +38,33 @@ unless valid_commands.include?(command)
|
|
37
38
|
end
|
38
39
|
|
39
40
|
lib_path = File.join(Dir.pwd, options[:lib])
|
40
|
-
config_path = File.join(Dir.pwd,
|
41
|
-
|
42
|
-
config_hash = {}
|
41
|
+
config_path = options[:config] || File.join(Dir.pwd, 'config.json')
|
43
42
|
|
44
43
|
if File.exist?(config_path)
|
45
44
|
begin
|
46
|
-
|
47
|
-
rescue
|
48
|
-
|
45
|
+
config = JSON.parse(File.read(config_path), symbolize_names: true)
|
46
|
+
rescue => e
|
47
|
+
puts e.inspect
|
48
|
+
Trollop.die "Invalid or malformed config file (#{config_path})"
|
49
49
|
end
|
50
|
-
|
51
|
-
Trollop.die
|
50
|
+
else
|
51
|
+
Trollop.die "Unable to find config file (#{config_path})"
|
52
52
|
end
|
53
53
|
|
54
|
-
|
55
|
-
config = Dimples::Configuration.new(config_hash)
|
54
|
+
config[:verbose_logging] = options[:verbose] || false
|
56
55
|
|
57
56
|
if Dir.exist?(lib_path)
|
58
|
-
Dir.glob(File.join(lib_path, '**', '
|
57
|
+
Dir.glob(File.join(lib_path, '**', '*.rb')) do |path|
|
59
58
|
require path
|
60
59
|
end
|
61
60
|
end
|
62
61
|
|
63
|
-
site_klass = config
|
62
|
+
site_klass = if config[:class_overrides][:site]
|
63
|
+
Object.const_get(config[:class_overrides][:site])
|
64
|
+
else
|
65
|
+
Dimples::Site
|
66
|
+
end
|
67
|
+
|
64
68
|
site = site_klass.new(config)
|
65
69
|
|
66
70
|
case command.to_sym
|
data/lib/dimples/category.rb
CHANGED
@@ -4,83 +4,70 @@ module Dimples
|
|
4
4
|
# A class that models a site's configuration.
|
5
5
|
class Configuration
|
6
6
|
def initialize(config = {})
|
7
|
-
@settings =
|
8
|
-
|
9
|
-
config.each_key do |key|
|
10
|
-
if @settings[key].is_a?(Hash)
|
11
|
-
@settings[key].merge!(config[key])
|
12
|
-
else
|
13
|
-
@settings[key] = config[key]
|
14
|
-
end
|
15
|
-
end
|
7
|
+
@settings = Configuration.default_settings.merge(config)
|
16
8
|
end
|
17
9
|
|
18
10
|
def [](key)
|
19
11
|
@settings[key]
|
20
12
|
end
|
21
13
|
|
22
|
-
def class_override(type)
|
23
|
-
klass = @settings['class_overrides'][type.to_s]
|
24
|
-
Object.const_get(klass) unless klass.nil?
|
25
|
-
end
|
26
|
-
|
27
14
|
def self.default_settings
|
28
15
|
{
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
16
|
+
source_path: Dir.pwd,
|
17
|
+
destination_path: File.join(Dir.pwd, 'site'),
|
18
|
+
verbose_logging: false,
|
19
|
+
class_overrides: { site: nil, post: nil },
|
20
|
+
rendering: {},
|
21
|
+
category_names: {},
|
22
|
+
paths: default_paths,
|
23
|
+
layouts: default_layouts,
|
24
|
+
pagination: default_pagination,
|
25
|
+
generation: default_generation,
|
26
|
+
date_formats: default_date_formats
|
40
27
|
}
|
41
28
|
end
|
42
29
|
|
43
30
|
def self.default_layouts
|
44
31
|
{
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
32
|
+
posts: 'posts',
|
33
|
+
post: 'post',
|
34
|
+
category: 'category',
|
35
|
+
year_archives: 'year_archives',
|
36
|
+
month_archives: 'month_archives',
|
37
|
+
day_archives: 'day_archives'
|
51
38
|
}
|
52
39
|
end
|
53
40
|
|
54
41
|
def self.default_paths
|
55
42
|
{
|
56
|
-
|
57
|
-
|
58
|
-
|
43
|
+
archives: 'archives',
|
44
|
+
posts: 'archives/%Y/%m/%d',
|
45
|
+
categories: 'archives/categories'
|
59
46
|
}
|
60
47
|
end
|
61
48
|
|
62
49
|
def self.default_pagination
|
63
50
|
{
|
64
|
-
|
51
|
+
per_page: 10
|
65
52
|
}
|
66
53
|
end
|
67
54
|
|
68
55
|
def self.default_generation
|
69
56
|
{
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
57
|
+
categories: true,
|
58
|
+
year_archives: true,
|
59
|
+
month_archives: true,
|
60
|
+
day_archives: true,
|
61
|
+
feeds: true,
|
62
|
+
category_feeds: true
|
76
63
|
}
|
77
64
|
end
|
78
65
|
|
79
66
|
def self.default_date_formats
|
80
67
|
{
|
81
|
-
|
82
|
-
|
83
|
-
|
68
|
+
year: '%Y',
|
69
|
+
month: '%Y-%m',
|
70
|
+
day: '%Y-%m-%d'
|
84
71
|
}
|
85
72
|
end
|
86
73
|
end
|
data/lib/dimples/page.rb
CHANGED
data/lib/dimples/pagination.rb
CHANGED
@@ -5,9 +5,9 @@ module Dimples
|
|
5
5
|
module Pagination
|
6
6
|
def paginate(site, items, path, layout, options = {})
|
7
7
|
context = options.delete(:context) || {}
|
8
|
-
url = path.
|
8
|
+
url = path.sub(site.output_paths[:site], '') + '/'
|
9
9
|
per_page = options.delete(:per_page) ||
|
10
|
-
site.config[
|
10
|
+
site.config[:pagination][:per_page]
|
11
11
|
|
12
12
|
pager = Pager.new(url, items, per_page, options)
|
13
13
|
|
data/lib/dimples/post.rb
CHANGED
data/lib/dimples/renderable.rb
CHANGED
@@ -38,8 +38,8 @@ module Dimples
|
|
38
38
|
callback = proc { contents }
|
39
39
|
|
40
40
|
if @path
|
41
|
-
|
42
|
-
options = @site.config[
|
41
|
+
extension = File.extname(@path)[1..-1]
|
42
|
+
options = @site.config[:rendering][extension.to_sym] || {}
|
43
43
|
Tilt.new(@path, options, &callback)
|
44
44
|
else
|
45
45
|
Tilt::StringTemplate.new(&callback)
|
data/lib/dimples/site.rb
CHANGED
@@ -17,8 +17,8 @@ module Dimples
|
|
17
17
|
attr_accessor :post_class
|
18
18
|
attr_accessor :errors
|
19
19
|
|
20
|
-
def initialize(config)
|
21
|
-
@config = config
|
20
|
+
def initialize(config = {})
|
21
|
+
@config = Dimples::Configuration.new(config)
|
22
22
|
|
23
23
|
@templates = {}
|
24
24
|
@categories = {}
|
@@ -29,18 +29,24 @@ module Dimples
|
|
29
29
|
@archives = { year: {}, month: {}, day: {} }
|
30
30
|
@latest_post = false
|
31
31
|
|
32
|
-
@post_class = @config
|
32
|
+
@post_class = if @config[:class_overrides][:post]
|
33
|
+
Object.const_get(config[:class_overrides][:post])
|
34
|
+
else
|
35
|
+
Dimples::Post
|
36
|
+
end
|
33
37
|
|
34
|
-
@source_paths = { root: File.expand_path(@config[
|
35
|
-
@output_paths = { site: File.expand_path(@config[
|
38
|
+
@source_paths = { root: File.expand_path(@config[:source_path]) }
|
39
|
+
@output_paths = { site: File.expand_path(@config[:destination_path]) }
|
36
40
|
|
37
41
|
%w[pages posts public templates].each do |path|
|
38
42
|
@source_paths[path.to_sym] = File.join(@source_paths[:root], path)
|
39
43
|
end
|
40
44
|
|
41
45
|
%w[archives posts categories].each do |path|
|
42
|
-
|
43
|
-
@output_paths[
|
46
|
+
path_sym = path.to_sym
|
47
|
+
@output_paths[path_sym] = File.join(
|
48
|
+
@output_paths[:site], @config[:paths][path_sym]
|
49
|
+
)
|
44
50
|
end
|
45
51
|
end
|
46
52
|
|
@@ -53,7 +59,7 @@ module Dimples
|
|
53
59
|
unless @posts.count.zero?
|
54
60
|
generate_posts
|
55
61
|
generate_archives
|
56
|
-
generate_categories if @config[
|
62
|
+
generate_categories if @config[:generation][:categories]
|
57
63
|
end
|
58
64
|
|
59
65
|
copy_assets
|
@@ -68,7 +74,7 @@ module Dimples
|
|
68
74
|
end
|
69
75
|
|
70
76
|
def scan_files
|
71
|
-
Dimples.logger.debug('Scanning files...') if @config[
|
77
|
+
Dimples.logger.debug('Scanning files...') if @config[:verbose_logging]
|
72
78
|
|
73
79
|
scan_templates
|
74
80
|
scan_pages
|
@@ -83,8 +89,8 @@ module Dimples
|
|
83
89
|
if parent_path == @source_paths[:templates]
|
84
90
|
slug = template.slug
|
85
91
|
else
|
86
|
-
relative_path = parent_path.
|
87
|
-
slug = relative_path.
|
92
|
+
relative_path = parent_path.sub(@source_paths[:templates], '')[1..-1]
|
93
|
+
slug = relative_path.sub(File::SEPARATOR, '.') + ".#{template.slug}"
|
88
94
|
end
|
89
95
|
|
90
96
|
@templates[slug] = template
|
@@ -144,7 +150,7 @@ module Dimples
|
|
144
150
|
end
|
145
151
|
|
146
152
|
def generate_posts
|
147
|
-
if @config[
|
153
|
+
if @config[:verbose_logging]
|
148
154
|
Dimples.logger.debug_generation('posts', @posts.length)
|
149
155
|
end
|
150
156
|
|
@@ -154,14 +160,14 @@ module Dimples
|
|
154
160
|
self,
|
155
161
|
@posts,
|
156
162
|
@output_paths[:archives],
|
157
|
-
@config[
|
163
|
+
@config[:layouts][:posts]
|
158
164
|
)
|
159
165
|
|
160
|
-
generate_posts_feeds if @config[
|
166
|
+
generate_posts_feeds if @config[:generation][:feeds]
|
161
167
|
end
|
162
168
|
|
163
169
|
def generate_pages
|
164
|
-
if @config[
|
170
|
+
if @config[:verbose_logging]
|
165
171
|
Dimples.logger.debug_generation('pages', @pages.length)
|
166
172
|
end
|
167
173
|
|
@@ -169,7 +175,7 @@ module Dimples
|
|
169
175
|
end
|
170
176
|
|
171
177
|
def generate_categories
|
172
|
-
if @config[
|
178
|
+
if @config[:verbose_logging]
|
173
179
|
Dimples.logger.debug_generation('category pages', @categories.length)
|
174
180
|
end
|
175
181
|
|
@@ -185,31 +191,32 @@ module Dimples
|
|
185
191
|
self,
|
186
192
|
category.posts,
|
187
193
|
path,
|
188
|
-
@config[
|
194
|
+
@config[:layouts][:category],
|
189
195
|
options
|
190
196
|
)
|
191
197
|
end
|
192
198
|
|
193
|
-
generate_category_feeds if @config[
|
199
|
+
generate_category_feeds if @config[:generation][:category_feeds]
|
194
200
|
end
|
195
201
|
|
196
202
|
def generate_archives
|
197
203
|
%w[year month day].each do |date_type|
|
198
|
-
|
204
|
+
date_archives_sym = "#{date_type}_archives".to_sym
|
205
|
+
next unless @config[:generation][date_archives_sym]
|
199
206
|
|
200
207
|
@archives[date_type.to_sym].each do |date, posts|
|
201
|
-
year, month, day = date.split('
|
208
|
+
year, month, day = date.split('-')
|
202
209
|
|
203
210
|
dates = { year: year }
|
204
211
|
dates[:month] = month if month
|
205
212
|
dates[:day] = day if day
|
206
213
|
|
207
214
|
path = File.join(@output_paths[:archives], dates.values)
|
208
|
-
layout = @config[
|
215
|
+
layout = @config[:layouts][date_archives_sym]
|
209
216
|
|
210
217
|
options = {
|
211
218
|
context: dates,
|
212
|
-
title: posts[0].date.strftime(@config[
|
219
|
+
title: posts[0].date.strftime(@config[:date_formats][date_type.to_sym])
|
213
220
|
}
|
214
221
|
|
215
222
|
paginate(self, posts, path, layout, options)
|
@@ -233,14 +240,14 @@ module Dimples
|
|
233
240
|
end
|
234
241
|
|
235
242
|
def generate_posts_feeds
|
236
|
-
posts = @posts[0..@config[
|
243
|
+
posts = @posts[0..@config[:pagination][:per_page] - 1]
|
237
244
|
generate_feeds(@output_paths[:site], posts: posts)
|
238
245
|
end
|
239
246
|
|
240
247
|
def generate_category_feeds
|
241
248
|
@categories.each_value do |category|
|
242
249
|
path = File.join(@output_paths[:categories], category.slug)
|
243
|
-
posts = category.posts[0..@config[
|
250
|
+
posts = category.posts[0..@config[:pagination][:per_page] - 1]
|
244
251
|
|
245
252
|
generate_feeds(path, posts: posts, category: category.slug)
|
246
253
|
end
|
@@ -252,7 +259,7 @@ module Dimples
|
|
252
259
|
|
253
260
|
def copy_assets
|
254
261
|
if Dir.exist?(@source_paths[:public])
|
255
|
-
Dimples.logger.debug('Copying assets...') if @config[
|
262
|
+
Dimples.logger.debug('Copying assets...') if @config[:verbose_logging]
|
256
263
|
|
257
264
|
path = File.join(@source_paths[:public], '.')
|
258
265
|
FileUtils.cp_r(path, @output_paths[:site])
|
@@ -274,11 +281,11 @@ module Dimples
|
|
274
281
|
end
|
275
282
|
|
276
283
|
def archive_month(year, month)
|
277
|
-
@archives[:month]["#{year}
|
284
|
+
@archives[:month]["#{year}-#{month}"] ||= []
|
278
285
|
end
|
279
286
|
|
280
287
|
def archive_day(year, month, day)
|
281
|
-
@archives[:day]["#{year}
|
288
|
+
@archives[:day]["#{year}-#{month}-#{day}"] ||= []
|
282
289
|
end
|
283
290
|
end
|
284
291
|
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:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Bogan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tilt
|
@@ -72,6 +72,20 @@ dependencies:
|
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '2.7'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: little-fixtures
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 0.0.1
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 0.0.1
|
75
89
|
- !ruby/object:Gem::Dependency
|
76
90
|
name: minitest
|
77
91
|
requirement: !ruby/object:Gem::Requirement
|