spontaneous 0.2.0.alpha7 → 0.2.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +10 -4
- data/Readme.markdown +1 -1
- data/application/css/definitions.css.scss +5 -0
- data/application/css/dialogue.css.scss +62 -0
- data/application/js/content.js +1 -1
- data/application/js/dom.js +1 -1
- data/application/js/event_source.js +3 -0
- data/application/js/{field_types/date_field.js → field/date.js} +2 -2
- data/application/js/{field_types/file_field.js → field/file.js} +2 -2
- data/application/js/{field_types/image_field.js → field/image.js} +54 -20
- data/application/js/{field_types/long_string_field.js → field/long_string.js} +2 -2
- data/application/js/{field_types/markdown_field.js → field/markdown.js} +2 -2
- data/application/js/{field_types/select_field.js → field/select.js} +2 -2
- data/application/js/{field_types/string_field.js → field/string.js} +21 -7
- data/application/js/{field_types/webvideo_field.js → field/webvideo.js} +2 -2
- data/application/js/field.js +2 -2
- data/application/js/publish.js +99 -19
- data/application/js/spontaneous.js +8 -8
- data/application/js/top_bar.js +6 -4
- data/db/migrations/20130109125023_add_page_publish_lock.rb +17 -0
- data/db/migrations/20130111161934_convert_bcrypt_passwords.rb +22 -0
- data/db/migrations/20130114120000_create_revision_tables.rb +106 -0
- data/db/migrations/20130116220423_add_index_to_archive.rb +9 -0
- data/lib/spontaneous/box.rb +53 -18
- data/lib/spontaneous/box_style.rb +2 -3
- data/lib/spontaneous/change.rb +39 -13
- data/lib/spontaneous/cli/fields.rb +29 -0
- data/lib/spontaneous/cli/init.rb +2 -2
- data/lib/spontaneous/cli/migrate.rb +0 -1
- data/lib/spontaneous/cli/server.rb +14 -10
- data/lib/spontaneous/cli/site.rb +20 -9
- data/lib/spontaneous/cli.rb +8 -6
- data/lib/spontaneous/collections/box_set.rb +11 -0
- data/lib/spontaneous/collections/field_set.rb +24 -1
- data/lib/spontaneous/concern.rb +37 -0
- data/lib/spontaneous/config.rb +3 -4
- data/lib/spontaneous/crypt/version.rb +130 -0
- data/lib/spontaneous/crypt.rb +84 -0
- data/lib/spontaneous/data_mapper/content_model/associations.rb +199 -0
- data/lib/spontaneous/data_mapper/content_model/column_accessors.rb +52 -0
- data/lib/spontaneous/data_mapper/content_model/instance_hooks.rb +34 -0
- data/lib/spontaneous/data_mapper/content_model/serialization.rb +54 -0
- data/lib/spontaneous/data_mapper/content_model/timestamps.rb +39 -0
- data/lib/spontaneous/data_mapper/content_model.rb +343 -0
- data/lib/spontaneous/data_mapper/content_table.rb +103 -0
- data/lib/spontaneous/data_mapper/dataset.rb +194 -0
- data/lib/spontaneous/data_mapper/scope.rb +195 -0
- data/lib/spontaneous/data_mapper.rb +161 -0
- data/lib/spontaneous/facet.rb +2 -2
- data/lib/spontaneous/field/base.rb +418 -0
- data/lib/spontaneous/field/date.rb +54 -0
- data/lib/spontaneous/{field_version.rb → field/field_version.rb} +1 -1
- data/lib/spontaneous/field/file.rb +100 -0
- data/lib/spontaneous/{field_types/image_field.rb → field/image.rb} +33 -33
- data/lib/spontaneous/{field_types/location_field.rb → field/location.rb} +2 -2
- data/lib/spontaneous/{field_types/long_string_field.rb → field/long_string.rb} +3 -3
- data/lib/spontaneous/field/markdown.rb +36 -0
- data/lib/spontaneous/{field_types/select_field.rb → field/select.rb} +4 -5
- data/lib/spontaneous/field/string.rb +17 -0
- data/lib/spontaneous/field/update.rb +156 -0
- data/lib/spontaneous/field/webvideo.rb +310 -0
- data/lib/spontaneous/field.rb +80 -0
- data/lib/spontaneous/generators/site/Gemfile.tt +2 -2
- data/lib/spontaneous/generators/site/config/environments/development.rb.tt +1 -1
- data/lib/spontaneous/generators/site/config/environments/production.rb.tt +1 -1
- data/lib/spontaneous/generators/site/lib/content.rb.tt +6 -0
- data/lib/spontaneous/generators/site/schema/box.rb.tt +3 -2
- data/lib/spontaneous/generators/site/schema/page.rb.tt +3 -1
- data/lib/spontaneous/generators/site/schema/piece.rb.tt +3 -1
- data/lib/spontaneous/generators/site/templates/layouts/standard.html.cut.tt +3 -1
- data/lib/spontaneous/generators/site.rb +4 -3
- data/lib/spontaneous/image_size.rb +8 -1
- data/lib/spontaneous/layout.rb +5 -1
- data/lib/spontaneous/loader.rb +2 -5
- data/lib/spontaneous/media/file.rb +11 -2
- data/lib/spontaneous/media/temp_file.rb +23 -0
- data/lib/spontaneous/media.rb +20 -39
- data/lib/spontaneous/{plugins → model/box}/allowed_types.rb +38 -17
- data/lib/spontaneous/model/box.rb +18 -0
- data/lib/spontaneous/{plugins → model/core}/aliases.rb +10 -14
- data/lib/spontaneous/{plugins → model/core}/boxes.rb +2 -2
- data/lib/spontaneous/{plugins → model/core}/content_groups.rb +2 -2
- data/lib/spontaneous/model/core/editor_class.rb +4 -0
- data/lib/spontaneous/{plugins → model/core}/entries.rb +19 -7
- data/lib/spontaneous/{plugins → model/core}/entry.rb +3 -3
- data/lib/spontaneous/{plugins → model/core}/fields.rb +38 -5
- data/lib/spontaneous/{plugins → model/core}/instance_code.rb +2 -2
- data/lib/spontaneous/{plugins → model/core}/media.rb +2 -12
- data/lib/spontaneous/{plugins → model/core}/modifications.rb +7 -6
- data/lib/spontaneous/model/core/page_search.rb +36 -0
- data/lib/spontaneous/{plugins → model/core}/permissions.rb +4 -4
- data/lib/spontaneous/{plugins → model/core}/prototypes.rb +4 -4
- data/lib/spontaneous/{plugins → model/core}/publishing.rb +93 -115
- data/lib/spontaneous/{plugins → model/core}/render.rb +2 -2
- data/lib/spontaneous/{plugins → model/core}/schema_hierarchy.rb +7 -11
- data/lib/spontaneous/model/core/schema_id.rb +65 -0
- data/lib/spontaneous/{plugins → model/core}/schema_title.rb +2 -2
- data/lib/spontaneous/{plugins → model/core}/serialisation.rb +2 -2
- data/lib/spontaneous/{plugins → model/core}/styles.rb +2 -2
- data/lib/spontaneous/{plugins → model/core}/supertype.rb +2 -2
- data/lib/spontaneous/{plugins → model/core}/visibility.rb +7 -48
- data/lib/spontaneous/model/core.rb +143 -0
- data/lib/spontaneous/{plugins → model/page}/controllers.rb +3 -3
- data/lib/spontaneous/{plugins → model}/page/formats.rb +2 -2
- data/lib/spontaneous/{plugins → model/page}/layouts.rb +2 -2
- data/lib/spontaneous/model/page/locks.rb +14 -0
- data/lib/spontaneous/{plugins → model/page}/page_tree.rb +3 -3
- data/lib/spontaneous/{plugins → model/page}/paths.rb +30 -12
- data/lib/spontaneous/{plugins → model}/page/request.rb +2 -2
- data/lib/spontaneous/{plugins → model/page}/site_map.rb +2 -2
- data/lib/spontaneous/model/page/site_timestamps.rb +44 -0
- data/lib/spontaneous/{page.rb → model/page.rb} +49 -28
- data/lib/spontaneous/{piece.rb → model/piece.rb} +7 -6
- data/lib/spontaneous/model.rb +97 -0
- data/lib/spontaneous/output/context.rb +1 -1
- data/lib/spontaneous/output/format.rb +4 -0
- data/lib/spontaneous/output/template/renderer.rb +2 -2
- data/lib/spontaneous/output.rb +2 -2
- data/lib/spontaneous/page_lock.rb +62 -0
- data/lib/spontaneous/page_piece.rb +1 -1
- data/lib/spontaneous/permissions/access_key.rb +9 -4
- data/lib/spontaneous/permissions/user.rb +19 -9
- data/lib/spontaneous/permissions.rb +2 -5
- data/lib/spontaneous/plugins/application/facets.rb +1 -2
- data/lib/spontaneous/plugins/application/features.rb +1 -1
- data/lib/spontaneous/plugins/application/paths.rb +1 -1
- data/lib/spontaneous/plugins/application/render.rb +1 -1
- data/lib/spontaneous/plugins/application/serialisation.rb +1 -1
- data/lib/spontaneous/plugins/application/state.rb +30 -1
- data/lib/spontaneous/plugins/application/system.rb +12 -12
- data/lib/spontaneous/prototypes/box_prototype.rb +1 -1
- data/lib/spontaneous/prototypes/field_prototype.rb +3 -6
- data/lib/spontaneous/prototypes/style_prototype.rb +1 -1
- data/lib/spontaneous/publishing/immediate.rb +77 -49
- data/lib/spontaneous/publishing/revision.rb +355 -0
- data/lib/spontaneous/publishing/simultaneous.rb +10 -49
- data/lib/spontaneous/publishing.rb +1 -0
- data/lib/spontaneous/rack/around_back.rb +1 -1
- data/lib/spontaneous/rack/around_front.rb +2 -4
- data/lib/spontaneous/rack/around_preview.rb +1 -1
- data/lib/spontaneous/rack/back.rb +80 -63
- data/lib/spontaneous/rack/cacheable_file.rb +2 -2
- data/lib/spontaneous/rack/cookie_authentication.rb +1 -1
- data/lib/spontaneous/rack/front.rb +1 -1
- data/lib/spontaneous/rack/helpers.rb +8 -9
- data/lib/spontaneous/{page_controller.rb → rack/page_controller.rb} +1 -1
- data/lib/spontaneous/rack/public.rb +3 -3
- data/lib/spontaneous/rack.rb +15 -15
- data/lib/spontaneous/schema/uid.rb +4 -1
- data/lib/spontaneous/schema.rb +57 -24
- data/lib/spontaneous/search/database.rb +12 -1
- data/lib/spontaneous/search/index.rb +34 -6
- data/lib/spontaneous/search/results.rb +1 -1
- data/lib/spontaneous/server.rb +3 -3
- data/lib/spontaneous/simultaneous.rb +53 -0
- data/lib/spontaneous/{plugins/site → site}/features.rb +2 -2
- data/lib/spontaneous/{plugins/site → site}/helpers.rb +2 -3
- data/lib/spontaneous/{plugins/site → site}/hooks.rb +2 -2
- data/lib/spontaneous/{plugins/site → site}/instance.rb +4 -6
- data/lib/spontaneous/{plugins/site → site}/level.rb +2 -2
- data/lib/spontaneous/{plugins/site → site}/map.rb +4 -4
- data/lib/spontaneous/{plugins/site → site}/paths.rb +2 -2
- data/lib/spontaneous/site/publishing.rb +89 -0
- data/lib/spontaneous/{plugins/site → site}/schema.rb +4 -4
- data/lib/spontaneous/{plugins/site → site}/search.rb +2 -2
- data/lib/spontaneous/{plugins/site → site}/selectors.rb +15 -7
- data/lib/spontaneous/{plugins/site → site}/state.rb +2 -2
- data/lib/spontaneous/{plugins/site → site}/storage.rb +2 -2
- data/lib/spontaneous/{plugins/site → site}/url.rb +2 -2
- data/lib/spontaneous/site.rb +31 -14
- data/lib/spontaneous/state.rb +5 -6
- data/lib/spontaneous/style.rb +3 -2
- data/lib/spontaneous/utils/database/mysql_dumper.rb +13 -0
- data/lib/spontaneous/utils/database/postgres_dumper.rb +5 -0
- data/lib/spontaneous/version.rb +1 -1
- data/lib/spontaneous.rb +34 -89
- data/spontaneous.gemspec +112 -114
- data/test/experimental/test_crypt.rb +158 -0
- data/test/experimental/test_features.rb +3 -3
- data/test/fixtures/example_application/config/environments/development.rb +1 -1
- data/test/fixtures/example_application/lib/content.rb +5 -0
- data/test/fixtures/example_application/schema/page.rb +2 -1
- data/test/fixtures/example_application/schema/piece.rb +3 -2
- data/test/fixtures/serialisation/class_hash.yaml.erb +5 -5
- data/test/fixtures/serialisation/root_hash.yaml.erb +8 -0
- data/test/functional/test_application.rb +12 -1
- data/test/functional/test_back.rb +80 -48
- data/test/functional/test_front.rb +39 -46
- data/test/functional/test_user_manager.rb +3 -9
- data/test/javascript/test_markdown.rb +2 -2
- data/test/test_helper.rb +78 -23
- data/test/unit/test_alias.rb +21 -15
- data/test/unit/test_asset_bundler.rb +3 -3
- data/test/unit/test_assets.rb +2 -2
- data/test/unit/test_async.rb +7 -6
- data/test/unit/test_authentication.rb +43 -37
- data/test/unit/test_boxes.rb +46 -21
- data/test/unit/test_changesets.rb +65 -20
- data/test/unit/test_config.rb +9 -9
- data/test/unit/test_content.rb +50 -51
- data/test/unit/test_content_inheritance.rb +6 -20
- data/test/unit/test_datamapper.rb +1330 -0
- data/test/unit/test_datamapper_content.rb +214 -0
- data/test/unit/test_fields.rb +543 -54
- data/test/unit/test_formats.rb +2 -3
- data/test/unit/test_generators.rb +6 -6
- data/test/unit/test_helpers.rb +1 -1
- data/test/unit/test_image_size.rb +10 -5
- data/test/unit/test_images.rb +17 -18
- data/test/unit/test_layouts.rb +18 -3
- data/test/unit/test_media.rb +74 -49
- data/test/unit/test_modifications.rb +43 -43
- data/test/unit/test_page.rb +7 -10
- data/test/unit/test_permissions.rb +3 -10
- data/test/unit/test_piece.rb +5 -6
- data/test/unit/test_plugins.rb +7 -14
- data/test/unit/test_prototypes.rb +3 -3
- data/test/unit/test_publishing.rb +49 -27
- data/test/unit/test_render.rb +46 -15
- data/test/unit/test_revisions.rb +124 -127
- data/test/unit/test_schema.rb +53 -58
- data/test/unit/test_search.rb +64 -16
- data/test/unit/test_serialisation.rb +4 -11
- data/test/unit/test_site.rb +11 -12
- data/test/unit/test_structure.rb +2 -5
- data/test/unit/test_styles.rb +22 -24
- data/test/unit/test_type_hierarchy.rb +7 -5
- data/test/unit/test_visibility.rb +79 -55
- metadata +128 -102
- data/lib/sequel/plugins/content_table_inheritance.rb +0 -203
- data/lib/sequel/plugins/scoped_table_name.rb +0 -54
- data/lib/spontaneous/content.rb +0 -129
- data/lib/spontaneous/field_types/date_field.rb +0 -56
- data/lib/spontaneous/field_types/field.rb +0 -302
- data/lib/spontaneous/field_types/file_field.rb +0 -68
- data/lib/spontaneous/field_types/markdown_field.rb +0 -38
- data/lib/spontaneous/field_types/string_field.rb +0 -19
- data/lib/spontaneous/field_types/webvideo_field.rb +0 -313
- data/lib/spontaneous/field_types.rb +0 -38
- data/lib/spontaneous/generators/site/lib/site.rb.tt +0 -4
- data/lib/spontaneous/plugins/field/editor_class.rb +0 -13
- data/lib/spontaneous/plugins/page/site_timestamps.rb +0 -28
- data/lib/spontaneous/plugins/page_search.rb +0 -63
- data/lib/spontaneous/plugins/schema_id.rb +0 -68
- data/lib/spontaneous/plugins/site/publishing.rb +0 -75
- data/lib/spontaneous/rack/fiber_pool.rb +0 -26
- data/test/unit/test_table_scoping.rb +0 -80
@@ -0,0 +1,418 @@
|
|
1
|
+
module Spontaneous
|
2
|
+
module Field
|
3
|
+
class Base
|
4
|
+
module ClassMethods
|
5
|
+
def has_editor
|
6
|
+
define_singleton_method(:editor_class) { ui_class }
|
7
|
+
end
|
8
|
+
|
9
|
+
def register(*labels)
|
10
|
+
labels = self.labels if labels.empty?
|
11
|
+
# logger.debug("Registering #{self} as #{labels.join(", ")}")
|
12
|
+
Field.register(self, *labels)
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
def labels
|
17
|
+
[self.name.demodulize.gsub(/Field$/, '').underscore]
|
18
|
+
end
|
19
|
+
|
20
|
+
def inherited(subclass, real_caller = nil)
|
21
|
+
if self.respond_to?(:editor_class)
|
22
|
+
editor_class = self.editor_class
|
23
|
+
subclass.singleton_class.send(:define_method, :editor_class) do
|
24
|
+
editor_class
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def prototype=(prototype)
|
30
|
+
@prototype = prototype
|
31
|
+
end
|
32
|
+
|
33
|
+
def prototype
|
34
|
+
@prototype
|
35
|
+
end
|
36
|
+
|
37
|
+
def accepts
|
38
|
+
%w(text/.+)
|
39
|
+
end
|
40
|
+
|
41
|
+
def accepts?(mime_type)
|
42
|
+
accepts.find do |pattern|
|
43
|
+
Regexp.new(pattern).match(mime_type)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Provides the ability for specific field types to customize the schema values
|
48
|
+
# they return to the UI
|
49
|
+
def export(user)
|
50
|
+
{}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
extend ClassMethods
|
55
|
+
|
56
|
+
attr_accessor :owner, :name, :unprocessed_value, :template_params, :version
|
57
|
+
attr_reader :processed_values
|
58
|
+
|
59
|
+
alias_method :values, :processed_values
|
60
|
+
|
61
|
+
|
62
|
+
def initialize(params={}, default_values=true)
|
63
|
+
@processed_values = {}
|
64
|
+
deserialize(params, default_values)
|
65
|
+
end
|
66
|
+
|
67
|
+
def id
|
68
|
+
[owner.id, schema_id].join("/")
|
69
|
+
end
|
70
|
+
|
71
|
+
def writable?(user)
|
72
|
+
owner.field_writable?(user, name)
|
73
|
+
end
|
74
|
+
|
75
|
+
# If a field type needs to do some long running processing
|
76
|
+
# then it should declare itself as asynchronous so as not to tie up
|
77
|
+
# the CMS process.
|
78
|
+
def asynchronous?
|
79
|
+
false
|
80
|
+
end
|
81
|
+
|
82
|
+
def pending_value=(value)
|
83
|
+
values[:__pending__] = {
|
84
|
+
:value => value,
|
85
|
+
:version => version + 1,
|
86
|
+
:timestamp => Spontaneous::Field.timestamp
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
def pending_value
|
91
|
+
values[:__pending__]
|
92
|
+
end
|
93
|
+
|
94
|
+
def has_pending_value?
|
95
|
+
values.key?(:__pending__) && values[:__pending__].key?(:value)
|
96
|
+
end
|
97
|
+
|
98
|
+
def clear_pending_value
|
99
|
+
values.delete(:__pending__)
|
100
|
+
end
|
101
|
+
|
102
|
+
def process_pending_value
|
103
|
+
process_pending_value!
|
104
|
+
save
|
105
|
+
end
|
106
|
+
|
107
|
+
def process_pending_value!
|
108
|
+
if has_pending_value?
|
109
|
+
@previous_values = values.dup
|
110
|
+
set_value!(pending_value[:value])
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def conflicted_update?
|
115
|
+
return false if is_valid_pending_value?
|
116
|
+
self.processed_values = @previous_values
|
117
|
+
true
|
118
|
+
end
|
119
|
+
|
120
|
+
def is_valid_pending_value?
|
121
|
+
return true if @previous_values.nil?
|
122
|
+
reloaded = reload
|
123
|
+
pending = @previous_values[:__pending__] || {}
|
124
|
+
p1 = pending[:timestamp] || 0
|
125
|
+
p2 = (reloaded.pending_value || {})[:timestamp] || 0
|
126
|
+
if p1 >= p2
|
127
|
+
true
|
128
|
+
else
|
129
|
+
@previous_values = reloaded.values
|
130
|
+
false
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def reload
|
135
|
+
Spontaneous::Content.scope! do
|
136
|
+
Spontaneous::Field.find(self.id)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
# Called by Field::Update before launching the background
|
141
|
+
# task that updates the field values.
|
142
|
+
def before_asynchronous_update
|
143
|
+
end
|
144
|
+
|
145
|
+
def page_lock_description
|
146
|
+
"Updating to new value"
|
147
|
+
end
|
148
|
+
|
149
|
+
def outputs
|
150
|
+
[:html, :plain]
|
151
|
+
end
|
152
|
+
|
153
|
+
def process_value(value)
|
154
|
+
@modified = (@initial_value != value)
|
155
|
+
increment_version if @modified
|
156
|
+
self.processed_values = generate_outputs(@unprocessed_value)
|
157
|
+
end
|
158
|
+
|
159
|
+
def set_value(v, process = true)
|
160
|
+
set_value!(v, process)
|
161
|
+
save
|
162
|
+
end
|
163
|
+
|
164
|
+
def set_value!(v, process = true)
|
165
|
+
set_unprocessed_value(v)
|
166
|
+
process_value(v) if process
|
167
|
+
end
|
168
|
+
|
169
|
+
def modified!
|
170
|
+
owner.field_modified!(self) if owner
|
171
|
+
end
|
172
|
+
|
173
|
+
def increment_version
|
174
|
+
self.version += 1
|
175
|
+
end
|
176
|
+
|
177
|
+
def version
|
178
|
+
@version ||= 0
|
179
|
+
end
|
180
|
+
|
181
|
+
def pending_version
|
182
|
+
return version unless has_pending_value?
|
183
|
+
pending_value[:version]
|
184
|
+
end
|
185
|
+
|
186
|
+
def matches_version?(v)
|
187
|
+
(version != v) && (pending_version != v)
|
188
|
+
end
|
189
|
+
|
190
|
+
# value used to show conflicts between the current value and the value they're attempting to enter
|
191
|
+
def conflicted_value
|
192
|
+
unprocessed_value
|
193
|
+
end
|
194
|
+
|
195
|
+
def generate_outputs(value)
|
196
|
+
values = {}
|
197
|
+
value = preprocess(value)
|
198
|
+
outputs.each do |output|
|
199
|
+
process_method = "generate_#{output}"
|
200
|
+
values[output] = \
|
201
|
+
if respond_to?(process_method)
|
202
|
+
send(process_method, value)
|
203
|
+
else
|
204
|
+
generate(output, value)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
values
|
208
|
+
end
|
209
|
+
|
210
|
+
# should be overwritten in subclasses that actually do something
|
211
|
+
# with the field value
|
212
|
+
def preprocess(value)
|
213
|
+
value
|
214
|
+
end
|
215
|
+
|
216
|
+
HTML_ESCAPE_TABLE = {
|
217
|
+
'&' => '&'
|
218
|
+
}
|
219
|
+
|
220
|
+
def escape_html(value)
|
221
|
+
value.to_s.gsub(%r{[#{HTML_ESCAPE_TABLE.keys.join}]}) { |s| HTML_ESCAPE_TABLE[s] }
|
222
|
+
end
|
223
|
+
|
224
|
+
def generate(output, value)
|
225
|
+
value
|
226
|
+
end
|
227
|
+
|
228
|
+
# attr_accessor :values
|
229
|
+
|
230
|
+
# override this to return custom values derived from (un)processed_value
|
231
|
+
# alias_method :value, :processed_value
|
232
|
+
def value(format=:html)
|
233
|
+
processed_values[format.to_sym] || unprocessed_value
|
234
|
+
end
|
235
|
+
alias_method :processed_value, :value
|
236
|
+
|
237
|
+
def image?
|
238
|
+
false
|
239
|
+
end
|
240
|
+
|
241
|
+
def indexable_value
|
242
|
+
unprocessed_value
|
243
|
+
end
|
244
|
+
|
245
|
+
def to_s(format = :html)
|
246
|
+
value(format).to_s
|
247
|
+
end
|
248
|
+
|
249
|
+
def render(format=:html, *args)
|
250
|
+
value(format)
|
251
|
+
end
|
252
|
+
|
253
|
+
def render_using(renderer, format=:html, *args)
|
254
|
+
render(format)
|
255
|
+
end
|
256
|
+
|
257
|
+
def to_html(*args)
|
258
|
+
render(:html, *args)
|
259
|
+
end
|
260
|
+
|
261
|
+
def to_pdf(*args)
|
262
|
+
render(:pdf, *args)
|
263
|
+
end
|
264
|
+
|
265
|
+
def value=(value)
|
266
|
+
self.set_value value, true
|
267
|
+
end
|
268
|
+
|
269
|
+
alias_method :unprocessed_value=, :value=
|
270
|
+
|
271
|
+
def save
|
272
|
+
owner.field_modified!(self) if owner
|
273
|
+
end
|
274
|
+
|
275
|
+
def mark_unmodified
|
276
|
+
@modified = false
|
277
|
+
end
|
278
|
+
|
279
|
+
def modified?
|
280
|
+
@modified
|
281
|
+
end
|
282
|
+
|
283
|
+
attr_accessor :prototype
|
284
|
+
# def prototype
|
285
|
+
# self.class.prototype
|
286
|
+
# end
|
287
|
+
|
288
|
+
def schema_id
|
289
|
+
self.prototype.schema_id
|
290
|
+
end
|
291
|
+
|
292
|
+
|
293
|
+
def schema_name
|
294
|
+
self.prototype.schema_name
|
295
|
+
end
|
296
|
+
|
297
|
+
def schema_owner
|
298
|
+
self.prototype.owner
|
299
|
+
end
|
300
|
+
|
301
|
+
def owner_sid
|
302
|
+
schema_owner.schema_id
|
303
|
+
end
|
304
|
+
|
305
|
+
def serialize_db
|
306
|
+
S::Field.serialize_field(self)
|
307
|
+
end
|
308
|
+
|
309
|
+
# def start_inline_edit_marker
|
310
|
+
# "spontaneous:previewedit:start:field id:#{owner.id} name:#{self.name}"
|
311
|
+
# end
|
312
|
+
# def end_inline_edit_marker
|
313
|
+
# "spontaneous:previewedit:end:field id:#{owner.id} name:#{self.name}"
|
314
|
+
# end
|
315
|
+
|
316
|
+
def export(user)
|
317
|
+
{
|
318
|
+
:name => name.to_s,
|
319
|
+
:id => schema_id.to_s,
|
320
|
+
:unprocessed_value => unprocessed_value,
|
321
|
+
:processed_value => ui_preview_value,
|
322
|
+
:version => version
|
323
|
+
}
|
324
|
+
end
|
325
|
+
|
326
|
+
def ui_preview_value
|
327
|
+
value(:html)
|
328
|
+
end
|
329
|
+
|
330
|
+
def inspect
|
331
|
+
%(#<#{self.class.name}:#{self.object_id} #{self.serialize_db.inspect}>)
|
332
|
+
end
|
333
|
+
|
334
|
+
def blank?
|
335
|
+
unprocessed_value.blank?
|
336
|
+
end
|
337
|
+
|
338
|
+
alias_method :empty?, :blank?
|
339
|
+
|
340
|
+
|
341
|
+
def or(field)
|
342
|
+
return field if self.blank?
|
343
|
+
self
|
344
|
+
end
|
345
|
+
|
346
|
+
alias_method :'/', :or
|
347
|
+
alias_method :'|', :or
|
348
|
+
|
349
|
+
def versions
|
350
|
+
owner.field_versions(self)
|
351
|
+
end
|
352
|
+
|
353
|
+
def previous_version
|
354
|
+
versions.first
|
355
|
+
end
|
356
|
+
|
357
|
+
def create_version
|
358
|
+
Spontaneous::Field::FieldVersion.create(
|
359
|
+
:content_id => owner.id,
|
360
|
+
:field_sid => self.schema_id.to_s,
|
361
|
+
:version => version,
|
362
|
+
:value => @initial_value,
|
363
|
+
:user => owner.current_editor)
|
364
|
+
end
|
365
|
+
|
366
|
+
def <=>(o)
|
367
|
+
unprocessed_value <=> o.unprocessed_value
|
368
|
+
end
|
369
|
+
|
370
|
+
def ==(o)
|
371
|
+
eql?(o)
|
372
|
+
end
|
373
|
+
|
374
|
+
def eql?(o)
|
375
|
+
super || (o.class == self.class &&
|
376
|
+
o.id == id &&
|
377
|
+
o.unprocessed_value == unprocessed_value &&
|
378
|
+
o.values == values)
|
379
|
+
end
|
380
|
+
|
381
|
+
def hash
|
382
|
+
id.hash
|
383
|
+
end
|
384
|
+
|
385
|
+
protected
|
386
|
+
|
387
|
+
def deserialize(params={}, default_values=true)
|
388
|
+
data = params.dup
|
389
|
+
unprocessed_value = data.delete(:unprocessed_value) || ""
|
390
|
+
processed_values = data.delete(:processed_values) || {}
|
391
|
+
@processed_values = processed_values
|
392
|
+
set_value(unprocessed_value, default_values)
|
393
|
+
data.each do |property, value|
|
394
|
+
setter = "#{property}="
|
395
|
+
self.send(setter, value) if respond_to?(setter)
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
def processed_values=(values)
|
400
|
+
@processed_values = values
|
401
|
+
end
|
402
|
+
|
403
|
+
def set_unprocessed_value(new_value, preprocessed = false)
|
404
|
+
# initial_value should only be set once so that it can act as a test for field modification
|
405
|
+
@initial_value ||= new_value
|
406
|
+
@unprocessed_value = new_value
|
407
|
+
end
|
408
|
+
|
409
|
+
def method_missing(method, *args)
|
410
|
+
if outputs.include?(method)
|
411
|
+
value(method)
|
412
|
+
else
|
413
|
+
super
|
414
|
+
end
|
415
|
+
end
|
416
|
+
end
|
417
|
+
end
|
418
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Spontaneous::Field
|
4
|
+
class Date < Base
|
5
|
+
has_editor
|
6
|
+
|
7
|
+
DEFAULT_FORMAT = "%A, %-d %B, %Y"
|
8
|
+
|
9
|
+
def self.export(user)
|
10
|
+
super.merge({
|
11
|
+
:date_format => prototype.options[:format] || DEFAULT_FORMAT
|
12
|
+
})
|
13
|
+
end
|
14
|
+
|
15
|
+
def value(output = :html, *args)
|
16
|
+
return date if date.is_a?(::String)
|
17
|
+
case output
|
18
|
+
when :html
|
19
|
+
date.strftime(html_format)
|
20
|
+
else
|
21
|
+
date.strftime(format)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def outputs
|
26
|
+
[:julian]
|
27
|
+
end
|
28
|
+
|
29
|
+
def preprocess(value)
|
30
|
+
return value if value.blank?
|
31
|
+
::Date.parse(value)
|
32
|
+
end
|
33
|
+
|
34
|
+
def html_format
|
35
|
+
%(<time datetime="%Y-%m-%d">#{ format }</time>)
|
36
|
+
end
|
37
|
+
|
38
|
+
def generate_julian(date)
|
39
|
+
return date.jd if date.is_a?(::Date)
|
40
|
+
date.to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
def date
|
44
|
+
return "" if values[:julian].blank?
|
45
|
+
::Date.jd values[:julian].to_i
|
46
|
+
end
|
47
|
+
|
48
|
+
def format
|
49
|
+
prototype.options[:format] || DEFAULT_FORMAT
|
50
|
+
end
|
51
|
+
|
52
|
+
self.register
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
module Spontaneous::Field
|
6
|
+
class File < Base
|
7
|
+
has_editor
|
8
|
+
|
9
|
+
def asynchronous?
|
10
|
+
true
|
11
|
+
end
|
12
|
+
|
13
|
+
def outputs
|
14
|
+
[:html, :filesize, :filename]
|
15
|
+
end
|
16
|
+
|
17
|
+
def pending_value=(value)
|
18
|
+
file = process_upload(value)
|
19
|
+
pending = case file
|
20
|
+
when String
|
21
|
+
{ :tempfile => file }
|
22
|
+
else
|
23
|
+
serialize_pending_file(file)
|
24
|
+
end
|
25
|
+
super(pending)
|
26
|
+
end
|
27
|
+
|
28
|
+
def page_lock_description
|
29
|
+
"Processing file '#{pending_value[:value][:filename]}'"
|
30
|
+
end
|
31
|
+
|
32
|
+
def serialize_pending_file(file)
|
33
|
+
{ :tempfile => file.path, :type => file.mimetype, :filename => file.filename, :src => file.url }
|
34
|
+
end
|
35
|
+
|
36
|
+
def preprocess(image)
|
37
|
+
file, filename, mimetype = fileinfo(image)
|
38
|
+
return "" if file.nil?
|
39
|
+
return file unless ::File.exist?(file)
|
40
|
+
|
41
|
+
media_file = Spontaneous::Media::File.new(owner, filename, mimetype)
|
42
|
+
media_file.copy(file)
|
43
|
+
set_unprocessed_value(media_file.path)
|
44
|
+
media_file
|
45
|
+
end
|
46
|
+
|
47
|
+
def process_upload(value)
|
48
|
+
file, filename, mimetype = fileinfo(value)
|
49
|
+
media_file = Spontaneous::Media::TempFile.new(owner, filename, mimetype)
|
50
|
+
media_file.copy(file)
|
51
|
+
media_file
|
52
|
+
end
|
53
|
+
|
54
|
+
def fileinfo(fileinfo)
|
55
|
+
file = filename = mimetype = nil
|
56
|
+
case fileinfo
|
57
|
+
when Hash
|
58
|
+
file, filename, mimetype = fileinfo.values_at(:tempfile, :filename, :type)
|
59
|
+
when ::String
|
60
|
+
filename = ::File.basename(fileinfo)
|
61
|
+
file = fileinfo
|
62
|
+
end
|
63
|
+
[file, filename, mimetype]
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def generate_filesize(input)
|
68
|
+
if input.respond_to?(:filesize)
|
69
|
+
input.filesize
|
70
|
+
else
|
71
|
+
::File.exist?(input) ? ::File.size(input) : 0
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def generate_filename(input)
|
76
|
+
if input.respond_to?(:filename)
|
77
|
+
input.filename
|
78
|
+
else
|
79
|
+
::File.basename(input.to_s)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def generate_html(input)
|
84
|
+
return input if input.is_a?(::String)
|
85
|
+
input.url
|
86
|
+
end
|
87
|
+
|
88
|
+
def export(user = nil)
|
89
|
+
super(user).merge({
|
90
|
+
:processed_value => processed_values
|
91
|
+
})
|
92
|
+
end
|
93
|
+
|
94
|
+
def path
|
95
|
+
value(:html)
|
96
|
+
end
|
97
|
+
|
98
|
+
self.register
|
99
|
+
end
|
100
|
+
end
|