mint 0.2 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Mint
2
- VERSION = '0.2'
2
+ VERSION = '0.2.2'
3
3
  end
@@ -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
- File.open @layout_file, 'w' do |f|
33
- f << @layout
34
- end
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
- File.open @style_file, 'w' do |f|
37
- f << @style
38
- end
39
- end
10
+ before do
11
+ @content_file = 'content.md'
12
+ @layout_file = 'local.haml'
13
+ @style_file = 'local.css'
40
14
 
41
- shared_examples_for "all documents" do
42
- it "loads content as its source" do
43
- @document.source.to_s.should == 'content.md'
44
- end
15
+ @content = <<-HERE
16
+ Header
17
+ ------
45
18
 
46
- it "guesses its name from the source" do
47
- @document.name.to_s.should =~ /content/
48
- end
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
- shared_examples_for "documents with the default template" do
52
- it "chooses the default layout" do
53
- @document.layout.should be_in_directory('default')
54
- end
35
+ File.open @layout_file, 'w' do |f|
36
+ f << @layout
37
+ end
55
38
 
56
- it "chooses the default style" do
57
- @document.style.should be_in_directory('default')
58
- end
39
+ File.open @style_file, 'w' do |f|
40
+ f << @style
59
41
  end
42
+ end
60
43
 
61
- shared_examples_for "documents with the pro template" do
62
- it "chooses the pro layout" do
63
- @document.layout.should be_in_directory('pro')
64
- end
44
+ after do
45
+ File.delete @content_file
46
+ File.delete @layout_file
47
+ File.delete @style_file
48
+ end
65
49
 
66
- it "chooses the pro style" do
67
- @document.style.should be_in_directory('pro')
68
- end
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
- shared_examples_for "documents with the local template" do
72
- it "chooses the 'local' layout" do
73
- @document.layout.name.to_s.should =~ /local/
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
- it "chooses the 'local' style" do
78
- @document.style.name.to_s.should =~ /local/
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
- shared_examples_for "documents without explicit directories" do
84
- it "sets the root directory as its destination directory" do
85
- @document.destination.to_s.should == ''
86
- end
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
- it "sets the style's current directory as the style's destination directory" do
89
- @document.style_destination.should ==
90
- @document.style.source.dirname.expand_path
91
- end
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
- shared_examples_for "documents with explicit directories" do
95
- it "sets the root directory as its destination directory" do
96
- @document.destination.to_s.should == 'destination'
97
- end
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
- it "sets the destination directory as its style destination directory" do
100
- @document.style_destination.to_s.should == 'styles'
101
- end
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
- context "when it's created without explicit options" do
105
- before(:each) do
106
- @document = Document.new @file
107
- end
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
- it_behaves_like "all documents"
110
- it_behaves_like "documents with the default template"
111
- it_behaves_like "documents without explicit directories"
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
- context "when it's created inline with named layouts and styles" do
115
- before(:each) do
116
- @document = Document.new @file, :layout => 'pro', :style => 'pro'
117
- end
111
+ it "chooses the default style" do
112
+ document.style.should be_in_directory('default')
113
+ end
114
+ end
118
115
 
119
- it_behaves_like "all documents"
120
- it_behaves_like "documents with the pro template"
121
- it_behaves_like "documents without explicit directories"
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
- context "when it's created inline with local layouts and styles" do
125
- before(:each) do
126
- @document = Document.new @file, :layout => 'local.haml',
127
- :style => 'local.sass'
128
- end
121
+ it "chooses the pro style" do
122
+ document.style.should be_in_directory('pro')
123
+ end
124
+ end
129
125
 
130
- it_behaves_like "all documents"
131
- it_behaves_like "documents with the local template"
132
- it_behaves_like "documents without explicit directories"
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
- context "when it's created with a template" do
136
- before(:each) do
137
- @document = Document.new @file, :template => 'pro'
138
- end
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
- it_behaves_like "all documents"
141
- it_behaves_like "documents with the pro template"
142
- it_behaves_like "documents without explicit directories"
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
- context "when it's created with a non-default destinations" do
146
- before(:each) do
147
- @document = Document.new @file, :root => 'root',
148
- :destination => 'destination', :style_destination => 'styles'
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
- it_behaves_like "all documents"
152
- it_behaves_like "documents with the default template"
153
- it_behaves_like "documents with explicit directories"
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
- context "when it's created with a block" do
157
- before(:each) do
158
- @document = Document.new @file do |document|
159
- document.destination = 'destination'
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
- document.layout = 'pro'
163
- document.style = 'pro'
164
- end
165
- end
158
+ context "when it's created without explicit options" do
159
+ let(:document) { Document.new @content_file }
166
160
 
167
- it_behaves_like "all documents"
168
- it_behaves_like "documents with the pro template"
169
- it_behaves_like "documents with explicit directories"
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