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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18bfc09d96924fc5ed5ed12f9d939ad035feaa2ede3f67b0045bd524da5d0d66
4
- data.tar.gz: 224f9dbecde7c7a57fc11d5843898fd2f3b553acc7448cd7639f73fb8c8d7fad
3
+ metadata.gz: 1851462f5263625c3180103f3be8e6484246bdd21609a401ab779f26d489cfc7
4
+ data.tar.gz: 5b2312987fd9ceb6c78f8be7152445bf25161fd4e16f6bf9a1e055b9b21d5502
5
5
  SHA512:
6
- metadata.gz: 6eb46d1192a47f326865c567372c1dc1a5d12f8c93a932d99c7d5c1f2269abbe5cef6a2511eab752938cabf276c92e21f4cf010fac6c206d71674cafd62213b9
7
- data.tar.gz: 4d360af4ddf70adeea836fa311f63bdc14cc5184ecd042b30a7b88670523a1611db707bd42ea66e76494d4b46466c7cc693ee40391c6d9b7a97b74f94db5eae5
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'].write(
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 ||= { posts: posts, categories: categories }
61
+ @metadata ||= Metadata.new(posts: posts, categories: categories)
61
62
  end
62
63
 
63
64
  private
@@ -15,17 +15,22 @@ module Dimples
15
15
  @metadata = default_metadata
16
16
  @contents = File.read(@path)
17
17
 
18
- matches = @contents.match(FRONT_MATTER_PATTERN)
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(metadata = {}, body = nil)
39
- output = template.render(context(metadata)) { body }
40
- return output unless @metadata[:layout] && @site.layouts[@metadata[:layout]]
43
+ def render(render_metadata = {}, body = nil)
44
+ render_metadata[:site] ||= @site.metadata
45
+ render_metadata[:page] ||= metadata
41
46
 
42
- @site.layouts[@metadata[:layout]].render(metadata, output)
43
- end
47
+ output = template.render(Metadata.new(render_metadata)) { body }
48
+ return output unless @metadata[:layout] && @site.layouts[@metadata[:layout]]
44
49
 
45
- def context(metadata)
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 context_key
73
- :page
74
- end
75
-
76
- def method_missing(method_name, *_args)
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
@@ -17,10 +17,6 @@ module Dimples
17
17
 
18
18
  private
19
19
 
20
- def context_key
21
- :post
22
- end
23
-
24
20
  def default_metadata
25
21
  super.tap do |defaults|
26
22
  defaults[:layout] = 'post'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dimples
4
- VERSION = '10.0.0'
4
+ VERSION = '10.1.1'
5
5
  end
data/lib/dimples.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  $LOAD_PATH.unshift(__dir__)
4
4
 
5
5
  require 'dimples/config'
6
+ require 'dimples/metadata'
6
7
  require 'dimples/pager'
7
8
  require 'dimples/site'
8
9
 
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.0.0
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-03 00:00:00.000000000 Z
11
+ date: 2024-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: erubi
14
+ name: erb
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.12'
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: '1.12'
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