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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 210cb297798f5992c71db2e89b590589415136b7
4
- data.tar.gz: e1b4d95452bbc28032d9518e1f8a0f6f6823b748
3
+ metadata.gz: 820bc4f9fe1209cee121d59246fda58457c7beb0
4
+ data.tar.gz: 7518c02daf38f7258bd43711279a271db699a909
5
5
  SHA512:
6
- metadata.gz: 7ea5d8994425e508b7df7c0f71a4c5fe01c8a95373c25231379d6d62c67d3ddf758c4b8f64baa1f30da29719d5d2967010b2a2bfe7843db36ad201176f22e30b
7
- data.tar.gz: 8265353af7f3dadc29ad6c7a56e0ea4bf2886134acbc78f1b8e6476ee54ffeb80141b8b9c491ddf6552d2c8cba2b4c69258c7887649358b73382cda5e0cbb287
6
+ metadata.gz: c4ef8b04a8a83d1126cccae72bf2e5246196b47b27ee461827472632d9a855dc9f5e66b0a00cbb5d10cf4e42fc7746877015b20c7f57446af9c7564557ee4f09
7
+ data.tar.gz: 877a09b84cf7a3ddecb653a20cbc48a650e7ab513d6b6be37ae00e7796021b8f3bee99f86a4c893b4b2362b24e61a47fbb9fc6d4d7582f957cd3303d729bb92c
@@ -1,3 +1,3 @@
1
1
  module Liquidoc
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
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
- @@cfg = config
166
+ @cfg = config
166
167
  end
167
168
 
168
169
  def steps
169
- @@cfg
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
- @@step = step
187
- if (defined?(@@step['action'])).nil?
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 @@step['action']
195
+ return @step['action']
195
196
  end
196
197
 
197
198
  def data
198
- return @@step['data']
199
+ return @step['data']
199
200
  end
200
201
 
201
202
  def source
202
- return @@step['source']
203
+ return @step['source']
203
204
  end
204
205
 
205
206
  def target
206
- return @@step['target']
207
+ return @step['target']
207
208
  end
208
209
 
209
210
  def options
210
- return @@step['options']
211
+ return @step['options']
211
212
  end
212
213
 
213
214
  def builds
214
- return @@step['builds']
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?(@@step[req])).nil?
228
- @@logger.error "Every #{@@step['action']}-type in the configuration file needs a '#{req}' declaration."
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
- @@build = build
240
- @@type = type
240
+ @build = build
241
+ @type = type
241
242
  end
242
243
 
243
244
  def template
244
- @@build['template']
245
+ @build['template']
245
246
  end
246
247
 
247
248
  def output
248
- @@build['output']
249
+ @build['output']
249
250
  end
250
251
 
251
252
  def style
252
- @@build['style']
253
+ @build['style']
253
254
  end
254
255
 
255
256
  def doctype
256
- @@build['doctype']
257
+ @build['doctype']
257
258
  end
258
259
 
259
260
  def backend
260
- @@build['backend']
261
+ @build['backend']
261
262
  end
262
263
 
263
264
  def attributes
264
- @@build['attributes']
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
- @@datasrc = {}
293
+ @datasrc = {}
288
294
  if datasrc.is_a? String # create a hash out of the filename
289
295
  begin
290
- @@datasrc['file'] = datasrc
291
- @@datasrc['ext'] = File.extname(datasrc)
292
- @@datasrc['type'] = false
293
- @@datasrc['pattern'] = false
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
- @@datasrc['file'] = datasrc['file']
300
- @@datasrc['ext'] = File.extname(datasrc['file'])
305
+ @datasrc['file'] = datasrc['file']
306
+ @datasrc['ext'] = File.extname(datasrc['file'])
301
307
  if (defined?(datasrc['pattern']))
302
- @@datasrc['pattern'] = datasrc['pattern']
308
+ @datasrc['pattern'] = datasrc['pattern']
303
309
  end
304
310
  if (defined?(datasrc['type']))
305
- @@datasrc['type'] = datasrc['type']
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
- @@datasrc['file']
320
+ @datasrc['file']
315
321
  end
316
322
 
317
323
  def ext
318
- @@datasrc['ext']
324
+ @datasrc['ext']
319
325
  end
320
326
 
321
327
  def type
322
- if @@datasrc['type'] # if we're carrying a 'type' setting for data, pass it along
323
- datatype = @@datasrc['type']
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 @@datasrc['ext'].downcase.match(/\.yml|\.json|\.xml|\.csv/)
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 = @@datasrc['ext']
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
- @@datasrc['pattern']
349
+ @datasrc['pattern']
344
350
  end
345
351
  end
346
352
 
347
353
  class AsciiDocument
348
354
  def initialize map, type='article'
349
- @@index = map
350
- @@attributes = {}
351
- @@type = type
355
+ @index = map
356
+ @attributes = {}
357
+ @type = type
352
358
  end
353
359
 
354
360
  def index
355
- @@index
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
- @@attributes
370
+ @attributes
365
371
  end
366
372
 
367
373
  def type
368
- @@type
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(dest) unless File.exists?(target_dir)
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
- if defined?(build.style).nil?
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
- Asciidoctor.convert_file(
572
- doc.index,
573
- to_file: to_file,
574
- attributes: doc.attributes,
575
- require: "pdf",
576
- backend: back,
577
- doctype: build.doctype,
578
- safe: "server",
579
- sourcemap: true,
580
- verbose: @verbose,
581
- mkdirs: true
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.1
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-10-29 00:00:00.000000000 Z
11
+ date: 2017-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler