dimples 11.2.0 → 11.3.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: 53b0d98c918f5d4860900213f9797177cc07a801464911856127d8f3bb4e6ac0
4
- data.tar.gz: c48d064da98832cfda7d8a878929dcfa1914e584521bc9cd2eab62f2c9245012
3
+ metadata.gz: ddce87571299076f5a160fc4dfd24bc5e0c8f7dd1fba61beebdb122908a76bda
4
+ data.tar.gz: adae9cec213ce2acf89e4a8d3bcb204298b0cba9fafccabe46f0f712361041b5
5
5
  SHA512:
6
- metadata.gz: 99fe1fdcdd089fa248708aace30b3593ca4935e344206bc37118e20c8421992fe0acf8c10c0b32a713c1b71533b2612f59fd1b089491fa2a5fe4dfb57a4b7abf
7
- data.tar.gz: 1d0a41b232f0f6caacaba68ed9ec39013e40a75812564c6391f7b2120f6cc2556b329cc774cdf6816ac9ac0b1df89059ae8229ca592a5bbd21211fd4991b54d9
6
+ metadata.gz: 6b9c4c7d622e7a9bb25164505b70427b1a03a843aba9ef7475408d941e9b0d0d55d9df88105b4e87c383035cbab5a4f11a79c64853f352ad777c8efdcd96c64b
7
+ data.tar.gz: 5f0b4b7bc39c3ded428d2a9643c5244d926b66dcc0524405210192ba77713867994e1b6bc717060f1eca2933385af38df1ccf2b686f51cbe89ec56edca806493
data/lib/dimples/entry.rb CHANGED
@@ -9,9 +9,11 @@ module Dimples
9
9
  FRONT_MATTER_PATTERN = /^(-{3}\n.*?\n?)^(-{3}*$\n?)/m
10
10
  DEFAULT_FILENAME = 'index.html'
11
11
 
12
- attr_reader :path, :contents, :metadata
12
+ attr_reader :site, :path, :contents, :metadata
13
+
14
+ def initialize(site:, source:)
15
+ @site = site
13
16
 
14
- def initialize(source:)
15
17
  contents = case source
16
18
  when Pathname
17
19
  @path = File.expand_path(source)
@@ -35,6 +37,41 @@ module Dimples
35
37
  end
36
38
  end
37
39
 
40
+ def template
41
+ return nil if layout.nil?
42
+
43
+ @site.templates[layout.to_sym]
44
+ end
45
+
46
+ def generate(output_path:, context: nil)
47
+ context ||= {}
48
+
49
+ unless context[:url]
50
+ url = output_path.gsub(@site.config.build_paths[:root], '')
51
+ url = File.join(url, filename) unless filename == DEFAULT_FILENAME
52
+
53
+ context[:url] = url
54
+ end
55
+
56
+ context = { page: Context.from_hash(@metadata.merge(context)), site: @site }
57
+ body = render(context:)
58
+ template = self.template
59
+
60
+ loop do
61
+ break if template.nil?
62
+
63
+ body = template.render(context:) { body }.strip
64
+ template = template.template
65
+ end
66
+
67
+ full_path = File.join(output_path, filename)
68
+
69
+ FileUtils.mkdir_p(output_path) unless File.directory?(output_path)
70
+ File.write(full_path, body)
71
+
72
+ full_path
73
+ end
74
+
38
75
  def render(context: nil)
39
76
  contents
40
77
  end
data/lib/dimples/post.rb CHANGED
@@ -11,8 +11,8 @@ module Dimples
11
11
 
12
12
  attr_reader :rendered_contents
13
13
 
14
- def initialize(path:)
15
- super(source: Pathname.new(path))
14
+ def initialize(site:, path:)
15
+ super(site:, source: Pathname.new(path))
16
16
  end
17
17
 
18
18
  def slug
@@ -22,7 +22,7 @@ module Dimples
22
22
  def render(context: nil)
23
23
  @rendered_contents ||= Redcarpet::Render::SmartyPants.render(
24
24
  Dimples::Post.markdown.render(contents)
25
- )
25
+ ).strip
26
26
  end
27
27
 
28
28
  private
data/lib/dimples/site.rb CHANGED
@@ -30,7 +30,7 @@ module Dimples
30
30
 
31
31
  def posts
32
32
  @posts ||= source_files(path: :posts, extension: 'markdown').map do |path|
33
- Dimples::Post.new(path: path)
33
+ Dimples::Post.new(site: self, path: path)
34
34
  end
35
35
  .sort_by!(&:date)
36
36
  .reverse!
@@ -38,13 +38,13 @@ module Dimples
38
38
 
