Module: SpiffyCli
- Defined in:
- lib/spiffy_cli.rb
Constant Summary collapse
- DEFAULT_DIR =
File.join(File.dirname(__FILE__), "../templates")
- DEFAULT_TEMPLATE_FILE =
File.join(DEFAULT_DIR, "default.haml")
- DEFAULT_CSS_FILE =
File.join(DEFAULT_DIR, "default.css")
- DEFAULT_HTML =
true
- DEFAULT_PDF =
false
- DOT_FILE =
".spiffy.yml"
Class Method Summary collapse
Class Method Details
.handle(options) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/spiffy_cli.rb', line 58 def self.handle() has_dot_file = File.exists?(DOT_FILE) if File.exists?(DOT_FILE) sets = YAML.load_file(DOT_FILE) end if ARGV.any? sets = ARGV.map do |arg| set = sets.find({}) do |set| set["markdown_files"].any? do |markdown_file| File.fnmatch(markdown_file, arg) end end set.merge({ "markdown_files" => [arg] }) end end if !sets puts opt_parser abort end sets.each do |set| set["markdown_files"].each do |input| Dir[input].each do |file| print "Converting #{file}..." output_html = [:html] output_html = set["html"] if output_html.nil? output_html = DEFAULT_HTML if output_html.nil? output_pdf = [:pdf] output_pdf = set["pdf"] if output_pdf.nil? output_pdf = DEFAULT_PDF if output_pdf.nil? Spiffy.markup_to_html(file, css_file: [:css_file] || set["css_file"] || DEFAULT_CSS_FILE, template_file: [:template_file] || set["template_file"] || DEFAULT_TEMPLATE_FILE, output_html: output_html, output_pdf: output_pdf) puts "done" end end end end |
.main ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/spiffy_cli.rb', line 15 def self.main = {} opt_parser = OptionParser.new do |opt| opt. = "Usage: spiffy [options] [file] [file] ..." opt.separator("Version: #{SpiffyVersion::VERSION}") opt.separator("") opt.separator("Options") opt.on("-c", "--css [css]", "CSS to include inline in the HTML file output") do |css| [:css_file] = css end opt.on("-t", "--template [template]", "Template to wrap the resulting HTML") do |template| [:template_file] = template end opt.on("-p", "--pdf [on|off]", "Output PDF files (default: off)") do |on_or_off| [:pdf] = on_or_off != "off" end opt.on("-h", "--html [on|off]", "Output HTML files (default: on)") do |on_or_off| [:html] = on_or_off != "off" end opt.on("-h", "--help", "This usage outline.") do puts opt_parser end opt.separator("") opt.separator("Alternatively:") opt.separator("Create a .spiffy.yml in this directory with options within.") opt.separator("See https://github.com/leighmcculloch/spiffy.") opt.separator("") end opt_parser.parse! self.handle() end |