dimples 9.0.0 → 10.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/dimples +12 -13
- data/lib/dimples/config.rb +33 -0
- data/lib/dimples/pager.rb +34 -16
- data/lib/dimples/site.rb +54 -123
- data/lib/dimples/sources/base.rb +85 -0
- data/lib/dimples/sources/layout.rb +12 -0
- data/lib/dimples/sources/page.rb +31 -0
- data/lib/dimples/sources/post.rb +34 -0
- data/lib/dimples/version.rb +1 -1
- data/lib/dimples.rb +8 -5
- metadata +20 -76
- data/lib/dimples/document.rb +0 -69
- data/lib/dimples/errors.rb +0 -12
- data/lib/dimples/frontmatter.rb +0 -20
- data/lib/dimples/page.rb +0 -8
- data/lib/dimples/post.rb +0 -21
- data/lib/dimples/template.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18bfc09d96924fc5ed5ed12f9d939ad035feaa2ede3f67b0045bd524da5d0d66
|
4
|
+
data.tar.gz: 224f9dbecde7c7a57fc11d5843898fd2f3b553acc7448cd7639f73fb8c8d7fad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6eb46d1192a47f326865c567372c1dc1a5d12f8c93a932d99c7d5c1f2269abbe5cef6a2511eab752938cabf276c92e21f4cf010fac6c206d71674cafd62213b9
|
7
|
+
data.tar.gz: 4d360af4ddf70adeea836fa311f63bdc14cc5184ecd042b30a7b88670523a1611db707bd42ea66e76494d4b46466c7cc693ee40391c6d9b7a97b74f94db5eae5
|
data/bin/dimples
CHANGED
@@ -1,27 +1,26 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
$LOAD_PATH.unshift(File.join(__dir__,
|
4
|
+
$LOAD_PATH.unshift(File.join(__dir__, '..', 'lib'))
|
5
5
|
|
6
|
-
require
|
7
|
-
|
8
|
-
source_path = ARGV[0]
|
9
|
-
output_path = ARGV[1]
|
10
|
-
|
11
|
-
config_path = File.join(Dir.pwd, "config.yml")
|
6
|
+
require 'dimples'
|
7
|
+
require 'yaml'
|
12
8
|
|
9
|
+
config_path = File.join(Dir.pwd, 'config.yml')
|
13
10
|
config = {}
|
14
11
|
|
15
12
|
if File.exist?(config_path)
|
16
|
-
begin
|
17
|
-
|
13
|
+
config = begin
|
14
|
+
YAML.safe_load_file(config_path, symbolize_names: true)
|
18
15
|
rescue YAML::Error
|
19
|
-
puts
|
16
|
+
puts 'Failed to parse config - using defaults'
|
17
|
+
ensure
|
18
|
+
{}
|
20
19
|
end
|
21
20
|
end
|
22
21
|
|
23
22
|
begin
|
24
|
-
Dimples::Site.generate(
|
25
|
-
rescue
|
26
|
-
puts "Error: #{
|
23
|
+
Dimples::Site.generate(config)
|
24
|
+
rescue StandardError => e
|
25
|
+
puts "Error generating site: #{e}"
|
27
26
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dimples
|
4
|
+
# Configuration settings for a site.
|
5
|
+
class Config
|
6
|
+
def self.defaults
|
7
|
+
{
|
8
|
+
sources: { root: '.', posts: './posts', pages: './pages', layouts: './layouts', static: './static' },
|
9
|
+
output: { root: './site', posts: './site/posts', categories: './site/categories' }
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(options = {})
|
14
|
+
@options = Config.defaults
|
15
|
+
|
16
|
+
options&.each do |key, value|
|
17
|
+
@options[key]&.merge!(value)
|
18
|
+
end
|
19
|
+
|
20
|
+
%i[sources output].each do |type|
|
21
|
+
@options[type].each { |key, value| @options[type][key] = File.expand_path(value) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def dig(*args)
|
26
|
+
@options.dig(*args)
|
27
|
+
end
|
28
|
+
|
29
|
+
def [](key)
|
30
|
+
@options[key]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/dimples/pager.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Dimples
|
4
|
+
# A class for paginating a collection of posts.
|
4
5
|
class Pager
|
5
6
|
PER_PAGE = 5
|
6
7
|
|
@@ -8,18 +9,31 @@ module Dimples
|
|
8
9
|
|
9
10
|
attr_reader :current_page, :previous_page, :next_page, :page_count
|
10
11
|
|
11
|
-
def
|
12
|
+
def self.paginate(site, url, posts, metadata = {})
|
13
|
+
new(site, url, posts).paginate(metadata)
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(site, url, posts)
|
17
|
+
@site = site
|
12
18
|
@url = url
|
13
19
|
@posts = posts
|
14
|
-
|
15
|
-
@
|
20
|
+
|
21
|
+
@per_page = @site.config.dig(:pagination, :per_page) || PER_PAGE
|
22
|
+
@page_prefix = @site.config.dig(:pagination, :page_prefix) || 'page_'
|
16
23
|
@page_count = (posts.length.to_f / @per_page.to_i).ceil
|
17
24
|
|
18
25
|
step_to(1)
|
19
26
|
end
|
20
27
|
|
21
|
-
def
|
22
|
-
(1..@page_count).each
|
28
|
+
def paginate(metadata)
|
29
|
+
(1..@page_count).each do |index|
|
30
|
+
step_to(index)
|
31
|
+
|
32
|
+
@site.layouts['posts'].write(
|
33
|
+
File.join(@site.config[:output][:root], current_page_url, 'index.html'),
|
34
|
+
metadata.merge(pagination: self.metadata, url: current_page_url)
|
35
|
+
)
|
36
|
+
end
|
23
37
|
end
|
24
38
|
|
25
39
|
def step_to(page)
|
@@ -43,7 +57,7 @@ module Dimples
|
|
43
57
|
end
|
44
58
|
|
45
59
|
def current_page_url
|
46
|
-
|
60
|
+
@current_page == 1 ? @url : "#{@url}#{@page_prefix}#{@current_page}"
|
47
61
|
end
|
48
62
|
|
49
63
|
def first_page_url
|
@@ -51,20 +65,30 @@ module Dimples
|
|
51
65
|
end
|
52
66
|
|
53
67
|
def last_page_url
|
54
|
-
|
68
|
+
@page_count == 1 ? @url : "#{@url}#{@page_prefix}#{@page_count}"
|
55
69
|
end
|
56
70
|
|
57
71
|
def previous_page_url
|
58
72
|
return unless @previous_page
|
59
73
|
|
60
|
-
|
74
|
+
@previous_page == 1 ? @url : "#{@url}#{@page_prefix}#{@previous_page}"
|
61
75
|
end
|
62
76
|
|
63
77
|
def next_page_url
|
64
78
|
"#{@url}#{@page_prefix}#{@next_page}" if @next_page
|
65
79
|
end
|
66
80
|
|
67
|
-
def
|
81
|
+
def urls
|
82
|
+
{
|
83
|
+
current_page: current_page_url,
|
84
|
+
first_page: first_page_url,
|
85
|
+
last_page: last_page_url,
|
86
|
+
previous_page: previous_page_url,
|
87
|
+
next_page: next_page_url
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
def metadata
|
68
92
|
{
|
69
93
|
posts: posts_at(current_page),
|
70
94
|
current_page: @current_page,
|
@@ -72,13 +96,7 @@ module Dimples
|
|
72
96
|
post_count: @posts.count,
|
73
97
|
previous_page: @previous_page,
|
74
98
|
next_page: @next_page,
|
75
|
-
urls:
|
76
|
-
current_page: current_page_url,
|
77
|
-
first_page: first_page_url,
|
78
|
-
last_page: last_page_url,
|
79
|
-
previous_page: previous_page_url,
|
80
|
-
next_page: next_page_url
|
81
|
-
}
|
99
|
+
urls: urls
|
82
100
|
}
|
83
101
|
end
|
84
102
|
end
|
data/lib/dimples/site.rb
CHANGED
@@ -1,173 +1,104 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require
|
6
|
-
require "tilt"
|
7
|
-
require "date"
|
3
|
+
require 'fileutils'
|
4
|
+
require 'tilt'
|
5
|
+
require 'date'
|
8
6
|
|
9
7
|
module Dimples
|
8
|
+
# A class representing a single generated website.
|
10
9
|
class Site
|
11
|
-
|
10
|
+
attr_accessor :config
|
12
11
|
|
13
|
-
def self.generate(
|
14
|
-
new(
|
12
|
+
def self.generate(config = {})
|
13
|
+
new(config).generate
|
15
14
|
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
def initialize(source_path, output_path, config)
|
20
|
-
@paths = {
|
21
|
-
source: File.expand_path(source_path || Dir.pwd),
|
22
|
-
destination: File.expand_path(output_path || File.join(Dir.pwd, "site"))
|
23
|
-
}
|
24
|
-
|
25
|
-
@config = DEFAULT_CONFIG
|
26
|
-
@config.merge!(config) if config&.is_a?(Hash)
|
27
|
-
|
28
|
-
%w[pages posts static templates].each do |type|
|
29
|
-
@paths[type.to_sym] = File.join(@paths[:source], type)
|
30
|
-
end
|
31
|
-
|
32
|
-
scan_posts
|
33
|
-
scan_pages
|
34
|
-
scan_templates
|
16
|
+
def initialize(config = {})
|
17
|
+
@config = Config.new(config)
|
35
18
|
end
|
36
19
|
|
37
20
|
def generate
|
38
|
-
|
39
|
-
unless @config.dig(:generation, :overwrite_directory)
|
40
|
-
raise GenerationError.new("The site directory (#{@paths[:destination]}) already exists.")
|
41
|
-
end
|
42
|
-
|
43
|
-
FileUtils.rm_rf(@paths[:destination])
|
44
|
-
end
|
45
|
-
|
46
|
-
Dir.mkdir(@paths[:destination])
|
21
|
+
prepare_output_directory
|
47
22
|
|
48
23
|
generate_posts
|
49
|
-
generate_pages
|
50
24
|
generate_categories
|
25
|
+
generate_pages
|
51
26
|
|
52
27
|
copy_assets
|
53
28
|
end
|
54
29
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
30
|
+
def posts
|
31
|
+
@posts ||= Dir.glob(File.join(@config[:sources][:posts], '**', '*.markdown')).map do |path|
|
32
|
+
Dimples::Sources::Post.new(self, path)
|
33
|
+
end.sort_by!(&:date).reverse!
|
59
34
|
end
|
60
35
|
|
61
|
-
def
|
62
|
-
@
|
63
|
-
|
64
|
-
|
65
|
-
@categories = {}
|
66
|
-
|
67
|
-
@posts.each do |post|
|
68
|
-
post.categories&.each do |category|
|
69
|
-
@categories[category] ||= []
|
70
|
-
@categories[category] << post
|
71
|
-
end
|
36
|
+
def pages
|
37
|
+
@pages ||= Dir.glob(File.join(@config[:sources][:pages], '**', '*.erb')).map do |path|
|
38
|
+
Dimples::Sources::Page.new(self, path)
|
72
39
|
end
|
73
40
|
end
|
74
41
|
|
75
|
-
def
|
76
|
-
@
|
42
|
+
def layouts
|
43
|
+
@layouts ||= Dir.glob(File.join(@config[:sources][:layouts], '**', '*.erb')).to_h do |path|
|
44
|
+
[File.basename(path, '.erb'), Dimples::Sources::Layout.new(self, path)]
|
45
|
+
end
|
77
46
|
end
|
78
47
|
|
79
|
-
def
|
80
|
-
@
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
48
|
+
def categories
|
49
|
+
@categories ||= {}.tap do |categories|
|
50
|
+
posts.each do |post|
|
51
|
+
post.categories.each do |category|
|
52
|
+
categories[category] ||= []
|
53
|
+
categories[category].append(post)
|
85
54
|
end
|
86
55
|
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def write_file(path, content)
|
90
|
-
directory_path = File.dirname(path)
|
91
|
-
|
92
|
-
Dir.mkdir(directory_path) unless Dir.exist?(directory_path)
|
93
|
-
File.write(path, content)
|
94
|
-
end
|
95
|
-
|
96
|
-
def generate_paginated_posts(posts, path, context = {})
|
97
|
-
pager = Dimples::Pager.new("#{path.sub(@paths[:destination], "")}/", posts)
|
98
|
-
|
99
|
-
pager.each do |index|
|
100
|
-
page = Dimples::Page.new(nil, layout: "posts")
|
101
|
-
|
102
|
-
page_path =
|
103
|
-
if index == 1
|
104
|
-
path
|
105
|
-
else
|
106
|
-
File.join(path, "page_#{index}")
|
107
|
-
end
|
108
|
-
|
109
|
-
write_file(
|
110
|
-
File.join(page_path, page.filename),
|
111
|
-
render(page, context.merge!(pagination: pager.to_context))
|
112
|
-
)
|
113
56
|
end
|
114
57
|
end
|
115
58
|
|
116
|
-
def
|
117
|
-
|
118
|
-
Dir.mkdir(directory_path)
|
119
|
-
|
120
|
-
@posts.each do |post|
|
121
|
-
path = File.join(directory_path, post.slug, post.filename)
|
122
|
-
write_file(path, render(post, post: post))
|
123
|
-
end
|
124
|
-
|
125
|
-
generate_paginated_posts(@posts, directory_path)
|
126
|
-
generate_feed(@posts.slice(0, 10), @paths[:destination])
|
59
|
+
def metadata
|
60
|
+
@metadata ||= { posts: posts, categories: categories }
|
127
61
|
end
|
128
62
|
|
129
|
-
|
130
|
-
@pages.each do |page|
|
131
|
-
path =
|
132
|
-
if page.path
|
133
|
-
File.dirname(page.path).sub(@paths[:pages], @paths[:destination])
|
134
|
-
else
|
135
|
-
@paths[:destination]
|
136
|
-
end
|
63
|
+
private
|
137
64
|
|
138
|
-
|
139
|
-
|
65
|
+
def generate_posts
|
66
|
+
posts.each(&:write)
|
67
|
+
Pager.paginate(self, @config[:output][:posts].gsub(@config[:output][:root], '').concat('/'), posts)
|
68
|
+
generate_feed(@config[:output][:root], posts)
|
140
69
|
end
|
141
70
|
|
142
71
|
def generate_categories
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
generate_feed(posts.slice(0, 10), category_path)
|
72
|
+
categories.each do |category, posts|
|
73
|
+
metadata = { title: category.capitalize, category: category }
|
74
|
+
Pager.paginate(self, "/categories/#{category}/", posts, metadata)
|
75
|
+
generate_feed(File.join(@config[:output][:root], 'categories', category), posts)
|
148
76
|
end
|
149
77
|
end
|
150
78
|
|
151
|
-
def
|
152
|
-
|
153
|
-
write_file(File.join(path, "feed.atom"), render(page, posts: posts))
|
79
|
+
def generate_pages
|
80
|
+
pages.each(&:write)
|
154
81
|
end
|
155
82
|
|
156
|
-
def
|
157
|
-
return
|
83
|
+
def generate_feed(output_path, posts)
|
84
|
+
return if layouts['feed'].nil?
|
158
85
|
|
159
|
-
|
86
|
+
layouts['feed'].write(
|
87
|
+
File.join(output_path, 'feed.atom'),
|
88
|
+
posts: posts.slice(0, 10)
|
89
|
+
)
|
160
90
|
end
|
161
91
|
|
162
|
-
def
|
163
|
-
|
92
|
+
def prepare_output_directory
|
93
|
+
raise "The site directory (#{@config[:output][:root]}) already exists." if Dir.exist?(@config[:output][:root])
|
164
94
|
|
165
|
-
|
95
|
+
Dir.mkdir(@config[:output][:root])
|
96
|
+
end
|
166
97
|
|
167
|
-
|
168
|
-
|
98
|
+
def copy_assets
|
99
|
+
return unless Dir.exist?(@config[:sources][:static])
|
169
100
|
|
170
|
-
output
|
101
|
+
FileUtils.cp_r(File.join(@config[:sources][:static], '.'), @config[:output][:root])
|
171
102
|
end
|
172
103
|
end
|
173
104
|
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dimples
|
4
|
+
module Sources
|
5
|
+
# A base class representing a source file with frontmatter metadata that can be rendered.
|
6
|
+
class Base
|
7
|
+
FRONT_MATTER_PATTERN = /^(-{3}\n.*?\n?)^(-{3}*$\n?)/m
|
8
|
+
|
9
|
+
attr_accessor :path, :metadata, :contents
|
10
|
+
|
11
|
+
def initialize(site, path)
|
12
|
+
@site = site
|
13
|
+
@path = File.expand_path(path)
|
14
|
+
|
15
|
+
@metadata = default_metadata
|
16
|
+
@contents = File.read(@path)
|
17
|
+
|
18
|
+
matches = @contents.match(FRONT_MATTER_PATTERN)
|
19
|
+
return unless matches
|
20
|
+
|
21
|
+
@metadata.merge!(YAML.safe_load(matches[1], symbolize_names: true, permitted_classes: [Date]))
|
22
|
+
@contents = matches.post_match.strip
|
23
|
+
end
|
24
|
+
|
25
|
+
def write(output_path = nil, metadata = {})
|
26
|
+
metadata[:site] ||= @site
|
27
|
+
metadata[context_key] ||= self
|
28
|
+
|
29
|
+
output = render(metadata)
|
30
|
+
|
31
|
+
output_path = File.join(output_directory, filename) if output_path.nil?
|
32
|
+
output_dir = File.dirname(output_path)
|
33
|
+
|
34
|
+
FileUtils.mkdir_p(output_dir) unless File.directory?(output_dir)
|
35
|
+
File.write(output_path, output)
|
36
|
+
end
|
37
|
+
|
38
|
+
def render(metadata = {}, body = nil)
|
39
|
+
output = template.render(context(metadata)) { body }
|
40
|
+
return output unless @metadata[:layout] && @site.layouts[@metadata[:layout]]
|
41
|
+
|
42
|
+
@site.layouts[@metadata[:layout]].render(metadata, output)
|
43
|
+
end
|
44
|
+
|
45
|
+
def context(metadata)
|
46
|
+
Object.new.tap do |context|
|
47
|
+
metadata.each { |key, variable| context.instance_variable_set("@#{key}", variable) }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def default_metadata
|
52
|
+
{
|
53
|
+
layout: nil,
|
54
|
+
filename: 'index.html'
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def output_directory
|
59
|
+
@site.config[:output][:root]
|
60
|
+
end
|
61
|
+
|
62
|
+
def url
|
63
|
+
@metadata[:url] || output_directory.gsub(@site.config[:output][:root], '')
|
64
|
+
end
|
65
|
+
|
66
|
+
def template
|
67
|
+
raise NotImplementedError, 'You must set a Tilt template for this class.'
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def context_key
|
73
|
+
:page
|
74
|
+
end
|
75
|
+
|
76
|
+
def method_missing(method_name, *_args)
|
77
|
+
@metadata[method_name] if @metadata.key?(method_name)
|
78
|
+
end
|
79
|
+
|
80
|
+
def respond_to_missing?(method_name, include_private)
|
81
|
+
@metadata.key?(method_name) || super
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dimples
|
4
|
+
module Sources
|
5
|
+
# A single page on a site.
|
6
|
+
class Page < Base
|
7
|
+
def output_directory
|
8
|
+
@output_directory ||= File.dirname(@path).gsub(
|
9
|
+
@site.config[:sources][:pages],
|
10
|
+
@site.config[:output][:root]
|
11
|
+
).concat('/')
|
12
|
+
end
|
13
|
+
|
14
|
+
def url
|
15
|
+
@metadata[:url] || super.tap do |url|
|
16
|
+
url.concat(filename) unless filename == 'index.html'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def template
|
21
|
+
@template ||= Tilt::ERBTemplate.new { @contents }
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def default_metadata
|
27
|
+
super.merge!(layout: 'page')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dimples
|
4
|
+
module Sources
|
5
|
+
# A page from a site with a date.
|
6
|
+
class Post < Base
|
7
|
+
def output_directory
|
8
|
+
@output_directory ||= File.dirname(@path).gsub(
|
9
|
+
@site.config[:sources][:posts],
|
10
|
+
@site.config[:output][:posts]
|
11
|
+
).concat("/#{@metadata[:slug]}/")
|
12
|
+
end
|
13
|
+
|
14
|
+
def template
|
15
|
+
@template ||= Tilt::RedcarpetTemplate.new { @contents }
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def context_key
|
21
|
+
:post
|
22
|
+
end
|
23
|
+
|
24
|
+
def default_metadata
|
25
|
+
super.tap do |defaults|
|
26
|
+
defaults[:layout] = 'post'
|
27
|
+
defaults[:slug] = File.basename(@path, '.markdown')
|
28
|
+
defaults[:date] = File.birthtime(@path)
|
29
|
+
defaults[:categories] = []
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/dimples/version.rb
CHANGED
data/lib/dimples.rb
CHANGED
@@ -2,8 +2,11 @@
|
|
2
2
|
|
3
3
|
$LOAD_PATH.unshift(__dir__)
|
4
4
|
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
|
9
|
-
require
|
5
|
+
require 'dimples/config'
|
6
|
+
require 'dimples/pager'
|
7
|
+
require 'dimples/site'
|
8
|
+
|
9
|
+
require 'dimples/sources/base'
|
10
|
+
require 'dimples/sources/page'
|
11
|
+
require 'dimples/sources/post'
|
12
|
+
require 'dimples/sources/layout'
|
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:
|
4
|
+
version: 10.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Bogan
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erubi
|
@@ -16,98 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.12'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.12'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: redcarpet
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '3.
|
33
|
+
version: '3.6'
|
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: '3.
|
40
|
+
version: '3.6'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: tilt
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '2.
|
47
|
+
version: '2.3'
|
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: '2.
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rake
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '13.0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '13.0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rspec
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '3.12'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '3.12'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rubocop-rspec
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '2.22'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '2.22'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: standard
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '1.28'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '1.28'
|
54
|
+
version: '2.3'
|
111
55
|
description: A simple tool for building static websites.
|
112
56
|
email:
|
113
57
|
- d+dimples@waferbaby.com
|
@@ -118,20 +62,20 @@ extra_rdoc_files: []
|
|
118
62
|
files:
|
119
63
|
- bin/dimples
|
120
64
|
- lib/dimples.rb
|
121
|
-
- lib/dimples/
|
122
|
-
- lib/dimples/errors.rb
|
123
|
-
- lib/dimples/frontmatter.rb
|
124
|
-
- lib/dimples/page.rb
|
65
|
+
- lib/dimples/config.rb
|
125
66
|
- lib/dimples/pager.rb
|
126
|
-
- lib/dimples/post.rb
|
127
67
|
- lib/dimples/site.rb
|
128
|
-
- lib/dimples/
|
68
|
+
- lib/dimples/sources/base.rb
|
69
|
+
- lib/dimples/sources/layout.rb
|
70
|
+
- lib/dimples/sources/page.rb
|
71
|
+
- lib/dimples/sources/post.rb
|
129
72
|
- lib/dimples/version.rb
|
130
73
|
homepage: http://github.com/waferbaby/dimples
|
131
74
|
licenses:
|
132
75
|
- MIT
|
133
|
-
metadata:
|
134
|
-
|
76
|
+
metadata:
|
77
|
+
rubygems_mfa_required: 'true'
|
78
|
+
post_install_message:
|
135
79
|
rdoc_options: []
|
136
80
|
require_paths:
|
137
81
|
- lib
|
@@ -139,15 +83,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
139
83
|
requirements:
|
140
84
|
- - ">"
|
141
85
|
- !ruby/object:Gem::Version
|
142
|
-
version: '
|
86
|
+
version: '3.0'
|
143
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
88
|
requirements:
|
145
89
|
- - ">="
|
146
90
|
- !ruby/object:Gem::Version
|
147
91
|
version: '0'
|
148
92
|
requirements: []
|
149
|
-
rubygems_version: 3.
|
150
|
-
signing_key:
|
93
|
+
rubygems_version: 3.4.10
|
94
|
+
signing_key:
|
151
95
|
specification_version: 4
|
152
96
|
summary: A basic static site generator
|
153
97
|
test_files: []
|
data/lib/dimples/document.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "frontmatter"
|
4
|
-
|
5
|
-
module Dimples
|
6
|
-
class Document
|
7
|
-
attr_accessor :metadata, :contents, :path, :rendered_contents
|
8
|
-
|
9
|
-
def initialize(path = nil, metadata = {})
|
10
|
-
@path = path
|
11
|
-
|
12
|
-
if @path
|
13
|
-
@metadata, @contents = Dimples::FrontMatter.parse(File.read(path))
|
14
|
-
else
|
15
|
-
@metadata = {}
|
16
|
-
@contents = ""
|
17
|
-
end
|
18
|
-
|
19
|
-
@metadata.merge!(metadata)
|
20
|
-
end
|
21
|
-
|
22
|
-
def filename
|
23
|
-
"#{basename}.#{extension}"
|
24
|
-
end
|
25
|
-
|
26
|
-
def basename
|
27
|
-
@metadata.fetch(:filename, "index")
|
28
|
-
end
|
29
|
-
|
30
|
-
def extension
|
31
|
-
@metadata.fetch(:extension, "html")
|
32
|
-
end
|
33
|
-
|
34
|
-
def layout
|
35
|
-
@metadata.fetch(:layout, nil)
|
36
|
-
end
|
37
|
-
|
38
|
-
def render(context = {}, content = "")
|
39
|
-
context_obj = Object.new
|
40
|
-
context.each do |key, value|
|
41
|
-
context_obj.instance_variable_set("@#{key}", value)
|
42
|
-
end
|
43
|
-
|
44
|
-
@rendered_contents = renderer.render(context_obj) { content }
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def renderer
|
50
|
-
@renderer ||= begin
|
51
|
-
callback = proc { contents }
|
52
|
-
|
53
|
-
if @path
|
54
|
-
Tilt.new(@path, {}, &callback)
|
55
|
-
else
|
56
|
-
Tilt::StringTemplate.new(&callback)
|
57
|
-
end
|
58
|
-
end
|
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
|
68
|
-
end
|
69
|
-
end
|
data/lib/dimples/errors.rb
DELETED
data/lib/dimples/frontmatter.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "yaml"
|
4
|
-
|
5
|
-
module Dimples
|
6
|
-
module FrontMatter
|
7
|
-
PATTERN = /^(-{3}\n.*?\n?)^(-{3}*$\n?)/m.freeze
|
8
|
-
|
9
|
-
def self.parse(contents)
|
10
|
-
metadata = {}
|
11
|
-
|
12
|
-
if (matches = contents.match(PATTERN))
|
13
|
-
metadata = YAML.safe_load(matches[1], symbolize_names: true, permitted_classes: [Date])
|
14
|
-
contents = matches.post_match.strip
|
15
|
-
end
|
16
|
-
|
17
|
-
[metadata, contents]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/lib/dimples/page.rb
DELETED
data/lib/dimples/post.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "document"
|
4
|
-
|
5
|
-
require "date"
|
6
|
-
|
7
|
-
module Dimples
|
8
|
-
class Post < Document
|
9
|
-
def date
|
10
|
-
@metadata.fetch(:date, DateTime.now)
|
11
|
-
end
|
12
|
-
|
13
|
-
def layout
|
14
|
-
@metadata.fetch(:layout, "post")
|
15
|
-
end
|
16
|
-
|
17
|
-
def slug
|
18
|
-
File.basename(@path, ".markdown")
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|