dimples 4.3.2 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,27 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dimples
4
- # A class that models a single template.
5
4
  class Template
6
5
  include Frontable
7
- include Renderable
8
6
 
9
7
  attr_accessor :path
10
- attr_accessor :title
11
- attr_accessor :slug
12
- attr_accessor :layout
13
8
  attr_accessor :contents
9
+ attr_accessor :metadata
14
10
 
15
11
  def initialize(site, path)
16
12
  @site = site
17
- @slug = File.basename(path, File.extname(path))
18
13
  @path = path
14
+ @contents, @metadata = read_with_front_matter(path)
15
+ end
19
16
 
20
- read_with_front_matter
17
+ def render(context = {}, body = nil)
18
+ context[:template] ||= Hashie::Mash.new(@metadata)
19
+ renderer.render(context, body)
21
20
  end
22
21
 
23
- def inspect
24
- "#<#{self.class} @slug=#{@slug} @path=#{@path}>"
22
+ private
23
+
24
+ def renderer
25
+ @renderer ||= Renderer.new(@site, self)
25
26
  end
26
27
  end
27
28
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dimples
4
- VERSION = '4.3.2'
4
+ VERSION = '5.0.0'
5
5
  end
metadata CHANGED
@@ -1,15 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dimples
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.2
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Bogan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-19 00:00:00.000000000 Z
11
+ date: 2018-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hashie
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.5'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 3.5.7
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '3.5'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 3.5.7
13
33
  - !ruby/object:Gem::Dependency
14
34
  name: tilt
15
35
  requirement: !ruby/object:Gem::Requirement
@@ -73,61 +93,53 @@ dependencies:
73
93
  - !ruby/object:Gem::Version
74
94
  version: '2.7'
75
95
  - !ruby/object:Gem::Dependency
76
- name: little-fixtures
96
+ name: rake
77
97
  requirement: !ruby/object:Gem::Requirement
78
98
  requirements:
79
99
  - - "~>"
80
100
  - !ruby/object:Gem::Version
81
- version: 0.0.1
101
+ version: '10.0'
82
102
  type: :development
83
103
  prerelease: false
84
104
  version_requirements: !ruby/object:Gem::Requirement
85
105
  requirements:
86
106
  - - "~>"
87
107
  - !ruby/object:Gem::Version
88
- version: 0.0.1
108
+ version: '10.0'
89
109
  - !ruby/object:Gem::Dependency
90
- name: minitest
110
+ name: redcarpet
91
111
  requirement: !ruby/object:Gem::Requirement
92
112
  requirements:
93
113
  - - "~>"
94
114
  - !ruby/object:Gem::Version
95
- version: '5.8'
115
+ version: '3.3'
96
116
  type: :development
97
117
  prerelease: false
98
118
  version_requirements: !ruby/object:Gem::Requirement
99
119
  requirements:
100
120
  - - "~>"
101
121
  - !ruby/object:Gem::Version
102
- version: '5.8'
122
+ version: '3.3'
103
123
  - !ruby/object:Gem::Dependency
104
- name: rake
124
+ name: rspec
105
125
  requirement: !ruby/object:Gem::Requirement
106
126
  requirements:
107
127
  - - "~>"
108
128
  - !ruby/object:Gem::Version
109
- version: '10.0'
110
- type: :development
111
- prerelease: false
112
- version_requirements: !ruby/object:Gem::Requirement
113
- requirements:
114
- - - "~>"
115
- - !ruby/object:Gem::Version
116
- version: '10.0'
117
- - !ruby/object:Gem::Dependency
118
- name: redcarpet
119
- requirement: !ruby/object:Gem::Requirement
120
- requirements:
121
- - - "~>"
129
+ version: '3.7'
130
+ - - ">="
122
131
  - !ruby/object:Gem::Version
123
- version: '3.3'
132
+ version: 3.7.0
124
133
  type: :development
125
134
  prerelease: false
126
135
  version_requirements: !ruby/object:Gem::Requirement
127
136
  requirements:
128
137
  - - "~>"
129
138
  - !ruby/object:Gem::Version
130
- version: '3.3'
139
+ version: '3.7'
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: 3.7.0
131
143
  - !ruby/object:Gem::Dependency
132
144
  name: simplecov
133
145
  requirement: !ruby/object:Gem::Requirement
@@ -156,7 +168,7 @@ dependencies:
156
168
  - - "~>"
157
169
  - !ruby/object:Gem::Version
158
170
  version: 0.9.1
159
- description: A very, very, very simple gem for building static websites.
171
+ description: A simple tool for building static websites.
160
172
  email:
161
173
  - d+dimples@waferbaby.com
162
174
  executables:
@@ -170,11 +182,11 @@ files:
170
182
  - lib/dimples/configuration.rb
171
183
  - lib/dimples/errors.rb
172
184
  - lib/dimples/frontable.rb
173
- - lib/dimples/logger.rb
174
185
  - lib/dimples/page.rb
175
- - lib/dimples/pagination.rb
186
+ - lib/dimples/pager.rb
187
+ - lib/dimples/plugin.rb
176
188
  - lib/dimples/post.rb
177
- - lib/dimples/renderable.rb
189
+ - lib/dimples/renderer.rb
178
190
  - lib/dimples/site.rb
179
191
  - lib/dimples/template.rb
180
192
  - lib/dimples/version.rb
@@ -198,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
210
  version: '0'
199
211
  requirements: []
200
212
  rubyforge_project:
201
- rubygems_version: 2.6.13
213
+ rubygems_version: 2.7.6
202
214
  signing_key:
203
215
  specification_version: 4