39
39
  def pages
40
40
  @pages ||= source_files(path: :pages, extension: 'erb').map do |path|
41
- Dimples::Template.new(path: path)
41
+ Dimples::Template.new(site: self, path: path)
42
42
  end
43
43
  end
44
44
 
45
45
  def templates
46
46
  @templates ||= source_files(path: :templates, extension: 'erb').to_h do |path|
47
- [File.basename(path, '.erb').to_sym, Dimples::Template.new(path: path)]
47
+ [File.basename(path, '.erb').to_sym, Dimples::Template.new(site: self, path: path)]
48
48
  end
49
49
  end
50
50
 
@@ -71,8 +71,7 @@ module Dimples
71
71
  url = @config.build_paths[:posts].gsub(@config.build_paths[:root], '').concat('/')
72
72
 
73
73
  Pager.paginate(url: url, posts: posts, options: @config.pagination) do |url, page_context|
74
- generate_entry(
75
- entry: templates[:posts],
74
+ templates[:posts].generate(
76
75
  output_path: File.join(@config.build_paths[:root], url),
77
76
  context: page_context
78
77
  )
@@ -87,7 +86,7 @@ module Dimples
87
86
  @config.build_paths[:posts]
88
87
  ).concat("/#{post.slug}/")
89
88
 
90
- generate_entry(entry: post, output_path: path)
89
+ post.generate(output_path: path)
91
90
  end
92
91
 
93
92
  def generate_pages
@@ -100,7 +99,7 @@ module Dimples
100
99
  @config.build_paths[:root]
101
100
  ).concat('/')
102
101
 
103
- generate_entry(entry: page, output_path: path)
102
+ page.generate(output_path: path)
104
103
  end
105
104
 
106
105
  def generate_categories
@@ -113,8 +112,7 @@ module Dimples
113
112
  context: context,
114
113
  options: @config.pagination
115
114
  ) do |url, page_context|
116
- generate_entry(
117
- entry: templates[:posts],
115
+ templates[:posts].generate(
118
116
  output_path: File.join(@config.build_paths[:root], url),
119
117
  context: page_context
120
118
  )
@@ -129,37 +127,12 @@ module Dimples
129
127
  def generate_feed(output_path:, posts:)
130
128
  return if templates[:feed].nil?
131
129
 
132
- generate_entry(
133
- entry: templates[:feed],
130
+ templates[:feed].generate(
134
131
  output_path: output_path,
135
132
  context: { posts: posts.slice(0, 10) }
136
133
  )
137
134
  end
138
135
 
139
- def generate_entry(entry:, output_path:, context: {})
140
- unless context[:url]
141
- url = output_path.gsub(@config.build_paths[:root], '')
142
- url = File.join(url, entry.filename) unless entry.filename == Dimples::Entry::DEFAULT_FILENAME
143
-
144
- context[:url] = url
145
- end
146
-
147
- context = { page: Context.from_hash(entry.metadata.merge(context)), site: self }
148
- full_path = File.join(output_path, entry.filename)
149
-
150
- FileUtils.mkdir_p(output_path) unless File.directory?(output_path)
151
- File.write(full_path, render_entry(entry: entry, context: context, body: entry.contents))
152
- end
153
-
154
- def render_entry(entry:, context: {}, body: nil)
155
- rendered_body = entry.render(context: context) { body }.strip
156
-
157
- template = templates[entry.layout&.to_sym]
158
- return rendered_body if template.nil?
159
-
160
- render_entry(entry: template, context:, body: rendered_body)
161
- end
162
-
163
136
  def prepare_output_directory
164
137
  if Dir.exist?(@config.build_paths[:root])
165
138
  unless @config.generation[:overwrite_existing_site]
@@ -5,13 +5,15 @@ require 'erb'
5
5
  module Dimples
6
6
  # A class for a single ERB template file used on a site.
7
7
  class Template < Entry
8
- def initialize(path:)
9
- super(source: Pathname.new(path))
8
+ def initialize(site:, path:)
9
+ super(site:, source: Pathname.new(path))
10
10
  end
11
11
 
12
- def render(context:)
13
- context.merge(metadata).each do |key, value|
14
- instance_variable_set("@#{key}", value)
12
+ def render(context: nil)
13
+ unless context.nil?
14
+ context.merge(metadata).each do |key, value|
15
+ instance_variable_set("@#{key}", value)
16
+ end
15
17
  end
16
18
 
17
19
  ERB.new(contents).result(binding)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dimples
4
- VERSION = '11.2.0'
4
+ VERSION = '11.3.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: 11.2.0
4
+ version: 11.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Bogan