dimples 7.0.3 → 7.0.4

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: 8fd729f8831f7117dec77633ca687cb478952d674c26e1c4720f12bc2a019ff8
4
- data.tar.gz: ecc6f32cb1c207f1b1c57bec0ec770706680a86f3c9ef75796a61ad9eea7e89a
3
+ metadata.gz: ec92ee367aa0923a32bd9638a7fc72c074ac4e6447bee213de65279747ff9344
4
+ data.tar.gz: 7ec38efb0f64cc6c7681a836062663da96542bff95d5f7283f4fd1dd69e05069
5
5
  SHA512:
6
- metadata.gz: e75b7b11f69b44d2015cd0262c1c3d93f87df7f78af881ef193e2de6b63e8ece2f0ae31649d73f27dbeb15c3a676c9a05b178a48f768ee1416abfe132a29fdbd
7
- data.tar.gz: c8e6a752a8b64b5aeae3cefa9faf82f3a1d25d7051c664a93ad2ec6f813274805feae18f19adeefe4c8ae8cc14ac3f4ce85163ec1fd3a305905d2229b0098ff5
6
+ metadata.gz: 6fcd12629c5d6e61507207f244880a96672ddb19f5dd1156c257ce0c44956ce438b29edc8b870ede84ff1c84f15a33ccf2c954e3edaf85065de4eba454613e24
7
+ data.tar.gz: c1871eeb7a84bc5d61973d15bd4c1e98e7c2c4bc52234aa22d671efbf2769d0f5a1b437df237d8c3debf2b9733cf40ed578ef892e566cb4622b8272b9001ae71
data/bin/dimples CHANGED
@@ -8,7 +8,7 @@ require 'dimples'
8
8
  path = if ARGV[0]
9
9
  File.expand_path(ARGV[0])
10
10
  else
11
- File.join(Dir.pwd(), 'site')
11
+ File.join(Dir.pwd, 'site')
12
12
  end
13
13
 
14
14
  Dimples::Site.generate(path)
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'frontmatter'
2
4
 
3
5
  module Dimples
4
6
  class Document
5
7
  attr_accessor :metadata, :contents, :path, :rendered_contents
6
8
 
7
- def initialize(path = nil)
9
+ def initialize(path = nil, metadata = {})
8
10
  @path = path
9
11
 
10
12
  if @path
@@ -13,6 +15,8 @@ module Dimples
13
15
  @metadata = {}
14
16
  @contents = ''
15
17
  end
18
+
19
+ @metadata.merge!(metadata)
16
20
  end
17
21
 
18
22
  def filename
@@ -44,22 +48,22 @@ module Dimples
44
48
 
45
49
  def renderer
46
50
  @renderer ||= begin
47
- callback = proc { contents }
48
-
49
- if @path
50
- Tilt.new(@path, {}, &callback)
51
- else
52
- Tilt::StringTemplate.new(&callback)
53
- end
54
- end
55
- end
51
+ callback = proc { contents }
56
52
 
57
- def method_missing(method_name, *args, &block)
58
- if @metadata.key?(method_name)
59
- @metadata[method_name]
60
- else
61
- nil
53
+ if @path
54
+ Tilt.new(@path, {}, &callback)
55
+ else
56
+ Tilt::StringTemplate.new(&callback)
57
+ end
62
58
  end
63
59
  end
60
+
61
+ def method_missing(method_name, *_args)
62
+ @metadata[method_name] if @metadata.key?(method_name)
63
+ end
64
+
65
+ def respond_to_missing?(method_name, include_private)
66
+ @metadata.key?(method_name) || super
67
+ end
64
68
  end
65
69
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
 
3
5
  module Dimples
@@ -7,8 +9,8 @@ module Dimples
7
9
  def self.parse(contents)
8
10
  metadata = {}
9
11
 
10
- if matches = contents.match(PATTERN)
11
- metadata = YAML.load(matches[1], symbolize_names: true)
12
+ if (matches = contents.match(PATTERN))
13
+ metadata = YAML.safe_load(matches[1], symbolize_names: true, permitted_classes: [Date])
12
14
  contents = matches.post_match.strip
13
15
  end
14
16
 
data/lib/dimples/page.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'document'
2
4
 
3
5
  module Dimples
data/lib/dimples/pager.rb CHANGED
@@ -6,10 +6,7 @@ module Dimples
6
6
 
7
7
  include Enumerable
8
8
 
9
- attr_reader :current_page
10
- attr_reader :previous_page
11
- attr_reader :next_page
12
- attr_reader :page_count
9
+ attr_reader :current_page, :previous_page, :next_page, :page_count
13
10
 
14
11
  def initialize(url, posts, options = {})
15
12
  @url = url
data/lib/dimples/post.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'document'
2
4
 
3
5
  require 'date'
data/lib/dimples/site.rb CHANGED
@@ -4,6 +4,7 @@ require_relative 'pager'
4
4
 
5
5
  require 'fileutils'
6
6
  require 'tilt'
7
+ require 'date'
7
8
 
