dimples 11.3.0 → 12.0.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: ddce87571299076f5a160fc4dfd24bc5e0c8f7dd1fba61beebdb122908a76bda
4
- data.tar.gz: adae9cec213ce2acf89e4a8d3bcb204298b0cba9fafccabe46f0f712361041b5
3
+ metadata.gz: 0fcf6e00b6b3aa4b7096a9d7e52d403b5bc6bdd0f4564139d1d625fc6a95f7f6
4
+ data.tar.gz: 7f794a7c556717f7096e18cc82b5d4c0fb64ae36c426c0720bf10dff7538c6c5
5
5
  SHA512:
6
- metadata.gz: 6b9c4c7d622e7a9bb25164505b70427b1a03a843aba9ef7475408d941e9b0d0d55d9df88105b4e87c383035cbab5a4f11a79c64853f352ad777c8efdcd96c64b
7
- data.tar.gz: 5f0b4b7bc39c3ded428d2a9643c5244d926b66dcc0524405210192ba77713867994e1b6bc717060f1eca2933385af38df1ccf2b686f51cbe89ec56edca806493
6
+ metadata.gz: 15291e14e987e06abd9d4ff514eef20129b7f177f7d3b7016238739060b1de8d33f314cbf02a171974cc43fe2fbbbfd85dcdb478b9bdd868d88132dc998a5033
7
+ data.tar.gz: f7e89be6177ecd1464258e7414445caf79e609c55ca74ddc8458165a53d2008b61b1da49a3d6ff25b105229a8685b80d6d9020999df832d4eacb866edea6c457
@@ -47,7 +47,16 @@ module Dimples
47
47
  def expand_paths(root, paths)
48
48
  root = File.expand_path(root)
49
49
 
50
- paths.transform_values! { |value| File.expand_path(File.join(root, value)) }
50
+ paths = paths.to_h do |key, value|
51
+ expanded_path = if value.is_a?(Hash)
52
+ expand_paths(File.join(root, key.to_s), value)
53
+ else
54
+ File.expand_path(File.join(root, value))
55
+ end
56
+
57
+ [key, expanded_path]
58
+ end
59
+
51
60
  paths.tap { |expanded_paths| expanded_paths[:root] = root }
52
61
  end
53
62
  end
data/lib/dimples/entry.rb CHANGED
@@ -43,24 +43,28 @@ module Dimples
43
43
  @site.templates[layout.to_sym]
44
44
  end
45
45
 
46
- def generate(output_path:, context: nil)
47
- context ||= {}
46
+ def generate(output_path:, payload: nil)
47
+ payload ||= {}
48
48
 
49
- unless context[:url]
49
+ unless payload[:url]
50
50
  url = output_path.gsub(@site.config.build_paths[:root], '')
51
- url = File.join(url, filename) unless filename == DEFAULT_FILENAME
51
+ url = File.join(url, filename) unless filename.start_with?('index.')
52
52
 
53
- context[:url] = url
53
+ payload[:url] = url
54
54
  end
55
55
 
56
- context = { page: Context.from_hash(@metadata.merge(context)), site: @site }
57
- body = render(context:)
56
+ type = self.class.to_s.split('::')[-1].downcase.to_sym
57
+
58
+ payload[:site] ||= site
59
+ payload[type] = @metadata
60
+
61
+ body = render(payload: payload)
58
62
  template = self.template
59
63
 
60
64
  loop do
61
65
  break if template.nil?
62
66
 
63
- body = template.render(context:) { body }.strip
67
+ body = template.render(payload: payload) { body }.strip
64
68
  template = template.template
65
69
  end
66
70
 
@@ -72,7 +76,7 @@ module Dimples
72
76
  full_path
73
77
  end
74
78
 
75
- def render(context: nil)
79
+ def render(payload: nil)
76
80
  contents
77
81
  end
78
82
 
data/lib/dimples/pager.rb CHANGED
@@ -9,8 +9,8 @@ module Dimples
9
9
 
10
10
  attr_reader :current_page, :previous_page, :next_page, :page_count
11
11
 
12
- def self.paginate(url:, posts:, options: {}, context: {}, &block)
13
- new(url: url, posts: posts, options: options).paginate(context: context, &block)
12
+ def self.paginate(url:, posts:, options: {}, payload: {}, &block)
13
+ new(url: url, posts: posts, options: options).paginate(payload: payload, &block)
14
14
  end
15
15
 
16
16
  def initialize(url:, posts:, options: {})
@@ -24,11 +24,11 @@ module Dimples
24
24
  step_to(1)
25
25
  end
26
26
 
27
- def paginate(context: {})
27
+ def paginate(payload: {})
28
28
  (1..@page_count).each do |index|
29
29
  step_to(index)
30
30
 
