dimples 11.3.0 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/dimples/config.rb +10 -1
- data/lib/dimples/entry.rb +13 -9
- data/lib/dimples/pager.rb +4 -4
- data/lib/dimples/post.rb +1 -1
- data/lib/dimples/site.rb +34 -16
- data/lib/dimples/template.rb +3 -6
- data/lib/dimples/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0fcf6e00b6b3aa4b7096a9d7e52d403b5bc6bdd0f4564139d1d625fc6a95f7f6
|
|
4
|
+
data.tar.gz: 7f794a7c556717f7096e18cc82b5d4c0fb64ae36c426c0720bf10dff7538c6c5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 15291e14e987e06abd9d4ff514eef20129b7f177f7d3b7016238739060b1de8d33f314cbf02a171974cc43fe2fbbbfd85dcdb478b9bdd868d88132dc998a5033
|
|
7
|
+
data.tar.gz: f7e89be6177ecd1464258e7414445caf79e609c55ca74ddc8458165a53d2008b61b1da49a3d6ff25b105229a8685b80d6d9020999df832d4eacb866edea6c457
|
data/lib/dimples/config.rb
CHANGED
|
@@ -47,7 +47,16 @@ module Dimples
|
|
|
47
47
|
def expand_paths(root, paths)
|
|
48
48
|
root = File.expand_path(root)
|
|
49
49
|
|
|
50
|
-
paths.
|
|
50
|
+
paths = paths.to_h do |key, value|
|
|
51
|
+
expanded_path = if value.is_a?(Hash)
|
|
52
|
+
expand_paths(File.join(root, key.to_s), value)
|
|
53
|
+
else
|
|
54
|
+
File.expand_path(File.join(root, value))
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
[key, expanded_path]
|
|
58
|
+
end
|
|
59
|
+
|
|
51
60
|
paths.tap { |expanded_paths| expanded_paths[:root] = root }
|
|
52
61
|
end
|
|
53
62
|
end
|
data/lib/dimples/entry.rb
CHANGED
|
@@ -43,24 +43,28 @@ module Dimples
|
|
|
43
43
|
@site.templates[layout.to_sym]
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
def generate(output_path:,
|
|
47
|
-
|
|
46
|
+
def generate(output_path:, payload: nil)
|
|
47
|
+
payload ||= {}
|
|
48
48
|
|
|
49
|
-
unless
|
|
49
|
+
unless payload[:url]
|
|
50
50
|
url = output_path.gsub(@site.config.build_paths[:root], '')
|
|
51
|
-
url = File.join(url, filename) unless filename
|
|
51
|
+
url = File.join(url, filename) unless filename.start_with?('index.')
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
payload[:url] = url
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
type = self.class.to_s.split('::')[-1].downcase.to_sym
|
|
57
|
+
|
|
58
|
+
payload[:site] ||= site
|
|
59
|
+
payload[type] = @metadata
|
|
60
|
+
|
|
61
|
+
body = render(payload: payload)
|
|
58
62
|
template = self.template
|
|
59
63
|
|
|
60
64
|
loop do
|
|
61
65
|
break if template.nil?
|
|
62
66
|
|
|
63
|
-
body = template.render(
|
|
67
|
+
body = template.render(payload: payload) { body }.strip
|
|
64
68
|
template = template.template
|
|
65
69
|
end
|
|
66
70
|
|
|
@@ -72,7 +76,7 @@ module Dimples
|
|
|
72
76
|
full_path
|
|
73
77
|
end
|
|
74
78
|
|
|
75
|
-
def render(
|
|
79
|
+
def render(payload: nil)
|
|
76
80
|
contents
|
|
77
81
|
end
|
|
78
82
|
|
data/lib/dimples/pager.rb
CHANGED
|
@@ -9,8 +9,8 @@ module Dimples
|
|
|
9
9
|
|
|
10
10
|
attr_reader :current_page, :previous_page, :next_page, :page_count
|
|
11
11
|
|
|
12
|
-
def self.paginate(url:, posts:, options: {},
|
|
13
|
-
new(url: url, posts: posts, options: options).paginate(
|
|
12
|
+
def self.paginate(url:, posts:, options: {}, payload: {}, &block)
|
|
13
|
+
new(url: url, posts: posts, options: options).paginate(payload: payload, &block)
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def initialize(url:, posts:, options: {})
|
|
@@ -24,11 +24,11 @@ module Dimples
|
|
|
24
24
|
step_to(1)
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
def paginate(
|
|
27
|
+
def paginate(payload: {})
|
|
28
28
|
(1..@page_count).each do |index|
|
|
29
29
|
step_to(index)
|
|
30
30
|
|
|
31
|
-
yield(current_page_path,
|
|
31
|
+
yield(current_page_path, payload.merge(metadata)) if block_given?
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
|
data/lib/dimples/post.rb
CHANGED
data/lib/dimples/site.rb
CHANGED
|
@@ -44,7 +44,12 @@ module Dimples
|
|
|
44
44
|
|
|
45
45
|
def templates
|
|
46
46
|
@templates ||= source_files(path: :templates, extension: 'erb').to_h do |path|
|
|
47
|
-
|
|
47
|
+
key = File.basename(
|
|
48
|
+
path.gsub(@config.source_paths[:templates] + File::SEPARATOR, '').tr(File::SEPARATOR, '_'),
|
|
49
|
+
'.erb'
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
[key.to_sym, Dimples::Template.new(site: self, path: path)]
|
|
48
53
|
end
|
|
49
54
|
end
|
|
50
55
|
|
|
@@ -70,14 +75,16 @@ module Dimples
|
|
|
70
75
|
|
|
71
76
|
url = @config.build_paths[:posts].gsub(@config.build_paths[:root], '').concat('/')
|
|
72
77
|
|
|
73
|
-
Pager.paginate(url: url, posts: posts, options: @config.pagination) do |url,
|
|
78
|
+
Pager.paginate(url: url, posts: posts, options: @config.pagination) do |url, payload|
|
|
74
79
|
templates[:posts].generate(
|
|
75
80
|
output_path: File.join(@config.build_paths[:root], url),
|
|
76
|
-
|
|
81
|
+
payload: payload
|
|
77
82
|
)
|
|
78
83
|
end
|
|
79
84
|
|
|
80
|
-
|
|
85
|
+
return unless @config.generation[:main_feed]
|
|
86
|
+
|
|
87
|
+
generate_feed(output_path: @config.build_paths[:root], posts: posts)
|
|
81
88
|
end
|
|
82
89
|
|
|
83
90
|
def generate_post(post)
|
|
@@ -104,23 +111,24 @@ module Dimples
|
|
|
104
111
|
|
|
105
112
|
def generate_categories
|
|
106
113
|
categories.each do |category, posts|
|
|
107
|
-
context = { title: category.capitalize, category: category }
|
|
108
|
-
|
|
109
114
|
Pager.paginate(
|
|
110
115
|
url: "/categories/#{category}/",
|
|
111
116
|
posts: posts,
|
|
112
|
-
|
|
117
|
+
payload: { title: category.capitalize, category: category },
|
|
113
118
|
options: @config.pagination
|
|
114
|
-
) do |url,
|
|
119
|
+
) do |url, payload|
|
|
115
120
|
templates[:posts].generate(
|
|
116
121
|
output_path: File.join(@config.build_paths[:root], url),
|
|
117
|
-
|
|
122
|
+
payload: payload
|
|
118
123
|
)
|
|
119
124
|
end
|
|
120
125
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
126
|
+
return unless @config.generation[:category_feeds]
|
|
127
|
+
|
|
128
|
+
generate_feed(
|
|
129
|
+
output_path: File.join(@config.build_paths[:root], 'categories', category),
|
|
130
|
+
posts: posts
|
|
131
|
+
)
|
|
124
132
|
end
|
|
125
133
|
end
|
|
126
134
|
|
|
@@ -129,7 +137,7 @@ module Dimples
|
|
|
129
137
|
|
|
130
138
|
templates[:feed].generate(
|
|
131
139
|
output_path: output_path,
|
|
132
|
-
|
|
140
|
+
payload: { posts: posts.slice(0, 10) }
|
|
133
141
|
)
|
|
134
142
|
end
|
|
135
143
|
|
|
@@ -139,9 +147,19 @@ module Dimples
|
|
|
139
147
|
raise "The site directory (#{@config.build_paths[:root]}) already exists."
|
|
140
148
|
end
|
|
141
149
|
|
|
142
|
-
FileUtils.rm_rf(
|
|
143
|
-
|
|
144
|
-
|
|
150
|
+
FileUtils.rm_rf(@config.build_paths[:root], secure: true)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
create_build_paths(@config.build_paths)
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def create_build_paths(paths)
|
|
157
|
+
paths.except(:root).each_value do |path|
|
|
158
|
+
if path.is_a?(Hash)
|
|
159
|
+
create_build_paths(path)
|
|
160
|
+
else
|
|
161
|
+
FileUtils.mkdir_p(path) unless Dir.exist?(path)
|
|
162
|
+
end
|
|
145
163
|
end
|
|
146
164
|
end
|
|
147
165
|
|
data/lib/dimples/template.rb
CHANGED
|
@@ -9,13 +9,10 @@ module Dimples
|
|
|
9
9
|
super(site:, source: Pathname.new(path))
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
def render(
|
|
13
|
-
|
|
14
|
-
context.merge(metadata).each do |key, value|
|
|
15
|
-
instance_variable_set("@#{key}", value)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
12
|
+
def render(payload: nil)
|
|
13
|
+
payload ||= {}
|
|
18
14
|
|
|
15
|
+
instance_variable_set("@this", Context.from_hash(payload.merge(metadata)))
|
|
19
16
|
ERB.new(contents).result(binding)
|
|
20
17
|
end
|
|
21
18
|
end
|
data/lib/dimples/version.rb
CHANGED