liquidoc 0.5.3 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 215dbf8660c2a4ed7689ce7db31e945bc15ddfe5
4
- data.tar.gz: 6b119022ec3949db974ae0595c2d539ab6279213
3
+ metadata.gz: d93d2ba43725019138268b7cbc3e90df6a8edf7f
4
+ data.tar.gz: 4ae07aca59730f64a1e9769d9c2c2c964027d0ba
5
5
  SHA512:
6
- metadata.gz: 49a70aca7fdb170ef2e5b65c3ebe50c0a0a1eb203139fb34ccd73f0080e8c0f53de3dc3d590994992d810f0965fc723db9445b1e6351b780430a48cb7e4183df
7
- data.tar.gz: 8609f7d60cb0929ff16c6af3d07308fa0e5d6e3890cb09cd018e13de9ff97fc4144571f8c27772e0431fa67e489667d9adca37f75c620d26396d9194d21c8338
6
+ metadata.gz: 94f1db1b4a534a2ac0630290286ed98e133d4412fc2a42e4121c4733a751219f76713c7992e8bf4bb128d30667c5343edc658f1729b5dd48557652ec69bac2f0
7
+ data.tar.gz: 0a5fbaf300323cc475ca61ab1b2ddb475b9a4ca91944bdadf34c10a83373e9a7f462efc4dc39c3fed3755fb575c680c7c408e607703e28e4127ceacd06ca5762
@@ -92,7 +92,6 @@ def iterate_build cfg
92
92
  copy_assets(step.source, step.target, inclusive)
93
93
  when "render"
94
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")
96
95
  attrs = ingest_attributes(step.data)
97
96
  else
98
97
  attrs = {}
@@ -290,28 +289,21 @@ class DataSrc
290
289
  # initialization means establishing a proper hash for the 'data' param
291
290
  def initialize datasrc
292
291
  @datasrc = {}
293
- if datasrc.is_a? String # create a hash out of the filename
294
- begin
295
- @datasrc['file'] = datasrc
296
- @datasrc['ext'] = File.extname(datasrc)
297
- @datasrc['type'] = false
298
- @datasrc['pattern'] = false
299
- rescue
300
- raise "InvalidDataFilename"
292
+ @datasrc['file'] = datasrc
293
+ @datasrc['ext'] = File.extname(datasrc)
294
+ @datasrc['type'] = false
295
+ @datasrc['pattern'] = false
296
+ if datasrc.is_a? Hash # data var is a hash, so add 'ext' to it by extracting it from filename
297
+ @datasrc['file'] = datasrc['file']
298
+ @datasrc['ext'] = File.extname(datasrc['file'])
299
+ if (defined?(datasrc['pattern']))
300
+ @datasrc['pattern'] = datasrc['pattern']
301
301
  end
302
- else
303
- if datasrc.is_a? Hash # data var is a hash, so add 'ext' to it by extracting it from filename
304
- @datasrc['file'] = datasrc['file']
305
- @datasrc['ext'] = File.extname(datasrc['file'])
306
- if (defined?(datasrc['pattern']))
307
- @datasrc['pattern'] = datasrc['pattern']
308
- end
309
- if (defined?(datasrc['type']))
310
- @datasrc['type'] = datasrc['type']
311
- end
312
- else # datasrc is neither String nor Hash
313
- raise "InvalidDataSource"
302
+ if (defined?(datasrc['type']))
303
+ @datasrc['type'] = datasrc['type']
314
304
  end
305
+ else # datasrc is neither String nor Hash
306
+ raise "InvalidDataSource"
315
307
  end
316
308
  end
317
309
 
@@ -396,20 +388,20 @@ def ingest_data datasrc
396
388
  case datasrc.type
397
389
  when "yml"
398
390
  begin
399
- return YAML.load_file(datasrc.file)
391
+ data = YAML.load_file(datasrc.file)
400
392
  rescue Exception => ex
401
393
  @logger.error "There was a problem with the data file. #{ex.message}"
402
394
  end
403
395
  when "json"
404
396
  begin
405
- return JSON.parse(File.read(datasrc.file))
397
+ data = JSON.parse(File.read(datasrc.file))
406
398
  rescue Exception => ex
407
399
  @logger.error "There was a problem with the data file. #{ex.message}"
408
400
  end
409
401
  when "xml"
410
402
  begin
411
403
  data = Crack::XML.parse(File.read(datasrc.file))
412
- return data['root']
404
+ data = data['root']
413
405
  rescue Exception => ex
414
406
  @logger.error "There was a problem with the data file. #{ex.message}"
415
407
  end
@@ -422,13 +414,13 @@ def ingest_data datasrc
422
414
  i = i+1
423
415
  end
424
416
  output = {"data" => output}
425
- return output
417
+ data = output
426
418
  rescue
427
419
  @logger.error "The CSV format is invalid."
428
420
  end
