mint 0.5.1 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/Gemfile +18 -0
  2. data/README.md +3 -3
  3. data/bin/mint +27 -27
  4. data/bin/mint-epub +6 -6
  5. data/config/syntax.yaml +12 -12
  6. data/{templates → config/templates}/base/style.sass +11 -4
  7. data/config/templates/default/css/style.css +158 -0
  8. data/config/templates/default/layout.haml +8 -0
  9. data/{templates → config/templates}/default/style.sass +0 -0
  10. data/{templates/default → config/templates/protocol}/layout.haml +0 -0
  11. data/config/templates/protocol/style.sass +20 -0
  12. data/config/templates/reset.css +92 -0
  13. data/config/templates/zen/css/style.css +145 -0
  14. data/{templates/pro → config/templates/zen}/layout.haml +0 -0
  15. data/config/templates/zen/style.sass +24 -0
  16. data/features/config.feature +21 -0
  17. data/features/publish.feature +3 -3
  18. data/features/support/env.rb +9 -27
  19. data/features/templates.feature +79 -0
  20. data/lib/mint.rb +11 -11
  21. data/lib/mint/{commandline.rb → command_line.rb} +96 -80
  22. data/lib/mint/css.rb +43 -34
  23. data/lib/mint/document.rb +99 -93
  24. data/lib/mint/helpers.rb +21 -17
  25. data/lib/mint/layout.rb +1 -1
  26. data/lib/mint/mint.rb +92 -36
  27. data/lib/mint/plugin.rb +5 -5
  28. data/lib/mint/plugins/epub.rb +51 -51
  29. data/lib/mint/resource.rb +2 -2
  30. data/lib/mint/style.rb +2 -2
  31. data/lib/mint/version.rb +1 -1
  32. data/spec/command_line_spec.rb +87 -0
  33. data/spec/css_spec.rb +46 -0
  34. data/spec/document_spec.rb +38 -40
  35. data/spec/helpers_spec.rb +101 -83
  36. data/spec/layout_spec.rb +1 -1
  37. data/spec/mint_spec.rb +184 -60
  38. data/spec/plugin_spec.rb +61 -67
  39. data/spec/plugins/epub_spec.rb +47 -47
  40. data/spec/resource_spec.rb +9 -9
  41. data/spec/spec_helper.rb +20 -93
  42. data/spec/style_spec.rb +6 -8
  43. data/spec/support/fixtures/content.md +16 -0
  44. data/spec/support/fixtures/dynamic.sass +3 -0
  45. data/spec/support/fixtures/layout.haml +3 -0
  46. data/spec/support/fixtures/static.css +3 -0
  47. data/spec/support/matchers.rb +15 -0
  48. metadata +160 -70
  49. data/spec/commandline_spec.rb +0 -91
  50. data/templates/pro/style.sass +0 -0
@@ -1,15 +1,15 @@
1
- require 'spec_helper'
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 'mint/plugins/epub'
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('content.md').chapters
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 'content.md', :destination => 'directory'
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('directory/content.html').length
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 'directory.epub'
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 'content.md'
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?('directory/content.html').should be_false
50
- File.exist?('directory.epub').should be_true
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('directory.epub')[0..1].should == 'PK'
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 'directory.epub', 'directory.zip'
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! 'directory.zip'
71
+ # EPub.unzip! "directory.zip"
72
72
  end
73
73
 
74
74
  after do
75
- FileUtils.rm_r 'directory.zip'
76
- FileUtils.rm_r 'directory'
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?('directory/META-INF/container.xml').should be_true
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?('directory/OPS').should be_true
84
+ File.exist?("directory/OPS").should be_true
85
85
  end
86
86
 
87
87
  it "contains a mimetype file" do
88
- File.exist?('directory/mimetype').should be_true
89
- File.read('directory/mimetype').chomp.should == 'application/epub+zip'
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?('directory/META-INF/container.xml').should be_true
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?('directory/OPS/content.opf').should be_true
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?('directory/OPS/toc.ncx').should be_true
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 'directory/OPS/chapter-1.html'
106
- chapter2 = File.read 'directory/OPS/chapter-2.html'
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('content.md').publish!
118
+ Document.new("content.md").publish!
119
119
 
120
- html_text = File.read 'content.html'
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, 'h2')
123
+ chapters = EPub.split_on(html_document, "h2")
124
124
 
125
125
  expected_document = Nokogiri::HTML.parse <<-HTML
126
- <div id='container'>
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 'div div'
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 'directory'
149
+ FileUtils.mkdir "directory"
150
150
 
151
151
  files = {
152
- first: 'First content',
153
- second: 'Second content',
154
- third: 'Third content'
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}", 'w' do |f|
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['directory*'].each {|dir| FileUtils.rm_r dir }
166
- # FileUtils.rm 'directory.zip'
167
- # FileUtils.rm_r 'directory'
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! 'directory'
176
- File.exist?('directory.zip').should be_true
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! 'directory', :extension => 'epub'
181
- File.exist?('directory.epub').should be_true
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! 'directory', :mimetype => 'text/epub'
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 = 'container'
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 = 'container'
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 = 'content'
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 = 'toc'
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! ['text1', 'text2']
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
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
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 == 'content.html' }
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 == 'content.html' }
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, 'w') do |f|
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 == 'content.html' }
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 == 'content.html' }
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 = 'destination'
111
+ resource.destination = "destination"
112
112
  end
113
113
  end
114
114
 
115
115
  subject { resource }
116
116
 
117
- its(:name) { should == 'content.html' }
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 == 'destination' }
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 'pathname'
2
- require 'mint'
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(:suite) do
6
+ config.before(:all) do
28
7
  @old_dir = Dir.getwd
29
- @tmp_dir = '/tmp/mint-test'
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(:suite) do
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
- instance = lambda do |name|
98
- instance_variable_get(:"@#{name}_file")
99
- end
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) + 'css' }.
34
+ map {|template| Pathname.new(template) + "css" }.
108
35
  select(&:exist?).
109
36
  map(&:children).
110
37
  flatten.