dimples 13.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/site.rb +23 -10
- 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/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/version.rb
CHANGED