429
421
  when "regex"
430
422
  if datasrc.pattern
431
- return parse_regex(datasrc.file, datasrc.pattern)
423
+ data = parse_regex(datasrc.file, datasrc.pattern)
432
424
  else
433
425
  @logger.error "You must supply a regex pattern with your free-form data file."
434
426
  raise "MissingRegexPattern"
@@ -533,16 +525,40 @@ end
533
525
  # RENDER-type procs
534
526
  # ===
535
527
 
536
- # Gather attributes from a fixed attributes file
537
- # Use _data/attributes.yml or designate as -a path/to/filename.yml
538
- def ingest_attributes attributes_file
539
- validate_file_input(attributes_file, "attributes")
540
- begin
541
- attributes = YAML.load_file(attributes_file)
542
- return attributes
543
- rescue
544
- @logger.warn "Attributes file invalid."
528
+ # Gather attributes from one or more fixed attributes files
529
+ def ingest_attributes attr_file
530
+ file_array = attr_file.split(",")
531
+ attrs = {}
532
+ for f in file_array
533
+ if f.include? ":"
534
+ file = f.split(":")
535
+ filename = file[0]
536
+ block_name = file[1]
537
+ else
538
+ filename = f
539
+ block_name = false
540
+ end
541
+ validate_file_input(filename, "attributes")
542
+ begin
543
+ new_attrs = YAML.load_file(filename)
544
+ if block_name
545
+ begin
546
+ new_attrs = new_attrs[block_name]
547
+ rescue
548
+ raise "InvalidAttributesBlock"
549
+ end
550
+ end
551
+ rescue Exception => ex
552
+ @logger.error "Attributes block invalid. #{ex.class}: #{ex.message}"
553
+ raise "AttributeBlockError"
554
+ end
555
+ begin
556
+ attrs.merge!new_attrs
557
+ rescue Exception => ex
558
+ raise "AttributesMergeError #{ex.message}"
559
+ end
545
560
  end
561
+ return attrs
546
562
  end
547
563
 
548
564
  def derive_backend type, out_file
@@ -593,7 +609,7 @@ def asciidocify doc, build
593
609
  verbose: @verbose,
594
610
  mkdirs: true
595
611
  )
596
- else # For PDFs, we're calling the asciidoctor-pdf CLI, as the main dependency does not seem to perform the same way
612
+ else # For PDFs, we're calling the asciidoctor-pdf CLI, as the main dependency doesn't seem to perform the same way
597
613
  attributes = '-a ' + doc.attributes.map{|k,v| "#{k}='#{v}'"}.join(' -a ')
598
614
  command = "asciidoctor-pdf -o #{to_file} -b pdf -d #{build.doctype} -S unsafe #{attributes} -a no-header-footer --trace #{doc.index}"
599
615
  @logger.debug "Running #{command}"
@@ -646,34 +662,14 @@ module CustomFilters
646
662
  end
647
663
  end
648
664
 
649
- # From Slate Studio's fork of Locomotive CMS engine
650
- # https://github.com/slate-studio/engine/blob/master/lib/locomotive/core_ext.rb
651
- def slugify(options = {})
652
- options = { :sep => '_', :without_extension => false, :downcase => false, :underscore => false }.merge(options)
653
- # replace accented chars with ther ascii equivalents
654
- s = ActiveSupport::Inflector.transliterate(self).to_s
655
- # No more than one slash in a row
656
- s.gsub!(/(\/[\/]+)/, '/')
657
- # Remove leading or trailing space
658
- s.strip!
659
- # Remove leading or trailing slash
660
- s.gsub!(/(^[\/]+)|([\/]+$)/, '')
661
- # Remove extensions
662
- s.gsub!(/(\.[a-zA-Z]{2,})/, '') if options[:without_extension]
665
+ def slugify input
663
666
  # Downcase
664
- s.downcase! if options[:downcase]
665
667
  # Turn unwanted chars into the seperator
666
- s.gsub!(/[^a-zA-Z0-9\-_\+\/]+/i, options[:sep])
667
- # Underscore
668
- s.gsub!(/[\-]/i, '_') if options[:underscore]
668
+ s = input.to_s.downcase
669
+ s.gsub!(/[^a-zA-Z0-9\-_\+\/]+/i, "-")
669
670
  s
670
671
  end
671
- def slugify!(options = {})
672
- replace(self.slugify(options))
673
- end
674
- def parameterize!(sep = '_')
675
- replace(self.parameterize(sep))
676
- end
672
+
677
673
  end
678
674
 
679
675
  # register custom Liquid filters
@@ -1,3 +1,3 @@
1
1
  module Liquidoc
2
- VERSION = "0.5.3"
2
+ VERSION = "0.6.0"
3
3
  end
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.3
4
+ version: 0.6.0
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-06 00:00:00.000000000 Z
11
+ date: 2018-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler