mango 0.5.4 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. data/.gitignore +1 -2
  2. data/.rvmrc +1 -0
  3. data/.yardopts +1 -3
  4. data/{CHANGES.mdown → CHANGES.md} +40 -0
  5. data/Gemfile.lock +35 -23
  6. data/LICENSE +1 -1
  7. data/{README.mdown → README.md} +38 -27
  8. data/Rakefile +0 -13
  9. data/lib/mango.rb +5 -0
  10. data/lib/mango/application.rb +361 -129
  11. data/lib/mango/content_page.rb +89 -115
  12. data/lib/mango/core_ext/string.rb +16 -0
  13. data/lib/mango/core_ext/uri.rb +14 -0
  14. data/lib/mango/dependencies.rb +5 -4
  15. data/lib/mango/flavored_markdown.rb +7 -0
  16. data/lib/mango/rack/debugger.rb +20 -0
  17. data/lib/mango/runner.rb +33 -50
  18. data/lib/mango/templates/.gitignore +0 -1
  19. data/lib/mango/templates/Gemfile +1 -1
  20. data/lib/mango/templates/content/index.erb +6 -0
  21. data/lib/mango/templates/themes/default/javascripts/timer.coffee +6 -0
  22. data/lib/mango/templates/themes/default/public/javascripts/fireworks.js +0 -0
  23. data/lib/mango/templates/themes/default/public/{styles → stylesheets}/fireworks.css +0 -0
  24. data/lib/mango/templates/themes/default/public/{styles → stylesheets}/reset.css +0 -2
  25. data/lib/mango/templates/themes/default/{styles → stylesheets}/screen.sass +0 -2
  26. data/lib/mango/templates/themes/default/views/layout.haml +5 -5
  27. data/lib/mango/templates/themes/default/views/page.haml +1 -3
  28. data/lib/mango/version.rb +1 -1
  29. data/mango.gemspec +12 -10
  30. data/spec/fixture/content/engines/erb.erb +7 -0
  31. data/spec/fixture/content/engines/haml.haml +4 -4
  32. data/spec/fixture/content/engines/liquid.liquid +7 -0
  33. data/spec/fixture/content/engines/markdown.markdown +0 -6
  34. data/spec/fixture/content/engines/md.md +0 -6
  35. data/spec/fixture/content/engines/mkd.mkd +1 -0
  36. data/spec/fixture/content/page_with_missing_view.haml +2 -2
  37. data/spec/fixture/content/page_with_unregistered_view.haml +4 -0
  38. data/spec/fixture/content/view_engines/erb.haml +4 -0
  39. data/spec/fixture/content/view_engines/liquid.haml +4 -0
  40. data/spec/fixture/themes/default/javascripts/override.coffee +1 -0
  41. data/spec/fixture/themes/default/javascripts/siblings.coffee +7 -0
  42. data/spec/fixture/themes/default/javascripts/songs/happy.coffee +5 -0
  43. data/spec/fixture/themes/default/public/404.html +11 -0
  44. data/spec/fixture/themes/default/public/javascripts/econ.js +8 -0
  45. data/spec/fixture/themes/default/public/javascripts/math/opposite.js +6 -0
  46. data/spec/fixture/themes/default/public/javascripts/override.js +1 -0
  47. data/spec/fixture/themes/default/public/root.js +5 -0
  48. data/spec/fixture/themes/default/public/{styles → stylesheets}/override.css +0 -0
  49. data/spec/fixture/themes/default/public/{styles → stylesheets}/reset.css +0 -0
  50. data/spec/fixture/themes/default/public/{styles → stylesheets}/subfolder/another.css +0 -0
  51. data/spec/fixture/themes/default/security_hole.js +1 -0
  52. data/spec/fixture/themes/default/{styles → stylesheets}/override.sass +0 -0
  53. data/spec/fixture/themes/default/{styles/screen.sass → stylesheets/sass.sass} +4 -2
  54. data/spec/fixture/themes/default/stylesheets/scss.scss +19 -0
  55. data/spec/fixture/themes/default/{styles → stylesheets}/subfolder/screen.sass +0 -2
  56. data/spec/fixture/themes/default/views/404.erb +11 -0
  57. data/spec/fixture/themes/default/views/404.haml +1 -0
  58. data/spec/fixture/themes/default/views/404.liquid +11 -0
  59. data/spec/fixture/themes/default/views/layout.erb +10 -0
  60. data/spec/fixture/themes/default/views/layout.haml +1 -1
  61. data/spec/fixture/themes/default/views/layout.liquid +10 -0
  62. data/spec/fixture/themes/default/views/page.erb +7 -0
  63. data/spec/fixture/themes/default/views/page.haml +3 -1
  64. data/spec/fixture/themes/default/views/page.liquid +7 -0
  65. data/spec/lib/application/routing_content_pages_spec.rb +298 -21
  66. data/spec/lib/application/routing_javascript_templates_spec.rb +278 -0
  67. data/spec/lib/application/routing_not_found_spec.rb +254 -0
  68. data/spec/lib/application/routing_public_files_spec.rb +9 -8
  69. data/spec/lib/application/{routing_style_sheets_spec.rb → routing_stylesheet_templates_spec.rb} +61 -24
  70. data/spec/lib/application_spec.rb +31 -2
  71. data/spec/lib/content_page/initializing_spec.rb +399 -126
  72. data/spec/lib/content_page_spec.rb +23 -19
  73. data/spec/lib/core_ext/string_spec.rb +12 -0
  74. data/spec/lib/core_ext/uri_spec.rb +42 -0
  75. data/spec/lib/dependencies_spec.rb +0 -1
  76. data/spec/lib/flavored_markdown_spec.rb +18 -3
  77. data/spec/lib/runner_spec.rb +40 -39
  78. data/spec/lib/version_spec.rb +4 -4
  79. metadata +145 -64
  80. data/lib/mango/templates/content/index.md +0 -5
  81. data/lib/mango/templates/themes/default/public/javascripts/timer.js +0 -5
  82. data/spec/fixture/content/engines/mdown.mdown +0 -7
  83. data/spec/lib/content_page/finding_spec.rb +0 -213
