dimples 12.0.0 → 13.0.1
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 +3 -2
- data/lib/dimples/context.rb +11 -2
- data/lib/dimples/entry.rb +5 -1
- data/lib/dimples/pager.rb +3 -3
- data/lib/dimples/site.rb +23 -10
- data/lib/dimples/template.rb +10 -1
- 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: 820b81c83ff8701c08520801dd39dc165578fbaa4e994699c2a3c3c5f8fe6a73
|
|
4
|
+
data.tar.gz: 3de38112fe45ea95eed771573c06401dbe6899dfd1883443fd20debfe64a6f5e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7676867a9acd8b29cc96e67c9396597e49ee8ae9e038e18087bfced6deca8a914a588c4fccf4e7c10e1fd11177af5a89b4c800d2a9ade78bc8860ded74a098bf
|
|
7
|
+
data.tar.gz: c86035f512c293e338468d4fd944eb046a1e4023fd9294758f30985f4ea380c49cf3279fbf37b24a03c2d5e935845768c9b36274c8738980edcbc17602057ef8
|
data/lib/dimples/config.rb
CHANGED
|
@@ -4,10 +4,11 @@ module Dimples
|
|
|
4
4
|
# Configuration settings for a site.
|
|
5
5
|
class Config
|
|
6
6
|
SOURCE_PATHS = {
|
|
7
|
+
data: 'data',
|
|
7
8
|
pages: 'pages',
|
|
8
9
|
posts: 'posts',
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
static: 'static',
|
|
11
|
+
templates: 'templates'
|
|
11
12
|
}.freeze
|
|
12
13
|
|
|
13
14
|
attr_accessor :source_paths, :build_paths, :site, :pagination, :generation
|
data/lib/dimples/context.rb
CHANGED
|
@@ -4,9 +4,18 @@ module Dimples
|
|
|
4
4
|
# Context used when rendering an item in a template
|
|
5
5
|
class Context
|
|
6
6
|
def self.from_hash(hash)
|
|
7
|
-
hash.transform_values!
|
|
7
|
+
hash.transform_values! do |value|
|
|
8
|
+
case value
|
|
9
|
+
when Hash
|
|
10
|
+
Context.from_hash(value)
|
|
11
|
+
when Array
|
|
12
|
+
value.map { |item| item.is_a?(Hash) ? Context.from_hash(item) : item }
|
|
13
|
+
else
|
|
14
|
+
value
|
|
15
|
+
end
|
|
16
|
+
end
|
|
8
17
|
|
|
9
|
-
Struct.new(*hash.keys) do |_klass|
|
|
18
|
+
Struct.new(*hash.keys.map(&:to_sym)) do |_klass|
|
|
10
19
|
def method_missing(_method_name, *_args)
|
|
11
20
|
nil
|
|
12
21
|
end
|
data/lib/dimples/entry.rb
CHANGED
|
@@ -31,6 +31,10 @@ module Dimples
|
|
|
31
31
|
matches = contents.match(FRONT_MATTER_PATTERN)
|
|
32
32
|
if matches
|
|
33
33
|
@metadata.merge!(YAML.safe_load(matches[1], symbolize_names: true, permitted_classes: [Date]))
|
|
34
|
+
@metadata.transform_values! do |value|
|
|
35
|
+
value.is_a?(Hash) ? Context.from_hash(value) : value
|
|
36
|
+
end
|
|
37
|
+
|
|
34
38
|
@contents = matches.post_match.strip
|
|
35
39
|
else
|
|
36
40
|
@contents = contents
|
|
@@ -56,7 +60,7 @@ module Dimples
|
|
|
56
60
|
type = self.class.to_s.split('::')[-1].downcase.to_sym
|
|
57
61
|
|
|
58
62
|
payload[:site] ||= site
|
|
59
|
-
payload[type] =
|
|
63
|
+
payload[type] = self
|
|
60
64
|
|
|
61
65
|
body = render(payload: payload)
|
|
62
66
|
template = self.template
|
data/lib/dimples/pager.rb
CHANGED
|
@@ -53,7 +53,7 @@ module Dimples
|
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
def current_page_path
|
|
56
|
-
@current_page == 1 ? @url : File.join(@url, "
|
|
56
|
+
@current_page == 1 ? @url : File.join(@url, "pages", current_page.to_s)
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
def current_page_url
|
|
@@ -91,14 +91,14 @@ module Dimples
|
|
|
91
91
|
def metadata
|
|
92
92
|
{
|
|
93
93
|
posts: posts_at(current_page),
|
|
94
|
-
pagination:
|
|
94
|
+
pagination: Context.from_hash(
|
|
95
95
|
current_page: @current_page,
|
|
96
96
|
page_count: @page_count,
|
|
97
97
|
post_count: @posts.count,
|
|
98
98
|
previous_page: @previous_page,
|
|
99
99
|
next_page: @next_page,
|
|
100
100
|
urls: urls
|
|
101
|
-
|
|
101
|
+
)
|
|
102
102
|
}
|
|
103
103
|
end
|
|
104
104
|
end
|
data/lib/dimples/site.rb
CHANGED
|
@@ -29,7 +29,7 @@ module Dimples
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def posts
|
|
32
|
-
@posts ||= source_files(
|
|
32
|
+
@posts ||= source_files(key: :posts, extension: 'markdown').map do |path|
|
|
33
33
|
Dimples::Post.new(site: self, path: path)
|
|
34
34
|
end
|
|
35
35
|
.sort_by!(&:date)
|
|
@@ -37,19 +37,28 @@ module Dimples
|
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
def pages
|
|
40
|
-
@pages ||= source_files(
|
|
40
|
+
@pages ||= source_files(key: :pages, extension: 'erb').map do |path|
|
|
41
41
|
Dimples::Template.new(site: self, path: path)
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
def templates
|
|
46
|
-
@templates ||= source_files(
|
|
47
|
-
key = File.basename(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
@templates ||= source_files(key: :templates, extension: 'erb').to_h do |path|
|
|
47
|
+
key = File.basename(flatten_source_path(path:, key: :templates), '.erb').to_sym
|
|
48
|
+
[key, Dimples::Template.new(site: self, path: path)]
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
def data
|
|
53
|
+
@data ||= source_files(key: :data, extension: 'json').to_h do |path|
|
|
54
|
+
key = File.basename(flatten_source_path(path:, key: :data), ".json").to_sym
|
|
55
|
+
value = begin
|
|
56
|
+
Context.from_hash(JSON.parse(File.read(path)))
|
|
57
|
+
rescue JSON::ParserError
|
|
58
|
+
nil
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
[key, value]
|
|
53
62
|
end
|
|
54
63
|
end
|
|
55
64
|
|
|
@@ -66,8 +75,12 @@ module Dimples
|
|
|
66
75
|
|
|
67
76
|
private
|
|
68
77
|
|
|
69
|
-
def source_files(
|
|
70
|
-
Dir.glob(File.join(@config.source_paths[
|
|
78
|
+
def source_files(key:, extension:)
|
|
79
|
+
Dir.glob(File.join(@config.source_paths[key], '**', "*.#{extension}"))
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def flatten_source_path(path:, key:)
|
|
83
|
+
path.gsub(@config.source_paths[key] + File::SEPARATOR, '').tr(File::SEPARATOR, '_')
|
|
71
84
|
end
|
|
72
85
|
|
|
73
86
|
def generate_posts
|
data/lib/dimples/template.rb
CHANGED
|
@@ -12,7 +12,16 @@ module Dimples
|
|
|
12
12
|
def render(payload: nil)
|
|
13
13
|
payload ||= {}
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
@entries.each { |key| remove_instance_variable(key) } unless @entries.nil?
|
|
16
|
+
@entries = []
|
|
17
|
+
|
|
18
|
+
payload.each do |key, value|
|
|
19
|
+
key = "@#{key}".to_sym
|
|
20
|
+
|
|
21
|
+
instance_variable_set(key, value)
|
|
22
|
+
@entries.append(key)
|
|
23
|
+
end
|
|
24
|
+
|
|
16
25
|
ERB.new(contents).result(binding)
|
|
17
26
|
end
|
|
18
27
|
end
|
data/lib/dimples/version.rb
CHANGED