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
@@ -40,12 +40,12 @@ module Spontaneous::Collections
|
|
40
40
|
# A call to ${ content } within a layout template will call
|
41
41
|
# this #render method. The obvious result of this should be
|
42
42
|
# to just render each of the contained boxes.
|
43
|
-
def render(format = :html,
|
44
|
-
map { |box| box.render(format,
|
43
|
+
def render(format = :html, locals = {}, parent_context = nil)
|
44
|
+
map { |box| box.render(format, locals, parent_context) }.join("\n")
|
45
45
|
end
|
46
46
|
|
47
|
-
def render_using(renderer, format = :html,
|
48
|
-
map { |box| box.render_using(renderer, format,
|
47
|
+
def render_using(renderer, format = :html, locals = {}, parent_context = nil)
|
48
|
+
map { |box| box.render_using(renderer, format, locals, parent_context) }.join("\n")
|
49
49
|
end
|
50
50
|
|
51
51
|
protected
|
@@ -36,12 +36,12 @@ module Spontaneous::Collections
|
|
36
36
|
# this #render method.
|
37
37
|
# This should only be used during development
|
38
38
|
#
|
39
|
-
def render(format = :html,
|
40
|
-
map { |field| wrap_field_value(field, field.render(format,
|
39
|
+
def render(format = :html, locals = {}, parent_context = nil)
|
40
|
+
map { |field| wrap_field_value(field, field.render(format, locals), format) }.join("\n")
|
41
41
|
end
|
42
42
|
|
43
|
-
def render_using(renderer, format = :html,
|
44
|
-
map { |field| wrap_field_value(field, field.render_using(renderer, format,
|
43
|
+
def render_using(renderer, format = :html, locals = {}, parent_context = nil)
|
44
|
+
map { |field| wrap_field_value(field, field.render_using(renderer, format, locals), format) }.join("\n")
|
45
45
|
end
|
46
46
|
|
47
47
|
protected
|
@@ -6,10 +6,11 @@ module Spontaneous::Collections
|
|
6
6
|
|
7
7
|
attr_reader :store, :local_order
|
8
8
|
|
9
|
-
def initialize(superobject = nil, superset_name = nil)
|
9
|
+
def initialize(superobject = nil, superset_name = nil, &default_proc)
|
10
10
|
@superobject, @superset_name = superobject, superset_name
|
11
11
|
@has_superset = !!(@superobject && @superobject.respond_to?(@superset_name))
|
12
|
-
@store =
|
12
|
+
@store = Hash.new
|
13
|
+
@default_proc = default_proc
|
13
14
|
@local_order = []
|
14
15
|
end
|
15
16
|
|
@@ -128,13 +129,20 @@ module Spontaneous::Collections
|
|
128
129
|
|
129
130
|
alias_method :names, :order
|
130
131
|
|
131
|
-
|
132
132
|
def indexed(index)
|
133
133
|
named(order[index])
|
134
134
|
end
|
135
135
|
|
136
136
|
def named(name)
|
137
|
-
|
137
|
+
key = name.to_sym
|
138
|
+
return @store[key] if @store.key?(key)
|
139
|
+
value = (superset? ? superset.named(name) : nil)
|
140
|
+
return value unless value.nil?
|
141
|
+
if @default_proc
|
142
|
+
@default_proc.call(self, key)
|
143
|
+
else
|
144
|
+
nil
|
145
|
+
end
|
138
146
|
end
|
139
147
|
|
140
148
|
def index(entry)
|
@@ -27,16 +27,19 @@ module Spontaneous
|
|
27
27
|
@keys = {
|
28
28
|
:visible => :"#{name}_mapper_visibility",
|
29
29
|
:revision => :"#{name}_mapper_revision",
|
30
|
-
:
|
30
|
+
:active_scope => :"#{name}_mapper_dataset"
|
31
31
|
}
|
32
32
|
end
|
33
33
|
|
34
|
-
def_delegators :
|
34
|
+
def_delegators :active_scope,
|
35
|
+
:dataset,
|
35
36
|
:filter, :where,
|
36
37
|
:filter!, :where!,
|
38
|
+
:untyped,
|
37
39
|
:count, :count!,
|
38
40
|
:order, :limit,
|
39
41
|
:all, :get, :[], :first,
|
42
|
+
:primary_key_lookup,
|
40
43
|
:all!, :first!,
|
41
44
|
:reload,
|
42
45
|
:instance,
|
@@ -47,6 +50,7 @@ module Spontaneous
|
|
47
50
|
:columns, :table_name,
|
48
51
|
:qualify_column, :quote_identifier,
|
49
52
|
:with_cache,
|
53
|
+
:sql, :to_sql,
|
50
54
|
:logger=, :logger
|
51
55
|
|
52
56
|
def_delegators :@schema,
|
@@ -88,7 +92,7 @@ module Spontaneous
|
|
88
92
|
if block_given?
|
89
93
|
yield
|
90
94
|
else
|
91
|
-
|
95
|
+
active_scope
|
92
96
|
end
|
93
97
|
else
|
94
98
|
scope!(revision, visible, &block)
|
@@ -97,7 +101,7 @@ module Spontaneous
|
|
97
101
|
|
98
102
|
def scope!(revision, visible, &block)
|
99
103
|
if block_given?
|
100
|
-
r, v, d = @keys.values_at(:revision, :visible, :
|
104
|
+
r, v, d = @keys.values_at(:revision, :visible, :active_scope)
|
101
105
|
thread = Thread.current
|
102
106
|
state = [thread[r], thread[v], thread[d]]
|
103
107
|
begin
|
@@ -113,12 +117,12 @@ module Spontaneous
|
|
113
117
|
end
|
114
118
|
end
|
115
119
|
|
116
|
-
def
|
117
|
-
Thread.current[@keys[:
|
120
|
+
def active_scope
|
121
|
+
Thread.current[@keys[:active_scope]] || current_scope
|
118
122
|
end
|
119
123
|
|
120
124
|
def cached_dataset?
|
121
|
-
!Thread.current[@keys[:
|
125
|
+
!Thread.current[@keys[:active_scope]].nil?
|
122
126
|
end
|
123
127
|
|
124
128
|
def use_current_scope?(revision, visible)
|
@@ -87,10 +87,18 @@ module Spontaneous
|
|
87
87
|
|
88
88
|
alias_method :[], :get
|
89
89
|
|
90
|
+
def primary_key_lookup(id)
|
91
|
+
mapper.primary_key_lookup(id)
|
92
|
+
end
|
93
|
+
|
90
94
|
def count
|
91
95
|
mapper.count(types)
|
92
96
|
end
|
93
97
|
|
98
|
+
def dataset
|
99
|
+
mapper.dataset(types)
|
100
|
+
end
|
101
|
+
|
94
102
|
def all
|
95
103
|
mapper.all(*types)
|
96
104
|
end
|
@@ -207,7 +207,7 @@ module Spontaneous
|
|
207
207
|
end
|
208
208
|
|
209
209
|
def load_one_to_many_association(assoc)
|
210
|
-
members = self.send(assoc[:dataset_method]).all
|
210
|
+
members = self.send(assoc[:dataset_method]).all.compact
|
211
211
|
if (reciprocal = assoc[:reciprocal])
|
212
212
|
members.each do |member|
|
213
213
|
member.send :set_association_cache, reciprocal, self
|
@@ -16,7 +16,7 @@ module Spontaneous
|
|
16
16
|
if (instance = @identity_map[id])
|
17
17
|
instance
|
18
18
|
else
|
19
|
-
|
19
|
+
primary_key_lookup(id)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -38,6 +38,10 @@ module Spontaneous
|
|
38
38
|
}
|
39
39
|
end
|
40
40
|
|
41
|
+
def primary_key_lookup(pk)
|
42
|
+
first(id: pk)
|
43
|
+
end
|
44
|
+
|
41
45
|
def first(*args, &block)
|
42
46
|
load_instance @dataset.first(*args, &block)
|
43
47
|
end
|
@@ -134,6 +138,11 @@ module Spontaneous
|
|
134
138
|
self
|
135
139
|
end
|
136
140
|
|
141
|
+
def invert
|
142
|
+
@dataset.invert!
|
143
|
+
self
|
144
|
+
end
|
145
|
+
|
137
146
|
def qualify_to_first_source
|
138
147
|
@dataset = @dataset.qualify_to_first_source
|
139
148
|
self
|
@@ -144,9 +153,11 @@ module Spontaneous
|
|
144
153
|
end
|
145
154
|
|
146
155
|
def to_sql
|
147
|
-
@dataset.
|
156
|
+
@dataset.sql
|
148
157
|
end
|
149
158
|
|
159
|
+
alias_method :sql, :to_sql
|
160
|
+
|
150
161
|
private
|
151
162
|
|
152
163
|
def get_raw(id)
|
@@ -185,6 +196,7 @@ module Spontaneous
|
|
185
196
|
instance
|
186
197
|
else
|
187
198
|
model = @schema.to_class(attributes[:type_sid])
|
199
|
+
return nil if model.nil?
|
188
200
|
instance = model.new(attributes, true)
|
189
201
|
@identity_map[instance.id] = instance
|
190
202
|
end
|
@@ -6,6 +6,7 @@ module Spontaneous
|
|
6
6
|
@revision, @visible = revision, visible
|
7
7
|
@table, @schema = table, schema
|
8
8
|
@identity_map = {}
|
9
|
+
@schema_types = @schema.types
|
9
10
|
end
|
10
11
|
|
11
12
|
def count(types = nil)
|
@@ -17,6 +18,10 @@ module Spontaneous
|
|
17
18
|
count(nil)
|
18
19
|
end
|
19
20
|
|
21
|
+
def untyped
|
22
|
+
untyped_dataset
|
23
|
+
end
|
24
|
+
|
20
25
|
def filter(types, *cond, &block)
|
21
26
|
dataset(types).filter(*cond, &block)
|
22
27
|
end
|
@@ -61,6 +66,10 @@ module Spontaneous
|
|
61
66
|
dataset.get(id)
|
62
67
|
end
|
63
68
|
|
69
|
+
def primary_key_lookup(id)
|
70
|
+
dataset.primary_key_lookup(id)
|
71
|
+
end
|
72
|
+
|
64
73
|
alias_method :[], :get
|
65
74
|
|
66
75
|
def insert(*values, &block)
|
@@ -84,8 +93,8 @@ module Spontaneous
|
|
84
93
|
dataset.for_update
|
85
94
|
end
|
86
95
|
|
87
|
-
def delete(types)
|
88
|
-
dataset(types).delete
|
96
|
+
def delete(types = nil)
|
97
|
+
dataset(types, {}).delete
|
89
98
|
end
|
90
99
|
|
91
100
|
def delete_instance(instance)
|
@@ -93,7 +102,7 @@ module Spontaneous
|
|
93
102
|
end
|
94
103
|
|
95
104
|
def reload(instance)
|
96
|
-
|
105
|
+
untyped_dataset.reload(instance)
|
97
106
|
end
|
98
107
|
|
99
108
|
def create(instance)
|
@@ -101,7 +110,7 @@ module Spontaneous
|
|
101
110
|
end
|
102
111
|
|
103
112
|
def save(instance)
|
104
|
-
|
113
|
+
untyped_dataset.save(instance)
|
105
114
|
end
|
106
115
|
|
107
116
|
def order(types, *columns, &block)
|
@@ -164,30 +173,41 @@ module Spontaneous
|
|
164
173
|
@visible || false
|
165
174
|
end
|
166
175
|
|
167
|
-
def dataset(types = nil)
|
168
|
-
Dataset.new(table_dataset(types), @schema, @identity_map)
|
176
|
+
def dataset(types = nil, fallback_type_condition = all_types_condition)
|
177
|
+
Dataset.new(table_dataset(types, fallback_type_condition), @schema, @identity_map)
|
178
|
+
end
|
179
|
+
|
180
|
+
def untyped_dataset
|
181
|
+
Dataset.new(naked_dataset, @schema, @identity_map)
|
169
182
|
end
|
170
183
|
|
171
184
|
private
|
172
185
|
|
173
|
-
def table_dataset(types)
|
174
|
-
naked_dataset.filter(conditions(types))
|
186
|
+
def table_dataset(types, fallback_type_condition)
|
187
|
+
naked_dataset.filter(conditions(types, fallback_type_condition))
|
175
188
|
end
|
176
189
|
|
177
190
|
def naked_dataset
|
178
191
|
@table.dataset(@revision)
|
179
192
|
end
|
180
193
|
|
181
|
-
def conditions(types)
|
182
|
-
cond = type_conditions(types)
|
194
|
+
def conditions(types, fallback_type_condition)
|
195
|
+
cond = type_conditions(types, fallback_type_condition)
|
183
196
|
cond[:hidden] = false if @visible
|
184
197
|
cond
|
185
198
|
end
|
186
199
|
|
187
|
-
def type_conditions(types)
|
188
|
-
return {} if types.nil?
|
200
|
+
def type_conditions(types, fallback_type_condition)
|
189
201
|
types = Array(types)
|
190
|
-
return
|
202
|
+
return fallback_type_condition if types.empty?
|
203
|
+
{ :type_sid => types.flatten.map { |model| @schema.to_id(model) } }
|
204
|
+
end
|
205
|
+
|
206
|
+
def all_types_condition
|
207
|
+
type_condition(@schema_types)
|
208
|
+
end
|
209
|
+
|
210
|
+
def type_condition(types)
|
191
211
|
{ :type_sid => types.flatten.map { |model| @schema.to_id(model) } }
|
192
212
|
end
|
193
213
|
end
|
data/lib/spontaneous/facet.rb
CHANGED
data/lib/spontaneous/field.rb
CHANGED
@@ -40,33 +40,33 @@ module Spontaneous
|
|
40
40
|
(time.to_f * 10000000).to_i
|
41
41
|
end
|
42
42
|
|
43
|
-
def self.update(content, params, user, asynchronous = false)
|
43
|
+
def self.update(site, content, params, user, asynchronous = false)
|
44
44
|
fields = Hash[params.map { |sid, value| [content.fields.sid(sid), value] }]
|
45
|
-
Update.perform(fields, user, asynchronous)
|
45
|
+
Update.perform(site, fields, user, asynchronous)
|
46
46
|
end
|
47
47
|
|
48
|
-
def self.update_asynchronously(content, params, user)
|
49
|
-
update(content, params, user, true)
|
48
|
+
def self.update_asynchronously(site, content, params, user)
|
49
|
+
update(site, content, params, user, true)
|
50
50
|
end
|
51
51
|
|
52
|
-
def self.set(field, value, user, asynchronous = false)
|
53
|
-
Update.perform({field => value}, user, asynchronous)
|
52
|
+
def self.set(site, field, value, user, asynchronous = false)
|
53
|
+
Update.perform(site, {field => value}, user, asynchronous)
|
54
54
|
end
|
55
55
|
|
56
|
-
def self.set_asynchronously(field, value, user)
|
57
|
-
set(field, value, user, true)
|
56
|
+
def self.set_asynchronously(site, field, value, user)
|
57
|
+
set(site, field, value, user, true)
|
58
58
|
end
|
59
59
|
|
60
|
-
def self.find(*ids)
|
61
|
-
fields = ids.map { |id| resolve_id(id) }.compact
|
60
|
+
def self.find(content_model, *ids)
|
61
|
+
fields = ids.map { |id| resolve_id(content_model, id) }.compact
|
62
62
|
return fields.first if ids.length == 1
|
63
63
|
fields
|
64
64
|
end
|
65
65
|
|
66
|
-
def self.resolve_id(id)
|
66
|
+
def self.resolve_id(content_model, id)
|
67
67
|
content_id, box_sid, field_sid = id.split("/")
|
68
68
|
field_sid, box_sid = box_sid, field_sid if field_sid.nil?
|
69
|
-
content = target =
|
69
|
+
content = target = content_model.get(content_id)
|
70
70
|
return nil if target.nil?
|
71
71
|
target = content.boxes.sid(box_sid) if box_sid
|
72
72
|
return nil if target.nil?
|
@@ -121,6 +121,10 @@ module Spontaneous
|
|
121
121
|
end
|
122
122
|
|
123
123
|
def pending_value=(value)
|
124
|
+
set_pending_value(value, Spontaneous::Site.instance)
|
125
|
+
end
|
126
|
+
|
127
|
+
def set_pending_value(value, site)
|
124
128
|
values[:__pending__] = {
|
125
129
|
:value => value,
|
126
130
|
:version => version + 1,
|
@@ -148,18 +152,18 @@ module Spontaneous
|
|
148
152
|
values.delete(:__pending__)
|
149
153
|
end
|
150
154
|
|
151
|
-
def process_pending_value
|
152
|
-
if (pending = process_pending_value!)
|
155
|
+
def process_pending_value(site = Spontaneous::Site.instance)
|
156
|
+
if (pending = process_pending_value!(site))
|
153
157
|
cleanup_pending_value!(pending)
|
154
158
|
end
|
155
159
|
save
|
156
160
|
end
|
157
161
|
|
158
|
-
def process_pending_value!
|
162
|
+
def process_pending_value!(site)
|
159
163
|
if has_pending_value?
|
160
164
|
pending = pending_value
|
161
165
|
@previous_values = values.dup
|
162
|
-
set_value!(pending_value[:value])
|
166
|
+
set_value!(pending_value[:value], true, site)
|
163
167
|
pending
|
164
168
|
end
|
165
169
|
end
|
@@ -206,8 +210,8 @@ module Spontaneous
|
|
206
210
|
end
|
207
211
|
|
208
212
|
def reload
|
209
|
-
|
210
|
-
Spontaneous::Field.find(
|
213
|
+
owner.model.scope! do
|
214
|
+
Spontaneous::Field.find(owner.model, id)
|
211
215
|
end
|
212
216
|
end
|
213
217
|
|
@@ -224,20 +228,20 @@ module Spontaneous
|
|
224
228
|
[:html, :plain]
|
225
229
|
end
|
226
230
|
|
227
|
-
def process_value(value)
|
231
|
+
def process_value(value, site)
|
228
232
|
@modified = (@initial_value != value)
|
229
233
|
increment_version if @modified
|
230
|
-
self.processed_values = generate_outputs(@unprocessed_value)
|
234
|
+
self.processed_values = generate_outputs(@unprocessed_value, site)
|
231
235
|
end
|
232
236
|
|
233
237
|
def set_value(v, process = true)
|
234
|
-
set_value!(v, process)
|
238
|
+
set_value!(v, process, Spontaneous::Site.instance)
|
235
239
|
save
|
236
240
|
end
|
237
241
|
|
238
|
-
def set_value!(v, process = true)
|
242
|
+
def set_value!(v, process = true, site = nil)
|
239
243
|
set_unprocessed_value(v)
|
240
|
-
process_value(v) if process
|
244
|
+
process_value(v, site) if process
|
241
245
|
end
|
242
246
|
|
243
247
|
def modified!
|
@@ -266,16 +270,16 @@ module Spontaneous
|
|
266
270
|
unprocessed_value
|
267
271
|
end
|
268
272
|
|
269
|
-
def generate_outputs(value)
|
273
|
+
def generate_outputs(value, site)
|
270
274
|
values = {}
|
271
|
-
value = preprocess(value)
|
275
|
+
value = preprocess(value, site)
|
272
276
|
outputs.each do |output|
|
273
277
|
process_method = "generate_#{output}"
|
274
278
|
values[output] = \
|
275
279
|
if respond_to?(process_method)
|
276
|
-
send(process_method, value)
|
280
|
+
send(process_method, value, site)
|
277
281
|
else
|
278
|
-
generate(output, value)
|
282
|
+
generate(output, value, site)
|
279
283
|
end
|
280
284
|
end
|
281
285
|
values
|
@@ -283,7 +287,7 @@ module Spontaneous
|
|
283
287
|
|
284
288
|
# should be overwritten in subclasses that actually do something
|
285
289
|
# with the field value
|
286
|
-
def preprocess(value)
|
290
|
+
def preprocess(value, site)
|
287
291
|
value
|
288
292
|
end
|
289
293
|
|
@@ -295,7 +299,7 @@ module Spontaneous
|
|
295
299
|
value.to_s.gsub(%r{[#{HTML_ESCAPE_TABLE.keys.join}]}) { |s| HTML_ESCAPE_TABLE[s] }
|
296
300
|
end
|
297
301
|
|
298
|
-
def generate(output, value)
|
302
|
+
def generate(output, value, site)
|
299
303
|
value
|
300
304
|
end
|
301
305
|
|
@@ -323,16 +327,16 @@ module Spontaneous
|
|
323
327
|
value(format).to_s
|
324
328
|
end
|
325
329
|
|
326
|
-
def render(format
|
330
|
+
def render(format = :html, locals = {}, *args)
|
327
331
|
value(format)
|
328
332
|
end
|
329
333
|
|
330
|
-
def render_using(renderer, format
|
331
|
-
render(format)
|
334
|
+
def render_using(renderer, format = :html, locals = {}, *args)
|
335
|
+
render(format, locals)
|
332
336
|
end
|
333
337
|
|
334
|
-
def to_html(
|
335
|
-
|
338
|
+
def to_html(locals = {})
|
339
|
+
value(:html)
|
336
340
|
end
|
337
341
|
|
338
342
|
def to_pdf(*args)
|
@@ -460,6 +464,7 @@ module Spontaneous
|
|
460
464
|
data = params.dup
|
461
465
|
unprocessed_value = data.delete(:unprocessed_value) || ""
|
462
466
|
processed_values = data.delete(:processed_values) || {}
|
467
|
+
set_unprocessed_value(unprocessed_value)
|
463
468
|
@processed_values = processed_values
|
464
469
|
set_value(unprocessed_value, default_values)
|
465
470
|
data.each do |property, value|
|