liquidoc 0.4.0 → 0.5.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/liquidoc/version.rb +1 -1
  3. data/lib/liquidoc.rb +129 -43
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a430c1aff6da069b98f775ec32e1e6b4392bd44b
4
- data.tar.gz: 1b8b0d19f71c46709b4c6960f71567ab299c96a4
3
+ metadata.gz: 5a4da6a3e0ffecae192d8143237ecc0055c51e5e
4
+ data.tar.gz: a527ecde1277cc7e3db558d83685daf4ae332c39
5
5
  SHA512:
6
- metadata.gz: 541de3451669ef6a77cbc5c800baaa9d85f03033f660396eb0afaa6b694d3b803892d7daf7b5ad6479a7891f51d941313569e6147aea2d4a2bb5d5180c400180
7
- data.tar.gz: 340ba705cce103d733002e9ddc02b3ae3bb1f86c32149bbe78cb2b574e015a1951bbfc4024c559f12dc1179eed0ddeda87c136aabf0d5e786915d1520935ee86
6
+ metadata.gz: c5c82fceb1f91e3a0ddd088471f6794336672aa600f8b099e4f8187706433111acb62a3d4aea83e4b8ac9085fdcaea411a79c05c7d9b2822fa706fe2944cc499
7
+ data.tar.gz: b171e8757bed5ad7e1fc171a16ed503db71a5099f0fe6351148e6dc59e6b9d8540fb44007fd619e287659c4273fba5277fc6e4254b301bceb8bcbc3a88a88f5f
@@ -1,3 +1,3 @@
1
1
  module Liquidoc
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/liquidoc.rb CHANGED
@@ -4,6 +4,7 @@ require 'json'
4
4
  require 'optparse'
5
5
  require 'liquid'
6
6
  require 'asciidoctor'
7
+ require 'asciidoctor-pdf'
7
8
  require 'logger'
8
9
  require 'csv'
9
10
  require 'crack/xml'
@@ -40,6 +41,8 @@ require 'fileutils'
40
41
  @fonts_dir = 'theme/fonts/'
41
42
  @output_filename = 'index'
42
43
  @attributes = {}
44
+ @passed_attrs = {}
45
+ @verbose = false
43
46
 
44
47
  @logger = Logger.new(STDOUT)
45
48
  @logger.level = Logger::INFO
@@ -88,7 +91,19 @@ def iterate_build cfg
88
91
  inclusive = step.options['inclusive'] if defined?(step.options['inclusive'])
89
92
  copy_assets(step.source, step.target, inclusive)
90
93
  when "render"
91
- @logger.warn "Render actions not yet implemented."
94
+ if defined?(step.data)
95
+ attrs = ingest_attributes(step.data)
96
+ else
97
+ attrs = {}
98
+ end
99
+ validate_file_input(step.source, "source")
100
+ doc = AsciiDocument.new(step.source)
101
+ doc.add_attrs!(attrs)
102
+ builds = step.builds
103
+ for bld in builds
104
+ build = Build.new(bld, type) # create an instance of the Build class; Build.new accepts a 'bld' hash & action 'type'
105
+ asciidocify(doc, build) # perform the liquify operation
106
+ end
92
107
  when "deploy"
93
108
  @logger.warn "Deploy actions not yet implemented."
94
109
  else
@@ -169,11 +184,10 @@ class BuildConfigStep
169
184
 
170
185
  def initialize step
171
186
  @@step = step
172
- @@logger = Logger.new(STDOUT)
173
187
  if (defined?(@@step['action'])).nil?
174
- @logger.error "Every step in the configuration file needs an 'action' type declared."
175
188
  raise "ConfigStructError"
176
189
  end
190
+ validate()
177
191
  end
178
192
 
179
193
  def type
@@ -200,7 +214,15 @@ class BuildConfigStep
200
214
  return @@step['builds']
201
215
  end
202
216
 
