lib/liquidoc.rb in liquidoc-0.12.0.pre.rc4 vs lib/liquidoc.rb in liquidoc-0.12.0.pre.rc5

- old
+ new

@@ -43,11 +43,10 @@ @data_files = nil @attributes_file_def = '_data/asciidoctor.yml' @attributes_file = @attributes_file_def @pdf_theme_file = 'theme/pdf-theme.yml' @fonts_dir = 'theme/fonts/' -@output_filename = 'index' @attributes = {} @passed_attrs = {} @passed_vars = {} @passed_configvars = {} @parseconfig = false @@ -886,22 +885,27 @@ end def cli_liquify data_files=nil, template_file=nil, output_file=nil, passed_vars # converts command-line options into liquify or regurgidata inputs data_obj = DataObj.new() + if output_file + output = output_file + else + output = "stdout" + end if data_files payload = get_payload(data_files) data_obj.add_payload!(payload) end if template_file # data_obj.add_data!(ingested, "data") if df data_obj.add_data!(passed_vars, "vars") if passed_vars - liquify(data_obj, template_file, output_file) + liquify(data_obj, template_file, output) else data_obj.remove_scope("vars") data_obj.add_data!(passed_vars) if passed_vars - regurgidata(data_obj, output_file) + regurgidata(data_obj, output) end end def regurgidata data_obj, output # converts data files from one format directly to another @@ -1292,10 +1296,20 @@ def regexreplace input, regex, replacement='' input.to_s.gsub(Regexp.new(regex), replacement.to_s) end + def to_yaml input + o = input.to_yaml + o = o.gsub(/^\-\-\-$\n/, "") + o + end + + def to_json input + o = input.to_json + o + end end # register custom Liquid filters Liquid::Template.register_filter(CustomFilters) @@ -1342,11 +1356,11 @@ opts.on("-i PATH", "--index=PATH", "An AsciiDoc index file for mapping an Asciidoctor build." ) do |n| @index_file = n end opts.on("-o PATH", "--output=PATH", "Output file path for generated content. Ex. path/to/file.adoc. Required unless --config is called.") do |n| - @output_file = @base_dir + n + @output = @base_dir + n end opts.on("-t PATH", "--template=PATH", "Path to liquid template. Required unless --configuration is called." ) do |n| @template_file = @base_dir + n end @@ -1367,11 +1381,11 @@ @logger.level = Logger::WARN # Suppress all those INFO-level messages @explicit = true end opts.on("--stdout", "Puts the output in STDOUT instead of writing to a file.") do - @output_type = "stdout" + @output = "stdout" end opts.on("--deploy", "EXPERIMENTAL: Trigger a jekyll serve operation against the destination dir of a Jekyll render step.") do @jekyll_serve = true end @@ -1423,10 +1437,10 @@ # === unless @config_file @logger.debug "Executing config-free build based on API/CLI arguments alone." if @data_files - cli_liquify(@data_files, @template_file, @output_file, @passed_vars) + cli_liquify(@data_files, @template_file, @output, @passed_vars) end if @index_file @logger.warn "Rendering via command line arguments is not yet implemented. Use a config file." end else