mint 0.2 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +22 -47
- data/features/mint_document.feature +4 -4
- data/lib/mint.rb +5 -0
- data/lib/mint/commandline.rb +0 -2
- data/lib/mint/css.rb +2 -2
- data/lib/mint/document.rb +136 -0
- data/lib/mint/layout.rb +12 -0
- data/lib/mint/mint.rb +9 -196
- data/lib/mint/resource.rb +53 -0
- data/lib/mint/style.rb +17 -0
- data/lib/mint/version.rb +1 -1
- data/spec/document_spec.rb +183 -130
- data/templates/default/style.sass +114 -0
- metadata +120 -9
- data/templates/default/style.css +0 -110
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'mint/mint'
|
2
|
+
|
3
|
+
module Mint
|
4
|
+
class Resource
|
5
|
+
attr_accessor :type
|
6
|
+
|
7
|
+
attr_reader :source
|
8
|
+
def source=(source)
|
9
|
+
@source = Pathname.new(source) if source
|
10
|
+
end
|
11
|
+
|
12
|
+
# I haven't tested this - moved empty string from
|
13
|
+
# default options into this method, so that default options
|
14
|
+
# can be uniform - i.e., style_destination and destination
|
15
|
+
# can each be nil to indicate that any rendering will be
|
16
|
+
# done in the same folder the file is already in. I need
|
17
|
+
# to make sure that adding the empty string here actually
|
18
|
+
# keeps us in the current working directory
|
19
|
+
attr_reader :destination
|
20
|
+
def destination=(destination)
|
21
|
+
@destination = Pathname.new(destination) if destination
|
22
|
+
end
|
23
|
+
|
24
|
+
attr_reader :name
|
25
|
+
def name=(name)
|
26
|
+
@name = name
|
27
|
+
end
|
28
|
+
|
29
|
+
def renderer=(renderer)
|
30
|
+
@renderer = renderer
|
31
|
+
end
|
32
|
+
|
33
|
+
def initialize(source, type=:resource, options={})
|
34
|
+
return nil unless source
|
35
|
+
|
36
|
+
self.source = source
|
37
|
+
self.type = type
|
38
|
+
self.destination = options[:destination]
|
39
|
+
self.name = Mint.guess_name_from source
|
40
|
+
self.renderer = Mint.renderer source
|
41
|
+
end
|
42
|
+
|
43
|
+
def equal?(other)
|
44
|
+
self.destination + self.name == other.destination + other.name
|
45
|
+
end
|
46
|
+
alias_method :==, :equal?
|
47
|
+
|
48
|
+
def render(context=Object.new, args={})
|
49
|
+
# see Tilt TEMPLATES.md for more info
|
50
|
+
@renderer.render context, args
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/mint/style.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'mint/resource'
|
2
|
+
|
3
|
+
module Mint
|
4
|
+
# Style describes a resource whose type is `:style`. Beyond its type,
|
5
|
+
# it is a simple resource. However, its type helps decide which template
|
6
|
+
# file to use when a template name is specified.
|
7
|
+
class Style < Resource
|
8
|
+
def initialize(source, opts=Mint.default_options)
|
9
|
+
super(source, :style, opts)
|
10
|
+
self.destination ||= source.dirname.expand_path + 'css'
|
11
|
+
end
|
12
|
+
|
13
|
+
def need_rendering?
|
14
|
+
source.extname !~ /\.css$/
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/mint/version.rb
CHANGED
data/spec/document_spec.rb
CHANGED
@@ -1,173 +1,226 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'fakefs/safe'
|
3
|
-
|
4
|
-
FakeFS do
|
5
|
-
module Mint
|
6
|
-
describe Document do
|
7
|
-
before(:each) do
|
8
|
-
@file = 'content.md'
|
9
|
-
@layout_file = 'local.haml'
|
10
|
-
@style_file = 'local.sass'
|
11
|
-
|
12
|
-
@content = <<-HERE.gsub(/^\s*/, '')
|
13
|
-
Header
|
14
|
-
------
|
15
|
-
|
16
|
-
This is just a test.
|
17
|
-
HERE
|
18
|
-
|
19
|
-
@layout = <<-HERE.gsub(/^\s*/, '')
|
20
|
-
!!!
|
21
|
-
%html
|
22
|
-
%head
|
23
|
-
%body= content
|
24
|
-
HERE
|
25
|
-
|
26
|
-
@style = 'body { font-size: 16px }'
|
27
|
-
|
28
|
-
File.open @file, 'w' do |f|
|
29
|
-
f << @content
|
30
|
-
end
|
31
2
|
|
32
|
-
|
33
|
-
|
34
|
-
|
3
|
+
module Mint
|
4
|
+
describe Document do
|
5
|
+
before(:all) do
|
6
|
+
@old_dir = Dir.getwd
|
7
|
+
Dir.chdir 'tmp'
|
8
|
+
end
|
35
9
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
10
|
+
before do
|
11
|
+
@content_file = 'content.md'
|
12
|
+
@layout_file = 'local.haml'
|
13
|
+
@style_file = 'local.css'
|
40
14
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
15
|
+
@content = <<-HERE
|
16
|
+
Header
|
17
|
+
------
|
45
18
|
|
46
|
-
|
47
|
-
|
48
|
-
|
19
|
+
This is just a test.
|
20
|
+
HERE
|
21
|
+
|
22
|
+
@layout = <<-HERE
|
23
|
+
!!!
|
24
|
+
%html
|
25
|
+
%head
|
26
|
+
%body= content
|
27
|
+
HERE
|
28
|
+
|
29
|
+
@style = 'body { font-size: 16px }'
|
30
|
+
|
31
|
+
File.open @content_file, 'w' do |f|
|
32
|
+
f << @content
|
49
33
|
end
|
50
34
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
35
|
+
File.open @layout_file, 'w' do |f|
|
36
|
+
f << @layout
|
37
|
+
end
|
55
38
|
|
56
|
-
|
57
|
-
|
58
|
-
end
|
39
|
+
File.open @style_file, 'w' do |f|
|
40
|
+
f << @style
|
59
41
|
end
|
42
|
+
end
|
60
43
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
44
|
+
after do
|
45
|
+
File.delete @content_file
|
46
|
+
File.delete @layout_file
|
47
|
+
File.delete @style_file
|
48
|
+
end
|
65
49
|
|
66
|
-
|
67
|
-
|
68
|
-
|
50
|
+
after(:all) do
|
51
|
+
Dir.chdir @old_dir
|
52
|
+
end
|
53
|
+
|
54
|
+
shared_examples_for "all documents" do
|
55
|
+
it "loads content as its source" do
|
56
|
+
document.source.to_s.should == 'content.md'
|
69
57
|
end
|
70
58
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
@document.layout.source.to_s.should == @layout_file
|
75
|
-
end
|
59
|
+
it "guesses its name from the source" do
|
60
|
+
document.name.to_s.should =~ /content/
|
61
|
+
end
|
76
62
|
|
77
|
-
|
78
|
-
|
79
|
-
@document.style.source.to_s.should == @style_file
|
80
|
-
end
|
63
|
+
it "renders its content" do
|
64
|
+
document.content.should =~ /<p>This is just a test.<\/p>/
|
81
65
|
end
|
82
66
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
67
|
+
it "renders its layout, injecting content inside" do
|
68
|
+
document.render.should =~
|
69
|
+
/.*<html>.*<p>This is just a test.<\/p>.*<\/html>.*/m
|
70
|
+
end
|
87
71
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
72
|
+
# This test makes me think I want to add document.destination_file and
|
73
|
+
# change document.destination to document.destination_directory.
|
74
|
+
it "creates a named output file in its specified destination directory" do
|
75
|
+
pending
|
76
|
+
document.mint
|
77
|
+
document.destination_file.should exist
|
78
|
+
# file = Pathname.getwd + (document.destination || '') + document.name
|
79
|
+
# file.should exist
|
92
80
|
end
|
93
81
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
82
|
+
it "writes its rendered layout and content to that output file" do
|
83
|
+
pending
|
84
|
+
document.mint
|
85
|
+
content = File.read document.destination_file
|
86
|
+
content.should =~ /.*<html>.*<p>This is just a test.<\/p>.*<\/html>.*/m
|
87
|
+
end
|
88
|
+
end
|
98
89
|
|
99
|
-
|
100
|
-
|
101
|
-
|
90
|
+
shared_examples_for "documents with a static stylesheet" do
|
91
|
+
it "knows not to render its style" do
|
92
|
+
document.style.need_rendering?.should == false
|
102
93
|
end
|
94
|
+
|
95
|
+
it "does not render or write its style"
|
96
|
+
end
|
103
97
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
98
|
+
shared_examples_for "documents with a dynamic stylesheet" do
|
99
|
+
it "knows to render its style" do
|
100
|
+
document.style.need_rendering?.should == true
|
101
|
+
end
|
102
|
+
|
103
|
+
it "writes its rendered style into its style_destination"
|
104
|
+
end
|
108
105
|
|
109
|
-
|
110
|
-
|
111
|
-
|
106
|
+
shared_examples_for "documents with the default template" do
|
107
|
+
it "chooses the default layout" do
|
108
|
+
document.layout.should be_in_directory('default')
|
112
109
|
end
|
113
110
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
111
|
+
it "chooses the default style" do
|
112
|
+
document.style.should be_in_directory('default')
|
113
|
+
end
|
114
|
+
end
|
118
115
|
|
119
|
-
|
120
|
-
|
121
|
-
|
116
|
+
shared_examples_for "documents with the pro template" do
|
117
|
+
it "chooses the pro layout" do
|
118
|
+
document.layout.should be_in_directory('pro')
|
122
119
|
end
|
123
120
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
end
|
121
|
+
it "chooses the pro style" do
|
122
|
+
document.style.should be_in_directory('pro')
|
123
|
+
end
|
124
|
+
end
|
129
125
|
|
130
|
-
|
131
|
-
|
132
|
-
|
126
|
+
shared_examples_for "documents with the local template" do
|
127
|
+
it "chooses the local layout" do
|
128
|
+
document.layout.name.to_s.should =~ /local/
|
129
|
+
document.layout.source.to_s.should == 'local.haml'
|
133
130
|
end
|
134
131
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
132
|
+
it "chooses the local style" do
|
133
|
+
document.style.name.to_s.should =~ /local/
|
134
|
+
document.style.source.to_s.should == 'local.css'
|
135
|
+
end
|
136
|
+
end
|
139
137
|
|
140
|
-
|
141
|
-
|
142
|
-
|
138
|
+
shared_examples_for "documents without explicit directories" do
|
139
|
+
it "does not have a nested destination directory" do
|
140
|
+
document.destination.should be_nil
|
143
141
|
end
|
144
142
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
end
|
143
|
+
it "sets the style's current directory as its style destination" do
|
144
|
+
document.style_destination.should be_nil
|
145
|
+
end
|
146
|
+
end
|
150
147
|
|
151
|
-
|
152
|
-
|
153
|
-
|
148
|
+
shared_examples_for "documents with explicit directories" do
|
149
|
+
it "has a nested destination directory" do
|
150
|
+
document.destination.to_s.should == 'destination'
|
154
151
|
end
|
155
152
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
document.style_destination = 'styles'
|
153
|
+
it "sets the destination directory as its style destination" do
|
154
|
+
document.style_destination.to_s.should == 'styles'
|
155
|
+
end
|
156
|
+
end
|
161
157
|
|
162
|
-
|
163
|
-
|
164
|
-
end
|
165
|
-
end
|
158
|
+
context "when it's created without explicit options" do
|
159
|
+
let(:document) { Document.new @content_file }
|
166
160
|
|
167
|
-
|
168
|
-
|
169
|
-
|
161
|
+
it_behaves_like "all documents"
|
162
|
+
it_behaves_like "documents with the default template"
|
163
|
+
it_behaves_like "documents without explicit directories"
|
164
|
+
it_behaves_like "documents with a dynamic stylesheet"
|
165
|
+
end
|
166
|
+
|
167
|
+
context "when it's created inline with named layouts and styles" do
|
168
|
+
let(:document) { Document.new @content_file,
|
169
|
+
:layout => 'pro', :style => 'pro' }
|
170
|
+
|
171
|
+
it_behaves_like "all documents"
|
172
|
+
it_behaves_like "documents with the pro template"
|
173
|
+
it_behaves_like "documents without explicit directories"
|
174
|
+
it_behaves_like "documents with a dynamic stylesheet"
|
175
|
+
end
|
176
|
+
|
177
|
+
context "when it's created inline with local layouts and styles" do
|
178
|
+
let(:document) { Document.new @content_file,
|
179
|
+
:layout => 'local.haml', :style => 'local.css' }
|
180
|
+
|
181
|
+
it_behaves_like "all documents"
|
182
|
+
it_behaves_like "documents with the local template"
|
183
|
+
it_behaves_like "documents without explicit directories"
|
184
|
+
it_behaves_like "documents with a static stylesheet"
|
185
|
+
end
|
186
|
+
|
187
|
+
context "when it's created with a template" do
|
188
|
+
let(:document) { Document.new @content_file, :template => 'pro' }
|
189
|
+
|
190
|
+
it_behaves_like "all documents"
|
191
|
+
it_behaves_like "documents with the pro template"
|
192
|
+
it_behaves_like "documents without explicit directories"
|
193
|
+
it_behaves_like "documents with a dynamic stylesheet"
|
194
|
+
end
|
195
|
+
|
196
|
+
context "when it's created with a non-default destinations" do
|
197
|
+
let(:document) { Document.new @content_file,
|
198
|
+
:root => 'root', :destination => 'destination',
|
199
|
+
:style_destination => 'styles' }
|
200
|
+
|
201
|
+
it_behaves_like "all documents"
|
202
|
+
it_behaves_like "documents with the default template"
|
203
|
+
it_behaves_like "documents with explicit directories"
|
204
|
+
it_behaves_like "documents with a dynamic stylesheet"
|
205
|
+
end
|
206
|
+
|
207
|
+
context "when it's created with a block" do
|
208
|
+
let(:document) do
|
209
|
+
Document.new @content_file do |document|
|
210
|
+
document.destination = 'destination'
|
211
|
+
document.style_destination = 'styles'
|
212
|
+
document.layout = 'pro'
|
213
|
+
document.style = 'pro'
|
214
|
+
end
|
170
215
|
end
|
216
|
+
|
217
|
+
it_behaves_like "all documents"
|
218
|
+
it_behaves_like "documents with the pro template"
|
219
|
+
it_behaves_like "documents with explicit directories"
|
220
|
+
it_behaves_like "documents with a dynamic stylesheet"
|
171
221
|
end
|
222
|
+
|
223
|
+
context "when it's created with an existing layout"
|
224
|
+
context "when it's created with an existnig style"
|
172
225
|
end
|
173
226
|
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
@import '../reset.css'
|
2
|
+
|
3
|
+
body
|
4
|
+
font-family: 'Hoefler Text', Georgia, Garamond, FreeSerif, serif
|
5
|
+
|
6
|
+
h1, h2, h3, h4, h5, h6
|
7
|
+
line-height: 1.5
|
8
|
+
|
9
|
+
h1, h2, h3
|
10
|
+
font-weight: normal
|
11
|
+
|
12
|
+
h4, h5, h6
|
13
|
+
font-weight: bold
|
14
|
+
margin-bottom: 9px
|
15
|
+
|
16
|
+
h1
|
17
|
+
font-size: 130%
|
18
|
+
border-bottom: solid 2px #666
|
19
|
+
margin-bottom: 18px
|
20
|
+
|
21
|
+
h2
|
22
|
+
font-size: 125%
|
23
|
+
margin-top: 18px
|
24
|
+
margin-bottom: 9px
|
25
|
+
|
26
|
+
h3
|
27
|
+
font-size: 100%
|
28
|
+
font-style: normal
|
29
|
+
margin-top: 18px
|
30
|
+
margin-bottom: 9px
|
31
|
+
|
32
|
+
h4
|
33
|
+
font-size: 100%
|
34
|
+
|
35
|
+
ul
|
36
|
+
list-style-type: square
|
37
|
+
|
38
|
+
ul
|
39
|
+
list-style-type: circle
|
40
|
+
|
41
|
+
ul, ol
|
42
|
+
margin: 6px 0 0 5px
|
43
|
+
padding-left: 25px
|
44
|
+
|
45
|
+
p
|
46
|
+
margin: 9px 0 9px 0
|
47
|
+
|
48
|
+
p+p, ul+p, ol+p
|
49
|
+
// text-indent: 1em
|
50
|
+
|
51
|
+
$link_color: #cb0018
|
52
|
+
a
|
53
|
+
&:link
|
54
|
+
color: $link_color
|
55
|
+
&:visited
|
56
|
+
color: $link_color
|
57
|
+
&:active
|
58
|
+
color: $link_color
|
59
|
+
&:hover
|
60
|
+
color: #fff
|
61
|
+
background-color: $link_color
|
62
|
+
|
63
|
+
code
|
64
|
+
font-family: Menlo, Mensch, Monaco, Consolas, Monotype, mono
|
65
|
+
font-style: normal
|
66
|
+
|
67
|
+
pre, blockquote
|
68
|
+
display: block
|
69
|
+
width: 90%
|
70
|
+
margin-left: 0
|
71
|
+
padding: 5px 10px
|
72
|
+
|
73
|
+
background-color: #eee
|
74
|
+
font-size: 95%
|
75
|
+
|
76
|
+
p
|
77
|
+
margin: 0
|
78
|
+
|
79
|
+
blockquote
|
80
|
+
padding: 10px
|
81
|
+
border-left: solid 4px #ddd
|
82
|
+
|
83
|
+
font-style: italic
|
84
|
+
|
85
|
+
@media screen
|
86
|
+
body
|
87
|
+
font-size: 16px
|
88
|
+
background-color: #666
|
89
|
+
line-height: 18px
|
90
|
+
|
91
|
+
#container
|
92
|
+
display: block
|
93
|
+
border: solid 1px #999
|
94
|
+
width: 500px
|
95
|
+
padding: 50px
|
96
|
+
margin: 10px auto
|
97
|
+
background-color: #fff
|
98
|
+
|
99
|
+
code
|
100
|
+
font-size: 12px
|
101
|
+
|
102
|
+
pre
|
103
|
+
code
|
104
|
+
font-size: 11px
|
105
|
+
|
106
|
+
@media print
|
107
|
+
body
|
108
|
+
font-size: 12pt
|
109
|
+
margin: 1in 1.25in
|
110
|
+
line-height: 1.3
|
111
|
+
img
|
112
|
+
display: block
|
113
|
+
code
|
114
|
+
font-size: 12pt
|