204
216
  summary: A basic static site generator
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Dimples
4
- # A simple Logger subclass.
5
- class Logger < ::Logger
6
- def initialize(*)
7
- super
8
- @formatter = LogFormatter
9
- end
10
-
11
- def debug_generation(type, count)
12
- message = "Generating #{type} (#{count} item"
13
- message += 's' if count != 1
14
- message += ')...'
15
-
16
- debug(message)
17
- end
18
- end
19
-
20
- # A simple Logger formatting subclass.
21
- class LogFormatter < Logger::Formatter
22
- def self.call(severity, _time, _program_name, message)
23
- case severity
24
- when 'ERROR'
25
- prefix = "\033[31mError:\033[0m "
26
- when 'DEBUG'
27
- prefix = "\033[93m- "
28
- end
29
-
30
- "#{prefix}#{message}\033[0m\n"
31
- end
32
- end
33
- end
@@ -1,112 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Dimples
4
- # A module that supports pagination.
5
- module Pagination
6
- def paginate(site, items, path, layout, options = {})
7
- context = options.delete(:context) || {}
8
- url = path.sub(site.output_paths[:site], '') + '/'
9
- per_page = options.delete(:per_page) ||
10
- site.config[:pagination][:per_page]
11
-
12
- pager = Pager.new(url, items, per_page, options)
13
-
14
- pager.each do |index, page_items|
15
- page = Dimples::Page.new(site)
16
-
17
- page.output_directory = if index == 1
18
- path
19
- else
20
- File.join(path, "page#{index}")
21
- end
22
-
23
- page.layout = layout
24
- page.title = options[:title] || site.templates[layout]&.title
25
- page.extension = options[:extension] if options[:extension]
26
-
27
- context[:items] = page_items
28
- context[:pagination] = pager.to_h
29
-
30
- page.write(context)
31
- end
32
- end
33
-
34
- # A class that models the context of a single page during pagination.
35
- class Pager
36
- include Enumerable
37
-
38
- attr_reader :current_page
39
- attr_reader :previous_page
40
- attr_reader :next_page
41
- attr_reader :page_count
42
- attr_reader :item_count
43
-
44
- def initialize(url, items, per_page, options = {})
45
- @url = url
46
- @items = items
47
- @per_page = per_page
48
- @page_count = (items.length.to_f / per_page.to_i).ceil
49
- @page_prefix = options[:page_prefix] || 'page'
50
-
51
- step_to(1)
52
- end
53
-
54
- def each(&block)
55
- (1..@page_count).each do |index|
56
- block.yield step_to(index), items_at(index)
57
- end
58
- end
59
-
60
- def step_to(page)
61
- @current_page = (1..@page_count).cover?(page) ? page : 1
62
- @previous_page = (@current_page - 1).positive? ? @current_page - 1 : nil
63
- @next_page = @current_page + 1 <= @page_count ? @current_page + 1 : nil
64
-
65
- @current_page
66
- end
67
-
68
- def items_at(page)
69
- @items.slice((page - 1) * @per_page, @per_page)
70
- end
71
-
72
- def current_page_url
73
- @current_page != 1 ? "#{@url}#{@page_prefix}#{@current_page}" : @url
74
- end
75
-
76
- def first_page_url
77
- @url
78
- end
79
-
80
- def last_page_url
81
- @page_count != 1 ? "#{@url}#{@page_prefix}#{@page_count}" : @url
82
- end
83
-
84
- def previous_page_url
85
- return unless @previous_page
86
- @previous_page != 1 ? "#{@url}#{@page_prefix}#{@previous_page}" : @url
87
- end
88
-
89
- def next_page_url
90
- "#{@url}#{@page_prefix}#{@next_page}" if @next_page
91
- end
92
-
93
- def to_h
94
- {
95
- url: @url,
96
- current_page: @current_page,
97
- page_count: @page_count,
98
- item_count: @items.count,
99
- previous_page: @previous_page,
100
- next_page: @next_page,
101
- links: {
102
- current_page: current_page_url,
103
- first_page: first_page_url,
104
- last_page: last_page_url,
105
- previous_page: previous_page_url,
106
- next_page: next_page_url
107
- }
108
- }
109
- end
110
- end
111
- end
112
- end
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Dimples
4
- # A mixin class that allows a document to render via Tilt.
5
- module Renderable
6
- attr_accessor :rendered_contents
7
-
8
- def render(context = {}, body = nil)
9
- context[:site] ||= @site
10
- context[:this] ||= self
11
- context[:type] ||= self.class.name.split('::').last.downcase.to_sym
12
-
13
- output = rendering_engine.render(scope(context)) { body }.strip
14
- @rendered_contents = output
15
-
16
- if @site.templates[layout]
17
- @site.templates[layout].render(context, output)
18
- else
19
- output
20
- end
21
- end
22
-
23
- def scope(context)
24
- Object.new.tap do |scope|
25
- context.each_pair do |key, value|
26
- scope.instance_variable_set("@#{key}".to_sym, value)
27
- end
28
-
29
- method_name = :render_template
30
- scope.class.send(:define_method, method_name) do |template, locals = {}|
31
- @site.templates[template]&.render(locals)
32
- end
33
- end
34
- end
35
-
36
- def rendering_engine
37
- @rendering_engine ||= begin
38
- callback = proc { contents }
39
-
40
- if @path
41
- extension = File.extname(@path)[1..-1]
42
- options = @site.config[:rendering][extension.to_sym] || {}
43
- Tilt.new(@path, options, &callback)
44
- else
45
- Tilt::StringTemplate.new(&callback)
46
- end
47
- end
48
- end
49
- end
50
- end