glim 0.1.4 → 0.1.5
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/glim +35 -18
- data/lib/commands.rb +16 -6
- data/lib/liquid_ext.rb +33 -29
- data/lib/local_server.rb +1 -1
- data/lib/log_and_profile.rb +2 -2
- data/lib/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01bacc2f65ddafb3ecb82c6b1fed2931b6e48ded35fbd417c83e1a650076dd6f
|
4
|
+
data.tar.gz: 5353e5cdc32103ce3b372738cba0df2beeaef36559255d38ede8186bfe420d33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22c5bf3b00f89abeabad4dcfcb94023fdd1b206258d4c060a117c94a5326d014f618031c00050c5e80408e3077944d239c1befc593d7840a932ef0c36c459d25
|
7
|
+
data.tar.gz: dfd1a77d34431cff2c0d0ed566f60c9ce59250f9ca9a39b4938b9c7f0a04b97fd44709c9aff970087294ec31a87bc47020587b91259873fab961a2ca11098139
|
data/bin/glim
CHANGED
@@ -19,8 +19,8 @@ require 'mercenary'
|
|
19
19
|
if File.exists?('Gemfile')
|
20
20
|
begin
|
21
21
|
require 'bundler/setup'
|
22
|
-
rescue LoadError
|
23
|
-
$log.warn("Unable to load Bundler
|
22
|
+
rescue LoadError
|
23
|
+
$log.warn("Unable to load Bundler: Ignoring ./Gemfile")
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -51,9 +51,13 @@ module Util
|
|
51
51
|
|
52
52
|
def titlecase(input)
|
53
53
|
unless input.nil?
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
input.gsub(/[ _-]+/, ' ').gsub(/(\A)?(\w)(\w*)([^\s]*)(\z)?/) do |match|
|
55
|
+
if $1 || $5 || $3.size > 2
|
56
|
+
$2.upcase + $3 + $4
|
57
|
+
else
|
58
|
+
$&
|
59
|
+
end
|
60
|
+
end
|
57
61
|
end
|
58
62
|
end
|
59
63
|
|
@@ -170,14 +174,18 @@ module Glim
|
|
170
174
|
end
|
171
175
|
|
172
176
|
def transform(content, page, options)
|
173
|
-
|
177
|
+
if options[:filters].empty?
|
178
|
+
content
|
179
|
+
else
|
180
|
+
options[:filters].shift.transform(content, page, options)
|
181
|
+
end
|
174
182
|
end
|
175
183
|
end
|
176
184
|
|
177
185
|
module Filters
|
178
186
|
class Liquid < Glim::Filter
|
179
187
|
transforms 'liquid' => '*'
|
180
|
-
priority :
|
188
|
+
priority :lower
|
181
189
|
|
182
190
|
def initialize(site)
|
183
191
|
@site, @options = site, {
|
@@ -220,7 +228,7 @@ module Glim
|
|
220
228
|
|
221
229
|
class Layout < Glim::Filter
|
222
230
|
transforms '*' => 'output'
|
223
|
-
priority :
|
231
|
+
priority :lower
|
224
232
|
|
225
233
|
def initialize(site)
|
226
234
|
@site, @options = site, options = {
|
@@ -450,7 +458,7 @@ module Glim
|
|
450
458
|
end
|
451
459
|
|
452
460
|
def output_ext
|
453
|
-
pipeline.output_ext(self.extname) || self.extname
|
461
|
+
frontmatter? && pipeline.output_ext(self.extname) || self.extname
|
454
462
|
end
|
455
463
|
|
456
464
|
# ==============
|
@@ -869,7 +877,7 @@ module Glim
|
|
869
877
|
chunks = items.each_slice(per_page)
|
870
878
|
pages = chunks.each_with_index.map do |posts, i|
|
871
879
|
paginator = Paginator.new(posts, i + 1)
|
872
|
-
if i
|
880
|
+
if i.zero?
|
873
881
|
file.merge_data!({ 'paginator' => paginator })
|
874
882
|
file
|
875
883
|
else
|
@@ -1207,7 +1215,7 @@ module Glim
|
|
1207
1215
|
end
|
1208
1216
|
|
1209
1217
|
@transformations = temp.sort_by do |filter, from, to|
|
1210
|
-
[ -filter.class.priority, (from.partition('.').first != to.partition('.').first ? +1 : -1) ]
|
1218
|
+
[ (from == '*' ? +1 : -1), -filter.class.priority, (from.partition('.').first != to.partition('.').first ? +1 : -1) ]
|
1211
1219
|
end
|
1212
1220
|
|
1213
1221
|
@cache = {}
|
@@ -1253,8 +1261,16 @@ module Glim
|
|
1253
1261
|
to
|
1254
1262
|
end
|
1255
1263
|
|
1256
|
-
|
1257
|
-
|
1264
|
+
filters = [ filter ]
|
1265
|
+
|
1266
|
+
if from.partition('.').first != to.partition('.').first
|
1267
|
+
filters = transformations.select { |_, filter_from, filter_to| from == filter_from && to == filter_to }.map { |f, _, _| f }
|
1268
|
+
transformations.reject! { |_, filter_from, filter_to| from == filter_from && to = filter_to }
|
1269
|
+
else
|
1270
|
+
transformations.delete(transformation)
|
1271
|
+
end
|
1272
|
+
|
1273
|
+
result_nodes << PipelineNode.new(filters, from, to)
|
1258
1274
|
end
|
1259
1275
|
result_nodes
|
1260
1276
|
end
|
@@ -1262,18 +1278,19 @@ module Glim
|
|
1262
1278
|
class PipelineNode
|
1263
1279
|
attr_reader :from_format, :to_format
|
1264
1280
|
|
1265
|
-
def initialize(
|
1266
|
-
@
|
1281
|
+
def initialize(filters, from_format, to_format)
|
1282
|
+
@filters, @from_format, @to_format = filters, from_format, to_format
|
1267
1283
|
end
|
1268
1284
|
|
1269
1285
|
def dup
|
1270
|
-
PipelineNode.new(@
|
1286
|
+
PipelineNode.new(@filters, @from_format, @to_format)
|
1271
1287
|
end
|
1272
1288
|
|
1273
1289
|
def transform(content, page, options)
|
1274
1290
|
if @cache.nil?
|
1275
|
-
|
1276
|
-
|
1291
|
+
filter, *filters = @filters
|
1292
|
+
Profiler.group(filter.class.name) do
|
1293
|
+
@cache = filter.transform(content, page, options.merge({ :filters => filters })).freeze
|
1277
1294
|
end
|
1278
1295
|
end
|
1279
1296
|
@cache
|
data/lib/commands.rb
CHANGED
@@ -28,20 +28,20 @@ module Glim
|
|
28
28
|
|
29
29
|
[ [ 'Created', created ], [ 'Deleted', deleted ], [ 'Updated', updated ] ].each do |label, files|
|
30
30
|
unless files.empty?
|
31
|
-
STDERR.puts "==> #{label} #{files.
|
31
|
+
STDERR.puts "==> #{label} #{files.size} #{files.size == 1 ? 'File' : 'Files'}"
|
32
32
|
STDERR.puts files.map { |path| Util.relative_path(path, output_dir) }.sort.join(', ')
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
unless warnings.empty?
|
37
|
-
STDERR.puts "==> #{warnings.
|
37
|
+
STDERR.puts "==> #{warnings.size} #{warnings.size == 1 ? 'Warning' : 'Warnings'}"
|
38
38
|
warnings.each do |message|
|
39
39
|
STDERR.puts message
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
unless errors.empty?
|
44
|
-
STDERR.puts "==> Stopped After #{errors.
|
44
|
+
STDERR.puts "==> Stopped After #{errors.size} #{errors.size == 1 ? 'Error' : 'Errors'}"
|
45
45
|
errors.each do |arr|
|
46
46
|
arr.each_with_index do |err, i|
|
47
47
|
STDERR.puts err.gsub(/^/, ' '*i)
|
@@ -63,7 +63,7 @@ module Glim
|
|
63
63
|
end
|
64
64
|
else
|
65
65
|
deleted = delete_items(files, dirs)
|
66
|
-
STDOUT.puts "Deleted #{deleted.
|
66
|
+
STDOUT.puts "Deleted #{deleted.size} #{deleted.size == 1 ? 'File' : 'Files'}."
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
@@ -135,6 +135,8 @@ module Glim
|
|
135
135
|
[ files, dirs ]
|
136
136
|
end
|
137
137
|
|
138
|
+
private_class_method :items_in_directory
|
139
|
+
|
138
140
|
def self.delete_items(files, dirs, keep: [])
|
139
141
|
res = []
|
140
142
|
|
@@ -150,7 +152,7 @@ module Glim
|
|
150
152
|
end
|
151
153
|
end
|
152
154
|
|
153
|
-
dirs.sort.
|
155
|
+
dirs.sort.reverse_each do |path|
|
154
156
|
begin
|
155
157
|
Dir.rmdir(path)
|
156
158
|
rescue Errno::ENOTEMPTY => e
|
@@ -163,6 +165,8 @@ module Glim
|
|
163
165
|
res
|
164
166
|
end
|
165
167
|
|
168
|
+
private_class_method :delete_items
|
169
|
+
|
166
170
|
def self.generate(output_dir, number_of_jobs, files, backtrace: false)
|
167
171
|
Profiler.run("Creating pages") do
|
168
172
|
if number_of_jobs == 1
|
@@ -173,6 +177,8 @@ module Glim
|
|
173
177
|
end
|
174
178
|
end
|
175
179
|
|
180
|
+
private_class_method :generate
|
181
|
+
|
176
182
|
def self.generate_async(output_dir, files, number_of_jobs, backtrace: false)
|
177
183
|
total = files.size
|
178
184
|
slices = number_of_jobs.times.map do |i|
|
@@ -224,10 +230,12 @@ module Glim
|
|
224
230
|
[ created, updated, warnings, errors ]
|
225
231
|
end
|
226
232
|
|
233
|
+
private_class_method :generate_async
|
234
|
+
|
227
235
|
def self.generate_subset(output_dir, files, backtrace: false)
|
228
236
|
created, updated, warnings, errors = [], [], [], []
|
229
237
|
|
230
|
-
|
238
|
+
files.each do |file|
|
231
239
|
dest = file.output_path(output_dir)
|
232
240
|
file_exists = File.exists?(dest)
|
233
241
|
|
@@ -259,5 +267,7 @@ module Glim
|
|
259
267
|
|
260
268
|
[ created, updated, warnings, errors ]
|
261
269
|
end
|
270
|
+
|
271
|
+
private_class_method :generate_subset
|
262
272
|
end
|
263
273
|
end
|
data/lib/liquid_ext.rb
CHANGED
@@ -4,6 +4,8 @@ require 'liquid'
|
|
4
4
|
module Glim
|
5
5
|
module LiquidFilters
|
6
6
|
def markdownify(input)
|
7
|
+
return if input.nil?
|
8
|
+
|
7
9
|
Profiler.group('markdownify') do
|
8
10
|
if defined?(MultiMarkdown)
|
9
11
|
MultiMarkdown.new("\n" + input, 'snippet', 'no_metadata').to_html
|
@@ -12,7 +14,7 @@ module Glim
|
|
12
14
|
document = Kramdown::Document.new(input, options)
|
13
15
|
@context['warnings'].concat(document.warnings) if options[:show_warnings] && @context['warnings']
|
14
16
|
document.to_html
|
15
|
-
end
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
@@ -29,18 +31,24 @@ module Glim
|
|
29
31
|
end
|
30
32
|
|
31
33
|
def absolute_url(path)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
return if path.nil?
|
35
|
+
|
36
|
+
site, page = URI(@context['site']['url']), URI(@context['page']['url'])
|
37
|
+
host, port = @context['site']['host'], @context['site']['port']
|
38
|
+
|
39
|
+
if page.relative? || (site.host == host && site.port == port)
|
40
|
+
site.merge(URI(path)).to_s
|
41
|
+
else
|
42
|
+
page.merge(URI(path)).to_s
|
40
43
|
end
|
41
44
|
end
|
42
45
|
|
43
46
|
def relative_url(other)
|
47
|
+
return if other.nil?
|
48
|
+
|
49
|
+
site, page = URI(@context['site']['url']), URI(@context['page']['url'])
|
50
|
+
host, port = @context['site']['host'], @context['site']['port']
|
51
|
+
|
44
52
|
helper = lambda do |base, other|
|
45
53
|
base_url, other_url = URI(base), URI(other)
|
46
54
|
if other_url.absolute? && base_url.host == other_url.host
|
@@ -49,24 +57,22 @@ module Glim
|
|
49
57
|
other
|
50
58
|
end
|
51
59
|
end
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
helper.call(@context['site']['url'], other)
|
58
|
-
else
|
59
|
-
helper.call(@context['page']['url'], other)
|
60
|
-
end
|
60
|
+
|
61
|
+
if page.relative? || (site.host == host && site.port == port)
|
62
|
+
helper.call(@context['site']['url'], other)
|
63
|
+
else
|
64
|
+
helper.call(@context['page']['url'], other)
|
61
65
|
end
|
62
66
|
end
|
63
67
|
|
64
68
|
def path_to_url(input)
|
69
|
+
return if input.nil?
|
70
|
+
|
65
71
|
if file = Jekyll.sites.last.links[input]
|
66
72
|
file.url
|
67
73
|
else
|
68
74
|
raise Glim::Error.new("path_to_url: No file found for: #{input}")
|
69
|
-
end
|
75
|
+
end
|
70
76
|
end
|
71
77
|
|
72
78
|
def date_to_xmlschema(input)
|
@@ -104,17 +110,15 @@ module Glim
|
|
104
110
|
end
|
105
111
|
|
106
112
|
def group_by_exp(input, variable, expression)
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
groups.map { |key, value| { "name" => key, "items" => value, "size" => value.size } }
|
113
|
+
return input unless input.respond_to?(:group_by)
|
114
|
+
|
115
|
+
parsed_expr = Liquid::Variable.new(expression, Liquid::ParseContext.new)
|
116
|
+
@context.stack do
|
117
|
+
groups = input.group_by do |item|
|
118
|
+
@context[variable] = item
|
119
|
+
parsed_expr.render(@context)
|
115
120
|
end
|
116
|
-
|
117
|
-
input
|
121
|
+
groups.map { |key, value| { "name" => key, "items" => value, "size" => value.size } }
|
118
122
|
end
|
119
123
|
end
|
120
124
|
|
data/lib/local_server.rb
CHANGED
@@ -80,7 +80,7 @@ module WebSocket
|
|
80
80
|
running = false
|
81
81
|
break
|
82
82
|
end
|
83
|
-
$log.debug("Send ‘#{message}’ to #{connections.
|
83
|
+
$log.debug("Send ‘#{message}’ to #{connections.size} WebSocket #{connections.size == 1 ? 'client' : 'clients'}") unless connections.empty?
|
84
84
|
connections.each do |conn|
|
85
85
|
begin
|
86
86
|
conn.puts(message)
|
data/lib/log_and_profile.rb
CHANGED
@@ -100,13 +100,13 @@ class Profiler
|
|
100
100
|
STDERR.puts indent(level) + (@format % @duration)
|
101
101
|
|
102
102
|
if @groups
|
103
|
-
@groups.sort_by { |group, info| info[:duration] }.
|
103
|
+
@groups.sort_by { |group, info| info[:duration] }.reverse_each do |group, info|
|
104
104
|
STDERR.puts indent(level+1) + "[#{group}: %.3f seconds, called #{info[:count]} time(s), %.3f seconds/time]" % [ info[:duration], info[:duration] / info[:count] ]
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
108
|
if @children
|
109
|
-
@children.sort_by { |child| child.duration }.
|
109
|
+
@children.sort_by { |child| child.duration }.reverse_each do |child|
|
110
110
|
child.dump(level + 1)
|
111
111
|
end
|
112
112
|
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glim
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Allan Odgaard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mercenary
|