mint 0.5.1 → 0.7.1
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.
- data/Gemfile +18 -0
- data/README.md +3 -3
- data/bin/mint +27 -27
- data/bin/mint-epub +6 -6
- data/config/syntax.yaml +12 -12
- data/{templates → config/templates}/base/style.sass +11 -4
- data/config/templates/default/css/style.css +158 -0
- data/config/templates/default/layout.haml +8 -0
- data/{templates → config/templates}/default/style.sass +0 -0
- data/{templates/default → config/templates/protocol}/layout.haml +0 -0
- data/config/templates/protocol/style.sass +20 -0
- data/config/templates/reset.css +92 -0
- data/config/templates/zen/css/style.css +145 -0
- data/{templates/pro → config/templates/zen}/layout.haml +0 -0
- data/config/templates/zen/style.sass +24 -0
- data/features/config.feature +21 -0
- data/features/publish.feature +3 -3
- data/features/support/env.rb +9 -27
- data/features/templates.feature +79 -0
- data/lib/mint.rb +11 -11
- data/lib/mint/{commandline.rb → command_line.rb} +96 -80
- data/lib/mint/css.rb +43 -34
- data/lib/mint/document.rb +99 -93
- data/lib/mint/helpers.rb +21 -17
- data/lib/mint/layout.rb +1 -1
- data/lib/mint/mint.rb +92 -36
- data/lib/mint/plugin.rb +5 -5
- data/lib/mint/plugins/epub.rb +51 -51
- data/lib/mint/resource.rb +2 -2
- data/lib/mint/style.rb +2 -2
- data/lib/mint/version.rb +1 -1
- data/spec/command_line_spec.rb +87 -0
- data/spec/css_spec.rb +46 -0
- data/spec/document_spec.rb +38 -40
- data/spec/helpers_spec.rb +101 -83
- data/spec/layout_spec.rb +1 -1
- data/spec/mint_spec.rb +184 -60
- data/spec/plugin_spec.rb +61 -67
- data/spec/plugins/epub_spec.rb +47 -47
- data/spec/resource_spec.rb +9 -9
- data/spec/spec_helper.rb +20 -93
- data/spec/style_spec.rb +6 -8
- data/spec/support/fixtures/content.md +16 -0
- data/spec/support/fixtures/dynamic.sass +3 -0
- data/spec/support/fixtures/layout.haml +3 -0
- data/spec/support/fixtures/static.css +3 -0
- data/spec/support/matchers.rb +15 -0
- metadata +160 -70
- data/spec/commandline_spec.rb +0 -91
- data/templates/pro/style.sass +0 -0
data/lib/mint/resource.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "mint/mint"
|
2
2
|
|
3
3
|
module Mint
|
4
4
|
class Resource
|
@@ -45,7 +45,7 @@ module Mint
|
|
45
45
|
attr_accessor :destination
|
46
46
|
|
47
47
|
def destination_file_path
|
48
|
-
root_directory_path + (destination ||
|
48
|
+
root_directory_path + (destination || "") + name
|
49
49
|
end
|
50
50
|
|
51
51
|
def destination_file
|
data/lib/mint/style.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "mint/resource"
|
2
2
|
|
3
3
|
module Mint
|
4
4
|
class Style < Resource
|
@@ -19,7 +19,7 @@ module Mint
|
|
19
19
|
# However, if a destination directory is already specified, we
|
20
20
|
# leave it alone.
|
21
21
|
if Mint.template?(self.source_directory) and rendered?
|
22
|
-
self.destination ||=
|
22
|
+
self.destination ||= "css"
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
data/lib/mint/version.rb
CHANGED
@@ -0,0 +1,87 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Mint
|
4
|
+
describe CommandLine do
|
5
|
+
describe ".options" do
|
6
|
+
it "provides default options" do
|
7
|
+
CommandLine.options["template"]["long"].should == "template"
|
8
|
+
CommandLine.options["layout"]["long"].should == "layout"
|
9
|
+
CommandLine.options["style"]["long"].should == "style"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ".parse" do
|
14
|
+
it "does not mutate passed in ARGV" do
|
15
|
+
argv = ["--layout", "zen"]
|
16
|
+
lambda { CommandLine.parse(argv) }.should_not change { argv }
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns a hash of commandline options, unconsumed options, and the help message" do
|
20
|
+
OptionParser.any_instance.stub(:help => "Help message")
|
21
|
+
CommandLine.parse(["command", "--layout", "zen"]).should == {
|
22
|
+
help: "Help message",
|
23
|
+
argv: ["command"],
|
24
|
+
options: {
|
25
|
+
layout: "zen"
|
26
|
+
}
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe ".help" do
|
32
|
+
it "prints a help message" do
|
33
|
+
STDOUT.should_receive(:puts).with("message")
|
34
|
+
CommandLine.help("message")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe ".install" do
|
39
|
+
describe "when there is no template by the specified name" do
|
40
|
+
it "installs the specified file as a new template" do
|
41
|
+
CommandLine.install("dynamic.sass", :template => "pro")
|
42
|
+
Mint.find_template("pro", :style).should == Mint.template_path("pro", :style, :scope => :local, :ext => "sass")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe ".uninstall" do
|
48
|
+
it "uninstalls the specified template" do
|
49
|
+
CommandLine.install("dynamic.sass", :template => "pro")
|
50
|
+
CommandLine.uninstall("pro")
|
51
|
+
lambda do
|
52
|
+
Mint.find_template("pro", :style)
|
53
|
+
end.should raise_error
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe ".edit" do
|
58
|
+
it "pulls up a named template file in the user's editor" do
|
59
|
+
ENV["EDITOR"] = "vim"
|
60
|
+
CommandLine.should_receive(:system).with("vim #{@dynamic_style_file}")
|
61
|
+
CommandLine.edit(@dynamic_style_file)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe ".configure" do
|
66
|
+
it "writes options to the correct file for the scope specified" do
|
67
|
+
Mint.configuration[:layout].should == "default"
|
68
|
+
CommandLine.configure({ layout: "pro" }, :local)
|
69
|
+
Mint.configuration[:layout].should == "pro"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe ".set" do
|
74
|
+
it "sets and stores a scoped configuration variable" do
|
75
|
+
CommandLine.should_receive(:configure).with({ layout: "pro" }, :local)
|
76
|
+
CommandLine.set(:layout, "pro", :scope => :local)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe ".publish!" do
|
81
|
+
it "publishes a set of files" do
|
82
|
+
CommandLine.publish!([@content_file])
|
83
|
+
File.exist?("content.html").should be_true
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/spec/css_spec.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Mint
|
4
|
+
describe CSS do
|
5
|
+
describe ".stylify" do
|
6
|
+
it "translates from human-readable configuration to CSS" do
|
7
|
+
table = {
|
8
|
+
"Font: Helvetica" => "font-family: Helvetica",
|
9
|
+
'Font: "Lucida Grande"' => 'font-family: "Lucida Grande"',
|
10
|
+
"Font Size: 12pt" => "font-size: 12pt",
|
11
|
+
"Font Color: gray" => "color: gray",
|
12
|
+
"Color: gray" => "color: gray",
|
13
|
+
"Top Margin: 1in" => "padding-top: 1in",
|
14
|
+
"Top: 1in" => "padding-top: 1in",
|
15
|
+
"Bottom: 1in" => "padding-bottom: 1in",
|
16
|
+
"Left: 1in" => "padding-left: 1in",
|
17
|
+
"Right: 1in" => "padding-right: 1in",
|
18
|
+
"Height: 11in" => "height: 11in",
|
19
|
+
"Width: 8in" => "width: 8in",
|
20
|
+
"Columns: 2" => "column-count: 2",
|
21
|
+
"Column Gap: 1in" => "column-gap: 1in",
|
22
|
+
"Orientation: landscape" => "@page { size: landscape }",
|
23
|
+
"Indentation: 0.5in" => "p+p { text-indent: 0.5in }",
|
24
|
+
"Indent: 0.5in" => "p+p { text-indent: 0.5in }",
|
25
|
+
"Bullet: square" => "li { list-style-type: square }",
|
26
|
+
"Bullet Image: img.png" => "li { list-style-image: url(img.png) }",
|
27
|
+
"Before Paragraph: 0.5in" => "p { margin-top: 0.5in }",
|
28
|
+
"After Paragraph: 0.5in" => "p { margin-bottom: 0.5in }"
|
29
|
+
# "Smart Typography: On" => "text-rendering: optimizeLegibility",
|
30
|
+
# "Spacing: double" => "line-height: 2 * ?",
|
31
|
+
# "Bullet: checkbox.png" => "li { list-style-image: url(checkbox.png) }",
|
32
|
+
}
|
33
|
+
|
34
|
+
table.each do |human, machine|
|
35
|
+
CSS.stylify(*human.split(":").map(&:strip))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe ".parse" do
|
41
|
+
it "transforms a map of human-readable styles into a CSS string" do
|
42
|
+
CSS.parse({ "Font" => "Helvetica" }).should == "#container {\n font-family: Helvetica; }\n"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/spec/document_spec.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
module Mint
|
4
4
|
describe Document do
|
5
|
-
before { @tmp_dir = Dir.getwd }
|
6
|
-
|
7
5
|
# We're not going to re-test derivative methods like source_file_path
|
8
6
|
# or root_directory. resource_spec.rb tells us that if the master
|
9
7
|
# values hold true, then their derivatives will be what we expect, as well.
|
@@ -17,7 +15,7 @@ module Mint
|
|
17
15
|
# This test doesn't cover any plugin transformations. Those
|
18
16
|
# transformations are covered in the Plugin spec.
|
19
17
|
its(:content) { should =~ /<p>This is just a test.<\/p>/ }
|
20
|
-
its(:metadata) { should == {
|
18
|
+
its(:metadata) { should == { "metadata" => true } }
|
21
19
|
|
22
20
|
# Render output
|
23
21
|
|
@@ -55,15 +53,15 @@ module Mint
|
|
55
53
|
subject { document }
|
56
54
|
its(:root) { should == @tmp_dir }
|
57
55
|
its(:destination) { should be_nil }
|
58
|
-
its(:source) { should ==
|
56
|
+
its(:source) { should == "content.md" }
|
59
57
|
its(:style_destination) { should be_nil }
|
60
58
|
|
61
59
|
its(:style_destination_file) do
|
62
|
-
should == Mint.root +
|
60
|
+
should == Mint.root + "/config/templates/default/css/style.css"
|
63
61
|
end
|
64
62
|
|
65
63
|
its(:style_destination_directory) do
|
66
|
-
should == Mint.root +
|
64
|
+
should == Mint.root + "/config/templates/default/css"
|
67
65
|
end
|
68
66
|
|
69
67
|
its(:style_destination_file_path) do
|
@@ -74,24 +72,24 @@ module Mint
|
|
74
72
|
should == Pathname.new(document.style_destination_directory)
|
75
73
|
end
|
76
74
|
|
77
|
-
its(:layout) { should be_in_directory(
|
78
|
-
its(:style) { should be_in_directory(
|
75
|
+
its(:layout) { should be_in_directory("default") }
|
76
|
+
its(:style) { should be_in_directory("default") }
|
79
77
|
|
80
|
-
its(:stylesheet) { should == Mint.root +
|
78
|
+
its(:stylesheet) { should == Mint.root + "/config/templates/default/css/style.css" }
|
81
79
|
|
82
80
|
it_should_behave_like "all documents"
|
83
81
|
end
|
84
82
|
|
85
83
|
context "when it's created with explicit destination directories" do
|
86
84
|
let(:document) { Document.new @content_file,
|
87
|
-
:destination =>
|
88
|
-
:style_destination =>
|
85
|
+
:destination => "destination",
|
86
|
+
:style_destination => "styles" }
|
89
87
|
|
90
88
|
subject { document }
|
91
89
|
its(:root) { should == @tmp_dir }
|
92
|
-
its(:destination) { should ==
|
93
|
-
its(:source) { should ==
|
94
|
-
its(:style_destination) { should ==
|
90
|
+
its(:destination) { should == "destination" }
|
91
|
+
its(:source) { should == "content.md" }
|
92
|
+
its(:style_destination) { should == "styles" }
|
95
93
|
|
96
94
|
its(:style_destination_file) do
|
97
95
|
should == "#{@tmp_dir}/destination/styles/style.css"
|
@@ -109,10 +107,10 @@ module Mint
|
|
109
107
|
should == Pathname.new(document.style_destination_directory)
|
110
108
|
end
|
111
109
|
|
112
|
-
its(:layout) { should be_in_directory(
|
113
|
-
its(:style) { should be_in_directory(
|
110
|
+
its(:layout) { should be_in_directory("default") }
|
111
|
+
its(:style) { should be_in_directory("default") }
|
114
112
|
|
115
|
-
its(:stylesheet) { should ==
|
113
|
+
its(:stylesheet) { should == "styles/style.css" }
|
116
114
|
|
117
115
|
it_should_behave_like "all documents"
|
118
116
|
end
|
@@ -124,15 +122,15 @@ module Mint
|
|
124
122
|
subject { document }
|
125
123
|
its(:root) { should == "#{@tmp_dir}/alternative-root" }
|
126
124
|
its(:destination) { should be_nil }
|
127
|
-
its(:source) { should ==
|
125
|
+
its(:source) { should == "content.md" }
|
128
126
|
its(:style_destination) { should be_nil }
|
129
127
|
|
130
128
|
its(:style_destination_file) do
|
131
|
-
should == Mint.root +
|
129
|
+
should == Mint.root + "/config/templates/default/css/style.css"
|
132
130
|
end
|
133
131
|
|
134
132
|
its(:style_destination_directory) do
|
135
|
-
should == Mint.root +
|
133
|
+
should == Mint.root + "/config/templates/default/css"
|
136
134
|
end
|
137
135
|
|
138
136
|
its(:style_destination_file_path) do
|
@@ -143,10 +141,10 @@ module Mint
|
|
143
141
|
should == Pathname.new(document.style_destination_directory)
|
144
142
|
end
|
145
143
|
|
146
|
-
its(:layout) { should be_in_directory(
|
147
|
-
its(:style) { should be_in_directory(
|
144
|
+
its(:layout) { should be_in_directory("default") }
|
145
|
+
its(:style) { should be_in_directory("default") }
|
148
146
|
|
149
|
-
its(:stylesheet) { should == Mint.root +
|
147
|
+
its(:stylesheet) { should == Mint.root + "/config/templates/default/css/style.css" }
|
150
148
|
|
151
149
|
it_should_behave_like "all documents"
|
152
150
|
end
|
@@ -155,18 +153,18 @@ module Mint
|
|
155
153
|
let(:document) do
|
156
154
|
Document.new @content_file do |doc|
|
157
155
|
doc.root = "#{@tmp_dir}/alternative-root"
|
158
|
-
doc.destination =
|
159
|
-
doc.style_destination =
|
160
|
-
doc.layout =
|
161
|
-
doc.style =
|
156
|
+
doc.destination = "destination"
|
157
|
+
doc.style_destination = "styles"
|
158
|
+
doc.layout = "zen"
|
159
|
+
doc.style = "zen"
|
162
160
|
end
|
163
161
|
end
|
164
162
|
|
165
163
|
subject { document }
|
166
164
|
its(:root) { should == "#{@tmp_dir}/alternative-root" }
|
167
|
-
its(:destination) { should ==
|
168
|
-
its(:source) { should ==
|
169
|
-
its(:style_destination) { should ==
|
165
|
+
its(:destination) { should == "destination" }
|
166
|
+
its(:source) { should == "content.md" }
|
167
|
+
its(:style_destination) { should == "styles" }
|
170
168
|
|
171
169
|
its(:style_destination_file) do
|
172
170
|
should == "#{@tmp_dir}/alternative-root/destination/styles/style.css"
|
@@ -184,10 +182,10 @@ module Mint
|
|
184
182
|
should == Pathname.new(document.style_destination_directory)
|
185
183
|
end
|
186
184
|
|
187
|
-
its(:layout) { should be_in_directory(
|
188
|
-
its(:style) { should be_in_directory(
|
185
|
+
its(:layout) { should be_in_directory("zen") }
|
186
|
+
its(:style) { should be_in_directory("zen") }
|
189
187
|
|
190
|
-
its(:stylesheet) { should ==
|
188
|
+
its(:stylesheet) { should == "styles/style.css" }
|
191
189
|
|
192
190
|
it_should_behave_like "all documents"
|
193
191
|
end
|
@@ -196,29 +194,29 @@ module Mint
|
|
196
194
|
let(:text) { "metadata: true\n\nReal text" }
|
197
195
|
describe ".metadata_chunk" do
|
198
196
|
it "extracts, but does not parse, metadata from text" do
|
199
|
-
Document.metadata_chunk(text).should ==
|
197
|
+
Document.metadata_chunk(text).should == "metadata: true"
|
200
198
|
end
|
201
199
|
end
|
202
200
|
|
203
201
|
describe ".metadata_from" do
|
204
202
|
it "parses a documents metadata if present" do
|
205
|
-
Document.metadata_from(text).should == {
|
203
|
+
Document.metadata_from(text).should == { "metadata" => true }
|
206
204
|
end
|
207
205
|
|
208
206
|
it "returns the empty string if a document has bad/no metadata" do
|
209
|
-
Document.metadata_from(
|
207
|
+
Document.metadata_from("No metadata here").should == {}
|
210
208
|
end
|
211
209
|
end
|
212
210
|
|
213
211
|
describe ".parse_metadata_from" do
|
214
212
|
it "separates text from its metadata if present" do
|
215
213
|
Document.parse_metadata_from(text).should ==
|
216
|
-
[{
|
214
|
+
[{ "metadata" => true }, "Real text"]
|
217
215
|
end
|
218
216
|
|
219
217
|
it "returns the entire text if no metadata is found" do
|
220
|
-
Document.parse_metadata_from(
|
221
|
-
[{},
|
218
|
+
Document.parse_metadata_from("No metadata here").should ==
|
219
|
+
[{}, "No metadata here"]
|
222
220
|
end
|
223
221
|
end
|
224
222
|
end
|
data/spec/helpers_spec.rb
CHANGED
@@ -1,58 +1,58 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
module Mint
|
4
4
|
describe Helpers do
|
5
|
-
describe "
|
5
|
+
describe ".underscore" do
|
6
6
|
it "underscores class names per ActiveSupport conventions" do
|
7
|
-
Helpers.underscore(
|
7
|
+
Helpers.underscore("ClassName").should == "class_name"
|
8
8
|
end
|
9
9
|
|
10
10
|
it "allows for camel case prefixes" do
|
11
|
-
Helpers.underscore(
|
12
|
-
Helpers.underscore(
|
11
|
+
Helpers.underscore("EPub").should == "e_pub"
|
12
|
+
Helpers.underscore("EPub", :ignore_prefix => true).should == "epub"
|
13
13
|
end
|
14
14
|
|
15
15
|
it "allows for namespace removal" do
|
16
|
-
Helpers.underscore(
|
17
|
-
:namespaces => true).should ==
|
18
|
-
Helpers.underscore(
|
19
|
-
:namespaces => false).should ==
|
20
|
-
Helpers.underscore(
|
16
|
+
Helpers.underscore("Mint::EPub",
|
17
|
+
:namespaces => true).should == "mint/e_pub"
|
18
|
+
Helpers.underscore("Mint::EPub",
|
19
|
+
:namespaces => false).should == "e_pub"
|
20
|
+
Helpers.underscore("Mint::EPub",
|
21
21
|
:namespaces => true,
|
22
|
-
:ignore_prefix => true).should ==
|
22
|
+
:ignore_prefix => true).should == "mint/epub"
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
describe "
|
26
|
+
describe ".slugize" do
|
27
27
|
it "downcases everything" do
|
28
|
-
Helpers.slugize(
|
29
|
-
|
28
|
+
Helpers.slugize("This could use FEWER CAPITALS").should ==
|
29
|
+
"this-could-use-fewer-capitals"
|
30
30
|
end
|
31
31
|
|
32
32
|
it "parses 'and'" do
|
33
|
-
Helpers.slugize(
|
33
|
+
Helpers.slugize("You & me").should == "you-and-me"
|
34
34
|
end
|
35
35
|
|
36
36
|
it "parses spaces" do
|
37
|
-
Helpers.slugize(
|
37
|
+
Helpers.slugize("You and me").should == "you-and-me"
|
38
38
|
end
|
39
39
|
|
40
40
|
it "removes non-word/non-digits" do
|
41
|
-
Helpers.slugize(
|
41
|
+
Helpers.slugize("You // and :: me").should == "you-and-me"
|
42
42
|
end
|
43
43
|
|
44
44
|
it "condenses multiple hyphens" do
|
45
|
-
Helpers.slugize(
|
45
|
+
Helpers.slugize("You-----and me").should == "you-and-me"
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
describe "
|
49
|
+
describe ".symbolize" do
|
50
50
|
it "converts hyphens to underscores" do
|
51
|
-
Helpers.symbolize(
|
51
|
+
Helpers.symbolize("you-and-me").should == :you_and_me
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
describe "
|
55
|
+
describe ".pathize" do
|
56
56
|
it "converts a String to a Pathname" do
|
57
57
|
Helpers.pathize("filename.md").should ==
|
58
58
|
Pathname.new("filename.md").expand_path
|
@@ -64,18 +64,18 @@ module Mint
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
describe "
|
67
|
+
describe ".symbolize_keys" do
|
68
68
|
it "turns all string keys in a flat map into symbols" do
|
69
69
|
flat_map = {
|
70
|
-
|
71
|
-
|
72
|
-
|
70
|
+
"key1" => "value1",
|
71
|
+
"key2" => "value2",
|
72
|
+
"key3" => "value3"
|
73
73
|
}
|
74
74
|
|
75
75
|
expected_map = {
|
76
|
-
key1:
|
77
|
-
key2:
|
78
|
-
key3:
|
76
|
+
key1: "value1",
|
77
|
+
key2: "value2",
|
78
|
+
key3: "value3"
|
79
79
|
}
|
80
80
|
|
81
81
|
Helpers.symbolize_keys(flat_map).should == expected_map
|
@@ -83,22 +83,22 @@ module Mint
|
|
83
83
|
|
84
84
|
it "recursively turns all string keys in a nested map into symbols" do
|
85
85
|
nested_map = {
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
86
|
+
"key1" => "value1",
|
87
|
+
"key2" => "value2",
|
88
|
+
"key3" => "value3",
|
89
|
+
"key4" => {
|
90
|
+
"nested_key1" => "nested_value1",
|
91
|
+
"nested_key2" => "nested_value2"
|
92
92
|
}
|
93
93
|
}
|
94
94
|
|
95
95
|
expected_map = {
|
96
|
-
key1:
|
97
|
-
key2:
|
98
|
-
key3:
|
96
|
+
key1: "value1",
|
97
|
+
key2: "value2",
|
98
|
+
key3: "value3",
|
99
99
|
key4: {
|
100
|
-
nested_key1:
|
101
|
-
nested_key2:
|
100
|
+
nested_key1: "nested_value1",
|
101
|
+
nested_key2: "nested_value2"
|
102
102
|
}
|
103
103
|
}
|
104
104
|
|
@@ -107,22 +107,22 @@ module Mint
|
|
107
107
|
|
108
108
|
it "recursively downcases all keys if specified" do
|
109
109
|
capitalized_map = {
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
110
|
+
"Key1" => "value1",
|
111
|
+
"Key2" => "value2",
|
112
|
+
"Key3" => "value3",
|
113
|
+
"Key4" => {
|
114
|
+
"Nested_key1" => "nested_value1",
|
115
|
+
"Nested_key2" => "nested_value2"
|
116
116
|
}
|
117
117
|
}
|
118
118
|
|
119
119
|
expected_map = {
|
120
|
-
key1:
|
121
|
-
key2:
|
122
|
-
key3:
|
120
|
+
key1: "value1",
|
121
|
+
key2: "value2",
|
122
|
+
key3: "value3",
|
123
123
|
key4: {
|
124
|
-
nested_key1:
|
125
|
-
nested_key2:
|
124
|
+
nested_key1: "nested_value1",
|
125
|
+
nested_key2: "nested_value2"
|
126
126
|
}
|
127
127
|
}
|
128
128
|
|
@@ -130,28 +130,28 @@ module Mint
|
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
133
|
-
describe "
|
133
|
+
describe ".listify" do
|
134
134
|
it "joins a list of three or more with an ampersand, without the Oxford comma" do
|
135
|
-
Helpers.listify([
|
136
|
-
|
135
|
+
Helpers.listify(["Alex", "Chris", "John"]).should ==
|
136
|
+
"Alex, Chris & John"
|
137
137
|
end
|
138
138
|
|
139
139
|
it "joins a list of two with an ampersand" do
|
140
|
-
Helpers.listify([
|
140
|
+
Helpers.listify(["Alex", "Chris"]).should == "Alex & Chris"
|
141
141
|
end
|
142
142
|
|
143
143
|
it "does not do anything to a list of one" do
|
144
|
-
Helpers.listify([
|
144
|
+
Helpers.listify(["Alex"]).should == "Alex"
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
|
-
describe "
|
148
|
+
describe ".standardize" do
|
149
149
|
before do
|
150
150
|
@nonstandard = {
|
151
|
-
title:
|
152
|
-
author:
|
153
|
-
editors: [
|
154
|
-
barcode:
|
151
|
+
title: "Title",
|
152
|
+
author: "David",
|
153
|
+
editors: ["David", "Jake"],
|
154
|
+
barcode: "Unique ID"
|
155
155
|
}
|
156
156
|
|
157
157
|
@table = {
|
@@ -161,10 +161,10 @@ module Mint
|
|
161
161
|
}
|
162
162
|
|
163
163
|
@standard = {
|
164
|
-
title:
|
165
|
-
creators: [
|
166
|
-
collaborators: [
|
167
|
-
uuid:
|
164
|
+
title: "Title",
|
165
|
+
creators: ["David"],
|
166
|
+
collaborators: ["David", "Jake"],
|
167
|
+
uuid: "Unique ID"
|
168
168
|
}
|
169
169
|
end
|
170
170
|
|
@@ -174,43 +174,61 @@ module Mint
|
|
174
174
|
end
|
175
175
|
end
|
176
176
|
|
177
|
-
describe "
|
177
|
+
describe ".hashify" do
|
178
|
+
it "zips two lists of the same size into a Hash" do
|
179
|
+
Helpers.hashify([:one, :two, :three], [1, 2, 3]).should == {
|
180
|
+
one: 1,
|
181
|
+
two: 2,
|
182
|
+
three: 3
|
183
|
+
}
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
describe ".normalize_path" do
|
178
188
|
it "handles two files in the same directory" do
|
179
|
-
path1 =
|
180
|
-
path2 =
|
189
|
+
path1 = "~/file1"
|
190
|
+
path2 = "~/file2"
|
181
191
|
Helpers.normalize_path(path1, path2).should ==
|
182
|
-
Pathname.new(
|
192
|
+
Pathname.new("../file1")
|
183
193
|
end
|
184
194
|
|
185
195
|
it "handles two files one directory apart" do
|
186
|
-
path1 =
|
187
|
-
path2 =
|
196
|
+
path1 = "~/file1"
|
197
|
+
path2 = "~/subdir/file2"
|
188
198
|
Helpers.normalize_path(path1, path2).should ==
|
189
|
-
Pathname.new(
|
199
|
+
Pathname.new("../../file1")
|
190
200
|
end
|
191
201
|
|
192
202
|
it "handles two files linked only at the directory root" do
|
193
|
-
path1 =
|
194
|
-
path2 =
|
203
|
+
path1 = "/home/david/file1"
|
204
|
+
path2 = "/usr/local/src/file2"
|
195
205
|
Helpers.normalize_path(path1, path2).should ==
|
196
|
-
Pathname.new(
|
206
|
+
Pathname.new("/home/david/file1")
|
197
207
|
end
|
198
208
|
|
199
209
|
it "returns nil for identical files" do
|
200
|
-
path1 =
|
201
|
-
path2 =
|
202
|
-
Helpers.normalize_path(path1, path2).should == Pathname.new(
|
210
|
+
path1 = "~/file1"
|
211
|
+
path2 = "~/file1"
|
212
|
+
Helpers.normalize_path(path1, path2).should == Pathname.new(".")
|
203
213
|
end
|
204
214
|
end
|
205
215
|
|
206
|
-
describe "
|
207
|
-
|
208
|
-
|
216
|
+
describe ".update_yaml!" do
|
217
|
+
before do
|
218
|
+
File.open "example.yaml", "w" do |file|
|
219
|
+
file << "conflicting: foo\nnon-conflicting: bar"
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
it "combines specified data with data in YAML file and updates file" do
|
224
|
+
Helpers.update_yaml! "example.yaml", "conflicting" => "baz"
|
225
|
+
YAML.load_file("example.yaml")["conflicting"].should == "baz"
|
226
|
+
end
|
209
227
|
end
|
210
228
|
|
211
|
-
describe "
|
229
|
+
describe ".generate_temp_file!" do
|
212
230
|
before do
|
213
|
-
@file = Helpers.generate_temp_file!
|
231
|
+
@file = Helpers.generate_temp_file! "content.md"
|
214
232
|
@path = Pathname.new @file
|
215
233
|
end
|
216
234
|
|
@@ -220,7 +238,7 @@ module Mint
|
|
220
238
|
|
221
239
|
it "creates a temp file with the correct name and extension" do
|
222
240
|
@path.basename.to_s.should =~ /content/
|
223
|
-
@path.extname.should ==
|
241
|
+
@path.extname.should == ".md"
|
224
242
|
end
|
225
243
|
|
226
244
|
it "fills the temp file with the specified content" do
|