203
- def self.validate reqs
217
+ def validate
218
+ case self.type
219
+ when "parse"
220
+ reqs = ["data,builds"]
221
+ when "migrate"
222
+ reqs = ["source,target"]
223
+ when "render"
224
+ reqs = ["source,builds"]
225
+ end
204
226
  for req in reqs
205
227
  if (defined?(@@step[req])).nil?
206
228
  @@logger.error "Every #{@@step['action']}-type in the configuration file needs a '#{req}' declaration."
@@ -216,20 +238,6 @@ class Build
216
238
  def initialize build, type
217
239
  @@build = build
218
240
  @@type = type
219
- required = []
220
- case type
221
- when "parse"
222
- required = ["template,output"]
223
- when "migrate"
224
- required = ["source,target"]
225
- when "render"
226
- required = ["index,output"]
227
- end
228
- for req in required
229
- if (defined?(req)).nil?
230
- raise ActionSettingMissing
231
- end
232
- end
233
241
  end
234
242
 
235
243
  def template
@@ -240,8 +248,35 @@ class Build
240
248
  @@build['output']
241
249
  end
242
250
 
243
- def index
244
- @@build['index']
251
+ def style
252
+ @@build['style']
253
+ end
254
+
255
+ def doctype
256
+ @@build['doctype']
257
+ end
258
+
259
+ def backend
260
+ @@build['backend']
261
+ end
262
+
263
+ def attributes
264
+ @@build['attributes']
265
+ end
266
+
267
+ def validate
268
+ reqs = []
269
+ case self.type
270
+ when "parse"
271
+ reqs = ["template,output"]
272
+ when "render"
273
+ reqs = ["output"]
274
+ end
275
+ for req in required
276
+ if (defined?(req)).nil?
277
+ raise "ActionSettingMissing"
278
+ end
279
+ end
245
280
  end
246
281
 
247
282
  end #class Build
@@ -309,6 +344,37 @@ class DataSrc
309
344
  end
310
345
  end
311
346
 
347
+ class AsciiDocument
348
+ def initialize map, type='article'
349
+ @@index = map
350
+ @@attributes = {}
351
+ @@type = type
352
+ end
353
+
354
+ def index
355
+ @@index
356
+ end
357
+
358
+ def add_attrs! attrs
359
+ raise "InvalidAttributesFormat" unless attrs.is_a?(Hash)
360
+ self.attributes.merge!attrs
361
+ end
362
+
363
+ def attributes
364
+ @@attributes
365
+ end
366
+
367
+ def type
368
+ @@type
369
+ end
370
+ end
371
+
372
+ class AsciiDoctorConfig
373
+ def initialize out, type, back
374
+
375
+ end
376
+ end
377
+
312
378
  # ===
313
379
  # Action-specific procs
314
380
  # ===
@@ -451,7 +517,7 @@ def copy_assets src, dest, inclusive=true
451
517
  else
452
518
  FileUtils.cp(src, dest)
453
519
  end
454
- @logger.info "Copied assets."
520
+ @logger.info "Copied #{src} to #{dest}."
455
521
  rescue Exception => ex
456
522
  @logger.warn "Problem while copying assets. #{ex.message}"
457
523
  raise
@@ -464,10 +530,7 @@ end
464
530
 
465
531
  # Gather attributes from a fixed attributes file
466
532
  # Use _data/attributes.yml or designate as -a path/to/filename.yml
467
- def get_attributes attributes_file
468
- if attributes_file == nil
469
- attributes_file = @attributes_file_def
470
- end
533
+ def ingest_attributes attributes_file
471
534
  validate_file_input(attributes_file, "attributes")
472
535
  begin
473
536
  attributes = YAML.load_file(attributes_file)
@@ -477,20 +540,44 @@ def get_attributes attributes_file
477
540
  end
478
541
  end
479
542
 
