dimples 10.6.0 → 10.7.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 +0 -1
- data/lib/dimples/entry.rb +19 -15
- data/lib/dimples/metadata.rb +7 -39
- data/lib/dimples/pager.rb +8 -6
- data/lib/dimples/post.rb +0 -7
- data/lib/dimples/site.rb +2 -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: 4b5c714d45ca9e2ea1acc71d9cd7f4ce61baf15da289780e3bcca06195f7688d
|
|
4
|
+
data.tar.gz: 347fce125c6cae601b18d6becd20715203f1ebe98ffb265300eb1a5bfc0fc371
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f9086e486dc0a12e6ec28a526382f806dc338c45852ffb3226e571d135c2d1520662c8d49127076646edc416fef4a0cd68009410a8709631436fe53e5d31f654
|
|
7
|
+
data.tar.gz: 7481579f5ad52500f7085e1ce28a8f158066baf38fbe292c0cf903cbf2ca2f94dae23fb5e9336cdfc643e931c98a7bc554d4d2c598a62d6444dfd95c141e4ec3
|
data/lib/dimples/config.rb
CHANGED
|
@@ -17,7 +17,6 @@ module Dimples
|
|
|
17
17
|
source: Dir.pwd,
|
|
18
18
|
build: './site',
|
|
19
19
|
pathnames: { posts: 'posts', categories: 'categories' },
|
|
20
|
-
site: { name: nil, domain: nil },
|
|
21
20
|
pagination: { page_prefix: 'page_', per_page: 5 },
|
|
22
21
|
generation: { main_feed: true, category_feeds: false }
|
|
23
22
|
}
|
data/lib/dimples/entry.rb
CHANGED
|
@@ -42,7 +42,7 @@ module Dimples
|
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
def generate(output_path: nil, context: {})
|
|
45
|
-
output_path = File.join(output_directory,
|
|
45
|
+
output_path = File.join(output_directory, filename) if output_path.nil?
|
|
46
46
|
write(output_path: output_path, body: render(context: context))
|
|
47
47
|
end
|
|
48
48
|
|
|
@@ -55,20 +55,26 @@ module Dimples
|
|
|
55
55
|
|
|
56
56
|
def url
|
|
57
57
|
@url ||= output_directory.gsub(@site.config.build_paths[:root], '').tap do |url|
|
|
58
|
-
url.concat(
|
|
58
|
+
url.concat(filename) unless filename == 'index.html'
|
|
59
59
|
end
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
def render(context: {}, body: nil)
|
|
63
|
-
context[:site] ||= @site
|
|
64
|
-
context[:page] ||=
|
|
63
|
+
context[:site] ||= @site
|
|
64
|
+
context[:page] ||= self
|
|
65
65
|
|
|
66
|
-
@rendered_contents = template.render(
|
|
66
|
+
@rendered_contents = template.render(
|
|
67
|
+
Object.new.tap do |render_context|
|
|
68
|
+
context.each do |key, value|
|
|
69
|
+
render_context.instance_variable_set("@#{key}", value)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
) { body }
|
|
67
73
|
|
|
68
|
-
|
|
69
|
-
return @rendered_contents if
|
|
74
|
+
template = @site.layouts[layout.to_sym] unless layout.nil?
|
|
75
|
+
return @rendered_contents if template.nil?
|
|
70
76
|
|
|
71
|
-
|
|
77
|
+
template.render(context: context, body: @rendered_contents)
|
|
72
78
|
end
|
|
73
79
|
|
|
74
80
|
def output_directory
|
|
@@ -79,16 +85,14 @@ module Dimples
|
|
|
79
85
|
@template ||= Tilt::ERBTemplate.new { @contents }
|
|
80
86
|
end
|
|
81
87
|
|
|
82
|
-
def to_h
|
|
83
|
-
@metadata.to_h.merge({ contents: contents })
|
|
84
|
-
end
|
|
85
|
-
|
|
86
88
|
def method_missing(method_name, *_args)
|
|
87
|
-
|
|
89
|
+
method_sym = method_name.to_sym
|
|
90
|
+
|
|
91
|
+
@metadata.send(method_sym)
|
|
88
92
|
end
|
|
89
93
|
|
|
90
|
-
def respond_to_missing?(
|
|
91
|
-
|
|
94
|
+
def respond_to_missing?(method_name, _include_private = false)
|
|
95
|
+
@metadata.respond_to?(method_name.to_sym) || super
|
|
92
96
|
end
|
|
93
97
|
|
|
94
98
|
private
|
data/lib/dimples/metadata.rb
CHANGED
|
@@ -1,53 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Dimples
|
|
4
|
+
# A tiny wrapper around metadata for rendering
|
|
2
5
|
class Metadata
|
|
3
|
-
include Enumerable
|
|
4
|
-
|
|
5
6
|
def initialize(source)
|
|
6
7
|
source.each do |key, value|
|
|
7
8
|
self.class.send(:attr_reader, key)
|
|
8
|
-
instance_variable_set("@#{key}",
|
|
9
|
+
instance_variable_set("@#{key}", value.is_a?(Hash) ? Metadata.new(value) : value)
|
|
9
10
|
end
|
|
10
|
-
|
|
11
|
-
@data = source
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def keys
|
|
15
|
-
@data.keys
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def [](key)
|
|
19
|
-
@data[key]
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def each(&block)
|
|
23
|
-
@data.each(&block)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def each_key(&block)
|
|
27
|
-
@data.keys.each(&block)
|
|
28
11
|
end
|
|
29
12
|
|
|
30
|
-
def method_missing(
|
|
31
|
-
return @data[method_name] if @data.key?(method_name)
|
|
32
|
-
|
|
13
|
+
def method_missing(_method_name, *_args)
|
|
33
14
|
nil
|
|
34
15
|
end
|
|
35
16
|
|
|
36
|
-
def respond_to_missing?(
|
|
37
|
-
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
private
|
|
41
|
-
|
|
42
|
-
def build(item)
|
|
43
|
-
case item
|
|
44
|
-
when Array
|
|
45
|
-
item.map { |i| build(i) }
|
|
46
|
-
when Hash
|
|
47
|
-
item.empty? ? item : Metadata.new(item)
|
|
48
|
-
else
|
|
49
|
-
item
|
|
50
|
-
end
|
|
17
|
+
def respond_to_missing?(_method_name, _include_private = false)
|
|
18
|
+
true
|
|
51
19
|
end
|
|
52
20
|
end
|
|
53
21
|
end
|
data/lib/dimples/pager.rb
CHANGED
|
@@ -27,13 +27,11 @@ module Dimples
|
|
|
27
27
|
(1..@page_count).each do |index|
|
|
28
28
|
step_to(index)
|
|
29
29
|
|
|
30
|
-
output_directory = File.join(@site.config.build_paths[:root],
|
|
31
|
-
|
|
32
|
-
context.merge!(metadata, url: current_page_url)
|
|
30
|
+
output_directory = File.join(@site.config.build_paths[:root], current_page_path)
|
|
33
31
|
|
|
34
32
|
@site.layouts[:posts]&.generate(
|
|
35
33
|
output_path: File.join(output_directory, 'index.html'),
|
|
36
|
-
context: context
|
|
34
|
+
context: metadata.merge(context, url: current_page_url)
|
|
37
35
|
)
|
|
38
36
|
|
|
39
37
|
yield(output_directory, context) if block_given?
|
|
@@ -60,6 +58,10 @@ module Dimples
|
|
|
60
58
|
@current_page + 1 <= @page_count
|
|
61
59
|
end
|
|
62
60
|
|
|
61
|
+
def current_page_path
|
|
62
|
+
@current_page == 1 ? @url : File.join(@url, "page_#{@current_page}")
|
|
63
|
+
end
|
|
64
|
+
|
|
63
65
|
def current_page_url
|
|
64
66
|
@current_page == 1 ? @url : "#{@url}#{@page_prefix}#{@current_page}"
|
|
65
67
|
end
|
|
@@ -95,14 +97,14 @@ module Dimples
|
|
|
95
97
|
def metadata
|
|
96
98
|
{
|
|
97
99
|
posts: posts_at(current_page),
|
|
98
|
-
pagination:
|
|
100
|
+
pagination: Metadata.new(
|
|
99
101
|
current_page: @current_page,
|
|
100
102
|
page_count: @page_count,
|
|
101
103
|
post_count: @posts.count,
|
|
102
104
|
previous_page: @previous_page,
|
|
103
105
|
next_page: @next_page,
|
|
104
106
|
urls: urls
|
|
105
|
-
|
|
107
|
+
)
|
|
106
108
|
}
|
|
107
109
|
end
|
|
108
110
|
end
|
data/lib/dimples/post.rb
CHANGED
|
@@ -22,13 +22,6 @@ module Dimples
|
|
|
22
22
|
@template ||= Tilt::RedcarpetTemplate.new { @contents }
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
def to_h
|
|
26
|
-
super.reject { |k, _| %i[filename layout].include?(k) }.tap do |output|
|
|
27
|
-
output[:date] = output[:date].iso8601 unless output[:date].nil?
|
|
28
|
-
output[:url] ||= url
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
25
|
private
|
|
33
26
|
|
|
34
27
|
def default_metadata
|
data/lib/dimples/site.rb
CHANGED
|
@@ -31,7 +31,7 @@ module Dimples
|
|
|
31
31
|
def posts
|
|
32
32
|
@posts ||= Dir.glob(File.join(@config.source_paths[:posts], '**', '*.markdown')).map do |path|
|
|
33
33
|
Dimples::Post.new(site: self, path: path)
|
|
34
|
-
end.sort_by! { |post| post.
|
|
34
|
+
end.sort_by! { |post| post.date }.reverse!
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def pages
|
|
@@ -49,7 +49,7 @@ module Dimples
|
|
|
49
49
|
def categories
|
|
50
50
|
@categories ||= {}.tap do |categories|
|
|
51
51
|
posts.each do |post|
|
|
52
|
-
post.
|
|
52
|
+
post.categories.each do |category|
|
|
53
53
|
categories[category] ||= []
|
|
54
54
|
categories[category].append(post)
|
|
55
55
|
end
|
|
@@ -57,10 +57,6 @@ module Dimples
|
|
|
57
57
|
end
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
-
def metadata
|
|
61
|
-
@metadata ||= Metadata.new(posts: posts, categories: categories)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
60
|
private
|
|
65
61
|
|
|
66
62
|
def generate_posts
|
data/lib/dimples/version.rb
CHANGED