spiffy 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/spiffy +37 -20
  3. data/lib/spiffy.rb +12 -9
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 828c78dc74429cf3dd14590c089e3be7a2c4e352
4
- data.tar.gz: efdc6ef08397c4b148390b7e01fb02c88e0223ad
3
+ metadata.gz: e7ff4044805e8ed537f5035d99bcafb96c7a46d3
4
+ data.tar.gz: e9959f330337f9fc6a5b033b340f80ef52650b3d
5
5
  SHA512:
6
- metadata.gz: 8ebcdd6da57896fc3890da00c359a40a8c819b79b1dd07beea76fea2488ca6fb1aef928a43d6681aff6e901e967c82f74611921209b512bf0cd8bc1cb27660d0
7
- data.tar.gz: 9ac2f6de8bc2ef02dcb3e30cd01e5cedb47621db59576cafa6e8ad88e671e7c0595c988a42caee0810f73dbdbb51645b922c553b8c12db07ab8c34b04a0696d5
6
+ metadata.gz: d1001a81ae55f69bce7d938fa3f7b25835a8e6535afb111d899e5c09d59eed307ce2186631be8959be031919f9d25487cdafab0c78f5cf19ea9b617b8f7f9b58
7
+ data.tar.gz: 77cf5774bfc7327733d3515374179067fa68a446d1112060fb1e0f4ff611aeafa80f1d64eff26640247fafdefc3753f42b49d104cfc0d2e6daf514a5445b1e55
data/bin/spiffy CHANGED
@@ -8,13 +8,16 @@ require_relative "../lib/spiffy"
8
8
  DEFAULT_DIR = File.join(File.dirname(__FILE__), "../templates")
9
9
  DEFAULT_TEMPLATE_FILE = File.join(DEFAULT_DIR, "default.haml")
10
10
  DEFAULT_CSS_FILE = File.join(DEFAULT_DIR, "default.css")
11
+ DEFAULT_HTML = true
12
+ DEFAULT_PDF = false
11
13
 
12
14
  DOT_FILE = ".spiffy.yml"
13
15
 
14
16
  options = {
15
- :template_file => DEFAULT_TEMPLATE_FILE,
16
- :css_file => DEFAULT_CSS_FILE,
17
- :pdf => false
17
+ :template_file => nil,
18
+ :css_file => nil,
19
+ :html => nil,
20
+ :pdf => nil
18
21
  }
19
22
 
20
23
  opt_parser = OptionParser.new do |opt|
@@ -31,8 +34,12 @@ opt_parser = OptionParser.new do |opt|
31
34
  options[:template_file] = template
32
35
  end
33
36
 
34
- opt.on("-p", "--pdf", "Output PDF files (default: off)") do
35
- options[:pdf] = true
37
+ opt.on("-p", "--pdf [on|off]", "Output PDF files (default: off)") do |on_or_off|
38
+ options[:pdf] = on_or_off != "off"
39
+ end
40
+
41
+ opt.on("-h", "--html [on|off]", "Output HTML files (default: on)") do |on_or_off|
42
+ options[:html] = on_or_off != "off"
36
43
  end
37
44
 
38
45
  opt.on("-h", "--help", "This usage outline.") do
@@ -52,14 +59,19 @@ opt_parser.parse!
52
59
 
53
60
  has_dot_file = File.exists?(DOT_FILE)
54
61
 
55
- case
56
- when ARGV.any?
57
- warn "Ignoring .spiffy.yml as arguments provided." if has_dot_file
62
+ if File.exists?(DOT_FILE)
63
+ sets = YAML.load_file(DOT_FILE)
64
+ end
65
+
66
+ if ARGV.any?
58
67
  sets = ARGV.map do |arg|
59
- { "markdown_files" => [arg] }
68
+ set = sets.find({}) do |set|
69
+ set["markdown_files"].any? do |markdown_file|
70
+ File.fnmatch(markdown_file, arg)
71
+ end
72
+ end
73
+ set.merge({ "markdown_files" => [arg] })
60
74
  end
61
- when has_dot_file
62
- sets = YAML.load_file(DOT_FILE)
63
75
  end
64
76
 
65
77
  if !sets
@@ -67,15 +79,20 @@ if !sets
67
79
  abort
68
80
  end
69
81
 
70
- sets.each do |set|
71
- set["markdown_files"].each do |input|
72
- Dir[input].each do |file|
73
- print "Converting #{file}..."
74
- Spiffy.markup_to_html(file,
75
- css_file: set["css_file"] || options[:css_file],
76
- template_file: set["template_file"] || options[:template_file],
77
- pdf: set["pdf"] || options[:pdf])
78
- puts "done"
82
+ begin
83
+ sets.each do |set|
84
+ set["markdown_files"].each do |input|
85
+ Dir[input].each do |file|
86
+ print "Converting #{file}..."
87
+ Spiffy.markup_to_html(file,
88
+ css_file: options[:css_file] || set["css_file"] || DEFAULT_CSS_FILE,
89
+ template_file: options[:template_file] || set["template_file"] || DEFAULT_TEMPLATE_FILE,
90
+ output_html: options[:html].nil? ? set["html"] || DEFAULT_HTML : options[:html],
91
+ output_pdf: options[:pdf].nil? ? set["pdf"] || DEFAULT_PDF : options[:pdf])
92
+ puts "done"
93
+ end
79
94
  end
80
95
  end
96
+ rescue RuntimeError => e
97
+ warn e.message
81
98
  end
data/lib/spiffy.rb CHANGED
@@ -3,9 +3,9 @@ require "haml"
3
3
  require "pdfkit"
4
4
 
5
5
  module Spiffy
6
- VERSION = "0.0.15"
6
+ VERSION = "0.0.16"
7
7
 
8
- def self.markup_to_html(markup_file, css_file: nil, template_file: nil, pdf: false)
8
+ def self.markup_to_html(markup_file, css_file: nil, template_file: nil, output_html: true, output_pdf: false)
9
9
  markup_file_ext = File.extname(markup_file)
10
10
  markup_file_name = markup_file[0...-markup_file_ext.length]
11
11
  markup_file_directory = File.dirname(markup_file)
@@ -39,13 +39,16 @@ module Spiffy
39
39
  end
40
40
  end
41
41
 
42
- html_file = "#{markup_file_name}.html"
43
- File.open(html_file, "w:UTF-8") { |f| f.write(html) }
42
+ if output_html
43
+ html_file = "#{markup_file_name}.html"
44
+ File.open(html_file, "w:UTF-8") { |f| f.write(html) }
45
+ end
44
46
 
45
- return unless pdf
46
- pdf_file = "#{markup_file_name}.pdf"
47
- pdf = PDFKit.new(html)
48
- pdf.stylesheets << css_file if css_file
49
- pdf.to_file(pdf_file)
47
+ if output_pdf
48
+ pdf_file = "#{markup_file_name}.pdf"
49
+ pdf = PDFKit.new(html)
50
+ pdf.stylesheets << css_file if css_file
51
+ pdf.to_file(pdf_file)
52
+ end
50
53
  end
51
54
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spiffy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leigh McCulloch