dimples 11.3.0 → 13.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: 3b1507135dbcefde4af262ac48bc5b5fb34fb70d6ee8907f79fd65c53baccf37
4
+ data.tar.gz: e78540206127d0891cbbb3d6c04f21cf9ebbd98205f7c742feb8a0ee337245ed
5
5
  SHA512:
6
- metadata.gz: 6b9c4c7d622e7a9bb25164505b70427b1a03a843aba9ef7475408d941e9b0d0d55d9df88105b4e87c383035cbab5a4f11a79c64853f352ad777c8efdcd96c64b
7
- data.tar.gz: 5f0b4b7bc39c3ded428d2a9643c5244d926b66dcc0524405210192ba77713867994e1b6bc717060f1eca2933385af38df1ccf2b686f51cbe89ec56edca806493
6
+ metadata.gz: 5bb98fd65d3c953670d26c2b932d295c7ac478b77c1fa12f655104acc5350c51f8b85daa83efadc64fadf5a2c1f4cf3606a9b9ef80bdb2cd4ee3fc657e2420d1
7
+ data.tar.gz: ad6d763c238811a49d755b69d23fbbdf3f332b08594602fbc3fbf7bc0b468346720bf01dee04e00241178d052d8ba57e0f8a147742bb04ba19c76e0ef6511cad
@@ -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
@@ -31,6 +31,10 @@ module Dimples
31
31
  matches = contents.match(FRONT_MATTER_PATTERN)
32
32
  if matches
33
33
  @metadata.merge!(YAML.safe_load(matches[1], symbolize_names: true, permitted_classes: [Date]))
34
+ @metadata.transform_values! do |value|
35
+ value.is_a?(Hash) ? Context.from_hash(value) : value
36
+ end
37
+
34
38
  @contents = matches.post_match.strip
35
39
  else
36
40
  @contents = contents
@@ -43,24 +47,28 @@ module Dimples
43
47
  @site.templates[layout.to_sym]
44
48
  end
45
49
 
46
- def generate(output_path:, context: nil)
47
- context ||= {}
50
+ def generate(output_path:, payload: nil)
51
+ payload ||= {}
48
52
 
49
- unless context[:url]
53
+ unless payload[:url]
50
54
  url = output_path.gsub(@site.config.build_paths[:root], '')
51
- url = File.join(url, filename) unless filename == DEFAULT_FILENAME
55
+ url = File.join(url, filename) unless filename.start_with?('index.')
52
56
 
53
- context[:url] = url
57
+ payload[:url] = url
54
58
  end
55
59
 
56
- context = { page: Context.from_hash(@metadata.merge(context)), site: @site }
57
- body = render(context:)
60
+ type = self.class.to_s.split('::')[-1].downcase.to_sym
61
+
62
+ payload[:site] ||= site
63
+ payload[type] = self
64
+
65
+ body = render(payload: payload)
58
66
  template = self.template
59
67
 
60
68
  loop do
61
69
  break if template.nil?
62
70
 
63
- body = template.render(context:) { body }.strip
71
+ body = template.render(payload: payload) { body }.strip
64
72
  template = template.template
65
73
  end
66
74
 
@@ -72,7 +80,7 @@ module Dimples
72
80
  full_path
73
81
  end
74
82
 
75
- def render(context: nil)
83
+ def render(payload: nil)
76
84
  contents
77
85
  end
78
86
 
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
 
@@ -53,7 +53,7 @@ module Dimples
53
53
  end
54
54
 
55
55
  def current_page_path
56
- @current_page == 1 ? @url : File.join(@url, "page_#{@current_page}")
56
+ @current_page == 1 ? @url : File.join(@url, "pages", current_page.to_s)
57
57
  end
58
58
 
59
59
  def current_page_url
@@ -91,14 +91,14 @@ module Dimples
91
91
  def metadata
92
92
  {
93
93
  posts: posts_at(current_page),
94
- pagination: {
94
+ pagination: Context.from_hash(
95
95
  current_page: @current_page,
96
96
  page_count: @page_count,
97
97
  post_count: @posts.count,
98
98
  previous_page: @previous_page,
99
99
  next_page: @next_page,
100
100
  urls: urls
101
- }
101
+ )
102
102
  }
103
103
  end
104
104
  end
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,11 +9,17 @@ 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
12
+ def render(payload: nil)
13
+ payload ||= {}
14
+
15
+ @entries.each { |key| remove_instance_variable(key) } unless @entries.nil?
16
+ @entries = []
17
+
18
+ payload.each do |key, value|
19
+ key = "@#{key}".to_sym
20
+
21
+ instance_variable_set(key, value)
22
+ @entries.append(key)
17
23
  end
18
24
 
19
25
  ERB.new(contents).result(binding)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dimples
4
- VERSION = '11.3.0'
4
+ VERSION = '13.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: 13.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Bogan