exe/sg in signature_generator-0.1.1 vs exe/sg in signature_generator-0.1.2
- old
+ new
@@ -32,20 +32,23 @@
## Check Slop documentation for further info.
config.add_command_line_section do |slop|
slop.on :f, :'template-file', 'Specify the signature template file. Default is STDIN.', argument: true, as: String
slop.on :o, :'output-file', 'Specify the output file for the signature. Default is STDOUT.', argument: true, as: String
slop.on :force, 'Force overwriting output file.', argument: false
+ slop.on :'max-retry',
+ "Number of times retrying is allowed when prompted for values. Default is #{SignatureGenerator::Processor::MAX_RETRY}.",
+ argument: true, as: Integer
slop.on :var=, 'Define variables in the form name=value', argument: true, as: Array
slop.on :n, :'no-minify', 'Will not minify the resulting html signature. By default will do', argument: false
end
end
def do_process
# Your code here.
content = template_io.read
logger.debug content
- processor = SignatureGenerator::Processor.new context
+ processor = SignatureGenerator::Processor.new context: context, max_retry: config['max-retry']
signature = processor.transform content
logger.debug signature
unless config[:'no-minify']
minifier = HtmlMinifier::Minifier.new collapseWhitespace: true, collapseInlineTagWhitespace: true
signature = minifier.minify signature
@@ -59,21 +62,22 @@
end
def check_config
# Check the config and raise an exception if incorrect.
config[:var] ||=[]
+ # Context setup
@context = {}
config[:var].each do |definition|
valid = false
- definition.match(/^\s*(?<var_name>[a-z][a-z0-9_]*)\s*=\s*(?<var_value>.+)\s*$/) do |md|
+ definition.match(/^\s*(?<var_name>[a-z][a-z0-9_]*[!\?]?)\s*=\s*(?<var_value>.+)\s*$/) do |md|
logger.warning "Overwriting existing variable '#{md['var_name']}' !" if context[md['var_name']]
context[md['var_name'].to_sym] = md['var_value']
valid = true
end
raise SignatureGenerator::Error, 'Invalid property specified !' unless valid
end
-
+ # Input definition
@template_io = case config[:'template-file']
when NilClass
logger.debug 'Template from STDIN'
STDIN
when String
@@ -81,9 +85,10 @@
raise SignatureGenerator::Error, 'Invalid template file specified !' unless File.readable? file
io = File.open file, 'r'
logger.debug "Template from file '#{file}'"
io
end
+ # Output definition
@output_io = case config[:'output-file']
when NilClass
logger.debug 'Signature to STDOUT'
STDOUT
when String