dimples 10.1.4 → 10.3.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 +4 -4
- data/bin/dimples +3 -5
- data/lib/dimples/config.rb +16 -15
- data/lib/dimples/pager.rb +7 -9
- data/lib/dimples/site.rb +48 -25
- data/lib/dimples/sources/base.rb +12 -15
- data/lib/dimples/sources/page.rb +2 -2
- data/lib/dimples/sources/post.rb +2 -2
- data/lib/dimples/version.rb +1 -1
- metadata +3 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2f3ed77ff3e3b22b7b6698da3a659a250346ef631049636bed41726c460a7fb2
|
|
4
|
+
data.tar.gz: e8b5e726056c2786c548a22e478ef9094517870b6eb86bef30464cff0d5ba918
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 13ec6b697b2f9270abacb21836c515803b310398574d7fe7d4e57ba85fbc32e928268147bc96928efb0ea005344d7154fa55873c334829a9ef9e6d73d492d333
|
|
7
|
+
data.tar.gz: fcd634d9056027da441de34a1067a12f4e7122e54b164090a0fa48f396b3b622dec8d0165c3541b10990aba89dfacbc9768a181d07f45d876a95751e60eed5a0
|
data/bin/dimples
CHANGED
|
@@ -12,15 +12,13 @@ config = {}
|
|
|
12
12
|
if File.exist?(config_path)
|
|
13
13
|
config = begin
|
|
14
14
|
YAML.safe_load_file(config_path, symbolize_names: true)
|
|
15
|
-
rescue
|
|
16
|
-
puts
|
|
17
|
-
ensure
|
|
18
|
-
{}
|
|
15
|
+
rescue StandardError => e
|
|
16
|
+
puts "Failed to parse config #{e} - using defaults"
|
|
19
17
|
end
|
|
20
18
|
end
|
|
21
19
|
|
|
22
20
|
begin
|
|
23
|
-
Dimples::Site.generate(config)
|
|
21
|
+
Dimples::Site.generate(config:)
|
|
24
22
|
rescue StandardError => e
|
|
25
23
|
puts "Error generating site: #{e}"
|
|
26
24
|
end
|
data/lib/dimples/config.rb
CHANGED
|
@@ -3,31 +3,32 @@
|
|
|
3
3
|
module Dimples
|
|
4
4
|
# Configuration settings for a site.
|
|
5
5
|
class Config
|
|
6
|
+
SOURCE_PATHS = { pages: 'pages', posts: 'posts', layouts: 'layouts', static: 'static' }.freeze
|
|
7
|
+
|
|
8
|
+
attr_accessor :source_paths, :build_paths, :pagination
|
|
9
|
+
|
|
6
10
|
def self.defaults
|
|
7
11
|
{
|
|
8
|
-
|
|
9
|
-
|
|
12
|
+
build: './site',
|
|
13
|
+
source: Dir.pwd,
|
|
14
|
+
pathnames: { posts: 'posts', categories: 'categories' },
|
|
15
|
+
pagination: { page_prefix: 'page_', per_page: 5 }
|
|
10
16
|
}
|
|
11
17
|
end
|
|
12
18
|
|
|
13
19
|
def initialize(options = {})
|
|
14
|
-
|
|
20
|
+
options = Config.defaults.merge(options)
|
|
15
21
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
%i[sources output].each do |type|
|
|
21
|
-
@options[type].each { |key, value| @options[type][key] = File.expand_path(value) }
|
|
22
|
-
end
|
|
22
|
+
@source_paths = expand_paths(File.expand_path(options[:source]), SOURCE_PATHS.dup)
|
|
23
|
+
@build_paths = expand_paths(File.expand_path(options[:build]), options[:pathnames])
|
|
24
|
+
@pagination = options[:pagination]
|
|
23
25
|
end
|
|
24
26
|
|
|
25
|
-
def
|
|
26
|
-
|
|
27
|
-
end
|
|
27
|
+
def expand_paths(root, paths)
|
|
28
|
+
root = File.expand_path(root)
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
paths.transform_values! { |value| File.expand_path(File.join(root, value)) }
|
|
31
|
+
paths.tap { |expanded_paths| expanded_paths[:root] = root }
|
|
31
32
|
end
|
|
32
33
|
end
|
|
33
34
|
end
|
data/lib/dimples/pager.rb
CHANGED
|
@@ -3,23 +3,21 @@
|
|
|
3
3
|
module Dimples
|
|
4
4
|
# A class for paginating a collection of posts.
|
|
5
5
|
class Pager
|
|
6
|
-
PER_PAGE = 5
|
|
7
|
-
|
|
8
6
|
include Enumerable
|
|
9
7
|
|
|
10
8
|
attr_reader :current_page, :previous_page, :next_page, :page_count
|
|
11
9
|
|
|
12
|
-
def self.paginate(site
|
|
13
|
-
new(site
|
|
10
|
+
def self.paginate(site:, url:, posts:, metadata: {})
|
|
11
|
+
new(site:, url:, posts:).paginate(metadata)
|
|
14
12
|
end
|
|
15
13
|
|
|
16
|
-
def initialize(site
|
|
14
|
+
def initialize(site:, url:, posts:)
|
|
17
15
|
@site = site
|
|
18
16
|
@url = url
|
|
19
17
|
@posts = posts
|
|
20
18
|
|
|
21
|
-
@per_page = @site.config.
|
|
22
|
-
@page_prefix = @site.config.
|
|
19
|
+
@per_page = @site.config.pagination[:per_page]
|
|
20
|
+
@page_prefix = @site.config.pagination[:page_prefix]
|
|
23
21
|
@page_count = (posts.length.to_f / @per_page.to_i).ceil
|
|
24
22
|
|
|
25
23
|
step_to(1)
|
|
@@ -30,8 +28,8 @@ module Dimples
|
|
|
30
28
|
step_to(index)
|
|
31
29
|
|
|
32
30
|
@site.layouts['posts']&.write(
|
|
33
|
-
File.join(@site.config[:
|
|
34
|
-
metadata.merge(pagination: self.metadata, url: current_page_url)
|
|
31
|
+
output_path: File.join(@site.config.build_paths[:root], current_page_url, 'index.html'),
|
|
32
|
+
metadata: metadata.merge(pagination: self.metadata, url: current_page_url)
|
|
35
33
|
)
|
|
36
34
|
end
|
|
37
35
|
end
|
data/lib/dimples/site.rb
CHANGED
|
@@ -10,11 +10,11 @@ module Dimples
|
|
|
10
10
|
class Site
|
|
11
11
|
attr_accessor :config
|
|
12
12
|
|
|
13
|
-
def self.generate(config
|
|
14
|
-
new(config).generate
|
|
13
|
+
def self.generate(config: {})
|
|
14
|
+
new(config:).generate
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
def initialize(config
|
|
17
|
+
def initialize(config: {})
|
|
18
18
|
@config = Config.new(config)
|
|
19
19
|
end
|
|
20
20
|
|
|
@@ -29,20 +29,20 @@ module Dimples
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def posts
|
|
32
|
-
@posts ||= Dir.glob(File.join(@config[:
|
|
33
|
-
Dimples::Sources::Post.new(self, path)
|
|
32
|
+
@posts ||= Dir.glob(File.join(@config.source_paths[:posts], '**', '*.markdown')).map do |path|
|
|
33
|
+
Dimples::Sources::Post.new(site: self, path:)
|
|
34
34
|
end.sort_by!(&:date).reverse!
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def pages
|
|
38
|
-
@pages ||= Dir.glob(File.join(@config[:
|
|
39
|
-
Dimples::Sources::Page.new(self, path)
|
|
38
|
+
@pages ||= Dir.glob(File.join(@config.source_paths[:pages], '**', '*.erb')).map do |path|
|
|
39
|
+
Dimples::Sources::Page.new(site: self, path:)
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def layouts
|
|
44
|
-
@layouts ||= Dir.glob(File.join(@config[:
|
|
45
|
-
[File.basename(path, '.erb'), Dimples::Sources::Layout.new(self, path)]
|
|
44
|
+
@layouts ||= Dir.glob(File.join(@config.source_paths[:layouts], '**', '*.erb')).to_h do |path|
|
|
45
|
+
[File.basename(path, '.erb'), Dimples::Sources::Layout.new(site: self, path:)]
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
|
|
@@ -64,42 +64,65 @@ module Dimples
|
|
|
64
64
|
private
|
|
65
65
|
|
|
66
66
|
def generate_posts
|
|
67
|
-
posts.each(
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
posts.each { |post| generate_post(post) }
|
|
68
|
+
|
|
69
|
+
Pager.paginate(
|
|
70
|
+
site: self,
|
|
71
|
+
url: @config.build_paths[:posts].gsub(@config.build_paths[:root], '').concat('/'),
|
|
72
|
+
posts:
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
generate_feed(output_path: @config.build_paths[:root], posts:)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def generate_post(post)
|
|
79
|
+
post.write
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def generate_pages
|
|
83
|
+
pages.each { |page| generate_page(page) }
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def generate_page(page)
|
|
87
|
+
page.write
|
|
70
88
|
end
|
|
71
89
|
|
|
72
90
|
def generate_categories
|
|
73
91
|
categories.each do |category, posts|
|
|
74
92
|
metadata = { title: category.capitalize, category: category }
|
|
75
|
-
Pager.paginate(self, "/categories/#{category}/", posts, metadata)
|
|
76
|
-
generate_feed(File.join(@config[:output][:root], 'categories', category), posts)
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
93
|
|
|
80
|
-
|
|
81
|
-
|
|
94
|
+
Pager.paginate(
|
|
95
|
+
site: self,
|
|
96
|
+
url: "/categories/#{category}/",
|
|
97
|
+
posts:,
|
|
98
|
+
metadata:
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
generate_feed(output_path: File.join(@config.build_paths[:root], 'categories', category), posts:)
|
|
102
|
+
end
|
|
82
103
|
end
|
|
83
104
|
|
|
84
|
-
def generate_feed(output_path
|
|
105
|
+
def generate_feed(output_path:, posts:)
|
|
85
106
|
return if layouts['feed'].nil?
|
|
86
107
|
|
|
87
108
|
layouts['feed'].write(
|
|
88
|
-
File.join(output_path, 'feed.atom'),
|
|
89
|
-
posts: posts.slice(0, 10)
|
|
109
|
+
output_path: File.join(output_path, 'feed.atom'),
|
|
110
|
+
metadata: { posts: posts.slice(0, 10) }
|
|
90
111
|
)
|
|
91
112
|
end
|
|
92
113
|
|
|
93
114
|
def prepare_output_directory
|
|
94
|
-
|
|
115
|
+
if Dir.exist?(@config.build_paths[:root])
|
|
116
|
+
raise "The site directory (#{@config.build_paths[:root]}) already exists."
|
|
117
|
+
end
|
|
95
118
|
|
|
96
|
-
Dir.mkdir(@config[:
|
|
119
|
+
Dir.mkdir(@config.build_paths[:root])
|
|
97
120
|
end
|
|
98
121
|
|
|
99
122
|
def copy_assets
|
|
100
|
-
return unless Dir.exist?(@config[:
|
|
123
|
+
return unless Dir.exist?(@config.source_paths[:static])
|
|
101
124
|
|
|
102
|
-
FileUtils.cp_r(File.join(@config[:
|
|
125
|
+
FileUtils.cp_r(File.join(@config.source_paths[:static], '.'), @config.build_paths[:root])
|
|
103
126
|
end
|
|
104
127
|
end
|
|
105
128
|
end
|
data/lib/dimples/sources/base.rb
CHANGED
|
@@ -8,59 +8,56 @@ module Dimples
|
|
|
8
8
|
|
|
9
9
|
attr_accessor :path, :metadata, :contents
|
|
10
10
|
|
|
11
|
-
def initialize(site
|
|
11
|
+
def initialize(site:, path:)
|
|
12
12
|
@site = site
|
|
13
13
|
@path = File.expand_path(path)
|
|
14
|
-
|
|
15
|
-
@metadata = default_metadata
|
|
16
14
|
@contents = File.read(@path)
|
|
17
15
|
|
|
18
16
|
parse_metadata(@contents)
|
|
19
|
-
assign_metadata
|
|
20
17
|
end
|
|
21
18
|
|
|
22
19
|
def parse_metadata(contents)
|
|
20
|
+
@metadata = default_metadata
|
|
21
|
+
|
|
23
22
|
matches = contents.match(FRONT_MATTER_PATTERN)
|
|
24
23
|
return unless matches
|
|
25
24
|
|
|
26
25
|
@metadata.merge!(YAML.safe_load(matches[1], symbolize_names: true, permitted_classes: [Date]))
|
|
27
26
|
@contents = matches.post_match.strip
|
|
28
|
-
end
|
|
29
27
|
|
|
30
|
-
def assign_metadata
|
|
31
28
|
@metadata.each_key do |key|
|
|
32
29
|
self.class.send(:define_method, key.to_sym) { @metadata[key] }
|
|
33
30
|
end
|
|
34
31
|
end
|
|
35
32
|
|
|
36
|
-
def write(output_path
|
|
33
|
+
def write(output_path: nil, metadata: {})
|
|
37
34
|
output_path = File.join(output_directory, filename) if output_path.nil?
|
|
38
35
|
output_dir = File.dirname(output_path)
|
|
39
36
|
|
|
40
37
|
@metadata[:url] = url_for(output_dir)
|
|
41
38
|
|
|
42
|
-
output = render(metadata)
|
|
39
|
+
output = render(context: metadata)
|
|
43
40
|
|
|
44
41
|
FileUtils.mkdir_p(output_dir) unless File.directory?(output_dir)
|
|
45
42
|
File.write(output_path, output)
|
|
46
43
|
end
|
|
47
44
|
|
|
48
|
-
def render(
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
def render(context: {}, body: nil)
|
|
46
|
+
context[:site] ||= @site.metadata
|
|
47
|
+
context[:page] ||= metadata
|
|
51
48
|
|
|
52
|
-
output = template.render(Metadata.new(
|
|
49
|
+
output = template.render(Metadata.new(context)) { body }
|
|
53
50
|
return output unless @metadata[:layout] && @site.layouts[@metadata[:layout]]
|
|
54
51
|
|
|
55
|
-
@site.layouts[@metadata[:layout]].render(
|
|
52
|
+
@site.layouts[@metadata[:layout]].render(context:, body: output)
|
|
56
53
|
end
|
|
57
54
|
|
|
58
55
|
def output_directory
|
|
59
|
-
@site.config[:
|
|
56
|
+
@site.config.build_paths[:root]
|
|
60
57
|
end
|
|
61
58
|
|
|
62
59
|
def url_for(path)
|
|
63
|
-
path.gsub(@site.config[:
|
|
60
|
+
path.gsub(@site.config.build_paths[:root], '').concat('/')
|
|
64
61
|
end
|
|
65
62
|
|
|
66
63
|
def template
|
data/lib/dimples/sources/page.rb
CHANGED
|
@@ -6,8 +6,8 @@ module Dimples
|
|
|
6
6
|
class Page < Base
|
|
7
7
|
def output_directory
|
|
8
8
|
@output_directory ||= File.dirname(@path).gsub(
|
|
9
|
-
@site.config[:
|
|
10
|
-
@site.config[:
|
|
9
|
+
@site.config.source_paths[:pages],
|
|
10
|
+
@site.config.build_paths[:root]
|
|
11
11
|
).concat('/')
|
|
12
12
|
end
|
|
13
13
|
|
data/lib/dimples/sources/post.rb
CHANGED
|
@@ -6,8 +6,8 @@ module Dimples
|
|
|
6
6
|
class Post < Base
|
|
7
7
|
def output_directory
|
|
8
8
|
@output_directory ||= File.dirname(@path).gsub(
|
|
9
|
-
@site.config[:
|
|
10
|
-
@site.config[:
|
|
9
|
+
@site.config.source_paths[:posts],
|
|
10
|
+
@site.config.build_paths[:posts]
|
|
11
11
|
).concat("/#{slug}/")
|
|
12
12
|
end
|
|
13
13
|
|
data/lib/dimples/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dimples
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 10.
|
|
4
|
+
version: 10.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel Bogan
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: erb
|
|
@@ -76,7 +75,6 @@ licenses:
|
|
|
76
75
|
- MIT
|
|
77
76
|
metadata:
|
|
78
77
|
rubygems_mfa_required: 'true'
|
|
79
|
-
post_install_message:
|
|
80
78
|
rdoc_options: []
|
|
81
79
|
require_paths:
|
|
82
80
|
- lib
|
|
@@ -91,8 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
91
89
|
- !ruby/object:Gem::Version
|
|
92
90
|
version: '0'
|
|
93
91
|
requirements: []
|
|
94
|
-
rubygems_version: 3.
|
|
95
|
-
signing_key:
|
|
92
|
+
rubygems_version: 3.6.7
|
|
96
93
|
specification_version: 4
|
|
97
94
|
summary: A basic static site generator
|
|
98
95
|
test_files: []
|