mint 0.5.1 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- 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/plugins/epub_spec.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
# Mimics the requirement to actually require plugins for
|
4
4
|
# them to be registered/work.
|
5
|
-
require
|
5
|
+
require "mint/plugins/epub"
|
6
6
|
|
7
7
|
module Mint
|
8
8
|
describe Document do
|
9
9
|
describe "#chapters" do
|
10
10
|
it "splits a document's final text into chapters and maps onto IDs" do
|
11
11
|
# TODO: Clean up these long lines
|
12
|
-
chapters = Document.new(
|
12
|
+
chapters = Document.new("content.md").chapters
|
13
13
|
chapters[0].should =~ /This is just a test.*Paragraph number two/m
|
14
14
|
chapters[1].should =~ /Third sentence.*Fourth sentence/m
|
15
15
|
end
|
@@ -19,12 +19,12 @@ module Mint
|
|
19
19
|
describe EPub do
|
20
20
|
describe "#after_publish" do
|
21
21
|
let(:document) do
|
22
|
-
Document.new
|
22
|
+
Document.new "content.md", :destination => "directory"
|
23
23
|
end
|
24
24
|
|
25
25
|
before do
|
26
26
|
document.publish!
|
27
|
-
document_length = File.read(
|
27
|
+
document_length = File.read("directory/content.html").length
|
28
28
|
EPub.after_publish(document)
|
29
29
|
|
30
30
|
# We're going to consider a document successfully split
|
@@ -35,19 +35,19 @@ module Mint
|
|
35
35
|
end
|
36
36
|
|
37
37
|
after do
|
38
|
-
FileUtils.rm_r
|
38
|
+
FileUtils.rm_r "directory.epub"
|
39
39
|
end
|
40
40
|
|
41
41
|
it "does nothing if no destination is specified" do
|
42
|
-
invalid_document = Document.new
|
42
|
+
invalid_document = Document.new "content.md"
|
43
43
|
lambda do
|
44
44
|
EPub.after_publish(invalid_document)
|
45
45
|
end.should raise_error(InvalidDocumentError)
|
46
46
|
end
|
47
47
|
|
48
48
|
it "replaces the monolithic published file with a packaged ePub file" do
|
49
|
-
File.exist?(
|
50
|
-
File.exist?(
|
49
|
+
File.exist?("directory/content.html").should be_false
|
50
|
+
File.exist?("directory.epub").should be_true
|
51
51
|
end
|
52
52
|
|
53
53
|
it "produces a valid ePub file" do
|
@@ -55,55 +55,55 @@ module Mint
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it "ensures all files were compressed using PKZIP" do
|
58
|
-
File.read(
|
58
|
+
File.read("directory.epub")[0..1].should == "PK"
|
59
59
|
end
|
60
60
|
|
61
61
|
context "when the ePub file is unzipped" do
|
62
62
|
before do
|
63
63
|
# Copy instead of moving to make test cleanup more
|
64
64
|
# predictable in nested contexts.
|
65
|
-
FileUtils.cp
|
65
|
+
FileUtils.cp "directory.epub", "directory.zip"
|
66
66
|
|
67
67
|
# I will later replace this with my own EPub.unzip! function
|
68
68
|
# but don't want to get too distracted now.
|
69
69
|
`unzip -o directory.zip -d directory`
|
70
70
|
|
71
|
-
# EPub.unzip!
|
71
|
+
# EPub.unzip! "directory.zip"
|
72
72
|
end
|
73
73
|
|
74
74
|
after do
|
75
|
-
FileUtils.rm_r
|
76
|
-
FileUtils.rm_r
|
75
|
+
FileUtils.rm_r "directory.zip"
|
76
|
+
FileUtils.rm_r "directory"
|
77
77
|
end
|
78
78
|
|
79
79
|
it "contains a META-INF directory" do
|
80
|
-
File.exist?(
|
80
|
+
File.exist?("directory/META-INF/container.xml").should be_true
|
81
81
|
end
|
82
82
|
|
83
83
|
it "contains an OPS directory" do
|
84
|
-
File.exist?(
|
84
|
+
File.exist?("directory/OPS").should be_true
|
85
85
|
end
|
86
86
|
|
87
87
|
it "contains a mimetype file" do
|
88
|
-
File.exist?(
|
89
|
-
File.read(
|
88
|
+
File.exist?("directory/mimetype").should be_true
|
89
|
+
File.read("directory/mimetype").chomp.should == "application/epub+zip"
|
90
90
|
end
|
91
91
|
|
92
92
|
it "contains a container file that points to the OPF file" do
|
93
|
-
File.exist?(
|
93
|
+
File.exist?("directory/META-INF/container.xml").should be_true
|
94
94
|
end
|
95
95
|
|
96
96
|
it "contains an OPF manifest with book metadata" do
|
97
|
-
File.exist?(
|
97
|
+
File.exist?("directory/OPS/content.opf").should be_true
|
98
98
|
end
|
99
99
|
|
100
100
|
it "contains an NCX file with book spine and TOC" do
|
101
|
-
File.exist?(
|
101
|
+
File.exist?("directory/OPS/toc.ncx").should be_true
|
102
102
|
end
|
103
103
|
|
104
104
|
it "splits the document into chapters" do
|
105
|
-
chapter1 = File.read
|
106
|
-
chapter2 = File.read
|
105
|
+
chapter1 = File.read "directory/OPS/chapter-1.html"
|
106
|
+
chapter2 = File.read "directory/OPS/chapter-2.html"
|
107
107
|
|
108
108
|
chapter1.length.should < @target_length
|
109
109
|
chapter2.length.should < @target_length
|
@@ -115,15 +115,15 @@ module Mint
|
|
115
115
|
|
116
116
|
describe "#split_on" do
|
117
117
|
it "returns a copy of the HTML text it is passed, grouping elements" do
|
118
|
-
Document.new(
|
118
|
+
Document.new("content.md").publish!
|
119
119
|
|
120
|
-
html_text = File.read
|
120
|
+
html_text = File.read "content.html"
|
121
121
|
html_document = Nokogiri::HTML.parse(html_text)
|
122
122
|
|
123
|
-
chapters = EPub.split_on(html_document,
|
123
|
+
chapters = EPub.split_on(html_document, "h2")
|
124
124
|
|
125
125
|
expected_document = Nokogiri::HTML.parse <<-HTML
|
126
|
-
<div id=
|
126
|
+
<div id="container">
|
127
127
|
<div>
|
128
128
|
<h2>Header</h2>
|
129
129
|
<p>This is just a test.</p>
|
@@ -138,7 +138,7 @@ module Mint
|
|
138
138
|
</div>
|
139
139
|
HTML
|
140
140
|
|
141
|
-
expected_chapters = expected_document.search
|
141
|
+
expected_chapters = expected_document.search "div div"
|
142
142
|
|
143
143
|
cleanse(chapters).should == cleanse(expected_chapters)
|
144
144
|
end
|
@@ -146,25 +146,25 @@ module Mint
|
|
146
146
|
|
147
147
|
describe "#zip!" do
|
148
148
|
before do
|
149
|
-
FileUtils.mkdir
|
149
|
+
FileUtils.mkdir "directory"
|
150
150
|
|
151
151
|
files = {
|
152
|
-
first:
|
153
|
-
second:
|
154
|
-
third:
|
152
|
+
first: "First content",
|
153
|
+
second: "Second content",
|
154
|
+
third: "Third content"
|
155
155
|
}
|
156
156
|
|
157
157
|
files.each do |name, content|
|
158
|
-
File.open "directory/#{name}",
|
158
|
+
File.open "directory/#{name}", "w" do |f|
|
159
159
|
f << content
|
160
160
|
end
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
164
164
|
after do
|
165
|
-
Dir[
|
166
|
-
# FileUtils.rm
|
167
|
-
# FileUtils.rm_r
|
165
|
+
Dir["directory*"].each {|dir| FileUtils.rm_r dir }
|
166
|
+
# FileUtils.rm "directory.zip"
|
167
|
+
# FileUtils.rm_r "directory"
|
168
168
|
end
|
169
169
|
|
170
170
|
# This is not a great test of Zip functionality,
|
@@ -172,18 +172,18 @@ module Mint
|
|
172
172
|
# Most of the details of the Zip file creation will be tested
|
173
173
|
# above.
|
174
174
|
it "compresses the named file into a directory" do
|
175
|
-
EPub.zip!
|
176
|
-
File.exist?(
|
175
|
+
EPub.zip! "directory"
|
176
|
+
File.exist?("directory.zip").should be_true
|
177
177
|
end
|
178
178
|
|
179
179
|
it "accepts an extension parameter" do
|
180
|
-
EPub.zip!
|
181
|
-
File.exist?(
|
180
|
+
EPub.zip! "directory", :extension => "epub"
|
181
|
+
File.exist?("directory.epub").should be_true
|
182
182
|
end
|
183
183
|
|
184
184
|
it "creates a mimetype entry if specified" do
|
185
185
|
pending "a more robust Zip testing strategy"
|
186
|
-
EPub.zip!
|
186
|
+
EPub.zip! "directory", :mimetype => "text/epub"
|
187
187
|
end
|
188
188
|
end
|
189
189
|
|
@@ -195,7 +195,7 @@ module Mint
|
|
195
195
|
it "accepts a block for configuration options" do
|
196
196
|
lambda do
|
197
197
|
EPub.create! do |file|
|
198
|
-
file.type =
|
198
|
+
file.type = "container"
|
199
199
|
end
|
200
200
|
end.should_not raise_error
|
201
201
|
end
|
@@ -203,21 +203,21 @@ module Mint
|
|
203
203
|
it "render a container file" do
|
204
204
|
EPub.should_receive(:container_defaults).once.and_return({})
|
205
205
|
EPub.create! do |file|
|
206
|
-
file.type =
|
206
|
+
file.type = "container"
|
207
207
|
end
|
208
208
|
end
|
209
209
|
|
210
210
|
it "render a content file" do
|
211
211
|
EPub.should_receive(:content_defaults).once.and_return({})
|
212
212
|
EPub.create! do |file|
|
213
|
-
file.type =
|
213
|
+
file.type = "content"
|
214
214
|
end
|
215
215
|
end
|
216
216
|
|
217
217
|
it "render a table of contents file" do
|
218
218
|
EPub.should_receive(:toc_defaults).once.and_return({})
|
219
219
|
EPub.create! do |file|
|
220
|
-
file.type =
|
220
|
+
file.type = "toc"
|
221
221
|
end
|
222
222
|
end
|
223
223
|
|
@@ -231,12 +231,12 @@ module Mint
|
|
231
231
|
it "calls #create_chapter! for each chapter" do
|
232
232
|
EPub.should_receive(:create_chapter!).once.ordered
|
233
233
|
EPub.should_receive(:create_chapter!).once.ordered
|
234
|
-
EPub.create_chapters! [
|
234
|
+
EPub.create_chapters! ["text1", "text2"]
|
235
235
|
end
|
236
236
|
end
|
237
237
|
|
238
238
|
def cleanse(dom)
|
239
|
-
dom.to_s.squeeze.chomp.gsub(/^\s/,
|
239
|
+
dom.to_s.squeeze.chomp.gsub(/^\s/, "")
|
240
240
|
end
|
241
241
|
end
|
242
242
|
end
|
data/spec/resource_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
module Mint
|
4
4
|
describe Resource do
|
@@ -25,7 +25,7 @@ module Mint
|
|
25
25
|
let(:resource) { Resource.new @content_file }
|
26
26
|
subject { resource }
|
27
27
|
|
28
|
-
its(:name) { should ==
|
28
|
+
its(:name) { should == "content.html" }
|
29
29
|
its(:root) { should == @tmp_dir }
|
30
30
|
its(:source) { should == @content_file }
|
31
31
|
its(:source_file) { should == @full_content_file }
|
@@ -45,7 +45,7 @@ module Mint
|
|
45
45
|
let(:resource) { Resource.new @content_file, :root => @alternative_root }
|
46
46
|
subject { resource }
|
47
47
|
|
48
|
-
its(:name) { should ==
|
48
|
+
its(:name) { should == "content.html" }
|
49
49
|
its(:root) { should == @alternative_root }
|
50
50
|
its(:source) { should == @content_file }
|
51
51
|
its(:source_file) { should == @full_alt_content_file }
|
@@ -62,7 +62,7 @@ module Mint
|
|
62
62
|
# This is a use case we will only ever test here, so
|
63
63
|
# I'm not going to include it in the spec_helper
|
64
64
|
FileUtils.mkdir_p @alternative_root
|
65
|
-
File.open(@full_alt_content_file,
|
65
|
+
File.open(@full_alt_content_file, "w") do |f|
|
66
66
|
f << @content
|
67
67
|
end
|
68
68
|
end
|
@@ -70,7 +70,7 @@ module Mint
|
|
70
70
|
let(:resource) { Resource.new @full_alt_content_file }
|
71
71
|
subject { resource }
|
72
72
|
|
73
|
-
its(:name) { should ==
|
73
|
+
its(:name) { should == "content.html" }
|
74
74
|
its(:root) { should == @alternative_root }
|
75
75
|
its(:source) { should == @full_alt_content_file }
|
76
76
|
its(:source_file) { should == @full_alt_content_file}
|
@@ -92,7 +92,7 @@ module Mint
|
|
92
92
|
|
93
93
|
subject { resource }
|
94
94
|
|
95
|
-
its(:name) { should ==
|
95
|
+
its(:name) { should == "content.html" }
|
96
96
|
its(:root) { should == @alternative_root }
|
97
97
|
its(:source) { should == @full_content_file }
|
98
98
|
its(:source_file) { should == @full_content_file }
|
@@ -108,18 +108,18 @@ module Mint
|
|
108
108
|
let(:resource) do
|
109
109
|
Resource.new @content_file do |resource|
|
110
110
|
resource.root = @alternative_root
|
111
|
-
resource.destination =
|
111
|
+
resource.destination = "destination"
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
115
|
subject { resource }
|
116
116
|
|
117
|
-
its(:name) { should ==
|
117
|
+
its(:name) { should == "content.html" }
|
118
118
|
its(:root) { should == @alternative_root }
|
119
119
|
its(:source) { should == @content_file }
|
120
120
|
its(:source_file) { should == @full_alt_content_file }
|
121
121
|
its(:source_directory) { should == @alternative_root }
|
122
|
-
its(:destination) { should ==
|
122
|
+
its(:destination) { should == "destination" }
|
123
123
|
|
124
124
|
its(:destination_file) do
|
125
125
|
should == "#{@alternative_root}/destination/content.html"
|
data/spec/spec_helper.rb
CHANGED
@@ -1,110 +1,37 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
|
4
|
-
def delete_class(klass)
|
5
|
-
klass = nil
|
6
|
-
GC.start
|
7
|
-
sleep 1
|
8
|
-
end
|
9
|
-
|
10
|
-
RSpec::Matchers.define :be_in_directory do |name|
|
11
|
-
match {|resource| resource.source_directory =~ /#{name}/ }
|
12
|
-
end
|
13
|
-
|
14
|
-
RSpec::Matchers.define :be_path do |name|
|
15
|
-
match {|resource| resource == Pathname.new(name) }
|
16
|
-
end
|
17
|
-
|
18
|
-
RSpec::Matchers.define :be_in_template do |name|
|
19
|
-
match {|file| file =~ /#{Mint.root}.*#{name}/ }
|
20
|
-
end
|
21
|
-
|
22
|
-
RSpec::Matchers.define :be_a_template do |name|
|
23
|
-
match {|file| Mint.template? file }
|
24
|
-
end
|
1
|
+
require "pathname"
|
2
|
+
require "mint"
|
3
|
+
require_relative "support/matchers"
|
25
4
|
|
26
5
|
RSpec.configure do |config|
|
27
|
-
config.before(:
|
6
|
+
config.before(:all) do
|
28
7
|
@old_dir = Dir.getwd
|
29
|
-
|
8
|
+
FileUtils.mkdir_p "/tmp/mint-test"
|
9
|
+
@tmp_dir = File.realpath "/tmp/mint-test"
|
10
|
+
|
11
|
+
@content_file = "content.md"
|
12
|
+
@layout_file = "layout.haml"
|
13
|
+
@static_style_file = "static.css"
|
14
|
+
@dynamic_style_file = "dynamic.sass"
|
15
|
+
|
16
|
+
["content.md", "layout.haml", "static.css", "dynamic.sass"].each do |file|
|
17
|
+
FileUtils.cp "spec/support/fixtures/#{file}", @tmp_dir
|
18
|
+
end
|
30
19
|
|
31
|
-
FileUtils.mkdir_p @tmp_dir
|
32
20
|
Dir.chdir @tmp_dir
|
33
21
|
end
|
34
22
|
|
35
|
-
config.after(:
|
23
|
+
config.after(:all) do
|
36
24
|
Dir.chdir @old_dir
|
37
25
|
FileUtils.rm_r @tmp_dir
|
38
26
|
end
|
39
27
|
|
40
|
-
config.before(:each) do
|
41
|
-
@content_file = 'content.md'
|
42
|
-
@destination_file = 'content.html'
|
43
|
-
@layout_file = 'layout.haml'
|
44
|
-
@style_file = 'style.css'
|
45
|
-
|
46
|
-
@static_style_file = 'static.css'
|
47
|
-
@dynamic_style_file = 'dynamic.sass'
|
48
|
-
|
49
|
-
@content = <<-HERE
|
50
|
-
---
|
51
|
-
metadata: true
|
52
|
-
|
53
|
-
Header
|
54
|
-
------
|
55
|
-
|
56
|
-
This is just a test.
|
57
|
-
|
58
|
-
Paragraph number two.
|
59
|
-
|
60
|
-
Header 2
|
61
|
-
--------
|
62
|
-
|
63
|
-
Third sentence.
|
64
|
-
|
65
|
-
Fourth sentence.
|
66
|
-
HERE
|
67
|
-
|
68
|
-
@layout = <<-HERE
|
69
|
-
!!!
|
70
|
-
%html
|
71
|
-
%head
|
72
|
-
%body= content
|
73
|
-
HERE
|
74
|
-
|
75
|
-
@style = 'body { font-size: 16px }'
|
76
|
-
|
77
|
-
@static_style = <<-HERE
|
78
|
-
body #container {
|
79
|
-
padding: 1em;
|
80
|
-
}
|
81
|
-
HERE
|
82
|
-
|
83
|
-
@dynamic_style = <<HERE
|
84
|
-
body
|
85
|
-
#container
|
86
|
-
padding: 1em
|
87
|
-
HERE
|
88
|
-
|
89
|
-
[:content, :layout, :style, :static_style, :dynamic_style ].each do |v|
|
90
|
-
File.open(instance_variable_get(:"@#{v}_file"), 'w') do |f|
|
91
|
-
f << instance_variable_get(:"@#{v}")
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
28
|
config.after(:each) do
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
[:content, :destination, :layout, :style, :static_style, :dynamic_style].
|
102
|
-
map(&instance).
|
103
|
-
select {|file| File.file? file }.
|
104
|
-
each {|file| File.delete(file) }
|
29
|
+
["content.html", ".mint/defaults.yaml"].map {|file| Pathname.new file }.
|
30
|
+
select(&:exist?).
|
31
|
+
each {|file| FileUtils.rm_rf file }
|
105
32
|
|
106
33
|
Mint.templates.
|
107
|
-
map {|template| Pathname.new(template) +
|
34
|
+
map {|template| Pathname.new(template) + "css" }.
|
108
35
|
select(&:exist?).
|
109
36
|
map(&:children).
|
110
37
|
flatten.
|