dimples 10.6.1 → 10.7.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2dbafe84ea3b47edb09710e64408e2bd564463b3774812bf3738a4581778d14a
4
- data.tar.gz: 8cd626b91b5487ff5ccd139e600e28154c3b9cf419d0c4f4fec03fbf26a9eec0
3
+ metadata.gz: 4b5c714d45ca9e2ea1acc71d9cd7f4ce61baf15da289780e3bcca06195f7688d
4
+ data.tar.gz: 347fce125c6cae601b18d6becd20715203f1ebe98ffb265300eb1a5bfc0fc371
5
5
  SHA512:
6
- metadata.gz: 2fa0abf7b05309cc28a094682391f884c9739dda4721ce45bf2a51988b36ecafafa454f236cccacc2731635970385a3e678136eadca78fd21c05f9cf6b23df44
7
- data.tar.gz: '05093a25c038a0a2fe7b631de3c44135b313c83a82e3e59f8544b01caff9127bdb60ac8ff36f91f56185e9bfaaa640e25343d2811c0c0cef70b9ca3b9b091e53'
6
+ metadata.gz: f9086e486dc0a12e6ec28a526382f806dc338c45852ffb3226e571d135c2d1520662c8d49127076646edc416fef4a0cd68009410a8709631436fe53e5d31f654
7
+ data.tar.gz: 7481579f5ad52500f7085e1ce28a8f158066baf38fbe292c0cf903cbf2ca2f94dae23fb5e9336cdfc643e931c98a7bc554d4d2c598a62d6444dfd95c141e4ec3
@@ -17,7 +17,6 @@ module Dimples
17
17
  source: Dir.pwd,
18
18
  build: './site',
19
19
  pathnames: { posts: 'posts', categories: 'categories' },
20
- site: { name: nil, domain: nil, summary: nil },
21
20
  pagination: { page_prefix: 'page_', per_page: 5 },
22
21
  generation: { main_feed: true, category_feeds: false }
23
22
  }
data/lib/dimples/entry.rb CHANGED
@@ -42,7 +42,7 @@ module Dimples
42
42
  end
43
43
 
44
44
  def generate(output_path: nil, context: {})
45
- output_path = File.join(output_directory, @metadata[:filename]) if output_path.nil?
45
+ output_path = File.join(output_directory, filename) if output_path.nil?
46
46
  write(output_path: output_path, body: render(context: context))
47
47
  end
48
48
 
@@ -55,20 +55,26 @@ module Dimples
55
55
 
56
56
  def url
57
57
  @url ||= output_directory.gsub(@site.config.build_paths[:root], '').tap do |url|
58
- url.concat(@metadata[:filename]) unless @metadata[:filename] == 'index.html'
58
+ url.concat(filename) unless filename == 'index.html'
59
59
  end
60
60
  end
61
61
 
62
62
  def render(context: {}, body: nil)
63
- context[:site] ||= @site.metadata
64
- context[:page] ||= @metadata.merge(context)
63
+ context[:site] ||= @site
64
+ context[:page] ||= self
65
65
 
66
- @rendered_contents = template.render(Metadata.new(context)) { body }
66
+ @rendered_contents = template.render(
67
+ Object.new.tap do |render_context|
68
+ context.each do |key, value|
69
+ render_context.instance_variable_set("@#{key}", value)
70
+ end
71
+ end
72
+ ) { body }
67
73
 
68
- layout = @site.layouts[@metadata.layout.to_sym] if @metadata.layout
69
- return @rendered_contents if layout.nil?
74
+ template = @site.layouts[layout.to_sym] unless layout.nil?
75
+ return @rendered_contents if template.nil?
70
76
 
71
- layout.render(context: context, body: @rendered_contents)
77
+ template.render(context: context, body: @rendered_contents)
72
78
  end
73
79
 
74
80
  def output_directory
@@ -80,11 +86,13 @@ module Dimples
80
86
  end
81
87
 
82
88
  def method_missing(method_name, *_args)
