class JekyllLiquidDebug::Parser
Public Class Methods
func_set_file(file)
click to toggle source
# File lib/jekyll-liquid-debug.rb, line 65 def self.func_set_file(file) if File.file?(file) return file else puts "Fatal: < #{file} > is not a file" exit end end
parse(options)
click to toggle source
# File lib/jekyll-liquid-debug.rb, line 10 def self.parse(options) # Hash to contain all settings # it is needed to set default values, to help use Struct make Hash dottable. # because Struct does not have method to check whether key exists args = {file:false, html:false, kmd:false, outhtml:false, outmd:false, yaml:false, } OptionParser.new do |opt| opt.banner = "Usage: jekyll-liquid-debug [options]" opt.separator "" opt.separator "Input files:" opt.on("-f", "--file [FILE]", String, "input liquid template") do |v| args[:file] = Parser.func_set_file(v) end opt.on("-t", "--html [FILE]", String, "input html template") do |v| args[:html] = Parser.func_set_file(v) end opt.on("-y", "--yaml [FILE]", String, "input YAML file, parsed to `site.[var]'") do |v| args[:yaml] = Parser.func_set_file(v) end opt.on("-k", "--md [FILE]", String, "input raw markdown file, precedent for option `-t'") do |v| args[:kmd] = Parser.func_set_file(v) end opt.on("--out-html", TrueClass, "output html file, overwrite may happen") do |v| args[:outhtml] = true end opt.on("--out-md", TrueClass, "output markdown file, overwrite may happen") do |v| args[:outmd] = true end opt.separator "" opt.separator "Common options:" opt.on_tail("-h", "--help", "Show help message") do puts opt exit end opt.on_tail("-v", "--version", "Show version") do puts "Version #{VERSION}" exit end opt.on_tail("--feature", "Show development feature") do FEATURE.each { |x| puts x } exit end end.parse!(options) return args end