480
- # Set attributes for direct Asciidoctor operations
481
- def set_attributes attributes
482
- unless attributes.is_a?(Enumerable)
483
- attributes = { }
543
+ def derive_backend type, out_file
544
+ case File.extname(out_file)
545
+ when ".pdf"
546
+ backend = "pdf"
547
+ else
548
+ backend = "html5"
484
549
  end
485
- attributes["basedir"] = @base_path
486
- attributes.merge!get_attributes(@attributes_file)
487
- attributes = '-a ' + attributes.map{|k,v| "#{k}='#{v}'"}.join(' -a ')
488
- return attributes
550
+ return backend
489
551
  end
490
552
 
491
- # To be replaced with a gem call
492
- def publish pub, bld
493
- @logger.warn "Publish actions not yet implemented."
553
+ def asciidocify doc, build
554
+ @logger.debug "Executing Asciidoctor render operation for #{build.output}."
555
+ to_file = build.output
556
+ back = derive_backend(doc.type, build.output)
557
+ if back == "pdf" # pass optional style file and set a default pdf-fontsdir
558
+ unless defined?(build.style).nil?
559
+ doc.add_attrs!({"pdf-style"=>build.style})
560
+ end
561
+ end
562
+ # Add attributes from config file build section
563
+ doc.add_attrs!(build.attributes.to_h)
564
+ # Add attributes from command-line -a args
565
+ doc.add_attrs!(@passed_attrs)
566
+ @logger.debug "Final pre-parse attributes: #{doc.attributes}"
567
+ # Perform the aciidoctor convert
568
+ Asciidoctor.convert_file(
569
+ doc.index,
570
+ to_file: to_file,
571
+ attributes: doc.attributes,
572
+ require: "pdf",
573
+ backend: back,
574
+ doctype: build.doctype,
575
+ safe: "server",
576
+ sourcemap: true,
577
+ verbose: @verbose,
578
+ mkdirs: true
579
+ )
580
+ @logger.info "Rendered file #{to_file}."
494
581
  end
495
582
 
496
583
  # ===
@@ -582,12 +669,11 @@ Liquid::Template.register_filter(CustomFilters)
582
669
  command_parser = OptionParser.new do|opts|
583
670
  opts.banner = "Usage: liquidoc [options]"
584
671
 
585
- opts.on("-a PATH", "--attributes-file=PATH", "For passing in a standard YAML AsciiDoc attributes file. Default: #{@attributes_file_def}") do |n|
586
- @assets_path = n
587
- end
588
-
589
- opts.on("--attr=STRING", "For passing an AsciiDoc attribute parameter to Asciidoctor. Ex: --attr basedir=some/path --attr imagesdir=some/path/images") do |n|
590
- @passed_attrs = @passed_attrs.merge!n
672
+ opts.on("-a KEY=VALUE", "For passing an AsciiDoc attribute parameter to Asciidoctor. Ex: -a basedir=some/path -a custom_var='my value'") do |n|
673
+ pair = {}
674
+ k,v = n.split('=')
675
+ pair[k] = v
676
+ @passed_attrs.merge!pair
591
677
  end
592
678
 
593
679
  # Global Options
@@ -621,6 +707,7 @@ command_parser = OptionParser.new do|opts|
621
707
 
622
708
  opts.on("--verbose", "Run verbose") do |n|
623
709
  @logger.level = Logger::DEBUG
710
+ @verbose = true
624
711
  end
625
712
 
626
713
  opts.on("--stdout", "Puts the output in STDOUT instead of writing to a file.") do
@@ -639,7 +726,6 @@ command_parser.parse!
639
726
  # Upfront debug output
640
727
  @logger.debug "Base dir: #{@base_dir}"
641
728
  @logger.debug "Config file: #{@config_file}"
642
- @logger.debug "Index file: #{@index_file}"
643
729
 
644
730
  # ===
645
731
  # Execute
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.4.0
4
+ version: 0.5.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-10-26 00:00:00.000000000 Z
11
+ date: 2017-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler