frank 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/output_spec.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
3
  describe Frank::Output do
4
- include Rack::Test::Methods
5
-
4
+ include Rack::Test::Methods
5
+
6
6
  context 'default output' do
7
7
  before :all do
8
8
  bin_dir = File.join(File.dirname(File.dirname(__FILE__)), 'bin', 'frankout')
@@ -12,80 +12,80 @@ describe Frank::Output do
12
12
  system "#{bin_dir} #{output_dir} > /dev/null"
13
13
  end
14
14
  end
15
-
15
+
16
16
  it 'creates the output folder' do
17
17
  File.exist?(File.join(File.dirname(__FILE__), 'template/output')).should be_true
18
18
  end
19
-
19
+
20
20
  it 'creates index.html' do
21
21
  output = File.join(File.dirname(__FILE__), 'template/output/index.html')
22
22
  File.read(output).should == "<div id='p'>/</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <h2>/</h2>\n</div>\n"
23
23
  end
24
-
24
+
25
25
  it 'creates partial_test.html' do
26
26
  output = File.join(File.dirname(__FILE__), 'template/output/partial_test.html')
27
27
  File.read(output).should == "<div id='p'>/partial_test</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <h2>/partial_test</h2>\n <p>hello from partial</p>\n</div>\n"
28
28
  end
29
-
29
+
30
30
  it 'creates partial_locals_test.html' do
31
31
  output = File.join(File.dirname(__FILE__), 'template/output/partial_locals_test.html')
32
32
  File.read(output).should == "<div id='p'>/partial_locals_test</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <h2>/partial_locals_test</h2>\n <p>hello from local</p>\n</div>\n"
33
33
  end
34
-
34
+
35
35
  it 'creates child.html' do
36
36
  output = File.join(File.dirname(__FILE__), 'template/output/nested/child.html')
37
37
  File.read(output).should == "<div id='nested_layout'>\n <h1>hello from child</h1>\n</div>\n"
38
38
  end
39
-
39
+
40
40
  it 'creates deep.html' do
41
41
  output = File.join(File.dirname(__FILE__), 'template/output/nested/deeper/deep.html')
42
42
  File.read(output).should == "<div id='nested_layout'>\n <h1>really deep</h1>\n</div>\n"
43
43
  end
44
-
44
+
45
45
  it 'creates no_layout.html' do
46
46
  output = File.join(File.dirname(__FILE__), 'template/output/no_layout.html')
47
47
  File.read(output).should == "<h1>i have no layout</h1>\n"
48
48
  end
49
-
49
+
50
50
  it 'creates erb.html' do
51
51
  output = File.join(File.dirname(__FILE__), 'template/output/erb.html')
52
52
  File.read(output).should == "<div id='p'>/erb</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
53
53
  end
54
-
54
+
55
55
  it 'creates redcloth.html' do
56
56
  output = File.join(File.dirname(__FILE__), 'template/output/redcloth.html')
57
57
  File.read(output).should == "<div id='p'>/redcloth</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
58
58
  end
59
-
59
+
60
60
  it 'creates markdown.html' do
61
61
  output = File.join(File.dirname(__FILE__), 'template/output/markdown.html')
62
62
  File.read(output).should == "<div id='p'>/markdown</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
63
63
  end
64
-
64
+
65
65
  it 'creates mustache.html' do
66
66
  output = File.join(File.dirname(__FILE__), 'template/output/mustache.html')
67
67
  File.read(output).should == "<div id='p'>/mustache</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
68
68
  end
69
-
69
+
70
70
  it 'creates liquid.html' do
71
71
  output = File.join(File.dirname(__FILE__), 'template/output/liquid.html')
72
72
  File.read(output).should == "<div id='p'>/liquid</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
73
73
  end
74
-
74
+
75
75
  it 'creates builder.html' do
76
76
  output = File.join(File.dirname(__FILE__), 'template/output/builder.html')
77
77
  File.read(output).should == "<div id='p'>/builder</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
78
78
  end
79
-
79
+
80
80
  it 'copies static.html' do
81
81
  output = File.join(File.dirname(__FILE__), 'template/output/files/static.html')
82
82
  File.read(output).should == "hello from static"
83
83
  end
84
-
84
+
85
85
  it "doesn't create partials" do
86
86
  File.exist?(File.join(File.dirname(__FILE__), 'template/output/_partial.html')).should be_false
87
87
  end
88
-
88
+
89
89
  it 'handles lorem replacement fields' do
90
90
  output = File.join(File.dirname(__FILE__), 'template/output/lorem_test.html')
91
91
  File.read(output).should include("<p class='words'>replace-this</p>")
@@ -96,18 +96,18 @@ describe Frank::Output do
96
96
  File.read(output).should include("<p class='email'>replace-this</p>")
97
97
  File.read(output).should include("<img src='replace-this' />")
98
98
  end
99
-
99
+
100
100
  it 'should not render the refresh js' do
101
101
  output = File.join(File.dirname(__FILE__), 'template/output/refresh.html')
102
102
  File.read(output).should == "<div id='p'>/refresh</div>\n<div id='layout'>\n \n</div>\n"
103
103
  end
104
-
104
+
105
105
  after(:all) do
106
106
  FileUtils.rm_r File.join(File.dirname(__FILE__), 'template/output')
107
107
  end
108
-
108
+
109
109
  end
110
-
110
+
111
111
  context 'productions output' do
112
112
  before :all do
113
113
  bin_dir = File.join(File.dirname(File.dirname(__FILE__)), 'bin', 'frankout')
@@ -117,80 +117,80 @@ describe Frank::Output do
117
117
  system "#{bin_dir} #{output_dir} --production > /dev/null"
118
118
  end
119
119
  end
120
-
120
+
121
121
  it 'creates the output folder' do
122
122
  File.exist?(File.join(File.dirname(__FILE__), 'template/output')).should be_true
123
123
  end
124
-
124
+
125
125
  it 'creates index.html' do
126
126
  output = File.join(File.dirname(__FILE__), 'template/output/index.html')
127
127
  File.read(output).should == "<div id='p'>/</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <h2>/</h2>\n</div>\n"
128
128
  end
129
-
129
+
130
130
  it 'creates partial_test.html' do
131
131
  output = File.join(File.dirname(__FILE__), 'template/output/partial_test/index.html')
132
132
  File.read(output).should == "<div id='p'>/partial_test</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <h2>/partial_test</h2>\n <p>hello from partial</p>\n</div>\n"
133
133
  end
134
-
134
+
135
135
  it 'creates partial_locals_test.html' do
136
136
  output = File.join(File.dirname(__FILE__), 'template/output/partial_locals_test/index.html')
137
137
  File.read(output).should == "<div id='p'>/partial_locals_test</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <h2>/partial_locals_test</h2>\n <p>hello from local</p>\n</div>\n"
138
138
  end
139
-
139
+
140
140
  it 'creates child.html' do
141
141
  output = File.join(File.dirname(__FILE__), 'template/output/nested/child/index.html')
142
142
  File.read(output).should == "<div id='nested_layout'>\n <h1>hello from child</h1>\n</div>\n"
143
143
  end
144
-
144
+
145
145
  it 'creates deep.html' do
146
146
  output = File.join(File.dirname(__FILE__), 'template/output/nested/deeper/deep/index.html')
147
147
  File.read(output).should == "<div id='nested_layout'>\n <h1>really deep</h1>\n</div>\n"
148
148
  end
149
-
149
+
150
150
  it 'creates no_layout.html' do
151
151
  output = File.join(File.dirname(__FILE__), 'template/output/no_layout/index.html')
152
152
  File.read(output).should == "<h1>i have no layout</h1>\n"
153
153
  end
154
-
154
+
155
155
  it 'creates erb.html' do
156
156
  output = File.join(File.dirname(__FILE__), 'template/output/erb/index.html')
157
157
  File.read(output).should == "<div id='p'>/erb</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
158
158
  end
159
-
159
+
160
160
  it 'creates redcloth.html' do
161
161
  output = File.join(File.dirname(__FILE__), 'template/output/redcloth/index.html')
162
162
  File.read(output).should == "<div id='p'>/redcloth</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
163
163
  end
164
-
164
+
165
165
  it 'creates markdown.html' do
166
166
  output = File.join(File.dirname(__FILE__), 'template/output/markdown/index.html')
167
167
  File.read(output).should == "<div id='p'>/markdown</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
168
168
  end
169
-
169
+
170
170
  it 'creates mustache.html' do
171
171
  output = File.join(File.dirname(__FILE__), 'template/output/mustache/index.html')
172
172
  File.read(output).should == "<div id='p'>/mustache</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
173
173
  end
174
-
174
+
175
175
  it 'creates liquid.html' do
176
176
  output = File.join(File.dirname(__FILE__), 'template/output/liquid/index.html')
177
177
  File.read(output).should == "<div id='p'>/liquid</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
178
178
  end
179
-
179
+
180
180
  it 'creates builder.html' do
181
181
  output = File.join(File.dirname(__FILE__), 'template/output/builder/index.html')
182
182
  File.read(output).should == "<div id='p'>/builder</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
183
183
  end
184
-
184
+
185
185
  it 'copies static.html' do
186
186
  output = File.join(File.dirname(__FILE__), 'template/output/files/static.html')
187
187
  File.read(output).should == "hello from static"
188
188
  end
189
-
189
+
190
190
  it "doesn't create partials" do
191
191
  File.exist?(File.join(File.dirname(__FILE__), 'template/output/_partial/index.html')).should be_false
192
192
  end
193
-
193
+
194
194
  it 'handles lorem replacement fields' do
195
195
  output = File.join(File.dirname(__FILE__), 'template/output/lorem_test/index.html')
196
196
  File.read(output).should include("<p class='words'>replace-this</p>")
@@ -201,16 +201,16 @@ describe Frank::Output do
201
201
  File.read(output).should include("<p class='email'>replace-this</p>")
202
202
  File.read(output).should include("<img src='replace-this' />")
203
203
  end
204
-
204
+
205
205
  it 'should not render the refresh js' do
206
206
  output = File.join(File.dirname(__FILE__), 'template/output/refresh/index.html')
207
207
  File.read(output).should == "<div id='p'>/refresh</div>\n<div id='layout'>\n \n</div>\n"
208
208
  end
209
-
209
+
210
210
  after(:all) do
211
211
  FileUtils.rm_r File.join(File.dirname(__FILE__), 'template/output')
212
212
  end
213
-
213
+
214
214
  end
215
-
215
+
216
216
  end
data/spec/render_spec.rb CHANGED
@@ -1,59 +1,54 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
3
  describe Frank::Render do
4
- include Rack::Test::Methods
5
-
4
+ include Rack::Test::Methods
5
+
6
6
  def app
7
- proj_dir = File.join(File.dirname(__FILE__), 'template')
8
- settings = YAML.load_file(File.join(proj_dir, 'settings.yml'))
7
+ Frank.bootstrap(File.join(File.dirname(__FILE__), 'template'))
9
8
  Frank.new do
10
- settings.each do |name, value|
11
- set name.to_s, value
12
- end
13
9
  set :environment, :test
14
- set :proj_dir, proj_dir
15
10
  end
16
11
  end
17
-
12
+
18
13
  before(:all) do
19
14
  @app = app
20
15
  end
21
-
16
+
22
17
  it 'renders a template using layout' do
23
18
  template = @app.render('index.haml')
24
19
  template.should == "<div id='p'>/</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <h2>/</h2>\n</div>\n"
25
20
  end
26
-
21
+
27
22
  it 'renders a template using layout2' do
28
23
  template = @app.render('layout2_test.haml')
29
24
  template.should == "<div id='layout2'>\n <h1>hi inside layout2</h1>\n</div>\n"
30
25
  end
31
-
26
+
32
27
  it 'renders a markdown template inside haml layout' do
33
28
  template = @app.render('markdown_in_haml.md')
34
29
  template.should == "<div id='p'>/markdown_in_haml</div>\n<div id='layout'>\n <h1>hi inside layout</h1>\n</div>\n"
35
30
  end
36
-
31
+
37
32
  it 'renders a nested template with a nested layout' do
38
33
  template = @app.render('/nested/child.haml')
39
34
  template.should == "<div id='nested_layout'>\n <h1>hello from child</h1>\n</div>\n"
40
35
  end
41
-
36
+
42
37
  it 'renders a deeply nested template with a nested layout' do
43
38
  template = @app.render('/nested/deeper/deep.haml')
44
39
  template.should == "<div id='nested_layout'>\n <h1>really deep</h1>\n</div>\n"
45
40
  end
46
-
41
+
47
42
  it 'renders a haml template with no layout' do
48
43
  template = @app.render('no_layout.haml')
49
44
  template.should == "<h1>i have no layout</h1>\n"
50
45
  end
51
-
46
+
52
47
  it 'renders haml template' do
53
48
  template = @app.render('index.haml')
54
49
  template.should == "<div id='p'>/</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <h2>/</h2>\n</div>\n"
55
50
  end
56
-
51
+
57
52
  it 'renders haml template with a haml partial' do
58
53
  template = @app.render('partial_test.haml')
59
54
  template.should == "<div id='p'>/partial_test</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <h2>/partial_test</h2>\n <p>hello from partial</p>\n</div>\n"
@@ -63,44 +58,56 @@ describe Frank::Render do
63
58
  template = @app.render('partial_locals_test.haml')
64
59
  template.should == "<div id='p'>/partial_locals_test</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <h2>/partial_locals_test</h2>\n <p>hello from local</p>\n</div>\n"
65
60
  end
66
-
61
+
67
62
  it 'renders sass template' do
68
- template = @app.render('sass.sass')
69
- template.should == "#hello-worlds {\n background: red; }\n"
63
+ template = @app.render('stylesheets/sass.sass')
64
+ template.should include("#hello-worlds {\n background: red;\n}\n")
70
65
  end
71
-
66
+
67
+ it 'renders sass with compass reset' do
68
+ template = @app.render('stylesheets/sass_with_compass.sass')
69
+ template.should include("h1, h2, h3, h4, h5, h6, p, blockquote, pre,\n")
70
+ end
71
+
72
+ it 'renders scss with compass mixin' do
73
+ template = @app.render('stylesheets/scss_with_compass.scss')
74
+ template.should include("-moz-border-radius: 5px;\n")
75
+ template.should include("-webkit-border-radius: 5px;\n")
76
+ template.should include("border-radius: 5px;\n")
77
+ end
78
+
72
79
  it 'renders erb template' do
73
80
  template = @app.render('erb.erb')
74
81
  template.should == "<div id='p'>/erb</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
75
82
  end
76
-
83
+
77
84
  it 'renders redcloth template' do
78
85
  template = @app.render('redcloth.textile')
79
86
  template.should == "<div id='p'>/redcloth</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
80
87
  end
81
-
88
+
82
89
  it 'renders rdiscount template' do
83
90
  template = @app.render('markdown.md')
84
91
  template.should == "<div id='p'>/markdown</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
85
92
  end
86
-
93
+
87
94
  it 'renders mustache template' do
88
95
  template = @app.render('mustache.mustache')
89
96
  template.should == "<div id='p'>/mustache</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
90
97
  end
91
-
98
+
92
99
  it 'renders liquid template' do
93
100
  template = @app.render('liquid.liquid')
94
101
  template.should == "<div id='p'>/liquid</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
95
102
  end
96
-
103
+
97
104
  it 'renders builder template' do
98
105
  template = @app.render('builder.builder')
99
106
  template.should == "<div id='p'>/builder</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n</div>\n"
100
107
  end
101
-
108
+
102
109
  it 'raise template error' do
103
110
  lambda { @app.render('not_a.template') }.should raise_error(Frank::TemplateError)
104
111
  end
105
-
112
+
106
113
  end
@@ -1 +1 @@
1
- = non_method if @environment == :test
1
+ = non_method if @blowup_sometimes
@@ -4,4 +4,8 @@
4
4
  %p.date= lorem.date '%Y-%m-%d', 'replace-this'
5
5
  %p.name= lorem.name 'replace-this'
6
6
  %p.email= lorem.email 'replace-this'
7
- %img{:src => lorem.image(400, 300, true, 'replace-this')}
7
+ %img{:src => lorem.image('400x300', :random_color => true)}
8
+ %img{:src => lorem.image('400x300', :background_color => '444', :color => 'eee', :replacement => 'replace-this')}
9
+ %img{:src => lorem.image('400x300', :color => 'aaa')}
10
+ %img{:src => lorem.image('400x300', :background_color => '444', :text => 'blah')}
11
+
@@ -0,0 +1,2 @@
1
+ - title "BLAH!"
2
+ %h1 hello
@@ -0,0 +1 @@
1
+ @import compass/reset
@@ -0,0 +1,5 @@
1
+ @import "compass/css3";
2
+
3
+ .panel {
4
+ @include border-radius(5px);
5
+ }
@@ -2,4 +2,9 @@ module FrankHelpers
2
2
  def hello_helper
3
3
  'hello from helper'
4
4
  end
5
+
6
+ def title(val = nil)
7
+ @title = val if val
8
+ @title || ""
9
+ end
5
10
  end
@@ -1,3 +1,5 @@
1
+ - if @title
2
+ #title= @title
1
3
  #p= current_path
2
4
  #layout
3
5
  = yield
