Skip to content

Commit

Permalink
Fix options bug; add ability to skip missing migrate sources (#60)
Browse files Browse the repository at this point in the history
Fix options bug; add ability to skip missing migrate sources

The `options:` setting for `migrate` actions was reading an erroneous truthiness to test for the existence of a setting. Fixed this so opt settings other than `inclusive: false` actually work.

Added the ability to set an option `missing:` with either `warn`, `skip`, or `exit` as values.
If `missing: warn`, the operation skips the migrate step and logs a warning to console.
If `missing: exit` (the default, w/ backward compatibility) the operation throws an error and exits.

Added example and explanation for new `missing:` setting to README.

* Remove erroneous require (from testing)

* Rearrange missing handling; add 'skip' option

* Bump version to 0.9.5
  • Loading branch information
briandominick authored Feb 15, 2019
1 parent 3cafb4f commit 675606e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
14 changes: 12 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -554,14 +554,19 @@ In addition to designating `action: migrate`, migrate operations require just a
[source,yaml]
.Example config -- Instructing file copies with 'migrate' action
----
- action: migrate
source: index.adoc
target: _build/
- action: migrate
source: assets/images
target: _build/img
options:
inclusive: false
- action: migrate
source: index-map.adoc
target: _build/index-map.adoc
source: tmp/{{imported_file}}.adoc
target: _build/{{portal_path}}/{{imported_file}}.adoc
options:
missing: warn
----

The first action step above copies all the files and folders in `assets/images` and adds them to `_build/img`.
Expand All @@ -570,6 +575,11 @@ When both the source and target paths are directories and inclusive is `true`, t
When inclusive is `false`, they copy to `target/`.

Individual files must be listed in individual steps, one per step, as in the second step above.

In case of a missing source directory or file to be migrated, the default behavior is to exit the build operation (`missing: exit`).
This can be overridden and the migrate action skipped when the source is missing.
Setting the option `missing: warn` logs a warning to console, and `missing: skip` will only print a warning under `--verbose` operations.

// end::migrate-operations[]

=== Render Operations
Expand Down
32 changes: 27 additions & 5 deletions lib/liquidoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,12 @@ def iterate_build cfg
end
when "migrate"
inclusive = true
inclusive = step.options['inclusive'] if defined?(step.options['inclusive'])
copy_assets(step.source, step.target, inclusive)
missing = "exit"
if step.options
inclusive = step.options['inclusive'] if step.options.has_key?("inclusive")
missing = step.options['missing'] if step.options.has_key?("missing")
end
copy_assets(step.source, step.target, inclusive, missing)
when "render"
validate_file_input(step.source, "source") if step.source
builds = step.builds
Expand Down Expand Up @@ -252,6 +256,7 @@ def initialize step
if (defined?(@step['action'])).nil?
raise "ConfigStructError"
end
@step['options'] = nil unless defined?(step['options'])
validate()
end

Expand Down Expand Up @@ -787,11 +792,25 @@ def regurgidata datasrc, output
# ===

# Copy images and other files into target dir
def copy_assets src, dest, inclusive=true
def copy_assets src, dest, inclusive=true, missing='exit'
unless File.file?(src)
unless inclusive then src = src + "/." end
end
@logger.debug "Copying #{src} to #{dest}"
src_to_dest = "#{src} to #{dest}"
unless (File.file?(src) || File.directory?(src))
case missing
when "warn"
@logger.warn "Skipping migrate action (#{src_to_dest}); source not found."
return
when "skip"
@logger.debug "Skipping migrate action (#{src_to_dest}); source not found."
return
when "exit"
@logger.error "Unexpected missing source in migrate action (#{src_to_dest})."
raise "MissingSourceExit"
end
end
@logger.debug "Copying #{src_to_dest}"
begin
FileUtils.mkdir_p(dest) unless File.directory?(dest)
if File.directory?(src)
Expand All @@ -801,7 +820,7 @@ def copy_assets src, dest, inclusive=true
end
@logger.info "Copied #{src} to #{dest}."
rescue Exception => ex
@logger.warn "Problem while copying assets. #{ex.message}"
@logger.error "Problem while copying assets. #{ex.message}"
raise
end
end
Expand Down Expand Up @@ -905,6 +924,9 @@ def asciidocify doc, build
if build.backend == "pdf"
@logger.info "Generating PDF. This can take some time..."
end



Asciidoctor.convert_file(
doc.index,
to_file: to_file,
Expand Down
2 changes: 1 addition & 1 deletion lib/liquidoc/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Liquidoc
VERSION = "0.9.4"
VERSION = "0.9.5"
end

0 comments on commit 675606e

Please sign in to comment.