dimples 10.0.0 → 10.1.0
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 +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcf53e67d092ae60028fef082c0741343badb88483bc2d1c6b19fea30d0a5aca
|
4
|
+
data.tar.gz: bb884858e735d7e1c23c91a17c7f99ab8f4cddffa6b871530b85194147ac7fd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8735afa42f1a1c921764bcc5a80babfa3620662c55beddd13f8825e19807bec00c5e1de835ff121221423b1c9dd04615456078461ba1be1ac28c85545b42af09
|
7
|
+
data.tar.gz: a0ee67d073361ad66fbfa49f545b39b9753571d053b3d4cbab1fbbb54a0799a46cb53569c03dd6c3bbcc506b501ba758a40554fcc4a1fecf4a1118c709a225f5
|
@@ -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,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dimples
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 10.
|
4
|
+
version: 10.1.0
|
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
14
|
name: erubi
|
@@ -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
|