dimples 10.0.0 → 10.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dimples/metadata.rb +36 -0
- data/lib/dimples/pager.rb +1 -1
- data/lib/dimples/site.rb +2 -1
- data/lib/dimples/sources/base.rb +20 -30
- data/lib/dimples/sources/post.rb +0 -4
- data/lib/dimples/version.rb +1 -1
- data/lib/dimples.rb +1 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1851462f5263625c3180103f3be8e6484246bdd21609a401ab779f26d489cfc7
|
4
|
+
data.tar.gz: 5b2312987fd9ceb6c78f8be7152445bf25161fd4e16f6bf9a1e055b9b21d5502
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92451497846e5d3724a09d98ea88e9eec50f96b282061cf96fcb17be39bc180bad42d2e9994077545bd70b3f4ba68a8d11fee2d29cd66f2b812c82a8673c1811
|
7
|
+
data.tar.gz: a23cc742b62eed3ace4b40bb38002c392c5be58525177f4d159e3f983ad15ccbda1331e5cf9080841f1295b604cb09d361b215c647bd09040deb7c23f017eb47
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dimples
|
4
|
+
# A class representing metadata passed into a template for rendering.
|
5
|
+
class Metadata
|
6
|
+
attr_reader :keys
|
7
|
+
|
8
|
+
def initialize(source)
|
9
|
+
source.each do |key, value|
|
10
|
+
self.class.send(:attr_reader, key)
|
11
|
+
instance_variable_set("@#{key}", build(value))
|
12
|
+
end
|
13
|
+
|
14
|
+
@keys = source.keys
|
15
|
+
end
|
16
|
+
|
17
|
+
def build(item)
|
18
|
+
case item
|
19
|
+
when Array
|
20
|
+
item.map { |i| build(i) }
|
21
|
+
when Hash
|
22
|
+
item.empty? ? item : Metadata.new(item)
|
23
|
+
else
|
24
|
+
item
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def method_missing(_method_name, *_args)
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def respond_to_missing?(_method_name, _include_private)
|
33
|
+
true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/dimples/pager.rb
CHANGED
@@ -29,7 +29,7 @@ module Dimples
|
|
29
29
|
(1..@page_count).each do |index|
|
30
30
|
step_to(index)
|
31
31
|
|
32
|
-
@site.layouts['posts']
|
32
|
+
@site.layouts['posts']&.write(
|
33
33
|
File.join(@site.config[:output][:root], current_page_url, 'index.html'),
|
34
34
|
metadata.merge(pagination: self.metadata, url: current_page_url)
|
35
35
|
)
|
data/lib/dimples/site.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'fileutils'
|
4
4
|
require 'tilt'
|
5
5
|
require 'date'
|
6
|
+
require 'yaml'
|
6
7
|
|
7
8
|
module Dimples
|
8
9
|
# A class representing a single generated website.
|
@@ -57,7 +58,7 @@ module Dimples
|
|
57
58
|
end
|
58
59
|
|
59
60
|
def metadata
|
60
|
-
@metadata ||=
|
61
|
+
@metadata ||= Metadata.new(posts: posts, categories: categories)
|
61
62
|
end
|
62
63
|
|
63
64
|
private
|
data/lib/dimples/sources/base.rb
CHANGED
@@ -15,17 +15,22 @@ module Dimples
|
|
15
15
|
@metadata = default_metadata
|
16
16
|
@contents = File.read(@path)
|
17
17
|
|
18
|
-
|
18
|
+
parse_metadata(@contents)
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse_metadata(contents)
|
22
|
+
matches = contents.match(FRONT_MATTER_PATTERN)
|
19
23
|
return unless matches
|
20
24
|
|
21
25
|
@metadata.merge!(YAML.safe_load(matches[1], symbolize_names: true, permitted_classes: [Date]))
|
22
26
|
@contents = matches.post_match.strip
|
27
|
+
|
28
|
+
@metadata.each_key do |key|
|
29
|
+
self.class.send(:define_method, key.to_sym) { @metadata[key] }
|
30
|
+
end
|
23
31
|
end
|
24
32
|
|
25
33
|
def write(output_path = nil, metadata = {})
|
26
|
-
metadata[:site] ||= @site
|
27
|
-
metadata[context_key] ||= self
|
28
|
-
|
29
34
|
output = render(metadata)
|
30
35
|
|
31
36
|
output_path = File.join(output_directory, filename) if output_path.nil?
|
@@ -35,24 +40,14 @@ module Dimples
|
|
35
40
|
File.write(output_path, output)
|
36
41
|
end
|
37
42
|
|
38
|
-
def render(
|
39
|
-
|
40
|
-
|
43
|
+
def render(render_metadata = {}, body = nil)
|
44
|
+
render_metadata[:site] ||= @site.metadata
|
45
|
+
render_metadata[:page] ||= metadata
|
41
46
|
|
42
|
-
|
43
|
-
|
47
|
+
output = template.render(Metadata.new(render_metadata)) { body }
|
48
|
+
return output unless @metadata[:layout] && @site.layouts[@metadata[:layout]]
|
44
49
|
|
45
|
-
|
46
|
-
Object.new.tap do |context|
|
47
|
-
metadata.each { |key, variable| context.instance_variable_set("@#{key}", variable) }
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def default_metadata
|
52
|
-
{
|
53
|
-
layout: nil,
|
54
|
-
filename: 'index.html'
|
55
|
-
}
|
50
|
+
@site.layouts[@metadata[:layout]].render(render_metadata, output)
|
56
51
|
end
|
57
52
|
|
58
53
|
def output_directory
|
@@ -69,16 +64,11 @@ module Dimples
|
|
69
64
|
|
70
65
|
private
|
71
66
|
|
72
|
-
def
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
@metadata[method_name] if @metadata.key?(method_name)
|
78
|
-
end
|
79
|
-
|
80
|
-
def respond_to_missing?(method_name, include_private)
|
81
|
-
@metadata.key?(method_name) || super
|
67
|
+
def default_metadata
|
68
|
+
{
|
69
|
+
layout: nil,
|
70
|
+
filename: 'index.html'
|
71
|
+
}
|
82
72
|
end
|
83
73
|
end
|
84
74
|
end
|
data/lib/dimples/sources/post.rb
CHANGED
data/lib/dimples/version.rb
CHANGED
data/lib/dimples.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dimples
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 10.
|
4
|
+
version: 10.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Bogan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: erb
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '4.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: redcarpet
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- bin/dimples
|
64
64
|
- lib/dimples.rb
|
65
65
|
- lib/dimples/config.rb
|
66
|
+
- lib/dimples/metadata.rb
|
66
67
|
- lib/dimples/pager.rb
|
67
68
|
- lib/dimples/site.rb
|
68
69
|
- lib/dimples/sources/base.rb
|