@@ -12,7 +12,7 @@ describe Mango::Application do
12
12
  #################################################################################################
13
13
 
14
14
  describe "GET /robots.txt" do
15
- before(:each) do
15
+ before(:all) do
16
16
  get "/robots.txt"
17
17
  end
18
18
 
@@ -35,7 +35,7 @@ Disallow: /cgi-bin/
35
35
  #################################################################################################
36
36
 
37
37
  describe "GET /images/" do
38
- before(:each) do
38
+ before(:all) do
39
39
  get "/images/"
40
40
  end
41
41
 
@@ -66,7 +66,7 @@ Disallow: /cgi-bin/
66
66
  #################################################################################################
67
67
 
68
68
  describe "GET /" do
69
- before(:each) do
69
+ before(:all) do
70
70
  @file_name = File.join(Mango::Application.public, "index.html")
71
71
  @expected_body = <<-EXPECTED
72
72
  <!DOCTYPE html>
@@ -86,7 +86,7 @@ Disallow: /cgi-bin/
86
86
  get "/"
87
87
  end
88
88
 
89
- after(:each) do
89
+ after(:all) do
90
90
  File.delete(@file_name)
91
91
  end
92
92
 
@@ -106,7 +106,7 @@ Disallow: /cgi-bin/
106
106
  #################################################################################################
107
107
 
108
108
  describe "GET /images/ripe-mango.jpg" do
109
- before(:each) do
109
+ before(:all) do
110
110
  get "/images/ripe-mango.jpg"
111
111
  end
112
112
 
@@ -127,7 +127,7 @@ Disallow: /cgi-bin/
127
127
  #################################################################################################
128
128
 
129
129
  describe "GET /override" do
130
- before(:each) do
130
+ before(:all) do
131
131
  get "/override"
132
132
  end
133
133
 
@@ -159,7 +159,7 @@ Disallow: /cgi-bin/
159
159
 
160
160
  # see http://bit.ly/9kLBDx
161
161
  describe "GET /images/" do
162
- before(:each) do
162
+ before(:all) do
163
163
  get "/images/"
164
164
  end
165
165
 
@@ -190,7 +190,7 @@ Disallow: /cgi-bin/
190
190
  #################################################################################################
191
191
 
192
192
  describe "GET /../security_hole.txt" do
193
- before(:each) do
193
+ before(:all) do
194
194
  get "/../security_hole.txt"
195
195
  end
196
196
 
@@ -212,6 +212,7 @@ Disallow: /cgi-bin/
212
212
  </head>
213
213
  <body>
214
214
  <h1>Page not found</h1>
215
+ <p id='template'>404.html</p>
215
216
  </body>
216
217
  </html>
217
218
  EXPECTED
@@ -11,9 +11,9 @@ describe Mango::Application do
11
11
 
12
12
  #################################################################################################
13
13
 
14
- describe "GET /styles/screen.css" do
15
- before(:each) do
16
- get "/styles/screen.css"
14
+ describe "GET /stylesheets/sass.css" do
15
+ before(:all) do
16
+ get "/stylesheets/sass.css"
17
17
  end
18
18
 
19
19
  it "returns 200 status code" do
@@ -26,6 +26,9 @@ describe Mango::Application do
26
26
 
27
27
  it "sends the correct body content" do
28
28
  last_response.body.should == <<-EXPECTED