@@ -0,0 +1 @@
1
+ Frank.environment = :test
@@ -1,78 +1,84 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
3
  describe Frank::TemplateHelpers do
4
- include Rack::Test::Methods
5
-
4
+ include Rack::Test::Methods
5
+
6
6
  def app
7
- proj_dir = File.join(File.dirname(__FILE__), 'template')
8
- settings = YAML.load_file(File.join(proj_dir, 'settings.yml'))
9
- require File.join(proj_dir, 'helpers')
7
+ Frank.bootstrap(File.join(File.dirname(__FILE__), 'template'))
8
+ require File.join(Frank.root, 'helpers')
10
9
  Frank.new do
11
- settings.each do |name, value|
12
- set name.to_s, value
13
- end
14
10
  set :environment, :test
15
- set :proj_dir, proj_dir
16
11
  end
17
12
  end
18
-
13
+
19
14
  before(:all) do
20
15
  @app = app
21
16
  end
22
-
17
+
23
18
  it 'render haml and use hello_helper' do
24
19
  template = @app.render('helper_test.haml')
25
20
  template.should == "<div id='p'>/helper_test</div>\n<div id='layout'>\n <h1>hello from helper</h1>\n</div>\n"
26
21
  end
27
-
22
+
23
+ it 'sets an instance variable, which the layout should render correctly' do
24
+ template = @app.render('setting_in_layout.haml')
25
+ template.should == "<div id='title'>BLAH!</div>\n<div id='p'>/setting_in_layout</div>\n<div id='layout'>\n <h1>hello</h1>\n</div>\n"
26
+ end
27
+
28
28
  it 'should render the refresh javascript' do
29
29
  template = @app.render('refresh.haml')
30
30
  template.should include("<script type=\"text/javascript\">\n (function(){")
31
31
  end
32
-
32
+
33
33
  context 'Lorem' do
34
34
  it 'render haml with 3 random lorem words' do
35
35
  template = @app.render('lorem_test.haml')
36
36
  reg = /<p class='words'>(?:\w+\s?){3}<\/p>/
37
37
  template.should =~ reg
38
38
  end
39
-
39
+
40
40
  it 'render haml with 2 random lorem sentences' do
41
41
  template = @app.render('lorem_test.haml')
42
42
  reg = /<p class='sentences'>(?:[^.]+.){2}<\/p>/
43
43
  template.should =~ reg
44
44
  end
45
-
45
+
46
46
  it 'render haml with 1 random lorem paragraph' do
47
47
  template = @app.render('lorem_test.haml')
48
48
  reg = /<p class='paragraphs'>(?:[^\n]+(?:\n\n)?){1}<\/p>/m
49
49
  template.should =~ reg
50
50
  end
51
-
51
+
52
52
  it 'render haml with lorem name' do
53
53
  template = @app.render('lorem_test.haml')
54
54
  reg = /<p class='name'>[\w']+\s[\w']+<\/p>/m
55
55
  template.should =~ reg
56
56
  end
57
-
57
+
58
58
  it 'render haml with lorem email' do
59
59
  template = @app.render('lorem_test.haml')
60
60
  reg = /<p class='email'>[\w-]+@\w+\.\w+<\/p>/m
61
61
  template.should =~ reg
62
62
  end
63
-
63
+
64
64
  it 'render haml with lorem date' do
65
65
  template = @app.render('lorem_test.haml')
66
66
  reg = /<p class='date'>\d{4}-\d{2}-\d{2}<\/p>/m
67
67
  template.should =~ reg
68
68
  end
69
-
69
+
70
70
  it 'render image url using imager' do
71
71
  template = @app.render('lorem_test.haml')
72
- reg = /<img src='\/_img\/400x300.jpg\?random\d{5}' \/>/
73
- template.should =~ reg
72
+ reg1 = /<img src='http:\/\/placehold\.it\/400x300\/[a-z0-9]{6}\/[a-z0-9]{6}' \/>/
73
+ reg2 = /<img src='http:\/\/placehold\.it\/400x300\/444\/eee' \/>/
74
+ reg3 = /<img src='http:\/\/placehold\.it\/400x300\/ccc\/aaa' \/>/
75
+ reg4 = /<img src='http:\/\/placehold\.it\/400x300\/444(&amp;|&)text=blah' \/>/
76
+
77
+ template.should =~ reg1
78
+ template.should =~ reg2
79
+ template.should =~ reg3
80
+ template.should =~ reg4
74
81
  end
75
82
  end
76
-
83
+
77
84
  end
78
-