spiffy 0.0.15 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/spiffy +37 -20
- data/lib/spiffy.rb +12 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7ff4044805e8ed537f5035d99bcafb96c7a46d3
|
4
|
+
data.tar.gz: e9959f330337f9fc6a5b033b340f80ef52650b3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 =>
|
16
|
-
:css_file =>
|
17
|
-
:
|
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] =
|
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
|
-
|
56
|
-
|
57
|
-
|
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
|
-
|
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
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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.
|
6
|
+
VERSION = "0.0.16"
|
7
7
|
|
8
|
-
def self.markup_to_html(markup_file, css_file: nil, template_file: nil,
|
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
|
-
|
43
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|