29
+ .main {
30
+ background-image: url("sass.sass"); }
31
+
29
32
  .content-navigation {
30
33
  border-color: #3bbfce;
31
34
  color: #2ca2af; }
@@ -40,9 +43,41 @@ describe Mango::Application do
40
43
 
41
44
  #################################################################################################
42
45
 
43
- describe "GET /styles/subfolder/screen.css" do
44
- before(:each) do
45
- get "/styles/subfolder/screen.css"
46
+ describe "GET /stylesheets/scss.css" do
47
+ before(:all) do
48
+ get "/stylesheets/scss.css"
49
+ end
50
+
51
+ it "returns 200 status code" do
52
+ last_response.should be_ok
53
+ end
54
+
55
+ it "sends the correct Content-Type header" do
56
+ last_response["Content-Type"].should == "text/css;charset=utf-8"
57
+ end
58
+
59
+ it "sends the correct body content" do
60
+ last_response.body.should == <<-EXPECTED
61
+ .main {
62
+ background-image: url("scss.scss"); }
63
+
64
+ .content-navigation {
65
+ border-color: #3bbfce;
66
+ color: #2ca2af; }
67
+
68
+ .border {
69
+ padding: 8px;
70
+ margin: 8px;
71
+ border-color: #3bbfce; }
72
+ EXPECTED
73
+ end
74
+ end
75
+
76
+ #################################################################################################
77
+
78
+ describe "GET /stylesheets/subfolder/screen.css" do
79
+ before(:all) do
80
+ get "/stylesheets/subfolder/screen.css"
46
81
  end
47
82
 
48
83
  it "returns 200 status code" do
@@ -70,9 +105,9 @@ li {
70
105
 
71
106
  #################################################################################################
72
107
 
73
- describe "GET /styles/reset.css" do
74
- before(:each) do
75
- get "/styles/reset.css"
108
+ describe "GET /stylesheets/reset.css" do
109
+ before(:all) do
110
+ get "/stylesheets/reset.css"
76
111
  end
77
112
 
78
113
  it "returns 200 status code" do
@@ -118,9 +153,9 @@ time, mark, audio, video {
118
153
 
119
154
  #################################################################################################
120
155
 
121
- describe "GET /styles/override.css" do
122
- before(:each) do
123
- get "/styles/override.css"
156
+ describe "GET /stylesheets/override.css" do
157
+ before(:all) do
158
+ get "/stylesheets/override.css"
124
159
  end
125
160
 
126
161
  it "returns 200 status code" do
@@ -143,7 +178,7 @@ time, mark, audio, video {
143
178
  #################################################################################################
144
179
 
145
180
  describe "GET /default.css" do
146
- before(:each) do
181
+ before(:all) do
147
182
  get "/default.css"
148
183
  end
149
184
 
@@ -166,9 +201,9 @@ time, mark, audio, video {
166
201
 
167
202
  #################################################################################################
168
203
 
169
- describe "GET /styles/subfolder/another.css" do
170
- before(:each) do
171
- get "/styles/subfolder/another.css"
204
+ describe "GET /stylesheets/subfolder/another.css" do
205
+ before(:all) do
206
+ get "/stylesheets/subfolder/another.css"
172
207
  end
173
208
 
174
209
  it "returns 200 status code" do
@@ -190,9 +225,9 @@ time, mark, audio, video {
190
225
 
191
226
  #################################################################################################
192
227
 
193
- describe "GET /styles/style_not_found.css" do
194
- before(:each) do
195
- get "/styles/style_not_found.css"
228
+ describe "GET /stylesheets/not_found.css" do
229
+ before(:all) do
230
+ get "/stylesheets/not_found.css"
196
231
  end
197
232
 
198
233
  it "returns 404 status code" do
@@ -213,6 +248,7 @@ time, mark, audio, video {
213
248
  </head>
214
249
  <body>
215
250
  <h1>Page not found</h1>
251
+ <p id='template'>404.html</p>
216
252
  </body>
217
253
  </html>
218
254
  EXPECTED
@@ -222,7 +258,7 @@ time, mark, audio, video {
222
258
  #################################################################################################
223
259
 
224
260
  describe "GET /screen.css" do
225
- before(:each) do
261
+ before(:all) do
226
262
  get "/screen.css"
227
263
  end
228
264
 
@@ -244,6 +280,7 @@ time, mark, audio, video {
244
280
  </head>
245
281
  <body>
246
282
  <h1>Page not found</h1>
283
+ <p id='template'>404.html</p>
247
284
  </body>
248
285
  </html>
249
286
  EXPECTED
@@ -252,9 +289,9 @@ time, mark, audio, video {
252
289
 
253
290
  #################################################################################################
254
291
 
255
- describe "GET /styles/../security_hole.css" do
256
- before(:each) do
257
- get "/styles/../security_hole.css"
292
+ describe "GET /stylesheets/../security_hole.css" do
293
+ before(:all) do
294
+ get "/stylesheets/../security_hole.css"
258
295
  end
259
296
 
260
297
  it "returns 404 status code" do
@@ -275,10 +312,10 @@ time, mark, audio, video {
275
312
  </head>
276
313
  <body>
277
314
  <h1>Page not found</h1>
315
+ <p id='template'>404.html</p>
278
316
  </body>
279
317
  </html>
280
318
  EXPECTED
281
319
  end
282
320
  end
283
-
284
321
  end
@@ -19,12 +19,41 @@ describe Mango::Application do
19
19
  Mango::Application.public.should == (FIXTURE_ROOT + "themes/default/public").to_s
20
20
  end
21
21
 
22
- it "styles should be app_root/themes/default/styles/" do
23
- Mango::Application.styles.should == (FIXTURE_ROOT + "themes/default/styles").to_s
22
+ it "styles should be app_root/themes/default/stylesheets/" do
23
+ Mango::Application.stylesheets.should == (FIXTURE_ROOT + "themes/default/stylesheets").to_s
24
+ end
25
+
26
+ it "styles should be app_root/themes/default/javascripts/" do
27
+ Mango::Application.javascripts.should == (FIXTURE_ROOT + "themes/default/javascripts").to_s
24
28
  end
25
29
 
26
30
  it "content should be app_root/content/" do
27
31
  Mango::Application.content.should == (FIXTURE_ROOT + "content").to_s
28
32
  end
29
33
  end
34
+
35
+ #################################################################################################
36
+
37
+ describe "constants" do
38
+ it "defines JAVASCRIPT_TEMPLATE_ENGINES" do
39
+ Mango::Application::JAVASCRIPT_TEMPLATE_ENGINES.should == {
40
+ Tilt::CoffeeScriptTemplate => :coffee
41
+ }
42
+ end
43
+
44
+ it "defines STYLESHEET_TEMPLATE_ENGINES" do
45
+ Mango::Application::STYLESHEET_TEMPLATE_ENGINES.should == {
46
+ Tilt::ScssTemplate => :scss,
47
+ Tilt::SassTemplate => :sass
48
+ }
49
+ end
50
+
51
+ it "defines VIEW_TEMPLATE_ENGINES" do
52
+ Mango::Application::VIEW_TEMPLATE_ENGINES.should == {
53
+ Tilt::HamlTemplate => :haml,
54
+ Tilt::ERBTemplate => :erb,
55
+ Tilt::LiquidTemplate => :liquid
56
+ }
57
+ end
58
+ end
30
59
  end
@@ -2,277 +2,550 @@
2
2
  require "spec_helper"
3
3
 
4
4
  describe Mango::ContentPage do
5
+ describe "given data with header and Haml body, using the Haml engine" do
6
+ before(:all) do
7
+ @expected_data = <<-EOS
8
+ ---
9
+ title: Delicious Cake
10
+ view: blog.haml
11
+ engine: Will not persist
12
+ data: Will not persist
13
+ content: Will also not persist
14
+ ---
15
+ %h1= page.title
16
+ %p So delicious!
17
+ %p= page.view
18
+ %p= page.engine
19
+ %p= page.content
20
+ %p= page.data
21
+ %p= page.body
22
+ EOS
23
+ @expected_engine = Tilt::HamlTemplate
24
+ @page = Mango::ContentPage.new(:data => @expected_data, :engine => @expected_engine)
25
+ end
26
+
27
+ it "has the correct number of attributes" do
28
+ @page.attributes.should have(6).items
29
+ end
30
+
31
+ it "has the correct title attribute" do
32
+ @page.title.should == "Delicious Cake"
33
+ end
34
+
35
+ it "has the correct view attribute" do
36
+ @page.view.should == "blog.haml"
37
+ end
38
+
39
+ it "has the correct engine attribute" do
40
+ @page.engine.should == @expected_engine
41
+ end
42
+
43
+ it "has the correct data attribute" do
44
+ @page.data.should == @expected_data
45
+ end
46
+
47
+ it "has the correct body attribute" do
48
+ @page.body.should == <<-EOS
49
+ %h1= page.title
50
+ %p So delicious!
51
+ %p= page.view
52
+ %p= page.engine
53
+ %p= page.content
54
+ %p= page.data
55
+ %p= page.body
56
+ EOS
57
+ end
58
+
59
+ it "has the correct content attribute" do
60
+ @page.content.should == <<-EOS
61
+ <h1>Delicious Cake</h1>
62
+ <p>So delicious!</p>
63
+ <p>blog.haml</p>
64
+ <p>#{@expected_engine}</p>
65
+ <p></p>
66
+ <p>
67
+ ---
68
+ title: Delicious Cake
69
+ view: blog.haml
70
+ engine: Will not persist
71
+ data: Will not persist
72
+ content: Will also not persist
73
+ ---
74
+ %h1= page.title
75
+ %p So delicious!
76
+ %p= page.view
77
+ %p= page.engine
78
+ %p= page.content
79
+ %p= page.data
80
+ %p= page.body
81
+ </p>
82
+ <p>
83
+ %h1= page.title
84
+ %p So delicious!
85
+ %p= page.view
86
+ %p= page.engine
87
+ %p= page.content
88
+ %p= page.data
89
+ %p= page.body
90
+ </p>
91
+ EOS
92
+ end
93
+ end
5
94
 
6
95
  #################################################################################################
7
96
 
8
- describe "initializing with attributes and Haml body" do
97
+ describe "given data with header and Markdown body, using the Markdown engine" do
9
98
  before(:all) do
10
99
  @expected_data = <<-EOS
11
100
  ---
12
- title: Delicious Cake!
13
- view: blog
101
+ title: Chocolate Pie
102
+ view: blog.haml
14
103
  ---
15
- %p So delicious!
16
- EOS
17
- @expected_content_engine = :haml
18
- @page = Mango::ContentPage.new(@expected_data, :content_engine => @expected_content_engine)
104
+ ### Sweet and crumbly!
105
+ EOS
106
+ @expected_engine = Tilt::BlueClothTemplate
107
+ @page = Mango::ContentPage.new(:data => @expected_data, :engine => @expected_engine)
19
108
  end
20
109
 
21
- it "saves the data" do
22
- @page.data.should == @expected_data
110
+ it "has the correct number of attributes" do
111
+ @page.attributes.should have(6).items
112
+ end
113
+
114
+ it "has the correct title attribute" do
115
+ @page.title.should == "Chocolate Pie"
23
116
  end
24
117
 
25
- it "uses default content engine" do
26
- @page.content_engine.should == @expected_content_engine
118
+ it "has the correct view attribute" do
119
+ @page.view.should == "blog.haml"
27
120
  end
28
121
 
29
- it "loads the attributes" do
30
- @page.attributes.should have(2).items
31
- @page.attributes.should include("title" => "Delicious Cake!")
32
- @page.attributes.should include("view" => "blog")
122
+ it "has the correct engine attribute" do
123
+ @page.engine.should == @expected_engine
33
124
  end
34
125
 
35
- it "loads the body" do
36
- @page.body.should == "%p So delicious!\n"
126
+ it "has the correct data attribute" do
127
+ @page.data.should == @expected_data
37
128
  end
38
129
 
39
- it "converts to HTML" do
40
- @page.to_html.should == "<p>So delicious!</p>\n"
130
+ it "has the correct body attribute" do
131
+ @page.body.should == "### Sweet and crumbly!\n"
41
132
  end
42
133
 
43
- it "determines the view template's base file name" do
44
- @page.view.should == :blog
134
+ it "has the correct content attribute" do
135
+ @page.content.should == "<h3>Sweet and crumbly!</h3>"
45
136
  end
46
137
  end
47
138
 
48
139
  #################################################################################################
49
140
 
50
- describe "initializing with attributes and Markdown body" do
141
+ describe "given data with header and ERB body, using the ERB engine" do
51
142
  before(:all) do
52
143
  @expected_data = <<-EOS
53
144
  ---
54
- title: Chocolate Pie!
55
- view: blog
145
+ title: Cake Pops
146
+ view: blog.haml
56
147
  ---
57
- ### Sweet and crumbly!
58
- EOS
59
- @expected_content_engine = :markdown
60
- @page = Mango::ContentPage.new(@expected_data, :content_engine => @expected_content_engine)
148
+ <h1><%= page.title %></h1>
149
+ <p>Did you mean <%= 'crack' %> pops?</p>
150
+ <p><%= page.view %></p>
151
+ <p><%= page.content %></p>
152
+ <pre>
153
+ <%= page.data %>
154
+ </pre>
155
+ <pre>
156
+ <%= page.body %>
157
+ </pre>
158
+ EOS
159
+ @expected_engine = Tilt::ERBTemplate
160
+ @page = Mango::ContentPage.new(:data => @expected_data, :engine => @expected_engine)
61
161
  end
62
162
 
63
- it "saves the data" do
163
+ it "has the correct number of attributes" do
164
+ @page.attributes.should have(6).items
165
+ end
166
+
167
+ it "has the correct title attribute" do
168
+ @page.title.should == "Cake Pops"
169
+ end
170
+
171
+ it "has the correct view attribute" do
172
+ @page.view.should == "blog.haml"
173
+ end
174
+
175
+ it "has the correct engine attribute" do
176
+ @page.engine.should == @expected_engine
177
+ end
178
+
179
+ it "has the correct data attribute" do
64
180
  @page.data.should == @expected_data
65
181
  end
66
182
 
67
- it "uses default content engine" do
68
- @page.content_engine.should == @expected_content_engine
183
+ it "has the correct body attribute" do
184
+ @page.body.should == <<-EOS
185
+ <h1><%= page.title %></h1>
186
+ <p>Did you mean <%= 'crack' %> pops?</p>
187
+ <p><%= page.view %></p>
188
+ <p><%= page.content %></p>
189
+ <pre>
190
+ <%= page.data %>
191
+ </pre>
192
+ <pre>
193
+ <%= page.body %>
194
+ </pre>
195
+ EOS
69
196
  end
70
197
 
71
- it "loads the attributes" do
72
- @page.attributes.should have(2).items
73
- @page.attributes.should include("title" => "Chocolate Pie!")
74
- @page.attributes.should include("view" => "blog")
198
+ it "has the correct content attribute" do
199
+ @page.content.should == <<-EOS
200
+ <h1>Cake Pops</h1>
201
+ <p>Did you mean crack pops?</p>
202
+ <p>blog.haml</p>
203
+ <p></p>
204
+ <pre>
205
+ ---
206
+ title: Cake Pops
207
+ view: blog.haml
208
+ ---
209
+ <h1><%= page.title %></h1>
210
+ <p>Did you mean <%= 'crack' %> pops?</p>
211
+ <p><%= page.view %></p>
212
+ <p><%= page.content %></p>
213
+ <pre>
214
+ <%= page.data %>
215
+ </pre>
216
+ <pre>
217
+ <%= page.body %>
218
+ </pre>
219
+ </pre>
220
+ <pre>
221
+ <h1><%= page.title %></h1>
222
+ <p>Did you mean <%= 'crack' %> pops?</p>
223
+ <p><%= page.view %></p>
224
+ <p><%= page.content %></p>
225
+ <pre>
226
+ <%= page.data %>
227
+ </pre>
228
+ <pre>
229
+ <%= page.body %>
230
+ </pre>
231
+ </pre>
232
+ EOS
75
233
  end
234
+ end
76
235
 
77
- it "loads the body" do
78
- @page.body.should == "### Sweet and crumbly!\n"
236
+ #################################################################################################
237
+
238
+ describe "given data with header and Liquid body, using the Liquid engine" do
239
+ before(:all) do
240
+ @expected_data = <<-EOS
241
+ ---
242
+ title: Cake Pops
243
+ view: blog.liquid
244
+ ---
245
+ <h1>{{ page.title }}</h1>
246
+ <p>Did you mean {{ 'crack' }} pops?</p>
247
+ <p>{{ page.view }}</p>
248
+ <p>{{ page.content }}</p>
249
+ <pre>
250
+ {{ page.data }}
251
+ </pre>
252
+ <pre>
253
+ {{ page.body }}
254
+ </pre>
255
+ EOS
256
+ @expected_engine = Tilt::LiquidTemplate
257
+ @page = Mango::ContentPage.new(:data => @expected_data, :engine => @expected_engine)
258
+ end
259
+
260
+ it "has the correct number of attributes" do
261
+ @page.attributes.should have(6).items
262
+ end
263
+
264
+ it "converts itself to liquid format" do
265
+ @page.attributes.should == @page.to_liquid
266
+ end
267
+
268
+ it "has the correct title attribute" do
269
+ @page.title.should == "Cake Pops"
270
+ end
271
+
272
+ it "has the correct view attribute" do
273
+ @page.view.should == "blog.liquid"
274
+ end
275
+
276
+ it "has the correct engine attribute" do
277
+ @page.engine.should == @expected_engine
278
+ end
279
+
280
+ it "has the correct data attribute" do
281
+ @page.data.should == @expected_data
79
282
  end
80
283
 
81
- it "converts to HTML" do
82
- @page.to_html.should == "<h3>Sweet and crumbly!</h3>"
284
+ it "has the correct body attribute" do
285
+ @page.body.should == <<-EOS
286
+ <h1>{{ page.title }}</h1>
287
+ <p>Did you mean {{ 'crack' }} pops?</p>
288
+ <p>{{ page.view }}</p>
289
+ <p>{{ page.content }}</p>
290
+ <pre>
291
+ {{ page.data }}
292
+ </pre>
293
+ <pre>
294
+ {{ page.body }}
295
+ </pre>
296
+ EOS
83
297
  end
84
298
 
85
- it "determines the view template's base file name" do
86
- @page.view.should == :blog
299
+ it "has the correct content attribute" do
300
+ @page.content.should == <<-EOS
301
+ <h1>Cake Pops</h1>
302
+ <p>Did you mean crack pops?</p>
303
+ <p>blog.liquid</p>
304
+ <p></p>
305
+ <pre>
306
+ ---
307
+ title: Cake Pops
308
+ view: blog.liquid
309
+ ---
310
+ <h1>{{ page.title }}</h1>
311
+ <p>Did you mean {{ 'crack' }} pops?</p>
312
+ <p>{{ page.view }}</p>
313
+ <p>{{ page.content }}</p>
314
+ <pre>
315
+ {{ page.data }}
316
+ </pre>
317
+ <pre>
318
+ {{ page.body }}
319
+ </pre>
320
+
321
+ </pre>
322
+ <pre>
323
+ <h1>{{ page.title }}</h1>
324
+ <p>Did you mean {{ 'crack' }} pops?</p>
325
+ <p>{{ page.view }}</p>
326
+ <p>{{ page.content }}</p>
327
+ <pre>
328
+ {{ page.data }}
329
+ </pre>
330
+ <pre>
331
+ {{ page.body }}
332
+ </pre>
333
+
334
+ </pre>
335
+ EOS
87
336
  end
88
337
  end
89
338
 
90
339
  #################################################################################################
91
340
 
92
- describe "initializing with just attributes" do
341
+ describe "given data with header only, using the default engine" do
93
342
  before(:all) do
94
343
  @expected_data = <<-EOS
95
344
  ---
96
- title: Delicious Cake!
345
+ title: Delicious Cake
97
346
  view: blog.haml
98
347
  ---
99
- EOS
100
- @page = Mango::ContentPage.new(@expected_data)
348
+ EOS
349
+ @page = Mango::ContentPage.new(:data => @expected_data)
101
350
  end
102
351
 
103
- it "saves the data" do
104
- @page.data.should == @expected_data
352
+ it "has the correct number of attributes" do
353
+ @page.attributes.should have(6).items
105
354
  end
106
355
 
107
- it "uses default content engine" do
108
- @page.content_engine.should == Mango::ContentPage::DEFAULT[:content_engine]
356
+ it "has the correct title attribute" do
357
+ @page.title.should == "Delicious Cake"
109
358
  end
110
359
 
111
- it "loads the attributes" do
112
- @page.attributes.should have(2).items
113
- @page.attributes.should include("title" => "Delicious Cake!")
114
- @page.attributes.should include("view" => "blog.haml")
360
+ it "has the correct view attribute" do
361
+ @page.view.should == "blog.haml"
115
362
  end
116
363
 
117
- it "loads the body" do
118
- @page.body.should be_empty
364
+ it "has the correct engine attribute" do
365
+ @page.engine.should == Mango::ContentPage::DEFAULT_ATTRIBUTES["engine"]
366
+ end
367
+
368
+ it "has the correct data attribute" do
369
+ @page.data.should == @expected_data
119
370
  end
120
371
 
121
- it "converts to HTML" do
122
- @page.to_html.should be_empty
372
+ it "has the correct body attribute" do
373
+ @page.body.should be_empty
123
374
  end
124
375
 
125
- it "determines the view template's base file name" do
126
- @page.view.should == :blog
376
+ it "has the correct content attribute" do
377
+ @page.content.should be_empty
127
378
  end
128
379
  end
129
380
 
130
381
  #################################################################################################
131
382
 
132
- describe "initializing with just body using the default content engine" do
383
+ describe "given data with Markdown body only, using the default engine" do
133
384
  before(:all) do
134
385
  @expected_data = <<-EOS
135
386
  ### So delicious!
136
387
  EOS
137
- @page = Mango::ContentPage.new(@expected_data)
388
+ @page = Mango::ContentPage.new(:data => @expected_data)
138
389
  end
139
390
 
140
- it "saves the data" do
141
- @page.data.should == @expected_data
391
+ it "has the correct number of attributes" do
392
+ @page.attributes.should have(5).items
142
393
  end
143
394
 
144
- it "uses default content engine" do
145
- @page.content_engine.should == Mango::ContentPage::DEFAULT[:content_engine]
395
+ it "has the correct view attribute" do
396
+ @page.view.should == "page.haml"
146
397
  end
147
398
 
148
- it "loads the attributes" do
149
- @page.attributes.should have(1).items
150
- @page.attributes.should include("view" => :page)
399
+ it "has the correct engine attribute" do
400
+ @page.engine.should == Mango::ContentPage::DEFAULT_ATTRIBUTES["engine"]
151
401
  end
152
402
 
153
- it "loads the body" do
154
- @page.body.should == "### So delicious!\n"
403
+ it "has the correct data attribute" do
404
+ @page.data.should == @expected_data
155
405
  end
156
406
 
157
- it "converts to HTML" do
158
- @page.to_html.should == "<h3>So delicious!</h3>"
407
+ it "has the correct body attribute" do
408
+ @page.body.should == @expected_data
159
409
  end
160
410
 
161
- it "determines the view template's base file name" do
162
- @page.view.should == :page
411
+ it "has the correct content attribute" do
412
+ @page.content.should == "<h3>So delicious!</h3>"
163
413
  end
164
414
  end
165
415
 
166
416
  #################################################################################################
167
417
 
168
- describe "initializing with empty attributes and body" do
418
+ describe "given data with empty header only, using the default engine" do
169
419
  before(:all) do
170
420
  @expected_data = <<-EOS
171
421
  ---
172
422
  ---
173
423
  EOS
174
- @page = Mango::ContentPage.new(@expected_data)
424
+ @page = Mango::ContentPage.new(:data => @expected_data)
175
425
  end
176
426
 
177
427
  it "saves the data" do
178
428
  @page.data.should == @expected_data
179
429
  end
180
430
 
181
- it "uses default content engine" do
182
- @page.content_engine.should == Mango::ContentPage::DEFAULT[:content_engine]
431
+ it "has the correct number of attributes" do
432
+ @page.attributes.should have(5).items
183
433
  end
184
434
 
185
- it "loads the attributes" do
186
- @page.attributes.should have(1).items
187
- @page.attributes.should include("view" => :page)
435
+ it "has the correct view attribute" do
436
+ @page.view.should == "page.haml"
188
437
  end
189
438
 
190
- it "loads the body" do
191
- @page.body.should be_empty
439
+ it "has the correct engine attribute" do
440
+ @page.engine.should == Mango::ContentPage::DEFAULT_ATTRIBUTES["engine"]
192
441
  end
193
442
 
194
- it "converts to HTML" do
195
- @page.to_html.should be_empty
443
+ it "has the correct data attribute" do
444
+ @page.data.should == @expected_data
196
445
  end
197
446
 
198
- it "determines the view template's base file name" do
199
- @page.view.should == :page
447
+ it "has the correct body attribute" do
448
+ @page.body.should be_empty
449
+ end
450
+
451
+ it "has the correct content attribute" do
452
+ @page.content.should be_empty
200
453
  end
201
454
  end
202
455
 
203
456
  #################################################################################################
204
457
 
205
- describe "initializing with nil" do
458
+ describe "given no data" do
206
459
  before(:all) do
207
- @expected_data = nil
208
- @page = Mango::ContentPage.new(@expected_data)
460
+ @page = Mango::ContentPage.new
209
461
  end
210
462
 
211
463
  it "saves the data" do
212
- @page.data.should == @expected_data
464
+ @page.data.should == ""
213
465
  end
214
466
 
215
- it "uses default content engine" do
216
- @page.content_engine.should == Mango::ContentPage::DEFAULT[:content_engine]
467
+ it "has the correct number of attributes" do
468
+ @page.attributes.should have(5).items
217
469
  end
218
470
 
219
- it "loads the attributes" do
220
- @page.attributes.should have(1).items
221
- @page.attributes.should include("view" => :page)
471
+ it "has the correct view attribute" do
472
+ @page.view.should == "page.haml"
222
473
  end
223
474
 
224
- it "loads the body" do
225
- @page.body.should be_empty
475
+ it "has the correct engine attribute" do
476
+ @page.engine.should == Mango::ContentPage::DEFAULT_ATTRIBUTES["engine"]
477
+ end
478
+
479
+ it "has the correct data attribute" do
480
+ @page.data.should be_empty
226
481
  end
227
482
 
228
- it "converts to HTML" do
229
- @page.to_html.should be_empty
483
+ it "has the correct body attribute" do
484
+ @page.body.should be_empty
230
485
  end
231
486
 
232
- it "determines the view template's base file name" do
233
- @page.view.should == :page
487
+ it "has the correct content attribute" do
488
+ @page.content.should be_empty
234
489
  end
235
490
  end
236
491
 
237
492
  #################################################################################################
238
493
 
239
- describe "initializing with unknown content engine" do
494
+ describe "given data with an invalid title attribute within the header" do
240
495
  before(:all) do
241
- @expected_data = ""
242
- @expected_content_engine = :unknown
243
- @page = Mango::ContentPage.new(@expected_data, :content_engine => @expected_content_engine)
496
+ @expected_data = <<-EOS
497
+ ---
498
+ title: WARNING: This needs quotes
499
+ ---
500
+ EOS
244
501
  end
245
502
 
246
- it "saves the data" do
247
- @page.data.should == @expected_data
503
+ it "raises an exception" do
504
+ expected_message = "syntax error on line 1, col 15: `title: WARNING: This needs quotes'"
505
+ lambda {
506
+ Mango::ContentPage.new(:data => @expected_data)
507
+ }.should raise_exception(Mango::ContentPage::InvalidHeaderError, expected_message)
248
508
  end
509
+ end
249
510
 
250
- it "uses unknown content engine" do
251
- @page.content_engine.should == @expected_content_engine
252
- end
511
+ #################################################################################################
253
512
 
254
- it "loads the attributes" do
255
- @page.attributes.should have(1).items
256
- @page.attributes.should include("view" => :page)
513
+ describe "given data with an invalid header" do
514
+ before(:all) do
515
+ @expected_data = <<-EOS
516
+ ---
517
+ This is not a Hash
518
+ ---
519
+ EOS
257
520
  end
258
521
 
259
- it "loads the body" do
260
- @page.body.should be_empty
522
+ it "raises an exception" do
523
+ expected_message = 'Cannot parse header -- "This is not a Hash"'
524
+ lambda {
525
+ Mango::ContentPage.new(:data => @expected_data)
526
+ }.should raise_exception(Mango::ContentPage::InvalidHeaderError, expected_message)
261
527
  end
528
+ end
262
529
 
263
- it "raises a RuntimeError when converting to HTML" do
264
- lambda { @page.to_html }.should raise_exception(RuntimeError,"Unknown content engine -- unknown")
530
+ #################################################################################################
531
+
532
+ describe "given no data, using an unknown engine" do
533
+ before(:all) do
534
+ @unknown_engine = :unknown
265
535
  end
266
536
 
267
- it "determines the view template's base file name" do
268
- @page.view.should == :page
537
+ it "raises an exception" do
538
+ expected_message = "Cannot find registered content engine -- unknown"
539
+ lambda {
540
+ Mango::ContentPage.new(:engine => @unknown_engine)
541
+ }.should raise_exception(ArgumentError, expected_message)
269
542
  end
270
543
  end
271
544
 
272
545
  #################################################################################################
273
546
 
274
- describe "initializing with seasonable Markdown body" do
275
- it "seasons the rendered markup with Mango::FlavoredMarkdown" do
547
+ describe "given data with seasonable Markdown body, using the default engine" do
548
+ before(:all) do
276
549
  data = <<-EOS
277
550
  Mango is like a drug.
278
551
  You must have more and more and more of the Mango
@@ -280,8 +553,10 @@ until there is no Mango left.
280
553
  Not even for Mango!
281
554
  EOS
282
555
 
283
- page = Mango::ContentPage.new(data, :content_engine => :markdown)
556
+ @page = Mango::ContentPage.new(:data => data)
557
+ end
284
558
 
559
+ it "seasons the data before rendering the content" do
285
560
  expected = <<-EOS
286
561
  <p>Mango is like a drug.<br/>
287
562
  You must have more and more and more of the Mango<br/>
@@ -289,9 +564,7 @@ until there is no Mango left.<br/>
289
564
  Not even for Mango!</p>
290
565
  EOS
291
566
 
292
- page.to_html.should == expected.strip
567
+ @page.content.should == expected.strip
293
568
  end
294
-
295
569
  end
296
-
297
570
  end