dimples 7.0.5 → 9.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 +21 -8
- data/lib/dimples/document.rb +5 -5
- data/lib/dimples/errors.rb +12 -0
- data/lib/dimples/frontmatter.rb +1 -1
- data/lib/dimples/page.rb +1 -1
- data/lib/dimples/pager.rb +4 -4
- data/lib/dimples/post.rb +4 -4
- data/lib/dimples/site.rb +58 -53
- data/lib/dimples/template.rb +1 -1
- data/lib/dimples/version.rb +1 -1
- data/lib/dimples.rb +5 -4
- metadata +35 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca018b45bc347dc68c099d77fe18cba848f878c9c79dd4cd094b7a84db01cb37
|
4
|
+
data.tar.gz: 10e92c94c701b63a2d2d1c4c66087605b29b82f37d6f6bf99f5a5cf8f0b7ccf5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29f96b52b84bcbc10cf7d46779573d87fb7ea6918d4767c0686e1eb98e079cfee9bae15859b793421375eb898e36eaadbc081814a82c87c9f948c1e5b0ab6cb8
|
7
|
+
data.tar.gz: 730b91d62a8b121b0a43ba5d3e1183600381335195dc49934414dc06f3df75ffe1be458e960cc9e756259160f6a39dc34b3ca34a62e84983365769c4b1e0ed6e
|
data/bin/dimples
CHANGED
@@ -1,14 +1,27 @@
|
|
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
|
6
|
+
require "dimples"
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
else
|
11
|
-
File.join(Dir.pwd, 'site')
|
12
|
-
end
|
8
|
+
source_path = ARGV[0]
|
9
|
+
output_path = ARGV[1]
|
13
10
|
|
14
|
-
|
11
|
+
config_path = File.join(Dir.pwd, "config.yml")
|
12
|
+
|
13
|
+
config = {}
|
14
|
+
|
15
|
+
if File.exist?(config_path)
|
16
|
+
begin
|
17
|
+
config = YAML.safe_load(File.read(config_path), symbolize_names: true)
|
18
|
+
rescue YAML::Error
|
19
|
+
puts "Error reading config file - reverting to defaults"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
begin
|
24
|
+
Dimples::Site.generate(source_path, output_path, config)
|
25
|
+
rescue Dimples::Error => error
|
26
|
+
puts "Error: #{error.message}"
|
27
|
+
end
|
data/lib/dimples/document.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "frontmatter"
|
4
4
|
|
5
5
|
module Dimples
|
6
6
|
class Document
|
@@ -13,7 +13,7 @@ module Dimples
|
|
13
13
|
@metadata, @contents = Dimples::FrontMatter.parse(File.read(path))
|
14
14
|
else
|
15
15
|
@metadata = {}
|
16
|
-
@contents =
|
16
|
+
@contents = ""
|
17
17
|
end
|
18
18
|
|
19
19
|
@metadata.merge!(metadata)
|
@@ -24,18 +24,18 @@ module Dimples
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def basename
|
27
|
-
@metadata.fetch(:filename,
|
27
|
+
@metadata.fetch(:filename, "index")
|
28
28
|
end
|
29
29
|
|
30
30
|
def extension
|
31
|
-
@metadata.fetch(:extension,
|
31
|
+
@metadata.fetch(:extension, "html")
|
32
32
|
end
|
33
33
|
|
34
34
|
def layout
|
35
35
|
@metadata.fetch(:layout, nil)
|
36
36
|
end
|
37
37
|
|
38
|
-
def render(context = {}, content =
|
38
|
+
def render(context = {}, content = "")
|
39
39
|
context_obj = Object.new
|
40
40
|
context.each do |key, value|
|
41
41
|
context_obj.instance_variable_set("@#{key}", value)
|
data/lib/dimples/frontmatter.rb
CHANGED
data/lib/dimples/page.rb
CHANGED
data/lib/dimples/pager.rb
CHANGED
@@ -12,7 +12,7 @@ module Dimples
|
|
12
12
|
@url = url
|
13
13
|
@posts = posts
|
14
14
|
@per_page = options.fetch(:per_page, PER_PAGE)
|
15
|
-
@page_prefix = options.fetch(:page_prefix,
|
15
|
+
@page_prefix = options.fetch(:page_prefix, "page_")
|
16
16
|
@page_count = (posts.length.to_f / @per_page.to_i).ceil
|
17
17
|
|
18
18
|
step_to(1)
|
@@ -43,7 +43,7 @@ module Dimples
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def current_page_url
|
46
|
-
@current_page != 1 ? "#{@url}#{@page_prefix}#{@current_page}" : @url
|
46
|
+
(@current_page != 1) ? "#{@url}#{@page_prefix}#{@current_page}" : @url
|
47
47
|
end
|
48
48
|
|
49
49
|
def first_page_url
|
@@ -51,13 +51,13 @@ module Dimples
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def last_page_url
|
54
|
-
@page_count != 1 ? "#{@url}#{@page_prefix}#{@page_count}" : @url
|
54
|
+
(@page_count != 1) ? "#{@url}#{@page_prefix}#{@page_count}" : @url
|
55
55
|
end
|
56
56
|
|
57
57
|
def previous_page_url
|
58
58
|
return unless @previous_page
|
59
59
|
|
60
|
-
@previous_page != 1 ? "#{@url}#{@page_prefix}#{@previous_page}" : @url
|
60
|
+
(@previous_page != 1) ? "#{@url}#{@page_prefix}#{@previous_page}" : @url
|
61
61
|
end
|
62
62
|
|
63
63
|
def next_page_url
|
data/lib/dimples/post.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "document"
|
4
4
|
|
5
|
-
require
|
5
|
+
require "date"
|
6
6
|
|
7
7
|
module Dimples
|
8
8
|
class Post < Document
|
@@ -11,11 +11,11 @@ module Dimples
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def layout
|
14
|
-
@metadata.fetch(:layout,
|
14
|
+
@metadata.fetch(:layout, "post")
|
15
15
|
end
|
16
16
|
|
17
17
|
def slug
|
18
|
-
File.basename(@path,
|
18
|
+
File.basename(@path, ".markdown")
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
data/lib/dimples/site.rb
CHANGED
@@ -1,28 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "pager"
|
4
4
|
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
5
|
+
require "fileutils"
|
6
|
+
require "tilt"
|
7
|
+
require "date"
|
8
8
|
|
9
9
|
module Dimples
|
10
10
|
class Site
|
11
|
-
|
12
|
-
|
11
|
+
DEFAULT_CONFIG = { generation: { overwrite_directory: false }, paths: { posts: "posts" } }
|
12
|
+
|
13
|
+
def self.generate(source_path, output_path, config)
|
14
|
+
new(source_path, output_path, config).generate
|
13
15
|
end
|
14
16
|
|
15
|
-
attr_accessor :posts, :categories
|
17
|
+
attr_accessor :posts, :pages, :categories, :config
|
16
18
|
|
17
|
-
def initialize(output_path)
|
19
|
+
def initialize(source_path, output_path, config)
|
18
20
|
@paths = {
|
19
|
-
source: File.expand_path(Dir.pwd),
|
20
|
-
destination: File.expand_path(output_path)
|
21
|
+
source: File.expand_path(source_path || Dir.pwd),
|
22
|
+
destination: File.expand_path(output_path || File.join(Dir.pwd, "site"))
|
21
23
|
}
|
22
24
|
|
23
|
-
@config =
|
25
|
+
@config = DEFAULT_CONFIG
|
26
|
+
@config.merge!(config) if config&.is_a?(Hash)
|
24
27
|
|
25
|
-
%w[pages posts static templates].each
|
28
|
+
%w[pages posts static templates].each do |type|
|
29
|
+
@paths[type.to_sym] = File.join(@paths[:source], type)
|
30
|
+
end
|
26
31
|
|
27
32
|
scan_posts
|
28
33
|
scan_pages
|
@@ -31,8 +36,11 @@ module Dimples
|
|
31
36
|
|
32
37
|
def generate
|
33
38
|
if Dir.exist?(@paths[:destination])
|
34
|
-
|
35
|
-
|
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])
|
36
44
|
end
|
37
45
|
|
38
46
|
Dir.mkdir(@paths[:destination])
|
@@ -46,16 +54,8 @@ module Dimples
|
|
46
54
|
|
47
55
|
private
|
48
56
|
|
49
|
-
def read_config
|
50
|
-
config_path = File.join(@paths[:source], '.config')
|
51
|
-
|
52
|
-
return {} unless File.exist?(config_path)
|
53
|
-
|
54
|
-
YAML.safe_load(File.read(config_path), symbolize_names: true)
|
55
|
-
end
|
56
|
-
|
57
57
|
def read_files(path)
|
58
|
-
Dir[File.join(path,
|
58
|
+
Dir[File.join(path, "**", "*.*")].sort
|
59
59
|
end
|
60
60
|
|
61
61
|
def scan_posts
|
@@ -65,7 +65,7 @@ module Dimples
|
|
65
65
|
@categories = {}
|
66
66
|
|
67
67
|
@posts.each do |post|
|
68
|
-
post.categories
|
68
|
+
post.categories&.each do |category|
|
69
69
|
@categories[category] ||= []
|
70
70
|
@categories[category] << post
|
71
71
|
end
|
@@ -73,18 +73,17 @@ module Dimples
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def scan_pages
|
76
|
-
@pages = read_files(@paths[:pages]).map
|
77
|
-
Dimples::Page.new(path)
|
78
|
-
end
|
76
|
+
@pages = read_files(@paths[:pages]).map { |path| Dimples::Page.new(path) }
|
79
77
|
end
|
80
78
|
|
81
79
|
def scan_templates
|
82
|
-
@templates =
|
83
|
-
|
84
|
-
|
85
|
-
|
80
|
+
@templates =
|
81
|
+
{}.tap do |templates|
|
82
|
+
read_files(@paths[:templates]).each do |path|
|
83
|
+
key = File.basename(path, ".erb")
|
84
|
+
templates[key] = Dimples::Template.new(path)
|
85
|
+
end
|
86
86
|
end
|
87
|
-
end
|
88
87
|
end
|
89
88
|
|
90
89
|
def write_file(path, content)
|
@@ -95,23 +94,27 @@ module Dimples
|
|
95
94
|
end
|
96
95
|
|
97
96
|
def generate_paginated_posts(posts, path, context = {})
|
98
|
-
pager = Dimples::Pager.new("#{path.sub(@paths[:destination],
|
97
|
+
pager = Dimples::Pager.new("#{path.sub(@paths[:destination], "")}/", posts)
|
99
98
|
|
100
99
|
pager.each do |index|
|
101
|
-
page = Dimples::Page.new(nil, layout:
|
102
|
-
|
103
|
-
page_path =
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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
|
+
)
|
110
113
|
end
|
111
114
|
end
|
112
115
|
|
113
116
|
def generate_posts
|
114
|
-
directory_path = File.join(@paths[:destination], @config.dig(:paths, :posts)
|
117
|
+
directory_path = File.join(@paths[:destination], @config.dig(:paths, :posts))
|
115
118
|
Dir.mkdir(directory_path)
|
116
119
|
|
117
120
|
@posts.each do |post|
|
@@ -125,11 +128,12 @@ module Dimples
|
|
125
128
|
|
126
129
|
def generate_pages
|
127
130
|
@pages.each do |page|
|
128
|
-
path =
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
131
|
+
path =
|
132
|
+
if page.path
|
133
|
+
File.dirname(page.path).sub(@paths[:pages], @paths[:destination])
|
134
|
+
else
|
135
|
+
@paths[:destination]
|
136
|
+
end
|
133
137
|
|
134
138
|
write_file(File.join(path, page.filename), render(page, page: page))
|
135
139
|
end
|
@@ -137,7 +141,7 @@ module Dimples
|
|
137
141
|
|
138
142
|
def generate_categories
|
139
143
|
@categories.each do |category, posts|
|
140
|
-
category_path = File.join(@paths[:destination],
|
144
|
+
category_path = File.join(@paths[:destination], "categories", category)
|
141
145
|
|
142
146
|
generate_paginated_posts(posts, category_path, category: category)
|
143
147
|
generate_feed(posts.slice(0, 10), category_path)
|
@@ -145,14 +149,14 @@ module Dimples
|
|
145
149
|
end
|
146
150
|
|
147
151
|
def generate_feed(posts, path)
|
148
|
-
page = Dimples::Page.new(nil, layout:
|
149
|
-
write_file(File.join(path,
|
152
|
+
page = Dimples::Page.new(nil, layout: "feed")
|
153
|
+
write_file(File.join(path, "feed.atom"), render(page, posts: posts))
|
150
154
|
end
|
151
155
|
|
152
156
|
def copy_assets
|
153
157
|
return unless Dir.exist?(@paths[:static])
|
154
158
|
|
155
|
-
FileUtils.cp_r(File.join(@paths[:static],
|
159
|
+
FileUtils.cp_r(File.join(@paths[:static], "."), @paths[:destination])
|
156
160
|
end
|
157
161
|
|
158
162
|
def render(object, context = {}, content = nil)
|
@@ -160,7 +164,8 @@ module Dimples
|
|
160
164
|
|
161
165
|
output = object.render(context, content)
|
162
166
|
|
163
|
-
output = render(@templates[object.layout], context, output) if object.layout &&
|
167
|
+
output = render(@templates[object.layout], context, output) if object.layout &&
|
168
|
+
@templates[object.layout]
|
164
169
|
|
165
170
|
output
|
166
171
|
end
|
data/lib/dimples/template.rb
CHANGED
data/lib/dimples/version.rb
CHANGED
data/lib/dimples.rb
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
$LOAD_PATH.unshift(__dir__)
|
4
4
|
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
5
|
+
require "dimples/errors"
|
6
|
+
require "dimples/page"
|
7
|
+
require "dimples/post"
|
8
|
+
require "dimples/template"
|
9
|
+
require "dimples/site"
|
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: 9.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: 2023-
|
11
|
+
date: 2023-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erubi
|
@@ -58,28 +58,56 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '13.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: '13.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '3.
|
75
|
+
version: '3.12'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '3.
|
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'
|
83
111
|
description: A simple tool for building static websites.
|
84
112
|
email:
|
85
113
|
- d+dimples@waferbaby.com
|
@@ -91,6 +119,7 @@ files:
|
|
91
119
|
- bin/dimples
|
92
120
|
- lib/dimples.rb
|
93
121
|
- lib/dimples/document.rb
|
122
|
+
- lib/dimples/errors.rb
|
94
123
|
- lib/dimples/frontmatter.rb
|
95
124
|
- lib/dimples/page.rb
|
96
125
|
- lib/dimples/pager.rb
|