83
- @metadata.send(method_name)
89
+ method_sym = method_name.to_sym
90
+
91
+ @metadata.send(method_sym)
84
92
  end
85
93
 
86
- def respond_to_missing?(_method_name, _include_private = false)
87
- true
94
+ def respond_to_missing?(method_name, _include_private = false)
95
+ @metadata.respond_to?(method_name.to_sym) || super
88
96
  end
89
97
 
90
98
  private
@@ -1,57 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dimples
4
+ # A tiny wrapper around metadata for rendering
2
5
  class Metadata
3
- include Enumerable
4
-
5
6
  def initialize(source)
6
7
  source.each do |key, value|
7
8
  self.class.send(:attr_reader, key)
8
- instance_variable_set("@#{key}", build(value))
9
+ instance_variable_set("@#{key}", value.is_a?(Hash) ? Metadata.new(value) : value)
9
10
  end
10
-
11
- @data = source
12
- end
13
-
14
- def keys
15
- @data.keys
16
- end
17
-
18
- def merge(hash)
19
- @data.merge(hash)
20
- end
21
-
22
- def [](key)
23
- @data[key]
24
11
  end
25
12
 
26
- def each(&block)
27
- @data.each(&block)
28
- end
29
-
30
- def each_key(&block)
31
- @data.keys.each(&block)
32
- end
33
-
34
- def method_missing(method_name, *_args)
35
- return @data[method_name] if @data.key?(method_name)
36
-
13
+ def method_missing(_method_name, *_args)
37
14
  nil
38
15
  end
39
16
 
40
- def respond_to_missing?(method_name, include_private = false)
41
- @data.key?(method_name) || super
42
- end
43
-
44
- private
45
-
46
- def build(item)
47
- case item
48
- when Array
49
- item.map { |i| build(i) }
50
- when Hash
51
- item.empty? ? item : Metadata.new(item)
52
- else
53
- item
54
- end
17
+ def respond_to_missing?(_method_name, _include_private = false)
18
+ true
55
19
  end
56
20
  end
57
21
  end
data/lib/dimples/pager.rb CHANGED
@@ -97,14 +97,14 @@ module Dimples
97
97
  def metadata
98
98
  {
99
99
  posts: posts_at(current_page),
100
- pagination: {
100
+ pagination: Metadata.new(
101
101
  current_page: @current_page,
102
102
  page_count: @page_count,
103
103
  post_count: @posts.count,
104
104
  previous_page: @previous_page,
105
105
  next_page: @next_page,
106
106
  urls: urls
107
- }
107
+ )
108
108
  }
109
109
  end
110
110
  end
data/lib/dimples/site.rb CHANGED
@@ -31,7 +31,7 @@ module Dimples
31
31
  def posts
32
32
  @posts ||= Dir.glob(File.join(@config.source_paths[:posts], '**', '*.markdown')).map do |path|
33
33
  Dimples::Post.new(site: self, path: path)
34
- end.sort_by! { |post| post.metadata[:date] }.reverse!
34
+ end.sort_by! { |post| post.date }.reverse!
35
35
  end
36
36
 
37
37
  def pages
@@ -49,7 +49,7 @@ module Dimples
49
49
  def categories
50
50
  @categories ||= {}.tap do |categories|
51
51
  posts.each do |post|
52
- post.metadata[:categories].each do |category|
52
+ post.categories.each do |category|
53
53
  categories[category] ||= []
54
54
  categories[category].append(post)
55
55
  end
@@ -57,10 +57,6 @@ module Dimples
57
57
  end
58
58
  end
59
59
 
60
- def metadata
61
- @metadata ||= Metadata.new(@config.site.merge(posts: posts, categories: categories.merge))
62
- end
63
-
64
60
  private
65
61
 
66
62
  def generate_posts
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dimples
4
- VERSION = '10.6.1'
4
+ VERSION = '10.7.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dimples
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.6.1
4
+ version: 10.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Bogan