spontaneous 0.2.0.beta4 → 0.2.0.beta5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +39 -0
- data/Gemfile +11 -6
- data/Readme.markdown +136 -69
- data/application/css/core.css.scss +27 -7
- data/application/css/editing.css.scss +4 -26
- data/application/css/schema_error.css.scss +22 -0
- data/application/js/content.js +11 -3
- data/application/js/edit_panel.js +1 -4
- data/application/js/field/file.js +17 -0
- data/application/js/field/image.js +30 -21
- data/application/js/field/string.js +4 -1
- data/application/js/field_preview.js +21 -16
- data/application/js/publish.js +6 -6
- data/application/js/types.js +5 -13
- data/application/js/views.js +2 -2
- data/application/js/views/box_view.js +3 -2
- data/application/js/views/page_piece_view.js +1 -1
- data/application/js/views/piece_view.js +1 -1
- data/application/views/schema_modification_error.html.erb +13 -3
- data/db/migrations/20131104101935_site_must_publish_all.rb +14 -0
- data/lib/spontaneous.rb +0 -1
- data/lib/spontaneous/box_style.rb +15 -9
- data/lib/spontaneous/capistrano/deploy.rb +13 -1
- data/lib/spontaneous/change.rb +11 -13
- data/lib/spontaneous/cli.rb +5 -2
- data/lib/spontaneous/cli/assets.rb +7 -1
- data/lib/spontaneous/cli/console.rb +7 -1
- data/lib/spontaneous/cli/content.rb +35 -0
- data/lib/spontaneous/cli/fields.rb +3 -2
- data/lib/spontaneous/cli/generate.rb +5 -2
- data/lib/spontaneous/cli/server.rb +12 -8
- data/lib/spontaneous/cli/site.rb +12 -12
- data/lib/spontaneous/cli/user.rb +28 -14
- data/lib/spontaneous/collections/box_set.rb +4 -4
- data/lib/spontaneous/collections/field_set.rb +4 -4
- data/lib/spontaneous/collections/prototype_set.rb +12 -4
- data/lib/spontaneous/data_mapper.rb +11 -7
- data/lib/spontaneous/data_mapper/content_model.rb +8 -0
- data/lib/spontaneous/data_mapper/content_model/associations.rb +1 -1
- data/lib/spontaneous/data_mapper/dataset.rb +14 -2
- data/lib/spontaneous/data_mapper/scope.rb +33 -13
- data/lib/spontaneous/facet.rb +4 -0
- data/lib/spontaneous/field.rb +12 -12
- data/lib/spontaneous/field/base.rb +27 -22
- data/lib/spontaneous/field/boolean.rb +4 -4
- data/lib/spontaneous/field/date.rb +2 -2
- data/lib/spontaneous/field/file.rb +24 -18
- data/lib/spontaneous/field/html.rb +1 -1
- data/lib/spontaneous/field/image.rb +6 -19
- data/lib/spontaneous/field/location.rb +1 -1
- data/lib/spontaneous/field/long_string.rb +3 -3
- data/lib/spontaneous/field/markdown.rb +3 -3
- data/lib/spontaneous/field/select.rb +2 -2
- data/lib/spontaneous/field/string.rb +2 -2
- data/lib/spontaneous/field/tags.rb +2 -2
- data/lib/spontaneous/field/update.rb +21 -20
- data/lib/spontaneous/field/webvideo.rb +6 -6
- data/lib/spontaneous/field/webvideo/fallback.rb +2 -2
- data/lib/spontaneous/field/webvideo/vimeo.rb +7 -7
- data/lib/spontaneous/generators/site.rb +2 -2
- data/lib/spontaneous/generators/site/Gemfile.tt +5 -1
- data/lib/spontaneous/layout.rb +2 -2
- data/lib/spontaneous/media.rb +1 -0
- data/lib/spontaneous/media/file.rb +6 -5
- data/lib/spontaneous/media/image/attributes.rb +4 -0
- data/lib/spontaneous/media/image/renderable.rb +4 -4
- data/lib/spontaneous/media/store.rb +22 -0
- data/lib/spontaneous/{storage → media/store}/backend.rb +1 -1
- data/lib/spontaneous/{storage → media/store}/cloud.rb +1 -1
- data/lib/spontaneous/{storage → media/store}/local.rb +1 -1
- data/lib/spontaneous/media/temp_file.rb +1 -1
- data/lib/spontaneous/model.rb +10 -7
- data/lib/spontaneous/model/action.rb +7 -0
- data/lib/spontaneous/model/action/clean.rb +87 -0
- data/lib/spontaneous/model/box/allowed_types.rb +15 -1
- data/lib/spontaneous/model/core.rb +10 -0
- data/lib/spontaneous/model/core/aliases.rb +1 -1
- data/lib/spontaneous/model/core/content_groups.rb +1 -1
- data/lib/spontaneous/model/core/fields.rb +1 -1
- data/lib/spontaneous/model/core/modifications.rb +2 -2
- data/lib/spontaneous/model/core/page_search.rb +4 -0
- data/lib/spontaneous/model/core/publishing.rb +4 -17
- data/lib/spontaneous/model/core/render.rb +4 -4
- data/lib/spontaneous/model/core/styles.rb +2 -2
- data/lib/spontaneous/model/core/visibility.rb +6 -2
- data/lib/spontaneous/model/page.rb +6 -2
- data/lib/spontaneous/model/page/controllers.rb +55 -17
- data/lib/spontaneous/model/page/formats.rb +12 -7
- data/lib/spontaneous/model/page/layouts.rb +2 -2
- data/lib/spontaneous/model/page/locks.rb +4 -1
- data/lib/spontaneous/model/page/page_tree.rb +40 -6
- data/lib/spontaneous/output.rb +14 -52
- data/lib/spontaneous/output/context.rb +11 -39
- data/lib/spontaneous/output/context/navigation.rb +31 -0
- data/lib/spontaneous/output/format.rb +15 -19
- data/lib/spontaneous/output/renderable.rb +99 -0
- data/lib/spontaneous/output/store.rb +24 -0
- data/lib/spontaneous/output/store/backend.rb +52 -0
- data/lib/spontaneous/output/store/file.rb +77 -0
- data/lib/spontaneous/output/store/moneta.rb +117 -0
- data/lib/spontaneous/output/store/revision.rb +34 -0
- data/lib/spontaneous/output/store/store.rb +15 -0
- data/lib/spontaneous/output/store/transaction.rb +44 -0
- data/lib/spontaneous/output/template/engine.rb +17 -7
- data/lib/spontaneous/output/template/renderer.rb +66 -40
- data/lib/spontaneous/page_lock.rb +5 -7
- data/lib/spontaneous/page_piece.rb +2 -2
- data/lib/spontaneous/permissions/user.rb +14 -7
- data/lib/spontaneous/plugins/application/features.rb +8 -4
- data/lib/spontaneous/plugins/application/state.rb +12 -6
- data/lib/spontaneous/prototypes/box_prototype.rb +9 -10
- data/lib/spontaneous/prototypes/field_prototype.rb +66 -15
- data/lib/spontaneous/publishing/immediate.rb +30 -26
- data/lib/spontaneous/rack.rb +12 -7
- data/lib/spontaneous/rack/back.rb +43 -37
- data/lib/spontaneous/rack/back/base.rb +4 -4
- data/lib/spontaneous/rack/back/changes.rb +2 -2
- data/lib/spontaneous/rack/back/file.rb +16 -24
- data/lib/spontaneous/rack/back/map.rb +5 -5
- data/lib/spontaneous/rack/back/preview.rb +3 -4
- data/lib/spontaneous/rack/back/schema.rb +1 -1
- data/lib/spontaneous/rack/back/site.rb +6 -7
- data/lib/spontaneous/rack/front.rb +19 -16
- data/lib/spontaneous/rack/middleware/authenticate.rb +3 -3
- data/lib/spontaneous/rack/middleware/reloader.rb +3 -2
- data/lib/spontaneous/rack/middleware/scope.rb +25 -19
- data/lib/spontaneous/rack/page_controller.rb +164 -13
- data/lib/spontaneous/rack/public.rb +23 -62
- data/lib/spontaneous/rack/static.rb +2 -3
- data/lib/spontaneous/schema.rb +27 -8
- data/lib/spontaneous/schema/schema_modification.rb +9 -1
- data/lib/spontaneous/schema/uid.rb +2 -2
- data/lib/spontaneous/schema/uid_map.rb +3 -2
- data/lib/spontaneous/search/database.rb +2 -2
- data/lib/spontaneous/search/field.rb +5 -3
- data/lib/spontaneous/search/index.rb +12 -7
- data/lib/spontaneous/search/results.rb +5 -3
- data/lib/spontaneous/server.rb +2 -2
- data/lib/spontaneous/site.rb +10 -3
- data/lib/spontaneous/site/features.rb +26 -6
- data/lib/spontaneous/site/helpers.rb +9 -12
- data/lib/spontaneous/site/level.rb +7 -9
- data/lib/spontaneous/site/map.rb +9 -11
- data/lib/spontaneous/site/paths.rb +5 -5
- data/lib/spontaneous/site/publishing.rb +83 -80
- data/lib/spontaneous/site/schema.rb +1 -7
- data/lib/spontaneous/site/search.rb +8 -18
- data/lib/spontaneous/site/selectors.rb +60 -54
- data/lib/spontaneous/site/state.rb +36 -30
- data/lib/spontaneous/site/storage.rb +10 -16
- data/lib/spontaneous/state.rb +8 -0
- data/lib/spontaneous/style.rb +32 -33
- data/lib/spontaneous/version.rb +1 -1
- data/spontaneous.gemspec +22 -21
- data/test/fixtures/public/templates/layouts/default.html.cut +1 -1
- data/test/fixtures/public/templates/layouts/default.pdf.cut +1 -1
- data/test/fixtures/public/templates/layouts/default.rss.cut +1 -1
- data/test/fixtures/search/config/indexes.rb +1 -1
- data/test/fixtures/serialisation/class_hash.yaml.erb +13 -1
- data/test/fixtures/serialisation/root_hash.yaml.erb +10 -0
- data/test/functional/test_application.rb +20 -24
- data/test/functional/test_back.rb +26 -27
- data/test/functional/test_cli.rb +146 -0
- data/test/functional/test_front.rb +287 -216
- data/test/functional/test_user_manager.rb +1 -1
- data/test/test_helper.rb +15 -11
- data/test/unit/test_alias.rb +32 -25
- data/test/unit/test_asset_bundler.rb +1 -1
- data/test/unit/test_assets.rb +34 -33
- data/test/unit/test_authentication.rb +1 -1
- data/test/unit/test_boxes.rb +16 -2
- data/test/unit/test_changesets.rb +23 -11
- data/test/unit/test_content.rb +15 -0
- data/test/unit/test_context.rb +139 -0
- data/test/unit/test_controllers.rb +374 -0
- data/test/{experimental → unit}/test_crypt.rb +0 -0
- data/test/unit/test_datamapper.rb +260 -237
- data/test/unit/test_datamapper_content.rb +42 -12
- data/test/{experimental → unit}/test_features.rb +85 -3
- data/test/unit/test_fields.rb +117 -42
- data/test/unit/test_formats.rb +11 -1
- data/test/unit/test_generators.rb +2 -2
- data/test/unit/test_helpers.rb +7 -8
- data/test/unit/test_images.rb +39 -2
- data/test/unit/test_layouts.rb +14 -12
- data/test/unit/test_media.rb +32 -23
- data/test/unit/test_output_store.rb +342 -0
- data/test/unit/test_page.rb +8 -1
- data/test/unit/test_permissions.rb +11 -7
- data/test/unit/test_plugins.rb +3 -3
- data/test/unit/test_prototype_set.rb +8 -1
- data/test/unit/test_publishing.rb +67 -54
- data/test/unit/test_render.rb +91 -38
- data/test/unit/test_revisions.rb +4 -4
- data/test/unit/test_schema.rb +109 -84
- data/test/unit/test_search.rb +42 -42
- data/test/unit/test_serialisation.rb +3 -2
- data/test/unit/test_site.rb +39 -27
- data/test/unit/test_storage.rb +9 -6
- data/test/unit/test_styles.rb +25 -32
- data/test/unit/test_templates.rb +8 -4
- metadata +89 -54
- data/lib/spontaneous/model/page/request.rb +0 -105
- data/lib/spontaneous/storage.rb +0 -22
@@ -13,7 +13,7 @@ describe "Serialisation" do
|
|
13
13
|
|
14
14
|
class ::SerialisedPage < ::Page
|
15
15
|
field :direction, :title => "Pointing Direction", :comment => "NSEW" do
|
16
|
-
def preprocess(value)
|
16
|
+
def preprocess(value, site)
|
17
17
|
({
|
18
18
|
"N" => "North",
|
19
19
|
"S" => "South",
|
@@ -41,6 +41,7 @@ describe "Serialisation" do
|
|
41
41
|
width 50
|
42
42
|
end
|
43
43
|
end
|
44
|
+
field :another, list: false
|
44
45
|
|
45
46
|
style :freezing
|
46
47
|
style :boiling
|
@@ -92,7 +93,7 @@ describe "Serialisation" do
|
|
92
93
|
class InnerClass < Piece
|
93
94
|
end
|
94
95
|
end
|
95
|
-
|
96
|
+
@site.schema.export['SerialisedPage.InnerClass'].must_equal ::SerialisedPage::InnerClass.export
|
96
97
|
end
|
97
98
|
end
|
98
99
|
|
data/test/unit/test_site.rb
CHANGED
@@ -127,60 +127,72 @@ describe "Site" do
|
|
127
127
|
|
128
128
|
|
129
129
|
it "retrieve details of the root by default" do
|
130
|
-
|
130
|
+
@site.map.must_equal Page.root.map_entry
|
131
131
|
end
|
132
132
|
|
133
133
|
it "retrieve the details of the children of any page" do
|
134
|
-
|
135
|
-
|
134
|
+
@site.map(@root.id).must_equal Page.root.map_entry
|
135
|
+
@site.map(@page3_2.id).must_equal @page3_2.map_entry
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
139
139
|
describe "page retrieval" do
|
140
140
|
it "finds the root" do
|
141
|
-
|
141
|
+
@site.home.must_equal @root
|
142
142
|
end
|
143
143
|
|
144
144
|
it "returns all roots" do
|
145
145
|
hidden = Page.create slug: "hidden"
|
146
|
-
roots =
|
146
|
+
roots = @site.roots
|
147
147
|
roots["public"].must_equal "spontaneous.io"
|
148
148
|
roots["roots"].keys.must_equal ["spontaneous.io", "#hidden"]
|
149
149
|
end
|
150
150
|
|
151
151
|
it "returns an empty roots object if no root exists" do
|
152
152
|
@root.destroy
|
153
|
-
roots =
|
153
|
+
roots = @site.roots
|
154
154
|
roots['roots'].must_equal({})
|
155
155
|
end
|
156
156
|
|
157
|
+
it "finds ids" do
|
158
|
+
@page3_2.reload
|
159
|
+
[@page3_2.id, @page3_2.id.to_s].each do |id|
|
160
|
+
@site[id].must_equal @page3_2
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
157
164
|
it "work with paths" do
|
158
|
-
|
165
|
+
@site['/page1-1/page2-1'].must_equal @page2_1.reload
|
159
166
|
end
|
160
167
|
|
161
168
|
it "work with UIDs" do
|
162
|
-
|
163
|
-
|
169
|
+
@site["page3_2"].must_equal @page3_2.reload
|
170
|
+
@site["$page3_2"].must_equal @page3_2.reload
|
171
|
+
end
|
172
|
+
|
173
|
+
it "maps symbols to UIDs" do
|
174
|
+
@site[:page3_2].must_equal @page3_2.reload
|
164
175
|
end
|
165
176
|
|
166
177
|
it "finds hidden roots" do
|
167
178
|
root = Page.create slug: "hidden"
|
168
|
-
|
179
|
+
@site["#hidden"].must_equal root.reload
|
169
180
|
child = Page.create slug: "something"
|
170
181
|
root.subpages << child
|
171
182
|
root.save
|
172
|
-
|
183
|
+
@site["#hidden/something"].must_equal child.reload
|
173
184
|
end
|
174
185
|
|
175
186
|
it "have a shortcut direct method on Site" do
|
176
|
-
|
187
|
+
@site.page3_2.must_equal @page3_2.reload
|
177
188
|
end
|
178
189
|
|
179
190
|
it "return section pages in the right order" do
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
191
|
+
@site.at_depth(0).must_equal @root
|
192
|
+
@site.at_depth(:root).must_equal @root
|
193
|
+
@site.at_depth(:home).must_equal @root
|
194
|
+
@site.at_depth(1).must_equal [@page1_1, @page1_2]
|
195
|
+
@site.at_depth(:section).must_equal [@page1_1, @page1_2]
|
184
196
|
end
|
185
197
|
end
|
186
198
|
end
|
@@ -195,7 +207,7 @@ describe "Site" do
|
|
195
207
|
it "just return the current time if no modifications have been made" do
|
196
208
|
now = @now + 12
|
197
209
|
Time.stubs(:now).returns(now)
|
198
|
-
|
210
|
+
@site.modified_at.must_equal now
|
199
211
|
end
|
200
212
|
|
201
213
|
it "be updated when a page is added" do
|
@@ -203,7 +215,7 @@ describe "Site" do
|
|
203
215
|
Time.stubs(:now).returns(now)
|
204
216
|
root = ::Page.create
|
205
217
|
Time.stubs(:now).returns(now + 200)
|
206
|
-
|
218
|
+
@site.modified_at.must_equal now
|
207
219
|
end
|
208
220
|
|
209
221
|
it "be updated when a page's title changes" do
|
@@ -211,7 +223,7 @@ describe "Site" do
|
|
211
223
|
now = @now + 98
|
212
224
|
Time.stubs(:now).returns(now)
|
213
225
|
root.update(:title => "Some Title")
|
214
|
-
|
226
|
+
@site.modified_at.must_equal now
|
215
227
|
end
|
216
228
|
|
217
229
|
it "be updated when a page's slug changes" do
|
@@ -219,7 +231,7 @@ describe "Site" do
|
|
219
231
|
now = @now + 98
|
220
232
|
Time.stubs(:now).returns(now)
|
221
233
|
root.update(:slug => "updated-slug")
|
222
|
-
|
234
|
+
@site.modified_at.must_equal now
|
223
235
|
end
|
224
236
|
|
225
237
|
it "not be updated when a piece is added" do
|
@@ -229,7 +241,7 @@ describe "Site" do
|
|
229
241
|
now2 = @now + 240
|
230
242
|
Time.stubs(:now).returns(now2)
|
231
243
|
root.subpages << Piece.create
|
232
|
-
|
244
|
+
@site.modified_at.must_equal now1
|
233
245
|
end
|
234
246
|
|
235
247
|
it "be updated when a page is deleted" do
|
@@ -241,11 +253,11 @@ describe "Site" do
|
|
241
253
|
child = ::Page.new
|
242
254
|
root.subpages << child
|
243
255
|
root.save
|
244
|
-
|
256
|
+
@site.modified_at.must_equal now2
|
245
257
|
now3 = @now + 128
|
246
258
|
Time.stubs(:now).returns(now3)
|
247
259
|
child.destroy
|
248
|
-
|
260
|
+
@site.modified_at.must_equal now3
|
249
261
|
end
|
250
262
|
|
251
263
|
it "not be updated when a piece is deleted" do
|
@@ -256,11 +268,11 @@ describe "Site" do
|
|
256
268
|
Time.stubs(:now).returns(now2)
|
257
269
|
piece = ::Piece.create
|
258
270
|
root.subpages << piece
|
259
|
-
|
271
|
+
@site.modified_at.must_equal now1
|
260
272
|
now3 = @now + 480
|
261
273
|
Time.stubs(:now).returns(now3)
|
262
274
|
piece.reload.destroy
|
263
|
-
|
275
|
+
@site.modified_at.must_equal now1
|
264
276
|
end
|
265
277
|
end
|
266
278
|
|
@@ -270,7 +282,7 @@ describe "Site" do
|
|
270
282
|
@site.public_url.must_equal "http://spontaneouscms.org/"
|
271
283
|
@site.public_url("/").must_equal "http://spontaneouscms.org/"
|
272
284
|
@site.public_url("/something").must_equal "http://spontaneouscms.org/something"
|
273
|
-
|
285
|
+
@site.public_url("/something").must_equal "http://spontaneouscms.org/something"
|
274
286
|
end
|
275
287
|
end
|
276
288
|
|
@@ -289,7 +301,7 @@ describe "Site" do
|
|
289
301
|
|
290
302
|
it "include all facet paths for a particular path group" do
|
291
303
|
dirs = [@site.root / "templates", @template_dir1, @plugin_dir / "templates"]
|
292
|
-
|
304
|
+
@site.paths(:templates).must_equal dirs
|
293
305
|
end
|
294
306
|
end
|
295
307
|
end
|
data/test/unit/test_storage.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require File.expand_path('../../test_helper', __FILE__)
|
4
4
|
require 'fog'
|
5
5
|
|
6
|
-
describe "
|
6
|
+
describe "Media Store" do
|
7
7
|
before do
|
8
8
|
@site = setup_site
|
9
9
|
@config_dir = File.expand_path("../../fixtures/storage", __FILE__)
|
@@ -22,7 +22,7 @@ describe "Storage" do
|
|
22
22
|
@storage = @site.storage
|
23
23
|
end
|
24
24
|
it "be the default" do
|
25
|
-
@storage.must_be_instance_of Spontaneous::
|
25
|
+
@storage.must_be_instance_of Spontaneous::Media::Store::Local
|
26
26
|
end
|
27
27
|
it "have the right base url" do
|
28
28
|
@storage.public_url("test.jpg").must_equal "/media/test.jpg"
|
@@ -46,16 +46,19 @@ describe "Storage" do
|
|
46
46
|
}
|
47
47
|
::Fog.mock!
|
48
48
|
@connection = Fog::Storage.new(@aws_credentials)
|
49
|
-
@bucket = @connection.directories.create(:
|
49
|
+
@bucket = @connection.directories.create(key: @bucket_name)
|
50
50
|
@site.paths.add :config, File.expand_path(@config_dir / "cloud", __FILE__)
|
51
51
|
@site.load_config!
|
52
52
|
# sanity check
|
53
53
|
assert @site.config.test_setting
|
54
54
|
@storage = @site.storage
|
55
|
+
# Fog's mocks used to apply directory additions globally but latest version
|
56
|
+
# doesn't so I have to stub it out :(
|
57
|
+
@storage.stubs(:backend).returns(@connection)
|
55
58
|
end
|
56
59
|
|
57
60
|
it "be detected by configuration" do
|
58
|
-
@storage.must_be_instance_of Spontaneous::
|
61
|
+
@storage.must_be_instance_of Spontaneous::Media::Store::Cloud
|
59
62
|
end
|
60
63
|
|
61
64
|
it "have the correct bucket name" do
|
@@ -86,7 +89,7 @@ describe "Storage" do
|
|
86
89
|
|
87
90
|
it "be set as publicly visible" do
|
88
91
|
file = @storage.copy(@existing_file, @media_path, { content_type: "image/jpeg" })
|
89
|
-
acl = file.
|
92
|
+
acl = file.service.get_object_acl(file.directory.key, file.key).body['AccessControlList']
|
90
93
|
perms = acl.detect {|grant| grant['Grantee']['URI'] == 'http://acs.amazonaws.com/groups/global/AllUsers' }
|
91
94
|
perms["Permission"].must_equal "READ"
|
92
95
|
end
|
@@ -110,7 +113,7 @@ describe "Storage" do
|
|
110
113
|
|
111
114
|
|
112
115
|
it "use custom urls if configured" do
|
113
|
-
storage = Spontaneous::
|
116
|
+
storage = Spontaneous::Media::Store::Cloud.new(@aws_credentials.merge({
|
114
117
|
:public_host => "http://media.example.com",
|
115
118
|
}), @bucket_name)
|
116
119
|
storage.public_url(@media_path).must_equal "http://media.example.com/0003/0567/rose.jpg"
|
data/test/unit/test_styles.rb
CHANGED
@@ -9,8 +9,7 @@ describe "Styles" do
|
|
9
9
|
@site = setup_site
|
10
10
|
@template_root = File.expand_path(File.join(File.dirname(__FILE__), "../fixtures/styles"))
|
11
11
|
@site.paths.add(:templates, @template_root)
|
12
|
-
@renderer = S::Output::Template::PreviewRenderer.new
|
13
|
-
S::Output.renderer = @renderer
|
12
|
+
@renderer = S::Output::Template::PreviewRenderer.new(@site)
|
14
13
|
end
|
15
14
|
|
16
15
|
after do
|
@@ -53,12 +52,11 @@ describe "Styles" do
|
|
53
52
|
it "return anonymous style if no templates are found" do
|
54
53
|
piece = MissingClass.new
|
55
54
|
piece.style.class.must_equal Spontaneous::Style::Default
|
56
|
-
|
57
|
-
piece.style.template.call.must_equal ""
|
55
|
+
piece.style.template(:html, @renderer).call.must_equal ""
|
58
56
|
end
|
59
57
|
|
60
58
|
it "derive path from owning class and name" do
|
61
|
-
assert_correct_template(@piece, @template_root / 'template_class')
|
59
|
+
assert_correct_template(@piece, @template_root / 'template_class', @renderer)
|
62
60
|
end
|
63
61
|
|
64
62
|
it "render using correct template" do
|
@@ -87,28 +85,27 @@ describe "Styles" do
|
|
87
85
|
|
88
86
|
it "use template found in class directory if exists" do
|
89
87
|
TemplateClass.style :named1
|
90
|
-
assert_correct_template(@piece, @template_root / 'template_class/named1')
|
88
|
+
assert_correct_template(@piece, @template_root / 'template_class/named1', @renderer)
|
91
89
|
@piece.render.must_equal "template_class/named1.html.cut\n"
|
92
90
|
end
|
93
91
|
|
94
92
|
it "use template in template root with correct name if it exists" do
|
95
93
|
TemplateClass.style :named2
|
96
|
-
assert_correct_template(@piece, @template_root / 'named2')
|
94
|
+
assert_correct_template(@piece, @template_root / 'named2', @renderer)
|
97
95
|
@piece.render.must_equal "named2.html.cut\n"
|
98
96
|
end
|
99
97
|
|
100
98
|
it "allow passing of directory/stylename" do
|
101
99
|
TemplateClass.style :'orange/apple'
|
102
100
|
# piece.style.template.must_equal 'orange/apple'
|
103
|
-
assert_correct_template(@piece, @template_root / 'orange/apple')
|
101
|
+
assert_correct_template(@piece, @template_root / 'orange/apple', @renderer)
|
104
102
|
@piece.render.must_equal "orange/apple.html.cut\n"
|
105
103
|
end
|
106
104
|
|
107
105
|
it "default to styles marked as 'default'" do
|
108
106
|
TemplateClass.style :named1
|
109
107
|
TemplateClass.style :named2, :default => true
|
110
|
-
assert_correct_template(@piece, @template_root / 'named2')
|
111
|
-
# @piece.style.template.must_equal 'named2'
|
108
|
+
assert_correct_template(@piece, @template_root / 'named2', @renderer)
|
112
109
|
@piece.render.must_equal "named2.html.cut\n"
|
113
110
|
end
|
114
111
|
end
|
@@ -120,14 +117,13 @@ describe "Styles" do
|
|
120
117
|
@page = ::Page.new
|
121
118
|
@piece = TemplateClass.new
|
122
119
|
@page.box1 << @piece
|
123
|
-
assert_correct_template(@piece, @template_root / 'named2')
|
124
|
-
# @piece.style.template.must_equal 'named2'
|
120
|
+
assert_correct_template(@piece, @template_root / 'named2', @renderer)
|
125
121
|
@piece.render.must_equal "named2.html.cut\n"
|
126
122
|
end
|
127
123
|
|
128
124
|
it "be possible" do
|
129
125
|
@piece.style = :named1
|
130
|
-
assert_correct_template(@piece, @template_root / 'template_class/named1')
|
126
|
+
assert_correct_template(@piece, @template_root / 'template_class/named1', @renderer)
|
131
127
|
@piece.render.must_equal "template_class/named1.html.cut\n"
|
132
128
|
end
|
133
129
|
|
@@ -135,27 +131,24 @@ describe "Styles" do
|
|
135
131
|
@piece.style = :named1
|
136
132
|
@piece.save
|
137
133
|
@piece = Content[@piece.id]
|
138
|
-
|
139
|
-
assert_correct_template(@piece, @template_root / 'template_class/named1')
|
134
|
+
assert_correct_template(@piece, @template_root / 'template_class/named1', @renderer)
|
140
135
|
end
|
141
136
|
end
|
142
137
|
|
143
138
|
describe "inheriting styles" do
|
144
139
|
it "use default for sub class if it exists" do
|
145
140
|
piece = TemplateSubClass1.new
|
146
|
-
assert_correct_template(piece, @template_root / 'template_sub_class1')
|
141
|
+
assert_correct_template(piece, @template_root / 'template_sub_class1', @renderer)
|
147
142
|
end
|
148
143
|
|
149
144
|
it "fall back to default style for superclass if default for class doesn't exist" do
|
150
145
|
piece = TemplateSubClass2.new
|
151
|
-
assert_correct_template(piece, @template_root / 'template_class')
|
152
|
-
# piece.style.template.must_equal 'template_class'
|
146
|
+
assert_correct_template(piece, @template_root / 'template_class', @renderer)
|
153
147
|
end
|
154
148
|
it "fall back to defined default style for superclass if default for class doesn't exist" do
|
155
149
|
TemplateClass.style :named1
|
156
150
|
piece = TemplateSubClass2.new
|
157
|
-
|
158
|
-
assert_correct_template(piece, @template_root / 'template_class/named1')
|
151
|
+
assert_correct_template(piece, @template_root / 'template_class/named1', @renderer)
|
159
152
|
end
|
160
153
|
end
|
161
154
|
|
@@ -288,11 +281,11 @@ describe "Styles" do
|
|
288
281
|
end
|
289
282
|
|
290
283
|
it "be used to render the content" do
|
291
|
-
@a.
|
284
|
+
@a.render_using(@renderer).must_equal "html: Total Title"
|
292
285
|
end
|
293
286
|
|
294
287
|
it "be used to render the content with the right format" do
|
295
|
-
@a.
|
288
|
+
@a.render_using(@renderer, :pdf).must_equal "pdf: Total Title"
|
296
289
|
end
|
297
290
|
end
|
298
291
|
|
@@ -362,7 +355,7 @@ describe "Styles" do
|
|
362
355
|
|
363
356
|
it "use template with their name inside container class template dir if it exists" do
|
364
357
|
@piece.results << TemplateClass.new
|
365
|
-
assert_correct_template(@piece.results, @template_root / 'template_class/results')
|
358
|
+
assert_correct_template(@piece.results, @template_root / 'template_class/results', @renderer)
|
366
359
|
@piece.results.render.must_equal "template_class/results.html.cut\n"
|
367
360
|
end
|
368
361
|
|
@@ -370,7 +363,7 @@ describe "Styles" do
|
|
370
363
|
@piece.entities << TemplateClass.new
|
371
364
|
@piece.entities << TemplateClass.new
|
372
365
|
@piece.entities.render.must_equal "template_class.html.cut\n\ntemplate_class.html.cut\n"
|
373
|
-
@piece.entities.style.template.call.must_equal '${ render_content }'
|
366
|
+
@piece.entities.style.template(:html, @renderer).call.must_equal '${ render_content }'
|
374
367
|
end
|
375
368
|
|
376
369
|
|
@@ -380,7 +373,7 @@ describe "Styles" do
|
|
380
373
|
end
|
381
374
|
@piece = TemplateClass.new
|
382
375
|
@page.box1 << @piece
|
383
|
-
assert_correct_template(@piece.things, @template_root / 'template_class/named1')
|
376
|
+
assert_correct_template(@piece.things, @template_root / 'template_class/named1', @renderer)
|
384
377
|
@piece.things.render.must_equal "template_class/named1.html.cut\n"
|
385
378
|
|
386
379
|
TemplateClass.box :dongles do
|
@@ -388,7 +381,7 @@ describe "Styles" do
|
|
388
381
|
end
|
389
382
|
@piece = TemplateClass.new
|
390
383
|
@page.box1 << @piece
|
391
|
-
assert_correct_template(@piece.dongles, @template_root / 'named2')
|
384
|
+
assert_correct_template(@piece.dongles, @template_root / 'named2', @renderer)
|
392
385
|
@piece.dongles.render.must_equal "named2.html.cut\n"
|
393
386
|
end
|
394
387
|
|
@@ -422,7 +415,7 @@ describe "Styles" do
|
|
422
415
|
FileUtils.mkdir_p(File.dirname(path))
|
423
416
|
FileUtils.touch(path + '.html.cut')
|
424
417
|
|
425
|
-
assert_correct_template(box, template_root / "templates" / test_template)
|
418
|
+
assert_correct_template(box, template_root / "templates" / test_template, @renderer)
|
426
419
|
|
427
420
|
FileUtils.rm_r(template_root / "templates")
|
428
421
|
end
|
@@ -445,12 +438,12 @@ describe "Styles" do
|
|
445
438
|
end
|
446
439
|
|
447
440
|
it "use the box name template if it exists" do
|
448
|
-
assert_correct_template(@piece.results, @template_root / 'template_class/results')
|
441
|
+
assert_correct_template(@piece.results, @template_root / 'template_class/results', @renderer)
|
449
442
|
@piece.results.render.must_equal "template_class/results.html.cut\n"
|
450
443
|
end
|
451
444
|
|
452
445
|
it "use the box classes default template if box name template is missing" do
|
453
|
-
assert_correct_template(@piece.entities, @template_root / 'box_a')
|
446
|
+
assert_correct_template(@piece.entities, @template_root / 'box_a', @renderer)
|
454
447
|
@piece.entities.render.must_equal "box_a.html.cut\n"
|
455
448
|
end
|
456
449
|
|
@@ -463,7 +456,7 @@ describe "Styles" do
|
|
463
456
|
end
|
464
457
|
piece = TemplateSubClass.new
|
465
458
|
@page.box1 << piece
|
466
|
-
assert_correct_template(piece.lastly, @template_root / 'box_a')
|
459
|
+
assert_correct_template(piece.lastly, @template_root / 'box_a', @renderer)
|
467
460
|
Object.send(:remove_const, :BoxASubclass) rescue nil
|
468
461
|
Object.send(:remove_const, :TemplateSubClass) rescue nil
|
469
462
|
end
|
@@ -480,8 +473,8 @@ describe "Styles" do
|
|
480
473
|
page = ::Page.new
|
481
474
|
piece = TemplateClass.new
|
482
475
|
page.box1 << piece
|
483
|
-
assert_correct_template(piece.strollers, @template_root / 'template_class/walky')
|
484
|
-
assert_correct_template(piece.sprinters, @template_root / 'box_a/runny')
|
476
|
+
assert_correct_template(piece.strollers, @template_root / 'template_class/walky', @renderer)
|
477
|
+
assert_correct_template(piece.sprinters, @template_root / 'box_a/runny', @renderer)
|
485
478
|
end
|
486
479
|
end
|
487
480
|
end
|