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/spec/layout_spec.rb
CHANGED
data/spec/mint_spec.rb
CHANGED
@@ -1,94 +1,218 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Mint do
|
4
4
|
subject { Mint }
|
5
|
-
its(:root) { should == File.expand_path('../../../mint', __FILE__) }
|
6
|
-
its(:path) { should == ["#{Dir.getwd}/.mint", "~/.mint", Mint.root] }
|
7
|
-
its(:formats) { should include('md') }
|
8
|
-
its(:css_formats) { should include('sass') }
|
9
|
-
its(:templates) { should include(Mint.root + '/templates/default') }
|
10
5
|
|
11
6
|
its(:default_options) do
|
12
7
|
should == {
|
13
|
-
layout:
|
14
|
-
style:
|
8
|
+
layout: "default",
|
9
|
+
style: "default",
|
15
10
|
destination: nil,
|
16
11
|
style_destination: nil
|
17
12
|
}
|
18
13
|
end
|
19
14
|
|
20
|
-
its(:directories)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
15
|
+
its(:directories) { should == { templates: "templates" } }
|
16
|
+
its(:files) { should == { syntax: "syntax.yaml", defaults: "defaults.yaml" } }
|
17
|
+
|
18
|
+
describe ".root" do
|
19
|
+
it "returns the root of the Mint gem as a string" do
|
20
|
+
Mint.root.should == File.expand_path("../../../mint", __FILE__)
|
21
|
+
end
|
25
22
|
end
|
26
23
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
describe ".path" do
|
25
|
+
def as_pathname(files)
|
26
|
+
files.map {|file| Pathname.new(file) }
|
27
|
+
end
|
28
|
+
|
29
|
+
it "it returns the paths corresponding to all scopes as an array" do
|
30
|
+
Mint.path.should == [Pathname.new(".mint"),
|
31
|
+
Pathname.new("~/.mint").expand_path,
|
32
|
+
Pathname.new(Mint.root + "/config").expand_path]
|
33
|
+
end
|
34
|
+
|
35
|
+
it "can filter paths by one scope" do
|
36
|
+
Mint.path(:scopes => [:user]).should == [Pathname.new("~/.mint").expand_path]
|
37
|
+
end
|
38
|
+
|
39
|
+
it "can filter paths by many scopes" do
|
40
|
+
Mint.path(:scopes => [:local, :user]).should == [Pathname.new(".mint"),
|
41
|
+
Pathname.new("~/.mint").expand_path]
|
42
|
+
end
|
32
43
|
end
|
33
44
|
|
34
|
-
|
35
|
-
|
45
|
+
|
46
|
+
describe ".configuration" do
|
47
|
+
let(:defaults) do
|
48
|
+
{
|
49
|
+
layout: "default",
|
50
|
+
style: "default",
|
51
|
+
destination: nil,
|
52
|
+
style_destination: nil
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when there is no defaults.yaml file on the Mint path" do
|
57
|
+
it "returns a default set of options" do
|
58
|
+
Mint.configuration.should == defaults
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "when there is a defaults.yaml file on the Mint path" do
|
63
|
+
before do
|
64
|
+
FileUtils.mkdir_p ".mint"
|
65
|
+
File.open(".mint/defaults.yaml", "w") do |file|
|
66
|
+
file << "layout: zen"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
after do
|
71
|
+
FileUtils.rm_rf ".mint"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "merges all specified options with precedence according to scope" do
|
75
|
+
Mint.configuration[:layout].should == "zen"
|
76
|
+
end
|
77
|
+
|
78
|
+
it "can filter by scope (but always includes defaults)" do
|
79
|
+
Mint.configuration(:scopes => [:user]).should == defaults
|
80
|
+
end
|
81
|
+
end
|
36
82
|
end
|
37
83
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
84
|
+
describe ".configuration_with" do
|
85
|
+
it "displays the sum of all configuration files with other options added" do
|
86
|
+
Mint.configuration_with(:local => true).should == {
|
87
|
+
layout: "default",
|
88
|
+
style: "default",
|
89
|
+
destination: nil,
|
90
|
+
style_destination: nil,
|
91
|
+
local: true
|
92
|
+
}
|
93
|
+
end
|
42
94
|
end
|
43
95
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
96
|
+
describe ".templates" do
|
97
|
+
it "returns all templates if no scopes are passed in" do
|
98
|
+
Mint.templates.should include(Mint.root + "/config/templates/default")
|
99
|
+
end
|
100
|
+
|
101
|
+
it "returns all local templates if the scope is local" do
|
102
|
+
pending "a rearchitecture and unification of scopes"
|
103
|
+
Mint.templates(:scope => :local).should_not include(Mint.root + "/config/templates/default")
|
104
|
+
end
|
51
105
|
end
|
52
106
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
107
|
+
describe ".formats" do
|
108
|
+
it "includes Markdown" do
|
109
|
+
Mint.formats.should include("md")
|
110
|
+
end
|
111
|
+
|
112
|
+
it "includes Haml" do
|
113
|
+
Mint.formats.should include("haml")
|
114
|
+
end
|
57
115
|
end
|
58
116
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
117
|
+
describe ".css_formats" do
|
118
|
+
it "includes Sass" do
|
119
|
+
Mint.formats.should include("sass")
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe ".renderer" do
|
124
|
+
it "creates a valid renderer" do
|
125
|
+
Mint.renderer(@content_file).should respond_to(:render)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe ".path_for_scope" do
|
130
|
+
it "chooses the appropriate path for scope" do
|
131
|
+
expectations = {
|
132
|
+
local: Pathname.new(".mint"),
|
133
|
+
user: Pathname.new("~/.mint").expand_path,
|
134
|
+
global: Pathname.new(Mint.root + "/config").expand_path
|
135
|
+
}
|
63
136
|
|
64
|
-
|
65
|
-
|
66
|
-
|
137
|
+
expectations.each do |scope, path|
|
138
|
+
Mint.path_for_scope(scope).should == path
|
139
|
+
end
|
140
|
+
end
|
67
141
|
end
|
68
142
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
143
|
+
describe ".lookup_template" do
|
144
|
+
it "looks up the correct template according to scope" do
|
145
|
+
Mint.lookup_template(:default, :layout).should be_in_template("default")
|
146
|
+
Mint.lookup_template(:default, :style).should be_in_template("default")
|
147
|
+
Mint.lookup_template(:zen, :layout).should be_in_template("zen")
|
148
|
+
Mint.lookup_template(:zen, :style).should be_in_template("zen")
|
149
|
+
Mint.lookup_template("layout.haml").should == "layout.haml"
|
150
|
+
Mint.lookup_template("dynamic.sass").should == "dynamic.sass"
|
151
|
+
end
|
74
152
|
end
|
75
153
|
|
76
|
-
|
77
|
-
|
78
|
-
|
154
|
+
describe ".find_template" do
|
155
|
+
it "finds the correct template according to scope" do
|
156
|
+
Mint.find_template("default", :layout).should be_in_template("default")
|
157
|
+
Mint.find_template("zen", :layout).should be_in_template("zen")
|
158
|
+
Mint.find_template("zen", :style).should be_in_template("zen")
|
159
|
+
end
|
160
|
+
|
161
|
+
it "decides whether or not a file is a template file" do
|
162
|
+
actual_template = Mint.lookup_template(:default, :layout)
|
163
|
+
fake_template = "#{Mint.root}/config/templates/default.css"
|
164
|
+
obvious_nontemplate = @dynamic_style_file
|
165
|
+
|
166
|
+
actual_template.should be_a_template
|
167
|
+
fake_template.should_not be_a_template
|
168
|
+
obvious_nontemplate.should_not be_a_template
|
169
|
+
end
|
170
|
+
end
|
79
171
|
|
80
|
-
|
81
|
-
|
172
|
+
describe ".guess_name_from" do
|
173
|
+
it "properly guesses destination file names based on source file names" do
|
174
|
+
Mint.guess_name_from("content.md").should == "content.html"
|
175
|
+
Mint.guess_name_from("content.textile").should == "content.html"
|
176
|
+
Mint.guess_name_from("layout.haml").should == "layout.html"
|
177
|
+
Mint.guess_name_from("dynamic.sass").should == "dynamic.css"
|
178
|
+
end
|
82
179
|
end
|
83
180
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
181
|
+
describe ".destination_file_path and .style_destination_file_path" do
|
182
|
+
context "before it publishes a document" do
|
183
|
+
let(:document) { Mint::Document.new @content_file }
|
184
|
+
subject { document }
|
185
|
+
|
186
|
+
its(:destination_file_path) { should_not exist }
|
187
|
+
its(:style_destination_file_path) { should_not exist }
|
188
|
+
end
|
189
|
+
|
190
|
+
# These are copied from document_spec.rb. I eventually want to move
|
191
|
+
# to this non-OO style of publishing, and this is the transition
|
192
|
+
context "when it publishes a document" do
|
193
|
+
let(:document) { Mint::Document.new @content_file }
|
194
|
+
before { Mint.publish! document }
|
195
|
+
subject { document }
|
196
|
+
|
197
|
+
its(:destination_file_path) { should exist }
|
198
|
+
its(:style_destination_file_path) { should exist }
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe ".template_path" do
|
203
|
+
it "creates a template in the local directory" do
|
204
|
+
Mint.template_path("pro", :layout).should ==
|
205
|
+
".mint/templates/pro/layout.haml"
|
206
|
+
end
|
207
|
+
|
208
|
+
it "allows an extension to be specified" do
|
209
|
+
Mint.template_path("pro", :layout, :ext => "erb").should ==
|
210
|
+
".mint/templates/pro/layout.erb"
|
211
|
+
end
|
90
212
|
|
91
|
-
|
92
|
-
|
213
|
+
it "allows a scope to be specified" do
|
214
|
+
Mint.template_path("pro", :layout, :scope => :user).should ==
|
215
|
+
File.expand_path("~/.mint/templates/pro/layout.haml")
|
216
|
+
end
|
93
217
|
end
|
94
218
|
end
|
data/spec/plugin_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Mint do
|
4
4
|
# Remove unintended side effects of creating
|
@@ -17,12 +17,6 @@ describe Mint do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
describe ".activated_plugins" do
|
21
|
-
it "returns a list of plugins activated for a document"
|
22
|
-
it "returns a list of plugins activated for a set of documents"
|
23
|
-
it "returns a list of plugins activated for all documents"
|
24
|
-
end
|
25
|
-
|
26
20
|
describe ".register_plugin!" do
|
27
21
|
let(:plugin) { Class.new }
|
28
22
|
|
@@ -75,9 +69,9 @@ describe Mint do
|
|
75
69
|
let(:plugin) { Class.new(Mint::Plugin) }
|
76
70
|
|
77
71
|
it "gives access to a directory where template files can be stored" do
|
78
|
-
plugin.should_receive(:name).and_return(
|
72
|
+
plugin.should_receive(:name).and_return("DocBook")
|
79
73
|
Mint.template_directory(plugin).should ==
|
80
|
-
Mint.root +
|
74
|
+
Mint.root + "/plugins/templates/doc_book"
|
81
75
|
end
|
82
76
|
end
|
83
77
|
|
@@ -85,9 +79,9 @@ describe Mint do
|
|
85
79
|
let(:plugin) { Class.new(Mint::Plugin) }
|
86
80
|
|
87
81
|
it "gives access to a directory where template files can be stored" do
|
88
|
-
plugin.should_receive(:name).and_return(
|
82
|
+
plugin.should_receive(:name).and_return("DocBook")
|
89
83
|
Mint.config_directory(plugin).should ==
|
90
|
-
Mint.root +
|
84
|
+
Mint.root + "/plugins/config/doc_book"
|
91
85
|
end
|
92
86
|
end
|
93
87
|
|
@@ -95,9 +89,9 @@ describe Mint do
|
|
95
89
|
let(:plugin) { Class.new(Mint::Plugin) }
|
96
90
|
|
97
91
|
it "gives access to a directory where template files can be stored" do
|
98
|
-
plugin.should_receive(:name).and_return(
|
92
|
+
plugin.should_receive(:name).and_return("DocBook")
|
99
93
|
Mint.commandline_options_file(plugin).should ==
|
100
|
-
Mint.root +
|
94
|
+
Mint.root + "/plugins/config/doc_book/syntax.yml"
|
101
95
|
end
|
102
96
|
end
|
103
97
|
|
@@ -109,28 +103,28 @@ describe Mint do
|
|
109
103
|
|
110
104
|
context "when plugins are specified" do
|
111
105
|
before do
|
112
|
-
first_plugin.should_receive(callback).ordered.and_return(
|
113
|
-
second_plugin.should_receive(callback).ordered.and_return(
|
106
|
+
first_plugin.should_receive(callback).ordered.and_return("first")
|
107
|
+
second_plugin.should_receive(callback).ordered.and_return("second")
|
114
108
|
third_plugin.should_receive(callback).never
|
115
109
|
end
|
116
110
|
|
117
111
|
it "reduces .#{callback} across all specified plugins in order" do
|
118
112
|
plugins = [first_plugin, second_plugin]
|
119
|
-
Mint.send(callback,
|
113
|
+
Mint.send(callback, "text", :plugins => plugins).should == "second"
|
120
114
|
end
|
121
115
|
end
|
122
116
|
|
123
117
|
context "when plugins are activated, but no plugins are specified" do
|
124
118
|
before do
|
125
|
-
first_plugin.should_receive(callback).ordered.and_return(
|
126
|
-
second_plugin.should_receive(callback).ordered.and_return(
|
119
|
+
first_plugin.should_receive(callback).ordered.and_return("first")
|
120
|
+
second_plugin.should_receive(callback).ordered.and_return("second")
|
127
121
|
third_plugin.should_receive(callback).never
|
128
122
|
end
|
129
123
|
|
130
124
|
it "reduces .#{callback} across all activated plugins in order" do
|
131
125
|
Mint.activate_plugin! first_plugin
|
132
126
|
Mint.activate_plugin! second_plugin
|
133
|
-
Mint.send(callback,
|
127
|
+
Mint.send(callback, "text").should == "second"
|
134
128
|
end
|
135
129
|
end
|
136
130
|
|
@@ -142,7 +136,7 @@ describe Mint do
|
|
142
136
|
end
|
143
137
|
|
144
138
|
it "returns the parameter text" do
|
145
|
-
Mint.send(callback,
|
139
|
+
Mint.send(callback, "text").should == "text"
|
146
140
|
end
|
147
141
|
end
|
148
142
|
end
|
@@ -162,7 +156,7 @@ describe Mint do
|
|
162
156
|
|
163
157
|
it "iterates across all specified plugins in order" do
|
164
158
|
plugins = [first_plugin, second_plugin]
|
165
|
-
Mint.after_publish(
|
159
|
+
Mint.after_publish("fake document", :plugins => plugins)
|
166
160
|
end
|
167
161
|
end
|
168
162
|
|
@@ -176,7 +170,7 @@ describe Mint do
|
|
176
170
|
it "iterates across all activated plugins in order" do
|
177
171
|
Mint.activate_plugin! first_plugin
|
178
172
|
Mint.activate_plugin! second_plugin
|
179
|
-
Mint.after_publish(
|
173
|
+
Mint.after_publish("fake document")
|
180
174
|
end
|
181
175
|
end
|
182
176
|
|
@@ -188,7 +182,7 @@ describe Mint do
|
|
188
182
|
end
|
189
183
|
|
190
184
|
it "does not iterate over any plugins" do
|
191
|
-
Mint.after_publish(
|
185
|
+
Mint.after_publish("fake document")
|
192
186
|
end
|
193
187
|
end
|
194
188
|
end
|
@@ -213,7 +207,7 @@ describe Mint do
|
|
213
207
|
describe Mint::Plugin do
|
214
208
|
# We have to instantiate these plugins in a before block,
|
215
209
|
# and not in a let block. Because lets are lazily evaluated,
|
216
|
-
# the first two tests in the
|
210
|
+
# the first two tests in the "#inherited" suite will not
|
217
211
|
# pass.
|
218
212
|
before do
|
219
213
|
@first_plugin = Class.new(Mint::Plugin)
|
@@ -226,8 +220,8 @@ describe Mint do
|
|
226
220
|
it "when anonymous, returns a random identifier"
|
227
221
|
|
228
222
|
it "when named, returns its name, underscored" do
|
229
|
-
plugin.should_receive(:name).and_return(
|
230
|
-
plugin.underscore.should ==
|
223
|
+
plugin.should_receive(:name).and_return("EPub")
|
224
|
+
plugin.underscore.should == "epub"
|
231
225
|
end
|
232
226
|
end
|
233
227
|
|
@@ -271,11 +265,11 @@ describe Mint do
|
|
271
265
|
it "allows changes to the un-rendered content" do
|
272
266
|
plugin.instance_eval do
|
273
267
|
def before_render(text_document)
|
274
|
-
|
268
|
+
"base"
|
275
269
|
end
|
276
270
|
end
|
277
271
|
|
278
|
-
plugin.before_render(
|
272
|
+
plugin.before_render("text").should == "base"
|
279
273
|
end
|
280
274
|
end
|
281
275
|
|
@@ -283,21 +277,21 @@ describe Mint do
|
|
283
277
|
it "allows changes to the rendered HTML" do
|
284
278
|
plugin.instance_eval do
|
285
279
|
def after_render(html_document)
|
286
|
-
|
280
|
+
"<!doctype html>"
|
287
281
|
end
|
288
282
|
end
|
289
283
|
|
290
|
-
plugin.after_render(
|
284
|
+
plugin.after_render("<html></html>").should == "<!doctype html>"
|
291
285
|
end
|
292
286
|
end
|
293
287
|
|
294
288
|
describe ".after_mint" do
|
295
|
-
let(:document) { Mint::Document.new
|
289
|
+
let(:document) { Mint::Document.new "content.md" }
|
296
290
|
|
297
291
|
it "allows changes to the document extension" do
|
298
292
|
plugin.instance_eval do
|
299
293
|
def after_publish(document)
|
300
|
-
document.name.gsub! /html$/,
|
294
|
+
document.name.gsub! /html$/, "htm"
|
301
295
|
end
|
302
296
|
end
|
303
297
|
|
@@ -315,11 +309,11 @@ describe Mint do
|
|
315
309
|
first = content[0..fake_splitting_point]
|
316
310
|
second = content[fake_splitting_point..-1]
|
317
311
|
|
318
|
-
File.open
|
312
|
+
File.open "first-half.html", "w+" do |file|
|
319
313
|
file << first
|
320
314
|
end
|
321
315
|
|
322
|
-
File.open
|
316
|
+
File.open "second-half.html", "w+" do |file|
|
323
317
|
file << second
|
324
318
|
end
|
325
319
|
|
@@ -330,13 +324,13 @@ describe Mint do
|
|
330
324
|
document.publish! :plugins => [plugin]
|
331
325
|
|
332
326
|
File.exist?(document.destination_file).should be_false
|
333
|
-
File.exist?(
|
334
|
-
File.exist?(
|
327
|
+
File.exist?("first-half.html").should be_true
|
328
|
+
File.exist?("second-half.html").should be_true
|
335
329
|
end
|
336
330
|
|
337
331
|
it "allows changes to the style file" do
|
338
332
|
pending "figure out a better strategy for style manipulation"
|
339
|
-
document = Mint::Document.new
|
333
|
+
document = Mint::Document.new "content.md", :style => "style.css"
|
340
334
|
|
341
335
|
plugin.instance_eval do
|
342
336
|
def after_publish(document)
|
@@ -346,8 +340,8 @@ describe Mint do
|
|
346
340
|
# stylesheet in our current directory
|
347
341
|
style_source = document.style.source_file
|
348
342
|
style = File.read style_source
|
349
|
-
File.open style_source,
|
350
|
-
file << style.gsub(/#/,
|
343
|
+
File.open style_source, "w" do |file|
|
344
|
+
file << style.gsub(/#/, ".")
|
351
345
|
end
|
352
346
|
end
|
353
347
|
end
|
@@ -360,13 +354,13 @@ describe Mint do
|
|
360
354
|
context "when the output is in the default directory" do
|
361
355
|
it "doesn't allow changes to the document directory" do
|
362
356
|
pending "figuring out the best way to prevent directory manipulation"
|
363
|
-
document = Mint::Document.new
|
357
|
+
document = Mint::Document.new "content.md"
|
364
358
|
plugin.instance_eval do
|
365
359
|
def after_publish
|
366
360
|
original = document.destination_directory
|
367
|
-
new = File.expand_path
|
361
|
+
new = File.expand_path "invalid"
|
368
362
|
FileUtils.mv original, new
|
369
|
-
document.destination =
|
363
|
+
document.destination = "invalid"
|
370
364
|
end
|
371
365
|
|
372
366
|
lambda do
|
@@ -378,77 +372,77 @@ describe Mint do
|
|
378
372
|
|
379
373
|
context "when the output is a new directory" do
|
380
374
|
it "allows changes to the document directory" do
|
381
|
-
document = Mint::Document.new
|
375
|
+
document = Mint::Document.new "content.md", :destination => "destination"
|
382
376
|
plugin.instance_eval do
|
383
377
|
def after_publish(document)
|
384
378
|
original = document.destination_directory
|
385
|
-
new = File.expand_path
|
379
|
+
new = File.expand_path "book"
|
386
380
|
FileUtils.mv original, new
|
387
|
-
document.destination =
|
381
|
+
document.destination = "book"
|
388
382
|
end
|
389
383
|
end
|
390
384
|
|
391
385
|
document.publish! :plugins => [plugin]
|
392
|
-
File.exist?(
|
393
|
-
File.exist?(
|
394
|
-
document.destination_directory.should == File.expand_path(
|
386
|
+
File.exist?("destination").should be_false
|
387
|
+
File.exist?("book").should be_true
|
388
|
+
document.destination_directory.should == File.expand_path("book")
|
395
389
|
end
|
396
390
|
|
397
391
|
it "allows compression of the final output" do
|
398
|
-
require
|
399
|
-
require
|
392
|
+
require "zip/zip"
|
393
|
+
require "zip/zipfilesystem"
|
400
394
|
|
401
|
-
document = Mint::Document.new
|
395
|
+
document = Mint::Document.new "content.md", :destination => "destination"
|
402
396
|
plugin.instance_eval do
|
403
397
|
def after_publish(document)
|
404
|
-
Zip::ZipOutputStream.open
|
405
|
-
# zos.put_next_entry(
|
406
|
-
# zos.puts
|
407
|
-
zos.put_next_entry(
|
398
|
+
Zip::ZipOutputStream.open "book.zip" do |zos|
|
399
|
+
# zos.put_next_entry("mimetype", nil, nil, Zip::ZipEntry::STORED)
|
400
|
+
# zos.puts "text/epub"
|
401
|
+
zos.put_next_entry("chapter-1", nil, nil, Zip::ZipEntry::DEFLATED)
|
408
402
|
zos.puts File.read(document.destination_file)
|
409
403
|
end
|
410
404
|
|
411
|
-
FileUtils.mv
|
405
|
+
FileUtils.mv "book.zip", "book.epub"
|
412
406
|
end
|
413
407
|
end
|
414
408
|
|
415
409
|
document.publish! :plugins => [plugin]
|
416
410
|
|
417
|
-
File.exist?(
|
418
|
-
File.exist?(
|
419
|
-
File.exist?(
|
411
|
+
File.exist?("destination").should be_true
|
412
|
+
File.exist?("book.zip").should be_false
|
413
|
+
File.exist?("book.epub").should be_true
|
420
414
|
|
421
415
|
directory_size =
|
422
416
|
Dir["#{document.destination_directory}/**/*"].
|
423
417
|
flatten.
|
424
418
|
map {|file| File.stat(file).size }.
|
425
419
|
reduce(&:+)
|
426
|
-
compressed_size = File.stat(
|
420
|
+
compressed_size = File.stat("book.epub").size
|
427
421
|
directory_size.should > compressed_size
|
428
422
|
end
|
429
423
|
end
|
430
424
|
|
431
425
|
context "when the style output is a new directory" do
|
432
426
|
it "allows changes to the style directory" do
|
433
|
-
document = Mint::Document.new
|
427
|
+
document = Mint::Document.new "content.md", :style_destination => "styles"
|
434
428
|
plugin.instance_eval do
|
435
429
|
def after_publish(document)
|
436
430
|
original = document.style_destination_directory
|
437
|
-
new = File.expand_path
|
431
|
+
new = File.expand_path "looks"
|
438
432
|
FileUtils.mv original, new
|
439
|
-
document.style_destination =
|
433
|
+
document.style_destination = "looks"
|
440
434
|
end
|
441
435
|
end
|
442
436
|
|
443
437
|
document.publish! :plugins => [plugin]
|
444
438
|
|
445
|
-
File.exist?(
|
446
|
-
File.exist?(
|
447
|
-
document.style_destination_directory.should == File.expand_path(
|
439
|
+
File.exist?("styles").should be_false
|
440
|
+
File.exist?("looks").should be_true
|
441
|
+
document.style_destination_directory.should == File.expand_path("looks")
|
448
442
|
end
|
449
443
|
|
450
444
|
after do
|
451
|
-
FileUtils.rm_r File.expand_path(
|
445
|
+
FileUtils.rm_r File.expand_path("looks")
|
452
446
|
end
|
453
447
|
end
|
454
448
|
end
|