liquidoc 0.5.1 → 0.5.2
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/lib/liquidoc/version.rb +1 -1
- data/lib/liquidoc.rb +80 -60
- 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: 820bc4f9fe1209cee121d59246fda58457c7beb0
|
4
|
+
data.tar.gz: 7518c02daf38f7258bd43711279a271db699a909
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4ef8b04a8a83d1126cccae72bf2e5246196b47b27ee461827472632d9a855dc9f5e66b0a00cbb5d10cf4e42fc7746877015b20c7f57446af9c7564557ee4f09
|
7
|
+
data.tar.gz: 877a09b84cf7a3ddecb653a20cbc48a650e7ab513d6b6be37ae00e7796021b8f3bee99f86a4c893b4b2362b24e61a47fbb9fc6d4d7582f957cd3303d729bb92c
|
data/lib/liquidoc/version.rb
CHANGED
data/lib/liquidoc.rb
CHANGED
@@ -91,7 +91,8 @@ def iterate_build cfg
|
|
91
91
|
inclusive = step.options['inclusive'] if defined?(step.options['inclusive'])
|
92
92
|
copy_assets(step.source, step.target, inclusive)
|
93
93
|
when "render"
|
94
|
-
if defined?(step.data)
|
94
|
+
if defined?(step.data) # if we're passing attributes as a YAML file, let's ingest that up front
|
95
|
+
validate_file_input(step.data, "data")
|
95
96
|
attrs = ingest_attributes(step.data)
|
96
97
|
else
|
97
98
|
attrs = {}
|
@@ -162,11 +163,11 @@ class BuildConfig
|
|
162
163
|
raise "ConfigStructError"
|
163
164
|
end
|
164
165
|
|
165
|
-
|
166
|
+
@cfg = config
|
166
167
|
end
|
167
168
|
|
168
169
|
def steps
|
169
|
-
|
170
|
+
@cfg
|
170
171
|
end
|
171
172
|
|
172
173
|
def deprecated_format config # for backward compatibility with 0.1.0 and 0.2.0
|
@@ -183,35 +184,35 @@ end #class BuildConfig
|
|
183
184
|
class BuildConfigStep
|
184
185
|
|
185
186
|
def initialize step
|
186
|
-
|
187
|
-
if (defined?(
|
187
|
+
@step = step
|
188
|
+
if (defined?(@step['action'])).nil?
|
188
189
|
raise "ConfigStructError"
|
189
190
|
end
|
190
191
|
validate()
|
191
192
|
end
|
192
193
|
|
193
194
|
def type
|
194
|
-
return
|
195
|
+
return @step['action']
|
195
196
|
end
|
196
197
|
|
197
198
|
def data
|
198
|
-
return
|
199
|
+
return @step['data']
|
199
200
|
end
|
200
201
|
|
201
202
|
def source
|
202
|
-
return
|
203
|
+
return @step['source']
|
203
204
|
end
|
204
205
|
|
205
206
|
def target
|
206
|
-
return
|
207
|
+
return @step['target']
|
207
208
|
end
|
208
209
|
|
209
210
|
def options
|
210
|
-
return
|
211
|
+
return @step['options']
|
211
212
|
end
|
212
213
|
|
213
214
|
def builds
|
214
|
-
return
|
215
|
+
return @step['builds']
|
215
216
|
end
|
216
217
|
|
217
218
|
def validate
|
@@ -224,8 +225,8 @@ class BuildConfigStep
|
|
224
225
|
reqs = ["source,builds"]
|
225
226
|
end
|
226
227
|
for req in reqs
|
227
|
-
if (defined?(
|
228
|
-
|
228
|
+
if (defined?(@step[req])).nil?
|
229
|
+
@logger.error "Every #{@step['action']}-type in the configuration file needs a '#{req}' declaration."
|
229
230
|
raise "ConfigStructError"
|
230
231
|
end
|
231
232
|
end
|
@@ -236,32 +237,37 @@ end #class Action
|
|
236
237
|
class Build
|
237
238
|
|
238
239
|
def initialize build, type
|
239
|
-
|
240
|
-
|
240
|
+
@build = build
|
241
|
+
@type = type
|
241
242
|
end
|
242
243
|
|
243
244
|
def template
|
244
|
-
|
245
|
+
@build['template']
|
245
246
|
end
|
246
247
|
|
247
248
|
def output
|
248
|
-
|
249
|
+
@build['output']
|
249
250
|
end
|
250
251
|
|
251
252
|
def style
|
252
|
-
|
253
|
+
@build['style']
|
253
254
|
end
|
254
255
|
|
255
256
|
def doctype
|
256
|
-
|
257
|
+
@build['doctype']
|
257
258
|
end
|
258
259
|
|
259
260
|
def backend
|
260
|
-
|
261
|
+
@build['backend']
|
261
262
|
end
|
262
263
|
|
263
264
|
def attributes
|
264
|
-
|
265
|
+
@build['attributes']
|
266
|
+
end
|
267
|
+
|
268
|
+
def set key, val
|
269
|
+
@build[key] = val
|
270
|
+
puts "#{key} => #{@build[key]}"
|
265
271
|
end
|
266
272
|
|
267
273
|
def validate
|
@@ -284,25 +290,25 @@ end #class Build
|
|
284
290
|
class DataSrc
|
285
291
|
# initialization means establishing a proper hash for the 'data' param
|
286
292
|
def initialize datasrc
|
287
|
-
|
293
|
+
@datasrc = {}
|
288
294
|
if datasrc.is_a? String # create a hash out of the filename
|
289
295
|
begin
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
296
|
+
@datasrc['file'] = datasrc
|
297
|
+
@datasrc['ext'] = File.extname(datasrc)
|
298
|
+
@datasrc['type'] = false
|
299
|
+
@datasrc['pattern'] = false
|
294
300
|
rescue
|
295
301
|
raise "InvalidDataFilename"
|
296
302
|
end
|
297
303
|
else
|
298
304
|
if datasrc.is_a? Hash # data var is a hash, so add 'ext' to it by extracting it from filename
|
299
|
-
|
300
|
-
|
305
|
+
@datasrc['file'] = datasrc['file']
|
306
|
+
@datasrc['ext'] = File.extname(datasrc['file'])
|
301
307
|
if (defined?(datasrc['pattern']))
|
302
|
-
|
308
|
+
@datasrc['pattern'] = datasrc['pattern']
|
303
309
|
end
|
304
310
|
if (defined?(datasrc['type']))
|
305
|
-
|
311
|
+
@datasrc['type'] = datasrc['type']
|
306
312
|
end
|
307
313
|
else # datasrc is neither String nor Hash
|
308
314
|
raise "InvalidDataSource"
|
@@ -311,25 +317,25 @@ class DataSrc
|
|
311
317
|
end
|
312
318
|
|
313
319
|
def file
|
314
|
-
|
320
|
+
@datasrc['file']
|
315
321
|
end
|
316
322
|
|
317
323
|
def ext
|
318
|
-
|
324
|
+
@datasrc['ext']
|
319
325
|
end
|
320
326
|
|
321
327
|
def type
|
322
|
-
if
|
323
|
-
datatype =
|
328
|
+
if @datasrc['type'] # if we're carrying a 'type' setting for data, pass it along
|
329
|
+
datatype = @datasrc['type']
|
324
330
|
if datatype.downcase == "yaml" # This is an expected common error, so let's do the user a solid
|
325
331
|
datatype = "yml"
|
326
332
|
end
|
327
333
|
else # If there's no 'type' defined, extract it from the filename and validate it
|
328
|
-
unless
|
334
|
+
unless @datasrc['ext'].downcase.match(/\.yml|\.json|\.xml|\.csv/)
|
329
335
|
# @logger.error "Data file extension must be one of: .yml, .json, .xml, or .csv or else declared in config file."
|
330
336
|
raise "FileExtensionUnknown"
|
331
337
|
end
|
332
|
-
datatype =
|
338
|
+
datatype = @datasrc['ext']
|
333
339
|
datatype = datatype[1..-1] # removes leading dot char
|
334
340
|
end
|
335
341
|
unless datatype.downcase.match(/yml|json|xml|csv|regex/) # 'type' must be one of these permitted vals
|
@@ -340,19 +346,19 @@ class DataSrc
|
|
340
346
|
end
|
341
347
|
|
342
348
|
def pattern
|
343
|
-
|
349
|
+
@datasrc['pattern']
|
344
350
|
end
|
345
351
|
end
|
346
352
|
|
347
353
|
class AsciiDocument
|
348
354
|
def initialize map, type='article'
|
349
|
-
|
350
|
-
|
351
|
-
|
355
|
+
@index = map
|
356
|
+
@attributes = {}
|
357
|
+
@type = type
|
352
358
|
end
|
353
359
|
|
354
360
|
def index
|
355
|
-
|
361
|
+
@index
|
356
362
|
end
|
357
363
|
|
358
364
|
def add_attrs! attrs
|
@@ -361,11 +367,11 @@ class AsciiDocument
|
|
361
367
|
end
|
362
368
|
|
363
369
|
def attributes
|
364
|
-
|
370
|
+
@attributes
|
365
371
|
end
|
366
372
|
|
367
373
|
def type
|
368
|
-
|
374
|
+
@type
|
369
375
|
end
|
370
376
|
end
|
371
377
|
|
@@ -508,10 +514,8 @@ def copy_assets src, dest, inclusive=true
|
|
508
514
|
target_dir = dest
|
509
515
|
end
|
510
516
|
@logger.debug "Copying #{src} to #{dest}"
|
511
|
-
# puts "Dir name: " + File.dirname(dest)
|
512
|
-
# puts "Dir exists: " + File.exists?(File.dirname(dest)).to_s
|
513
517
|
begin
|
514
|
-
FileUtils.mkdir_p(
|
518
|
+
FileUtils.mkdir_p(target_dir) unless File.directory?(target_dir)
|
515
519
|
if File.directory?(src)
|
516
520
|
FileUtils.cp_r(src, dest)
|
517
521
|
else
|
@@ -553,13 +557,23 @@ end
|
|
553
557
|
def asciidocify doc, build
|
554
558
|
@logger.debug "Executing Asciidoctor render operation for #{build.output}."
|
555
559
|
to_file = build.output
|
560
|
+
unless doc.type == build.doctype
|
561
|
+
puts "performing..."
|
562
|
+
if build.doctype.nil?
|
563
|
+
build.set("doctype", doc.type)
|
564
|
+
end
|
565
|
+
end
|
566
|
+
puts "document doctype: #{doc.type}"
|
567
|
+
puts "build doctype: #{build.doctype}"
|
556
568
|
back = derive_backend(doc.type, build.output)
|
557
|
-
|
569
|
+
unless build.style.nil?
|
558
570
|
case back
|
559
571
|
when "pdf"
|
560
572
|
doc.add_attrs!({"pdf-style"=>build.style})
|
561
573
|
when "html5"
|
562
574
|
doc.add_attrs!({"stylesheet"=>build.style})
|
575
|
+
else
|
576
|
+
raise "UnrecognizedBackend"
|
563
577
|
end
|
564
578
|
end
|
565
579
|
# Add attributes from config file build section
|
@@ -568,18 +582,25 @@ def asciidocify doc, build
|
|
568
582
|
doc.add_attrs!(@passed_attrs)
|
569
583
|
@logger.debug "Final pre-parse attributes: #{doc.attributes}"
|
570
584
|
# Perform the aciidoctor convert
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
585
|
+
unless back == "pdf"
|
586
|
+
Asciidoctor.convert_file(
|
587
|
+
doc.index,
|
588
|
+
to_file: to_file,
|
589
|
+
attributes: doc.attributes,
|
590
|
+
require: "pdf",
|
591
|
+
backend: back,
|
592
|
+
doctype: build.doctype,
|
593
|
+
safe: "unsafe",
|
594
|
+
sourcemap: true,
|
595
|
+
verbose: @verbose,
|
596
|
+
mkdirs: true
|
597
|
+
)
|
598
|
+
else # For PDFs, we're calling the asciidoctor-pdf CLI, as the main dependency does not seem to perform the same way
|
599
|
+
attributes = '-a ' + doc.attributes.map{|k,v| "#{k}='#{v}'"}.join(' -a ')
|
600
|
+
command = "asciidoctor-pdf -o #{to_file} -b pdf -d #{build.doctype} -S unsafe #{attributes} -a no-header-footer --trace #{doc.index}"
|
601
|
+
@logger.debug "Running #{command}"
|
602
|
+
system command
|
603
|
+
end
|
583
604
|
@logger.info "Rendered file #{to_file}."
|
584
605
|
end
|
585
606
|
|
@@ -655,7 +676,6 @@ module CustomFilters
|
|
655
676
|
def parameterize!(sep = '_')
|
656
677
|
replace(self.parameterize(sep))
|
657
678
|
end
|
658
|
-
|
659
679
|
end
|
660
680
|
|
661
681
|
# register custom Liquid filters
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: liquidoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Dominick
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|