8
9
  module Dimples
9
10
  class Site
@@ -21,9 +22,7 @@ module Dimples
21
22
 
22
23
  @config = read_config
23
24
 
24
- %w[pages posts static templates].each do |type|
25
- @paths[type.to_sym] = File.join(@paths[:source], type)
26
- end
25
+ %w[pages posts static templates].each { |type| @paths[type.to_sym] = File.join(@paths[:source], type) }
27
26
 
28
27
  scan_posts
29
28
  scan_pages
@@ -51,7 +50,8 @@ module Dimples
51
50
  config_path = File.join(@paths[:source], '.config')
52
51
 
53
52
  return {} unless File.exist?(config_path)
54
- YAML.load(File.read(config_path), symbolize_names: true)
53
+
54
+ YAML.safe_load(File.read(config_path), symbolize_names: true)
55
55
  end
56
56
 
57
57
  def read_files(path)
@@ -59,11 +59,8 @@ module Dimples
59
59
  end
60
60
 
61
61
  def scan_posts
62
- @posts = read_files(@paths[:posts]).map do |path|
63
- Dimples::Post.new(path)
64
- end
65
-
66
- @posts.sort_by! { |post| post.date }.reverse!
62
+ @posts = read_files(@paths[:posts]).map { |path| Dimples::Post.new(path) }
63
+ @posts.sort_by!(&:date).reverse!
67
64
 
68
65
  @categories = {}
69
66
 
@@ -98,11 +95,10 @@ module Dimples
98
95
  end
99
96
 
100
97
  def generate_paginated_posts(posts, path, context = {})
101
- pager = Dimples::Pager.new(path.sub(@paths[:destination], '') + '/', posts)
98
+ pager = Dimples::Pager.new("#{path.sub(@paths[:destination], '')}/", posts)
102
99
 
103
100
  pager.each do |index|
104
- page = Dimples::Page.new()
105
- page.metadata[:layout] = 'posts'
101
+ page = Dimples::Page.new(nil, layout: 'posts')
106
102
 
107
103
  page_path = if index == 1
108
104
  path
@@ -110,8 +106,7 @@ module Dimples
110
106
  File.join(path, "page_#{index}")
111
107
  end
112
108
 
113
- context.merge!(pagination: pager.to_context)
114
- write_file(File.join(page_path, page.filename), render(page, context))
109
+ write_file(File.join(page_path, page.filename), render(page, context.merge!(pagination: pager.to_context)))
115
110
  end
116
111
  end
117
112
 
@@ -131,10 +126,7 @@ module Dimples
131
126
  def generate_pages
132
127
  @pages.each do |page|
133
128
  path = if page.path
134
- File.dirname(page.path).sub(
135
- @paths[:pages],
136
- @paths[:destination]
137
- )
129
+ File.dirname(page.path).sub(@paths[:pages], @paths[:destination])
138
130
  else
139
131
  @paths[:destination]
140
132
  end
@@ -153,14 +145,13 @@ module Dimples
153
145
  end
154
146
 
155
147
  def generate_feed(posts, path)
156
- page = Dimples::Page.new()
157
- page.metadata[:layout] = 'feed'
158
-
148
+ page = Dimples::Page.new(nil, layout: 'feed')
159
149
  write_file(File.join(path, 'feed.atom'), render(page, posts: posts))
160
150
  end
161
151
 
162
152
  def copy_assets
163
153
  return unless Dir.exist?(@paths[:static])
154
+
164
155
  FileUtils.cp_r(File.join(@paths[:static], '.'), @paths[:destination])
165
156
  end
166
157
 
@@ -169,9 +160,7 @@ module Dimples
169
160
 
170
161
  output = object.render(context, content)
171
162
 
172
- if object.layout && @templates[object.layout]
173
- output = render(@templates[object.layout], context, output)
174
- end
163
+ output = render(@templates[object.layout], context, output) if object.layout && @templates[object.layout]
175
164
 
176
165
  output
177
166
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'document'
2
4
 
3
5
  module Dimples
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dimples
4
- VERSION = '7.0.3'
4
+ VERSION = '7.0.4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dimples
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.3
4
+ version: 7.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Bogan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-20 00:00:00.000000000 Z
11
+ date: 2023-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubi
@@ -25,33 +25,33 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.10'
27
27
  - !ruby/object:Gem::Dependency
28
- name: tilt
28
+ name: redcarpet
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.0'
33
+ version: '3.5'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.0'
40
+ version: '3.5'
41
41
  - !ruby/object:Gem::Dependency
42
- name: redcarpet
42
+ name: tilt
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.5'
47
+ version: '2.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.5'
54
+ version: '2.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -108,7 +108,7 @@ require_paths:
108
108
  - lib
109
109
  required_ruby_version: !ruby/object:Gem::Requirement
110
110
  requirements:
111
- - - "~>"
111
+ - - ">="
112
112
  - !ruby/object:Gem::Version
113
113
  version: '2.7'
114
114
  required_rubygems_version: !ruby/object:Gem::Requirement