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
data/lib/spontaneous/media.rb
CHANGED
@@ -5,7 +5,8 @@ require 'digest/sha1'
|
|
5
5
|
module Spontaneous
|
6
6
|
module Media
|
7
7
|
|
8
|
-
autoload :File,
|
8
|
+
autoload :File, "spontaneous/media/file"
|
9
|
+
autoload :TempFile, "spontaneous/media/temp_file"
|
9
10
|
|
10
11
|
include Spontaneous::Constants
|
11
12
|
|
@@ -15,25 +16,6 @@ module Spontaneous
|
|
15
16
|
::File.join(Spontaneous.media_dir, *args)
|
16
17
|
end
|
17
18
|
|
18
|
-
@@upload_uid_lock = Mutex.new
|
19
|
-
@@upload_uid_index = 0
|
20
|
-
|
21
|
-
def upload_index
|
22
|
-
@@upload_uid_lock.synchronize do
|
23
|
-
@@upload_uid_index = (@@upload_uid_index + 1) % 0xFFFFFF
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def upload_path(filename)
|
28
|
-
time = Time.now.to_i
|
29
|
-
dir = "#{time}.#{upload_index}"
|
30
|
-
Spontaneous.cache_path("tmp", dir, filename)
|
31
|
-
end
|
32
|
-
|
33
|
-
# def to_urlpath(filepath)
|
34
|
-
# filepath.gsub(%r{^#{Spontaneous.media_dir}}, "/media")
|
35
|
-
# end
|
36
|
-
|
37
19
|
def to_filepath(urlpath)
|
38
20
|
parts = urlpath.split("/")
|
39
21
|
parts[1] = Spontaneous.media_dir
|
@@ -52,6 +34,14 @@ module Spontaneous
|
|
52
34
|
end
|
53
35
|
|
54
36
|
|
37
|
+
def pad_id(r)
|
38
|
+
r.to_s.rjust(5, "0")
|
39
|
+
end
|
40
|
+
|
41
|
+
def pad_revision(r)
|
42
|
+
r.to_s.rjust(4, "0")
|
43
|
+
end
|
44
|
+
|
55
45
|
def sha1(filepath)
|
56
46
|
Digest::SHA1.file(filepath).hexdigest
|
57
47
|
end
|
@@ -61,27 +51,18 @@ module Spontaneous
|
|
61
51
|
def combine_shards(hashes, &block)
|
62
52
|
hashes = hashes.split(',') unless hashes.is_a?(Array)
|
63
53
|
shards = hashes.map { |hash| Spontaneous.shard_path(hash) }
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
54
|
+
Tempfile.open('shard') do |combined|
|
55
|
+
combined.binmode
|
56
|
+
shards.each do |shard|
|
57
|
+
::File.open(shard, 'rb') do |part|
|
58
|
+
while (data = part.read(131072))
|
59
|
+
combined.write(data)
|
60
|
+
end
|
71
61
|
end
|
72
62
|
end
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
if block_given?
|
77
|
-
begin
|
78
|
-
yield(combined)
|
79
|
-
ensure
|
80
|
-
combined.close!
|
81
|
-
end
|
82
|
-
else
|
83
|
-
# caller's responsibility to close & delete tempfile
|
84
|
-
combined
|
63
|
+
combined.flush
|
64
|
+
combined.rewind
|
65
|
+
yield(combined) if block_given?
|
85
66
|
end
|
86
67
|
end
|
87
68
|
|
@@ -1,15 +1,17 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
module Spontaneous::
|
3
|
+
module Spontaneous::Model::Box
|
4
4
|
module AllowedTypes
|
5
|
-
extend
|
5
|
+
extend Spontaneous::Concern
|
6
6
|
|
7
7
|
class AllowedType
|
8
8
|
attr_accessor :allow_subclasses
|
9
9
|
|
10
|
-
def initialize(type, options={})
|
11
|
-
@
|
12
|
-
@
|
10
|
+
def initialize(box, type, options={}, &definition)
|
11
|
+
@box_class = box
|
12
|
+
@type = type
|
13
|
+
@options = options
|
14
|
+
define_instance_class(definition) if definition
|
13
15
|
end
|
14
16
|
|
15
17
|
def check_instance_class
|
@@ -31,13 +33,15 @@ module Spontaneous::Plugins
|
|
31
33
|
resolve_instance_class(@type)
|
32
34
|
end
|
33
35
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
def define_instance_class(definition)
|
37
|
+
content_type = Class.new(instance_class_supertype, &definition)
|
38
|
+
@box_class.const_set @type, content_type
|
39
|
+
@type = content_type.name
|
40
|
+
end
|
41
|
+
|
42
|
+
def instance_class_supertype
|
43
|
+
type = @options[:supertype] || (defined?(::Piece) ? ::Piece : Content::Piece)
|
44
|
+
constantize type
|
41
45
|
end
|
42
46
|
|
43
47
|
def styles(content)
|
@@ -93,6 +97,21 @@ module Spontaneous::Plugins
|
|
93
97
|
Spontaneous::Permissions.has_level?(user, user_level)
|
94
98
|
end
|
95
99
|
alias_method :addable?, :readable?
|
100
|
+
|
101
|
+
protected
|
102
|
+
|
103
|
+
def resolve_instance_class(name)
|
104
|
+
constantize(name)
|
105
|
+
end
|
106
|
+
|
107
|
+
def constantize(name)
|
108
|
+
case name
|
109
|
+
when Class
|
110
|
+
name
|
111
|
+
when Symbol, String
|
112
|
+
name.to_s.constantize
|
113
|
+
end
|
114
|
+
end
|
96
115
|
end
|
97
116
|
|
98
117
|
class AllowedGroup < AllowedType
|
@@ -102,7 +121,7 @@ module Spontaneous::Plugins
|
|
102
121
|
|
103
122
|
def instance_classes
|
104
123
|
schema = Spontaneous::Site.schema
|
105
|
-
names = groups.flat_map { |name|
|
124
|
+
names = groups.flat_map { |name| schema.groups[name] }
|
106
125
|
names.map { |name| resolve_instance_class(name) }.uniq
|
107
126
|
end
|
108
127
|
|
@@ -135,13 +154,15 @@ module Spontaneous::Plugins
|
|
135
154
|
# :prototype => The name of the prototype to use when creating pieces of this type
|
136
155
|
#
|
137
156
|
# TODO: finish these!
|
138
|
-
def allow(type, options={})
|
139
|
-
|
157
|
+
def allow(type, options={}, &definition)
|
158
|
+
allowed = AllowedType.new(self, type, options, &definition)
|
159
|
+
allowed_types_config << allowed
|
160
|
+
allowed
|
140
161
|
end
|
141
162
|
|
142
163
|
# TODO: implement this in a way that doesn't require searching through constants at load-time
|
143
164
|
def allow_subclasses(type, options = {})
|
144
|
-
parent_type = AllowedType.new(type)
|
165
|
+
parent_type = AllowedType.new(self, type)
|
145
166
|
parent_type.allow_subclasses = true
|
146
167
|
allowed_types_config << parent_type
|
147
168
|
# parent_type.instance_class.subclasses.each do |subclass|
|
@@ -151,7 +172,7 @@ module Spontaneous::Plugins
|
|
151
172
|
|
152
173
|
def allow_group(*group_names)
|
153
174
|
options = group_names.extract_options!
|
154
|
-
allowed_types_config << AllowedGroup.new(group_names, options)
|
175
|
+
allowed_types_config << AllowedGroup.new(self, group_names, options)
|
155
176
|
end
|
156
177
|
|
157
178
|
alias_method :allow_groups, :allow_group
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Spontaneous::Model
|
4
|
+
module Box
|
5
|
+
autoload :AllowedTypes, "spontaneous/model/box/allowed_types"
|
6
|
+
|
7
|
+
extend Spontaneous::Concern
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
|
11
|
+
def inherited(subclass)
|
12
|
+
subclass.instance_variable_set(:"@mapper", mapper)
|
13
|
+
mapper.schema.inherited(self, subclass)
|
14
|
+
super
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,17 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
|
4
|
-
module Spontaneous::
|
4
|
+
module Spontaneous::Model::Core
|
5
5
|
module Aliases
|
6
|
-
extend
|
7
|
-
|
8
|
-
included do
|
9
|
-
# '__target' rather than 'target' because we want to override the behaviour of the
|
10
|
-
# Content#target method only on classes that are aliases, and this is defined dynamically
|
11
|
-
many_to_one :__target, :class => self, :key => :target_id, :reciprocal => :aliases
|
12
|
-
one_to_many :aliases, :class => self, :key => :target_id, :reciprocal => :__target
|
13
|
-
add_association_dependencies :aliases => :destroy
|
14
|
-
end
|
6
|
+
extend Spontaneous::Concern
|
15
7
|
|
16
8
|
module ClassMethods
|
17
9
|
def alias_of(*args)
|
@@ -38,10 +30,14 @@ module Spontaneous::Plugins
|
|
38
30
|
when Proc
|
39
31
|
targets.concat(source[*proc_args])
|
40
32
|
else
|
41
|
-
|
33
|
+
type = source.to_s.constantize
|
34
|
+
classes.push(type)
|
35
|
+
classes.concat(type.subclasses)
|
42
36
|
end
|
43
37
|
end
|
44
|
-
|
38
|
+
|
39
|
+
query = content_model.filter(:type_sid => classes.map { |c| c.schema_id })
|
40
|
+
|
45
41
|
if (container_procs = @alias_options[:container])
|
46
42
|
containers = [container_procs].flatten.map { |p| p[*proc_args] }.flatten
|
47
43
|
params = []
|
@@ -50,7 +46,7 @@ module Spontaneous::Plugins
|
|
50
46
|
params << Sequel::SQL::BooleanExpression.new(:'=', :page_id, container.id)
|
51
47
|
else
|
52
48
|
box_params = [
|
53
|
-
[:box_sid, container.
|
49
|
+
[:box_sid, container.schema_id],
|
54
50
|
[:owner_id, container.owner.id]
|
55
51
|
]
|
56
52
|
params << Sequel::SQL::BooleanExpression.from_value_pairs(box_params, :AND)
|
@@ -174,7 +170,7 @@ module Spontaneous::Plugins
|
|
174
170
|
|
175
171
|
def exported_target(user = nil)
|
176
172
|
case target
|
177
|
-
when
|
173
|
+
when Spontaneous::Content
|
178
174
|
target.shallow_export(user)
|
179
175
|
else
|
180
176
|
target.to_json
|
@@ -1,12 +1,17 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
module Spontaneous::
|
3
|
+
module Spontaneous::Model::Core
|
4
4
|
module Entries
|
5
|
-
extend
|
5
|
+
extend Spontaneous::Concern
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
# before_include do
|
8
|
+
# puts "owner= defined?"
|
9
|
+
# p method_defined?(:owner=)
|
10
|
+
# end
|
11
|
+
|
12
|
+
# included do
|
13
|
+
# # alias_method :<<, :push
|
14
|
+
# end
|
10
15
|
#
|
11
16
|
# def self.configure(base)
|
12
17
|
# base.__send__(:alias_method, :<<, :push)
|
@@ -29,6 +34,10 @@ module Spontaneous::Plugins
|
|
29
34
|
super
|
30
35
|
end
|
31
36
|
|
37
|
+
def depth
|
38
|
+
super || 0
|
39
|
+
end
|
40
|
+
|
32
41
|
def after_save
|
33
42
|
contents.each do |entry|
|
34
43
|
entry.save if entry.modified?
|
@@ -71,7 +80,7 @@ module Spontaneous::Plugins
|
|
71
80
|
end
|
72
81
|
|
73
82
|
def contents
|
74
|
-
return visible_contents if
|
83
|
+
return visible_contents if model.visible_only?
|
75
84
|
all_contents
|
76
85
|
end
|
77
86
|
|
@@ -106,6 +115,8 @@ module Spontaneous::Plugins
|
|
106
115
|
insert(-1, page_or_piece)
|
107
116
|
end
|
108
117
|
|
118
|
+
alias_method :<<, :push
|
119
|
+
|
109
120
|
def insert(index, page_or_piece, box)
|
110
121
|
save if new?
|
111
122
|
if page_or_piece.page?
|
@@ -135,7 +146,7 @@ module Spontaneous::Plugins
|
|
135
146
|
end
|
136
147
|
|
137
148
|
def insert_with_style(type, index, content, box)
|
138
|
-
self.
|
149
|
+
self.pieces << content
|
139
150
|
entry_style = style_for_content(content, box)
|
140
151
|
content.box_sid = box.schema_id if box
|
141
152
|
content._prototype = box.prototype_for_content(content) if box
|
@@ -195,6 +206,7 @@ module Spontaneous::Plugins
|
|
195
206
|
content.class.styles
|
196
207
|
end
|
197
208
|
|
209
|
+
|
198
210
|
def owner=(owner)
|
199
211
|
super
|
200
212
|
set_visibility_path
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
module Spontaneous::
|
3
|
+
module Spontaneous::Model::Core
|
4
4
|
module Entry
|
5
|
-
extend
|
5
|
+
extend Spontaneous::Concern
|
6
6
|
|
7
7
|
# InstanceMethods
|
8
8
|
|
@@ -13,7 +13,7 @@ module Spontaneous::Plugins
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def box_sid
|
16
|
-
@box_sid ||=
|
16
|
+
@box_sid ||= mapper.schema_uid(self[:box_sid])
|
17
17
|
end
|
18
18
|
|
19
19
|
def box_sid=(sid)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
module Spontaneous::
|
3
|
+
module Spontaneous::Model::Core
|
4
4
|
module Fields
|
5
|
-
extend
|
5
|
+
extend Spontaneous::Concern
|
6
6
|
|
7
7
|
module ClassMethods
|
8
8
|
def field(name, type=nil, options={}, &block)
|
@@ -81,7 +81,7 @@ module Spontaneous::Plugins
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def field_versions(field)
|
84
|
-
Spontaneous::FieldVersion.filter(:content_id => self.id, :field_sid => field.schema_id.to_s).order(:created_at.desc)
|
84
|
+
Spontaneous::Field::FieldVersion.filter(:content_id => self.id, :field_sid => field.schema_id.to_s).order(:created_at.desc)
|
85
85
|
end
|
86
86
|
|
87
87
|
def save_field_versions
|
@@ -108,8 +108,41 @@ module Spontaneous::Plugins
|
|
108
108
|
end
|
109
109
|
|
110
110
|
# TODO: unify the update mechanism for these two stores
|
111
|
-
def field_modified!(modified_field)
|
112
|
-
|
111
|
+
def field_modified!(modified_field = nil)
|
112
|
+
serialize_fields
|
113
|
+
end
|
114
|
+
|
115
|
+
def serialize_fields(fields = nil)
|
116
|
+
self.field_store = update_serialized_fields(fields)
|
117
|
+
end
|
118
|
+
|
119
|
+
def update_serialized_fields(fields = nil)
|
120
|
+
if fields.nil?
|
121
|
+
@field_set.serialize_db
|
122
|
+
else
|
123
|
+
field_store = (self.field_store || []).dup
|
124
|
+
fields.each do |field|
|
125
|
+
before_save_field(field)
|
126
|
+
schema_id = field.schema_id.to_s
|
127
|
+
if (index = field_store.index { |f| f[0] == schema_id })
|
128
|
+
field_store[index.to_i] = field.serialize_db
|
129
|
+
else
|
130
|
+
field_store << field.serialize_db
|
131
|
+
end
|
132
|
+
end
|
133
|
+
field_store
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def before_save_field(field)
|
138
|
+
end
|
139
|
+
|
140
|
+
# Re-serializes the field store.
|
141
|
+
#
|
142
|
+
# If fields is given then only the fields included in it will be written
|
143
|
+
def save_fields(fields = nil)
|
144
|
+
serialize_fields(fields)
|
145
|
+
save
|
113
146
|
end
|
114
147
|
|
115
148
|
def type_for_mime_type(mime_type)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
module Spontaneous::
|
3
|
+
module Spontaneous::Model::Core
|
4
4
|
module Media
|
5
|
-
extend
|
5
|
+
extend Spontaneous::Concern
|
6
6
|
|
7
7
|
# InstanceMethods
|
8
8
|
|
@@ -26,15 +26,5 @@ module Spontaneous::Plugins
|
|
26
26
|
def padded_revision
|
27
27
|
Spontaneous::Site.working_revision.to_s.rjust(4, "0")
|
28
28
|
end
|
29
|
-
|
30
|
-
# TODO: Is this still used? It shouldn't be
|
31
|
-
def make_media_file(src_file, filename = nil)
|
32
|
-
filename ||= File.basename(src_file)
|
33
|
-
filename = Spontaneous::Media.to_filename(filename)
|
34
|
-
media_filepath = media_filepath(filename)
|
35
|
-
FileUtils.mkdir_p(File.dirname(media_filepath))
|
36
|
-
FileUtils.cp(src_file, media_filepath)
|
37
|
-
media_filepath
|
38
|
-
end
|
39
29
|
end
|
40
30
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
module Spontaneous::
|
1
|
+
module Spontaneous::Model::Core
|
2
2
|
# Modifications is responsible for tracking changes made to Content items
|
3
3
|
module Modifications
|
4
|
-
extend
|
4
|
+
extend Spontaneous::Concern
|
5
5
|
|
6
6
|
class SlugModification
|
7
7
|
def self.type
|
@@ -27,7 +27,7 @@ module Spontaneous::Plugins
|
|
27
27
|
|
28
28
|
def dataset
|
29
29
|
path_like = :ancestor_path.like("#{owner[:ancestor_path]}.#{owner.id}%")
|
30
|
-
|
30
|
+
owner.content_model.filter(path_like)
|
31
31
|
end
|
32
32
|
|
33
33
|
def count
|
@@ -70,14 +70,14 @@ module Spontaneous::Plugins
|
|
70
70
|
|
71
71
|
def apply(revision)
|
72
72
|
owner.with_revision(revision) do
|
73
|
-
published =
|
73
|
+
published = owner.content_model.get(owner.id)
|
74
74
|
published.set_visible_with_cascade!(!new_value)
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
78
|
def dataset
|
79
79
|
path_like = :visibility_path.like("#{owner[:visibility_path]}.#{owner.id}%")
|
80
|
-
|
80
|
+
owner.content_model::Page.filter(path_like)
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
@@ -116,6 +116,7 @@ module Spontaneous::Plugins
|
|
116
116
|
# This is to correctly map changes to a list of pages to publish. In the case of a page
|
117
117
|
# addition the change is owned by the new page.
|
118
118
|
self.modified_at = Time.now unless @__ignore_page_modification or changed_columns.empty?
|
119
|
+
@__ignore_page_modification = false
|
119
120
|
# marks this object as the modified object appending modifications to the list
|
120
121
|
# needed in order to know if changes to the modification list will be saved automatically
|
121
122
|
# or if we need an explicit call to #save
|
@@ -150,7 +151,7 @@ module Spontaneous::Plugins
|
|
150
151
|
|
151
152
|
def create_deletion_modifications
|
152
153
|
if @child_page_deletion_count && @child_page_deletion_count > 0
|
153
|
-
count =
|
154
|
+
count = content_model::Page.count
|
154
155
|
append_modification DeletionModification.new(self, current_editor, Time.now, count + @child_page_deletion_count, count)
|
155
156
|
end
|
156
157
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Spontaneous::Model::Core
|
4
|
+
module PageSearch
|
5
|
+
extend Spontaneous::Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
# An uncached test for the existance of a site home/root page.
|
9
|
+
def has_root?
|
10
|
+
content_model.filter(:path => Spontaneous::SLASH).count > 0
|
11
|
+
end
|
12
|
+
|
13
|
+
def root
|
14
|
+
path(Spontaneous::SLASH)
|
15
|
+
end
|
16
|
+
|
17
|
+
def uid(uid)
|
18
|
+
first_visible("uid:#{uid}", :uid => uid)
|
19
|
+
end
|
20
|
+
|
21
|
+
def path(path)
|
22
|
+
first_visible("path:#{path}", :path => path)
|
23
|
+
end
|
24
|
+
|
25
|
+
def first_visible(cache_key, params)
|
26
|
+
mapper.with_cache(cache_key) {
|
27
|
+
page = content_model.first(params)
|
28
|
+
# don't want to return nil if a page matching the params exists but is hidden
|
29
|
+
# if we return blank we force searches via other routes (such as aliased pages)
|
30
|
+
return false if page and mapper.visible_only? and page.hidden?
|
31
|
+
page
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end # ClassMethods
|
35
|
+
end
|
36
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
module Spontaneous::
|
3
|
+
module Spontaneous::Model::Core
|
4
4
|
module Permissions
|
5
|
-
extend
|
5
|
+
extend Spontaneous::Concern
|
6
6
|
|
7
7
|
module ClassMethods
|
8
8
|
def box_readable?(user, box_name)
|
@@ -21,7 +21,7 @@ module Spontaneous::Plugins
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def field_permission(user, field_name, test)
|
24
|
-
return true unless user
|
24
|
+
return true unless user
|
25
25
|
if field = field_prototypes[field_name.to_sym]
|
26
26
|
user.level >= field.__send__(test)
|
27
27
|
else
|
@@ -30,7 +30,7 @@ module Spontaneous::Plugins
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def box_permission(user, box_name, test)
|
33
|
-
return true unless user
|
33
|
+
return true unless user
|
34
34
|
if box = boxes[box_name.to_sym]
|
35
35
|
user.level >= box.__send__(test)
|
36
36
|
else
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
module Spontaneous::
|
3
|
+
module Spontaneous::Model::Core
|
4
4
|
module Prototypes
|
5
|
-
extend
|
5
|
+
extend Spontaneous::Concern
|
6
6
|
|
7
7
|
DEFAULT_PROTOTYPE_NAME = :__default_prototype unless defined?(DEFAULT_PROTOTYPE_NAME)
|
8
8
|
|
@@ -47,7 +47,7 @@ module Spontaneous::Plugins
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def prototype_method_name(name)
|
50
|
-
return Spontaneous::
|
50
|
+
return Spontaneous::Model::Core::Prototypes::DEFAULT_PROTOTYPE_NAME if name.blank?
|
51
51
|
"_apply_prototype_#{name}"
|
52
52
|
end
|
53
53
|
end # ClassMethods
|
@@ -60,7 +60,7 @@ module Spontaneous::Plugins
|
|
60
60
|
end
|
61
61
|
|
62
62
|
# Add in an empty default prototype method for subclasses to override
|
63
|
-
define_method(Spontaneous::
|
63
|
+
define_method(Spontaneous::Model::Core::Prototypes::DEFAULT_PROTOTYPE_NAME) { |instance| }
|
64
64
|
|
65
65
|
protected
|
66
66
|
|