31
- yield(current_page_path, context.merge(metadata)) if block_given?
31
+ yield(current_page_path, payload.merge(metadata)) if block_given?
32
32
  end
33
33
  end
34
34
 
data/lib/dimples/post.rb CHANGED
@@ -19,7 +19,7 @@ module Dimples
19
19
  File.basename(path, File.extname(path))&.downcase
20
20
  end
21
21
 
22
- def render(context: nil)
22
+ def render(payload: nil)
23
23
  @rendered_contents ||= Redcarpet::Render::SmartyPants.render(
24
24
  Dimples::Post.markdown.render(contents)
25
25
  ).strip
data/lib/dimples/site.rb CHANGED
@@ -44,7 +44,12 @@ module Dimples
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(site: self, path: path)]
47
+ key = File.basename(
48
+ path.gsub(@config.source_paths[:templates] + File::SEPARATOR, '').tr(File::SEPARATOR, '_'),
49
+ '.erb'
50
+ )
51
+
52
+ [key.to_sym, Dimples::Template.new(site: self, path: path)]
48
53
  end
49
54
  end
50
55
 
@@ -70,14 +75,16 @@ module Dimples
70
75
 
71
76
  url = @config.build_paths[:posts].gsub(@config.build_paths[:root], '').concat('/')
72
77
 
73
- Pager.paginate(url: url, posts: posts, options: @config.pagination) do |url, page_context|
78
+ Pager.paginate(url: url, posts: posts, options: @config.pagination) do |url, payload|
74
79
  templates[:posts].generate(
75
80
  output_path: File.join(@config.build_paths[:root], url),
76
- context: page_context
81
+ payload: payload
77
82
  )
78
83
  end
79
84
 
80
- generate_feed(output_path: @config.build_paths[:root], posts: posts) if @config.generation[:main_feed]
85
+ return unless @config.generation[:main_feed]
86
+
87
+ generate_feed(output_path: @config.build_paths[:root], posts: posts)
81
88
  end
82
89
 
83
90
  def generate_post(post)
@@ -104,23 +111,24 @@ module Dimples
104
111
 
105
112
  def generate_categories
106
113
  categories.each do |category, posts|
107
- context = { title: category.capitalize, category: category }
108
-
109
114
  Pager.paginate(
110
115
  url: "/categories/#{category}/",
111
116
  posts: posts,
112
- context: context,
117
+ payload: { title: category.capitalize, category: category },
113
118
  options: @config.pagination
114
- ) do |url, page_context|
119
+ ) do |url, payload|
115
120
  templates[:posts].generate(
116
121
  output_path: File.join(@config.build_paths[:root], url),
117
- context: page_context
122
+ payload: payload
118
123
  )
119
124
  end
120
125
 
121
- if @config.generation[:category_feeds]
122
- generate_feed(output_path: File.join(@config.build_paths[:root], 'categories', category), posts: posts)
123
- end
126
+ return unless @config.generation[:category_feeds]
127
+
128
+ generate_feed(
129
+ output_path: File.join(@config.build_paths[:root], 'categories', category),
130
+ posts: posts
131
+ )
124
132
  end
125
133
  end
126
134
 
@@ -129,7 +137,7 @@ module Dimples
129
137
 
130
138
  templates[:feed].generate(
131
139
  output_path: output_path,
132
- context: { posts: posts.slice(0, 10) }
140
+ payload: { posts: posts.slice(0, 10) }
133
141
  )
134
142
  end
135
143
 
@@ -139,9 +147,19 @@ module Dimples
139
147
  raise "The site directory (#{@config.build_paths[:root]}) already exists."
140
148
  end
141
149
 
142
- FileUtils.rm_rf(File.join(@config.build_paths[:root], '**', '*'), secure: true)
143
- else
144
- Dir.mkdir(@config.build_paths[:root])
150
+ FileUtils.rm_rf(@config.build_paths[:root], secure: true)
151
+ end
152
+
153
+ create_build_paths(@config.build_paths)
154
+ end
155
+
156
+ def create_build_paths(paths)
157
+ paths.except(:root).each_value do |path|
158
+ if path.is_a?(Hash)
159
+ create_build_paths(path)
160
+ else
161
+ FileUtils.mkdir_p(path) unless Dir.exist?(path)
162
+ end
145
163
  end
146
164
  end
147
165
 
@@ -9,13 +9,10 @@ module Dimples
9
9
  super(site:, source: Pathname.new(path))
10
10
  end
11
11
 
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
17
- end
12
+ def render(payload: nil)
13
+ payload ||= {}
18
14
 
15
+ instance_variable_set("@this", Context.from_hash(payload.merge(metadata)))
19
16
  ERB.new(contents).result(binding)
20
17
  end
21
18
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dimples
4
- VERSION = '11.3.0'
4
+ VERSION = '12.0.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.3.0
4
+ version: 12.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Bogan