dimples 2.1.0 → 2.2.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 +32 -14
- data/lib/dimples/errors.rb +3 -9
- data/lib/dimples/logger.rb +8 -1
- data/lib/dimples/renderable.rb +6 -2
- data/lib/dimples/site.rb +14 -34
- data/lib/dimples/version.rb +1 -1
- data/lib/dimples/writeable.rb +4 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 08b81d38a02d31e703220e8da704b1c5a907023f
|
4
|
+
data.tar.gz: 77dbd35e0466ae3af0ea1e43d52a97c0a10cfff3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e9012866a9d7f93efedf32d4d7047cfda09e0dcd69f984a39f575b8d0c617a1677e7cadf24e81b09a1ffb416d5da1bc94cf042732c5016199b45bb3c899b961
|
7
|
+
data.tar.gz: 69cb4cb077aa8ac22cb63396d2505dc3d2e6171443576c4ae552532a12a10bd4e91ece3aa2717f7473430464ead1f6fe89c1b268a8d794a762832ef8fc0b025c
|
data/bin/dimples
CHANGED
@@ -4,6 +4,11 @@ require 'dimples'
|
|
4
4
|
require 'dimples/version'
|
5
5
|
require 'trollop'
|
6
6
|
|
7
|
+
trap('SIGINT') do
|
8
|
+
puts "Generation cancelled!"
|
9
|
+
exit!
|
10
|
+
end
|
11
|
+
|
7
12
|
valid_commands = %w[build]
|
8
13
|
|
9
14
|
options = Trollop::options do
|
@@ -16,7 +21,7 @@ Usage:
|
|
16
21
|
|
17
22
|
Options:
|
18
23
|
EOS
|
19
|
-
opt :config, "Config file path",
|
24
|
+
opt :config, "Config file path", type: :string
|
20
25
|
opt :lib, "Library file path", default: 'lib'
|
21
26
|
opt :verbose, "Verbose mode", default: false
|
22
27
|
end
|
@@ -28,32 +33,45 @@ unless valid_commands.include?(command)
|
|
28
33
|
Trollop::die "Command must be '#{valid_commands.join('\', \'')}'"
|
29
34
|
end
|
30
35
|
|
31
|
-
config_path = File.join(Dir.pwd, options[:config])
|
32
36
|
lib_path = File.join(Dir.pwd, options[:lib])
|
37
|
+
config_path = File.join(Dir.pwd, options[:config] || 'config', 'site.yml')
|
33
38
|
|
34
|
-
|
35
|
-
|
39
|
+
if File.exist?(config_path)
|
40
|
+
begin
|
41
|
+
config_hash = YAML.load_file(config_path)
|
42
|
+
rescue
|
43
|
+
Trollop::die "Invalid or malformed YAML config file"
|
44
|
+
end
|
45
|
+
else
|
46
|
+
Trollop::die "Unable to find config file" if options[:config]
|
47
|
+
config_hash = {}
|
36
48
|
end
|
37
49
|
|
50
|
+
config_hash['verbose_logging'] = true if options[:verbose]
|
51
|
+
config = Dimples::Configuration.new(config_hash)
|
52
|
+
|
38
53
|
if Dir.exist?(lib_path)
|
39
54
|
Dir.glob(File.join(lib_path, '**', '*')) do |path|
|
40
55
|
require path
|
41
56
|
end
|
42
57
|
end
|
43
58
|
|
44
|
-
begin
|
45
|
-
config_hash = YAML.load_file(config_path)
|
46
|
-
config_hash['verbose_logging'] = true if options[:verbose]
|
47
|
-
|
48
|
-
config = Dimples::Configuration.new(config_hash)
|
49
|
-
rescue
|
50
|
-
Trollop::die "Invalid or malformed YAML config file"
|
51
|
-
end
|
52
|
-
|
53
59
|
site_klass = config.class_override(:site) || Dimples::Site
|
54
60
|
site = site_klass.new(config)
|
55
61
|
|
56
62
|
case command.to_sym
|
57
63
|
when :build
|
58
|
-
site.
|
64
|
+
Dimples.logger.info("Building site at #{site.output_paths[:site]}...")
|
65
|
+
|
66
|
+
result = Benchmark.measure do
|
67
|
+
site.generate
|
68
|
+
end
|
69
|
+
|
70
|
+
generation_time = result.real.round(2)
|
71
|
+
|
72
|
+
message = "\033[92mDone!\033[0m Site built in #{generation_time} second"
|
73
|
+
message += 's' if generation_time != 1
|
74
|
+
message += '.'
|
75
|
+
|
76
|
+
Dimples.logger.info(message)
|
59
77
|
end
|
data/lib/dimples/errors.rb
CHANGED
@@ -1,18 +1,12 @@
|
|
1
1
|
module Dimples
|
2
2
|
module Errors
|
3
|
-
class
|
4
|
-
attr_reader :file
|
5
|
-
|
6
|
-
def initialize(file, message)
|
7
|
-
@file = file
|
8
|
-
super(message)
|
9
|
-
end
|
3
|
+
class PublishingError < StandardError
|
10
4
|
end
|
11
5
|
|
12
|
-
class
|
6
|
+
class RenderingError < StandardError
|
13
7
|
end
|
14
8
|
|
15
|
-
class
|
9
|
+
class GenerationError < StandardError
|
16
10
|
end
|
17
11
|
end
|
18
12
|
end
|
data/lib/dimples/logger.rb
CHANGED
@@ -16,7 +16,14 @@ module Dimples
|
|
16
16
|
|
17
17
|
class LogFormatter < Logger::Formatter
|
18
18
|
def self.call(severity, time, program_name, message)
|
19
|
-
|
19
|
+
prefix = case severity
|
20
|
+
when "ERROR"
|
21
|
+
"\033[31mError:\033[0m "
|
22
|
+
when 'DEBUG'
|
23
|
+
"\033[93m- "
|
24
|
+
end
|
25
|
+
|
26
|
+
"#{prefix}#{message}\033[0m\n"
|
20
27
|
end
|
21
28
|
end
|
22
29
|
end
|
data/lib/dimples/renderable.rb
CHANGED
@@ -5,8 +5,12 @@ module Dimples
|
|
5
5
|
output = renderer.render(build_scope(context)) { body }.strip
|
6
6
|
@rendered_contents = output
|
7
7
|
rescue RuntimeError, TypeError, NoMethodError, SyntaxError, NameError => e
|
8
|
-
file = @path || "dynamic #{self.class}"
|
9
|
-
|
8
|
+
file = @path || "a dynamic #{self.class}"
|
9
|
+
|
10
|
+
error_message = "Unable to render #{file}"
|
11
|
+
error_message << " (#{e.message})" if @site.config['verbose_logging']
|
12
|
+
|
13
|
+
raise Errors::RenderingError.new(e.message)
|
10
14
|
end
|
11
15
|
|
12
16
|
if use_layout && defined?(@layout) && @site.templates[@layout]
|
data/lib/dimples/site.rb
CHANGED
@@ -43,26 +43,12 @@ module Dimples
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def generate
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
copy_assets
|
53
|
-
end
|
54
|
-
|
55
|
-
generation_time = result.real.round(2)
|
56
|
-
|
57
|
-
message = "Done! Site built in #{generation_time} second"
|
58
|
-
message += 's' if generation_time != 1
|
59
|
-
message += '.'
|
60
|
-
|
61
|
-
Dimples.logger.info(message)
|
62
|
-
rescue Errors::RenderingError => e
|
63
|
-
Dimples.logger.error("Failed to render #{e.file}: #{e.message}")
|
64
|
-
rescue Errors::PublishingError => e
|
65
|
-
Dimples.logger.error("Failed to publish #{e.file}: #{e.message}")
|
46
|
+
prepare_output_directory
|
47
|
+
scan_files
|
48
|
+
generate_files
|
49
|
+
copy_assets
|
50
|
+
rescue Errors::RenderingError, Errors::PublishingError, Errors::GenerationError => e
|
51
|
+
Dimples.logger.error("Failed to generate the site: #{e.message}.")
|
66
52
|
end
|
67
53
|
|
68
54
|
private
|
@@ -74,7 +60,10 @@ module Dimples
|
|
74
60
|
|
75
61
|
Dir.mkdir(@output_paths[:site])
|
76
62
|
rescue => e
|
77
|
-
|
63
|
+
error_message = "Couldn't prepare the output directory"
|
64
|
+
error_message << " (#{e.message})" if @config['verbose_logging']
|
65
|
+
|
66
|
+
raise Errors::GenerationError(error_message)
|
78
67
|
end
|
79
68
|
|
80
69
|
def scan_files
|
@@ -86,7 +75,6 @@ module Dimples
|
|
86
75
|
def scan_templates
|
87
76
|
Dir.glob(File.join(@source_paths[:templates], '**', '*.*')).each do |path|
|
88
77
|
template = Dimples::Template.new(self, path)
|
89
|
-
prepare_template(template)
|
90
78
|
@templates[template.slug] = template
|
91
79
|
end
|
92
80
|
end
|
@@ -94,7 +82,6 @@ module Dimples
|
|
94
82
|
def scan_pages
|
95
83
|
Dir.glob(File.join(@source_paths[:pages], '**', '*.*')).each do |path|
|
96
84
|
page = @page_class.new(self, path)
|
97
|
-
prepare_page(page)
|
98
85
|
@pages << page
|
99
86
|
end
|
100
87
|
end
|
@@ -102,7 +89,6 @@ module Dimples
|
|
102
89
|
def scan_posts
|
103
90
|
Dir.glob(File.join(@source_paths[:posts], '*.*')).reverse_each do |path|
|
104
91
|
post = @post_class.new(self, path)
|
105
|
-
prepare_post(post)
|
106
92
|
|
107
93
|
next if post.draft
|
108
94
|
|
@@ -147,15 +133,6 @@ module Dimples
|
|
147
133
|
@archives[:day]["#{year}/#{month}/#{day}"] ||= []
|
148
134
|
end
|
149
135
|
|
150
|
-
def prepare_template(template)
|
151
|
-
end
|
152
|
-
|
153
|
-
def prepare_page(page)
|
154
|
-
end
|
155
|
-
|
156
|
-
def prepare_post(post)
|
157
|
-
end
|
158
|
-
|
159
136
|
def generate_files
|
160
137
|
generate_posts
|
161
138
|
generate_pages
|
@@ -276,7 +253,10 @@ module Dimples
|
|
276
253
|
FileUtils.cp_r(path, @output_paths[:site])
|
277
254
|
end
|
278
255
|
rescue => e
|
279
|
-
|
256
|
+
error_message = "Site assets failed to copy"
|
257
|
+
error_message << " (#{e.message})" if @config['verbose_logging']
|
258
|
+
|
259
|
+
raise Errors::GenerationError.new(error_message)
|
280
260
|
end
|
281
261
|
|
282
262
|
def paginate(posts:, title: nil, paths:, layout: false, context: {})
|
data/lib/dimples/version.rb
CHANGED
data/lib/dimples/writeable.rb
CHANGED
@@ -11,7 +11,10 @@ module Dimples
|
|
11
11
|
file.write(output)
|
12
12
|
end
|
13
13
|
rescue SystemCallError => e
|
14
|
-
|
14
|
+
error_message = "Failed to write #{path}"
|
15
|
+
error_message << " (#{e.message})" if @site.config['verbose_logging']
|
16
|
+
|
17
|
+
raise Errors::PublishingError.new(error_message)
|
15
18
|
end
|
16
19
|
end
|
17
20
|
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: 2.
|
4
|
+
version: 2.2.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: 2017-03-
|
11
|
+
date: 2017-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tilt
|