spontaneous 0.2.0.beta5 → 0.2.0.beta6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +39 -0
- data/Gemfile +2 -0
- data/Readme.markdown +4 -4
- data/application/css/core.css.scss +144 -43
- data/application/css/definitions.css.scss +50 -16
- data/application/css/dialogue.css.scss +5 -2
- data/application/css/editing.css.scss +7 -7
- data/application/css/font.css.scss +1 -1
- data/application/css/meta.css.scss +6 -6
- data/application/css/popover.css.scss +6 -6
- data/application/css/top.css.scss +8 -1
- data/application/js/add_alias_dialogue.js +137 -36
- data/application/js/add_home_dialogue.js +10 -10
- data/application/js/ajax.js +26 -26
- data/application/js/authentication.js +2 -2
- data/application/js/box.js +21 -10
- data/application/js/box_container.js +13 -7
- data/application/js/compatibility.js +19 -17
- data/application/js/conflicted_field_dialogue.js +5 -5
- data/application/js/content.js +22 -16
- data/application/js/content_area.js +62 -33
- data/application/js/dialogue.js +16 -16
- data/application/js/dom.js +9 -10
- data/application/js/edit_panel.js +25 -20
- data/application/js/editing.js +21 -8
- data/application/js/entry.js +1 -1
- data/application/js/extensions.js +11 -11
- data/application/js/field/boolean.js +6 -6
- data/application/js/field/date.js +1 -1
- data/application/js/field/file.js +17 -17
- data/application/js/field/image.js +27 -27
- data/application/js/field/markdown.js +72 -71
- data/application/js/field/select.js +9 -9
- data/application/js/field/string.js +3 -3
- data/application/js/field/webvideo.js +2 -2
- data/application/js/field_preview.js +3 -0
- data/application/js/init.js +3 -2
- data/application/js/jquery-selection-position.js +13 -13
- data/application/js/location.js +17 -12
- data/application/js/login.js +2 -2
- data/application/js/meta_view/user_admin.js +101 -101
- data/application/js/metadata.js +1 -1
- data/application/js/page.js +2 -2
- data/application/js/page_browser.js +13 -13
- data/application/js/page_entry.js +1 -1
- data/application/js/panel/root_menu.js +10 -10
- data/application/js/popover.js +6 -5
- data/application/js/popover_view.js +5 -5
- data/application/js/preview.js +10 -4
- data/application/js/progress.js +6 -6
- data/application/js/properties.js +35 -6
- data/application/js/publish.js +43 -43
- data/application/js/require.js +14 -14
- data/application/js/services.js +3 -3
- data/application/js/sharded_upload.js +9 -8
- data/application/js/side_bar.js +5 -5
- data/application/js/state.js +2 -2
- data/application/js/status_bar.js +6 -6
- data/application/js/top_bar.js +97 -65
- data/application/js/types.js +9 -6
- data/application/js/upload.js +4 -4
- data/application/js/upload_manager.js +21 -21
- data/application/js/user.js +1 -1
- data/application/js/vendor/jquery.velocity.min.js +7 -0
- data/application/js/views.js +32 -8
- data/application/js/views/box_view.js +51 -31
- data/application/js/views/page_piece_view.js +17 -15
- data/application/js/views/page_view.js +54 -43
- data/application/js/views/piece_view.js +44 -37
- data/application/static/font/fontawesome-webfont-4f0022f25672c7f501c339cbf98d9117.ttf +0 -0
- data/application/views/index.erb +1 -0
- data/db/migrations/20130114120000_create_revision_tables.rb +2 -1
- data/db/migrations/20130813111009_increase_path_length.rb +11 -2
- data/db/migrations/20140506171823_add_index_to_target_id.rb +11 -0
- data/db/migrations/20140514090204_add_content_hash.rb +59 -0
- data/db/migrations/20140519150253_add_content_hash_timestamp.rb +20 -0
- data/lib/spontaneous.rb +0 -1
- data/lib/spontaneous/asset/environment.rb +77 -15
- data/lib/spontaneous/box.rb +21 -0
- data/lib/spontaneous/capistrano/deploy.rb +1 -1
- data/lib/spontaneous/capistrano/sync.rb +8 -7
- data/lib/spontaneous/change.rb +4 -2
- data/lib/spontaneous/cli/fields.rb +7 -3
- data/lib/spontaneous/cli/generate.rb +2 -0
- data/lib/spontaneous/cli/init.rb +24 -93
- data/lib/spontaneous/cli/init/db.rb +94 -0
- data/lib/spontaneous/cli/init/mysql.rb +17 -0
- data/lib/spontaneous/cli/init/postgresql.rb +33 -0
- data/lib/spontaneous/cli/init/sqlite.rb +14 -0
- data/lib/spontaneous/cli/site.rb +45 -20
- data/lib/spontaneous/collections/box_set.rb +3 -0
- data/lib/spontaneous/collections/entry_set.rb +43 -4
- data/lib/spontaneous/collections/field_set.rb +14 -2
- data/lib/spontaneous/data_mapper.rb +40 -7
- data/lib/spontaneous/data_mapper/content_model.rb +1 -1
- data/lib/spontaneous/data_mapper/content_model/associations.rb +63 -12
- data/lib/spontaneous/data_mapper/content_model/timestamps.rb +9 -14
- data/lib/spontaneous/data_mapper/content_table.rb +4 -2
- data/lib/spontaneous/data_mapper/dataset.rb +31 -2
- data/lib/spontaneous/data_mapper/scope.rb +37 -20
- data/lib/spontaneous/errors.rb +6 -0
- data/lib/spontaneous/facet.rb +20 -10
- data/lib/spontaneous/field/base.rb +8 -1
- data/lib/spontaneous/field/file.rb +28 -3
- data/lib/spontaneous/field/image.rb +2 -0
- data/lib/spontaneous/field/update.rb +6 -0
- data/lib/spontaneous/field/webvideo/vimeo.rb +6 -1
- data/lib/spontaneous/field/webvideo/vine.rb +1 -1
- data/lib/spontaneous/field/webvideo/youtube.rb +1 -1
- data/lib/spontaneous/generators/site.rb +6 -4
- data/lib/spontaneous/generators/site/.gitignore +1 -0
- data/lib/spontaneous/generators/site/Gemfile.tt +3 -3
- data/lib/spontaneous/generators/site/config/{indexes.rb.tt → initializers/indexes.rb.tt} +0 -0
- data/lib/spontaneous/generators/site/config/initializers/publishing.rb.tt +78 -0
- data/lib/spontaneous/generators/site/{config/database.yml.tt → db/mysql2.yml.tt} +7 -6
- data/lib/spontaneous/generators/site/db/postgres.yml.tt +25 -0
- data/lib/spontaneous/generators/site/db/sqlite3.yml.tt +18 -0
- data/lib/spontaneous/generators/site/public/humans.txt.tt +14 -0
- data/lib/spontaneous/generators/site/templates/layouts/standard.html.cut.tt +51 -0
- data/lib/spontaneous/loader.rb +1 -1
- data/lib/spontaneous/logger.rb +1 -1
- data/lib/spontaneous/media/image/optimizer.rb +1 -1
- data/lib/spontaneous/media/image/processor.rb +11 -2
- data/lib/spontaneous/media/image/renderable.rb +2 -0
- data/lib/spontaneous/model.rb +3 -0
- data/lib/spontaneous/model/box/allowed_types.rb +17 -4
- data/lib/spontaneous/model/core.rb +36 -3
- data/lib/spontaneous/model/core/aliases.rb +5 -2
- data/lib/spontaneous/model/core/boxes.rb +6 -0
- data/lib/spontaneous/model/core/cascading_change.rb +38 -0
- data/lib/spontaneous/model/core/content_hash.rb +171 -0
- data/lib/spontaneous/model/core/entries.rb +0 -19
- data/lib/spontaneous/model/core/fields.rb +11 -0
- data/lib/spontaneous/model/core/modifications.rb +22 -21
- data/lib/spontaneous/model/core/render.rb +3 -0
- data/lib/spontaneous/model/core/serialisation.rb +18 -17
- data/lib/spontaneous/model/page.rb +35 -8
- data/lib/spontaneous/model/page/page_tree.rb +20 -8
- data/lib/spontaneous/model/page/paths.rb +79 -50
- data/lib/spontaneous/model/page/singleton.rb +71 -0
- data/lib/spontaneous/model/page/site_map.rb +2 -1
- data/lib/spontaneous/model/page/site_timestamps.rb +2 -2
- data/lib/spontaneous/model/piece.rb +10 -0
- data/lib/spontaneous/output/context.rb +13 -6
- data/lib/spontaneous/output/format.rb +30 -5
- data/lib/spontaneous/output/helpers/script_helper.rb +8 -0
- data/lib/spontaneous/output/helpers/stylesheet_helper.rb +7 -0
- data/lib/spontaneous/output/renderable.rb +16 -0
- data/lib/spontaneous/output/store.rb +1 -1
- data/lib/spontaneous/output/template/renderer.rb +2 -2
- data/lib/spontaneous/page_piece.rb +25 -1
- data/lib/spontaneous/prototypes/box_prototype.rb +13 -0
- data/lib/spontaneous/prototypes/field_prototype.rb +7 -4
- data/lib/spontaneous/publishing.rb +10 -5
- data/lib/spontaneous/publishing/immediate.rb +32 -349
- data/lib/spontaneous/publishing/pipeline.rb +43 -0
- data/lib/spontaneous/publishing/progress.rb +186 -0
- data/lib/spontaneous/publishing/publish.rb +107 -0
- data/lib/spontaneous/publishing/rerender.rb +17 -0
- data/lib/spontaneous/publishing/revision.rb +53 -18
- data/lib/spontaneous/publishing/simultaneous.rb +1 -1
- data/lib/spontaneous/publishing/steps.rb +154 -0
- data/lib/spontaneous/publishing/steps/activate_revision.rb +45 -0
- data/lib/spontaneous/publishing/steps/archive_old_revisions.rb +22 -0
- data/lib/spontaneous/publishing/steps/base_step.rb +49 -0
- data/lib/spontaneous/publishing/steps/copy_static_files.rb +74 -0
- data/lib/spontaneous/publishing/steps/create_revision_directory.rb +24 -0
- data/lib/spontaneous/publishing/steps/generate_rackup_file.rb +51 -0
- data/lib/spontaneous/publishing/steps/generate_search_indexes.rb +24 -0
- data/lib/spontaneous/publishing/steps/render_revision.rb +69 -0
- data/lib/spontaneous/publishing/steps/write_revision_file.rb +43 -0
- data/lib/spontaneous/rack/back.rb +3 -1
- data/lib/spontaneous/rack/back/alias.rb +9 -8
- data/lib/spontaneous/rack/front.rb +1 -1
- data/lib/spontaneous/rack/middleware.rb +7 -4
- data/lib/spontaneous/rack/middleware/transaction.rb +14 -0
- data/lib/spontaneous/rack/page_controller.rb +23 -8
- data/lib/spontaneous/revision.rb +5 -10
- data/lib/spontaneous/schema.rb +5 -0
- data/lib/spontaneous/server.rb +3 -1
- data/lib/spontaneous/site.rb +17 -10
- data/lib/spontaneous/site/publishing.rb +25 -3
- data/lib/spontaneous/site/state.rb +7 -3
- data/lib/spontaneous/tasks/database.rake +5 -10
- data/lib/spontaneous/utils/database/mysql_dumper.rb +5 -1
- data/lib/spontaneous/version.rb +1 -1
- data/spontaneous.gemspec +4 -3
- data/test/fixtures/example_application/config/initializers/initializer1.rb +1 -0
- data/test/fixtures/example_application/config/initializers/initializer2.rb +1 -0
- data/test/fixtures/example_application/config/initializers/publishing.rb +13 -0
- data/test/fixtures/search/config/{indexes.rb → initializers/indexes.rb} +0 -0
- data/test/fixtures/serialisation/root_hash.yaml.erb +10 -4
- data/test/functional/test_application.rb +10 -0
- data/test/functional/test_back.rb +23 -5
- data/test/functional/test_cli.rb +98 -34
- data/test/functional/test_front.rb +7 -3
- data/test/test_helper.rb +35 -28
- data/test/unit/test_alias.rb +20 -3
- data/test/unit/test_assets.rb +58 -30
- data/test/unit/test_changesets.rb +20 -12
- data/test/unit/test_content_hash.rb +496 -0
- data/test/unit/test_context.rb +28 -1
- data/test/unit/test_controllers.rb +96 -61
- data/test/unit/test_crypt.rb +1 -8
- data/test/unit/test_datamapper.rb +95 -19
- data/test/unit/test_features.rb +1 -4
- data/test/unit/test_fields.rb +61 -12
- data/test/unit/test_generators.rb +39 -2
- data/test/unit/test_images.rb +3 -1
- data/test/unit/test_modifications.rb +224 -219
- data/test/unit/test_output_store.rb +10 -0
- data/test/unit/{test_formats.rb → test_outputs.rb} +75 -6
- data/test/unit/test_page.rb +61 -15
- data/test/unit/test_plugins.rb +2 -42
- data/test/unit/test_publishing_pipeline.rb +1050 -0
- data/test/unit/test_render.rb +30 -0
- data/test/unit/test_revisions.rb +110 -2
- data/test/unit/test_schema.rb +4 -0
- data/test/unit/test_search.rb +1 -1
- data/test/unit/test_serialisation.rb +6 -1
- data/test/unit/test_singletons.rb +159 -0
- data/test/unit/test_site.rb +71 -44
- metadata +140 -86
- data/application/static/font/fontawesome-webfont-1c66a4738b40ef0f6b1abca0ba9a796d.ttf +0 -0
- data/test/unit/test_publishing.rb +0 -330
@@ -4,22 +4,6 @@ module Spontaneous::Model::Core
|
|
4
4
|
module Entries
|
5
5
|
extend Spontaneous::Concern
|
6
6
|
|
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
|
15
|
-
#
|
16
|
-
# def self.configure(base)
|
17
|
-
# base.__send__(:alias_method, :<<, :push)
|
18
|
-
# end
|
19
|
-
|
20
|
-
# InstanceMethods
|
21
|
-
|
22
|
-
|
23
7
|
# because it's possible to build content out of order
|
24
8
|
# some relations don't necessarily get created straight away
|
25
9
|
def before_save
|
@@ -73,9 +57,6 @@ module Spontaneous::Model::Core
|
|
73
57
|
end
|
74
58
|
|
75
59
|
def entry_modified!(modified_entry)
|
76
|
-
# See plugins/modifications.rb for details of __ignore_page_modification ... basically
|
77
|
-
# it stops the parent page appearing in the publishing list when a new page is added.
|
78
|
-
@__ignore_page_modification = modified_entry && modified_entry.added? && modified_entry.page?
|
79
60
|
self.entry_store = all_contents.serialize_db
|
80
61
|
end
|
81
62
|
|
@@ -73,6 +73,11 @@ module Spontaneous::Model::Core
|
|
73
73
|
|
74
74
|
# InstanceMethods
|
75
75
|
|
76
|
+
def before_create
|
77
|
+
serialize_fields(fields.with_dynamic_default_values)
|
78
|
+
super
|
79
|
+
end
|
80
|
+
|
76
81
|
def after_save
|
77
82
|
super
|
78
83
|
fields.saved
|
@@ -106,6 +111,12 @@ module Spontaneous::Model::Core
|
|
106
111
|
@field_set ||= Spontaneous::Collections::FieldSet.new(self, field_store)
|
107
112
|
end
|
108
113
|
|
114
|
+
# Used by #content_hash to attempt to preserve content hashes across
|
115
|
+
# schema changes
|
116
|
+
def fields_with_consistent_order
|
117
|
+
fields.sort { |f1, f2| f1.schema_id <=> f2.schema_id }
|
118
|
+
end
|
119
|
+
|
109
120
|
def field?(field_name)
|
110
121
|
self.class.field?(field_name)
|
111
122
|
end
|
@@ -110,13 +110,6 @@ module Spontaneous::Model::Core
|
|
110
110
|
end
|
111
111
|
|
112
112
|
def before_save
|
113
|
-
# Home of many hacks.
|
114
|
-
#
|
115
|
-
# @__ignore_page_modification is set if a box has been modified by the addition of a page.
|
116
|
-
# This is to correctly map changes to a list of pages to publish. In the case of a page
|
117
|
-
# addition the change is owned by the new page.
|
118
|
-
self.modified_at = Time.now unless @__ignore_page_modification or changed_columns.empty?
|
119
|
-
@__ignore_page_modification = false
|
120
113
|
# marks this object as the modified object appending modifications to the list
|
121
114
|
# needed in order to know if changes to the modification list will be saved automatically
|
122
115
|
# or if we need an explicit call to #save
|
@@ -134,9 +127,7 @@ module Spontaneous::Model::Core
|
|
134
127
|
end
|
135
128
|
|
136
129
|
def generate_modification_list
|
137
|
-
create_slug_modifications
|
138
|
-
create_visibility_modifications
|
139
|
-
serialize_pending_modifications
|
130
|
+
serialize_pending_modifications if [create_slug_modifications, create_visibility_modifications].any? { |result| result }
|
140
131
|
end
|
141
132
|
|
142
133
|
def child_page_deleted!
|
@@ -159,28 +150,32 @@ module Spontaneous::Model::Core
|
|
159
150
|
def create_visibility_modifications
|
160
151
|
# We only want to record visibility changes that originate from user action, not ones propagated
|
161
152
|
# from higher up the tree, hence the check against the hidden_origin.
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
return nil
|
167
|
-
end
|
153
|
+
return false unless changed_columns.include?(:hidden) && hidden_origin.nil?
|
154
|
+
if (previous_modification = local_modifications.detect { |mod| mod.type == :visibility })
|
155
|
+
if previous_modification.old_value == hidden?
|
156
|
+
remove_modification(:visibility)
|
168
157
|
end
|
158
|
+
else
|
169
159
|
append_modification HiddenModification.new(self, current_editor, Time.now, !hidden?, hidden)
|
170
160
|
end
|
161
|
+
true
|
171
162
|
end
|
172
163
|
|
173
164
|
def create_slug_modifications
|
174
|
-
|
165
|
+
change = changes_to_cascade[:slug]
|
166
|
+
return false if change.nil?
|
167
|
+
old_slug, new_slug = change.old_value, self[:slug]
|
168
|
+
return false if old_slug.nil? # ignore first change of slug from nil to provided or generated
|
175
169
|
if (previous_modification = local_modifications.detect { |mod| mod.type == :slug })
|
176
|
-
if previous_modification.old_value ==
|
170
|
+
if previous_modification.old_value == new_slug
|
177
171
|
remove_modification(:slug)
|
178
|
-
|
172
|
+
else
|
173
|
+
previous_modification.new_value = new_slug
|
179
174
|
end
|
180
|
-
previous_modification.new_value = self[:slug]
|
181
175
|
else
|
182
|
-
append_modification SlugModification.new(self, current_editor, Time.now, old_slug,
|
176
|
+
append_modification SlugModification.new(self, current_editor, Time.now, old_slug, new_slug)
|
183
177
|
end
|
178
|
+
true
|
184
179
|
end
|
185
180
|
|
186
181
|
def remove_modification(type)
|
@@ -192,6 +187,12 @@ module Spontaneous::Model::Core
|
|
192
187
|
end
|
193
188
|
|
194
189
|
def pending_modifications(filter_type = nil)
|
190
|
+
mods = all_pending_modifications
|
191
|
+
return mods if filter_type.nil?
|
192
|
+
mods.select { |mod| mod.type == filter_type }
|
193
|
+
end
|
194
|
+
|
195
|
+
def all_pending_modifications
|
195
196
|
(local_modifications + pieces.flat_map { |piece| piece.local_modifications })
|
196
197
|
end
|
197
198
|
|
@@ -17,5 +17,8 @@ module Spontaneous::Model::Core
|
|
17
17
|
def render_using(renderer, format = :html, params = {}, parent_context = nil)
|
18
18
|
output(format).render_using(renderer, params, parent_context)
|
19
19
|
end
|
20
|
+
|
21
|
+
alias_method :render_inline, :render
|
22
|
+
alias_method :render_inline_using, :render_using
|
20
23
|
end
|
21
24
|
end
|
@@ -7,15 +7,15 @@ module Spontaneous::Model::Core
|
|
7
7
|
module ClassMethods
|
8
8
|
def export(user = nil)
|
9
9
|
{
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
10
|
+
type: ui_class,
|
11
|
+
id: schema_id.to_s,
|
12
|
+
is_page: page?,
|
13
|
+
is_alias: alias?,
|
14
|
+
title: title,
|
15
|
+
fields: readable_fields(user).map { |name| field_prototypes[name].export(user) },
|
16
|
+
styles: readable_styles(user).map { |style| style.export(user) },
|
17
|
+
boxes: readable_boxes(user).map { |box| box.export(user) },
|
18
|
+
source: __source_file
|
19
19
|
}
|
20
20
|
end
|
21
21
|
|
@@ -40,14 +40,15 @@ module Spontaneous::Model::Core
|
|
40
40
|
# InstanceMethods
|
41
41
|
|
42
42
|
def shallow_export(user)
|
43
|
-
{ :
|
44
|
-
:
|
45
|
-
:
|
46
|
-
:
|
47
|
-
:
|
48
|
-
:
|
49
|
-
:
|
50
|
-
:
|
43
|
+
{ id: id,
|
44
|
+
type: model.ui_class,
|
45
|
+
type_id: model.schema_id.to_s,
|
46
|
+
is_page: page?,
|
47
|
+
page_id: page_id || id,
|
48
|
+
hidden: (hidden? ? true : false),
|
49
|
+
depth: content_depth,
|
50
|
+
fields: fields.export(user),
|
51
|
+
label: label }
|
51
52
|
end
|
52
53
|
|
53
54
|
def export(user = nil)
|
@@ -8,6 +8,7 @@ require "spontaneous/model/page/page_tree"
|
|
8
8
|
require "spontaneous/model/page/paths"
|
9
9
|
require "spontaneous/model/page/site_map"
|
10
10
|
require "spontaneous/model/page/site_timestamps"
|
11
|
+
require "spontaneous/model/page/singleton"
|
11
12
|
|
12
13
|
module Spontaneous::Model
|
13
14
|
module Page
|
@@ -22,6 +23,8 @@ module Spontaneous::Model
|
|
22
23
|
include SiteMap
|
23
24
|
include SiteTimestamps
|
24
25
|
include Locks
|
26
|
+
include Singleton
|
27
|
+
include Spontaneous::Model::Core::ContentHash::PageMethods
|
25
28
|
|
26
29
|
included do
|
27
30
|
many_to_one_content :parent, :key => :parent_id, :reciprocal => :unordered_children
|
@@ -37,12 +40,22 @@ module Spontaneous::Model
|
|
37
40
|
end
|
38
41
|
|
39
42
|
def export(user = nil)
|
40
|
-
super(user).merge(:
|
43
|
+
super(user).merge(title_field: self.title_field_name.to_s)
|
41
44
|
end
|
42
45
|
|
43
|
-
def
|
46
|
+
def title_field_name
|
44
47
|
:title
|
45
48
|
end
|
49
|
+
|
50
|
+
# Use this to cause instances of the class to render as another content object.
|
51
|
+
# Useful if you want say a section to render its first child rather than itself
|
52
|
+
# This method calls #to_page on the result of the block to ensure that the value
|
53
|
+
# returned is a page & not an inline object.
|
54
|
+
def renders(&block)
|
55
|
+
define_method(:renderable) do
|
56
|
+
instance_eval(&block).try(:to_page)
|
57
|
+
end
|
58
|
+
end
|
46
59
|
end
|
47
60
|
|
48
61
|
def page?
|
@@ -60,8 +73,9 @@ module Spontaneous::Model
|
|
60
73
|
end
|
61
74
|
end
|
62
75
|
|
63
|
-
def children
|
64
|
-
@ordered_children
|
76
|
+
def children(reload = false)
|
77
|
+
@ordered_children = nil if reload
|
78
|
+
@ordered_children ||= generate_ordered_children(unordered_children(reload: reload))
|
65
79
|
end
|
66
80
|
|
67
81
|
def generate_ordered_children(unordered_children)
|
@@ -106,7 +120,7 @@ module Spontaneous::Model
|
|
106
120
|
end
|
107
121
|
|
108
122
|
def resolve_entry
|
109
|
-
owner.all_contents.
|
123
|
+
owner.all_contents.wrap_page(self)
|
110
124
|
end
|
111
125
|
|
112
126
|
def page=(page)
|
@@ -117,13 +131,13 @@ module Spontaneous::Model
|
|
117
131
|
end
|
118
132
|
|
119
133
|
def page_title
|
120
|
-
if field = self.fields[
|
134
|
+
if field = self.fields[title_field_name]
|
121
135
|
field.value
|
122
136
|
end
|
123
137
|
end
|
124
138
|
|
125
|
-
def
|
126
|
-
self.class.
|
139
|
+
def title_field_name
|
140
|
+
self.class.title_field_name
|
127
141
|
end
|
128
142
|
|
129
143
|
def shallow_export(user)
|
@@ -131,6 +145,7 @@ module Spontaneous::Model
|
|
131
145
|
:path => path,
|
132
146
|
:title => page_title,
|
133
147
|
:slug => slug,
|
148
|
+
:private => in_private_tree?,
|
134
149
|
:uid => uid
|
135
150
|
})
|
136
151
|
hash.delete(:label)
|
@@ -151,5 +166,17 @@ module Spontaneous::Model
|
|
151
166
|
def eql?(obj)
|
152
167
|
super || (Spontaneous::PagePiece === obj && obj.target.eql?(self))
|
153
168
|
end
|
169
|
+
|
170
|
+
# Ensure that the *_inline versions of these methods render the entry
|
171
|
+
# (i.e. a PagePiece) not the page instance itself. This avoids a
|
172
|
+
# 'page within page' moment when you try to load a page and then
|
173
|
+
# render it directly within a template.
|
174
|
+
def render_inline(format = :html, params = {}, parent_context = nil)
|
175
|
+
entry.render_inline(format, params, parent_context)
|
176
|
+
end
|
177
|
+
|
178
|
+
def render_inline_using(renderer, format = :html, params = {}, parent_context = nil)
|
179
|
+
entry.render_inline_using(renderer, format, params, parent_context)
|
180
|
+
end
|
154
181
|
end
|
155
182
|
end
|
@@ -15,10 +15,21 @@ module Spontaneous::Model::Page
|
|
15
15
|
end
|
16
16
|
|
17
17
|
# Returns a list of all the pages at a certain depth in the page tree for any page
|
18
|
+
# In the case of pages rooted in a private tree the calculation is done starting from
|
19
|
+
# the public root rather than the root of the tree the page belongs to
|
18
20
|
def at_depth(depth, opts = {})
|
19
|
-
return root_at_depth(depth) if
|
21
|
+
return root_at_depth(depth) if is_public_root? || is_private_root?
|
20
22
|
parent_depth = [0, depth - 1].max
|
21
|
-
parent
|
23
|
+
parent = if (parent_depth == 0)
|
24
|
+
public_root
|
25
|
+
else
|
26
|
+
ancestor(parent_depth)
|
27
|
+
end
|
28
|
+
|
29
|
+
# in the case of page aliases & private roots it's possible for a template
|
30
|
+
# to ask for an ancestor that doesn't exist.
|
31
|
+
return [] if parent.nil?
|
32
|
+
|
22
33
|
# This is made more complex because the #children method is unordered
|
23
34
|
# whereas the actual page order must come from the boxes
|
24
35
|
return parent.children if parent.boxes.empty?
|
@@ -69,11 +80,12 @@ module Spontaneous::Model::Page
|
|
69
80
|
end
|
70
81
|
|
71
82
|
def root_at_depth(depth)
|
83
|
+
root = public_root
|
72
84
|
case depth
|
73
85
|
when 0
|
74
|
-
|
86
|
+
root
|
75
87
|
when 1
|
76
|
-
|
88
|
+
root.children
|
77
89
|
else
|
78
90
|
raise ArgumentError.new("Cannot calculate descendents of root beyond a depth of 1")
|
79
91
|
end
|
@@ -87,12 +99,12 @@ module Spontaneous::Model::Page
|
|
87
99
|
page.id == self.id or ancestor?(page)
|
88
100
|
end
|
89
101
|
|
90
|
-
def generation
|
91
|
-
parent ? parent.children : [root].compact
|
102
|
+
def generation(reload = false)
|
103
|
+
parent ? parent.children(reload) : [root].compact
|
92
104
|
end
|
93
105
|
|
94
|
-
def siblings
|
95
|
-
generation.reject { |p| p.id == id }
|
106
|
+
def siblings(reload = false)
|
107
|
+
generation(reload).reject { |p| p.id == id }
|
96
108
|
end
|
97
109
|
|
98
110
|
def >(page)
|
@@ -13,24 +13,22 @@ module Spontaneous::Model::Page
|
|
13
13
|
/^page-\d{8}-\d{6}$/ === slug
|
14
14
|
end
|
15
15
|
|
16
|
-
def create_root(slug)
|
17
|
-
create(slug: slug, :
|
16
|
+
def create_root(slug, values = {})
|
17
|
+
create(values.merge(slug: slug, :__create_private_root => true))
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
# InstanceMethods
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
def __create_hidden_root=(state)
|
26
|
-
@__is_hidden_root = state
|
23
|
+
def __create_private_root=(state)
|
24
|
+
@__is_private_root = state
|
27
25
|
end
|
28
26
|
|
29
|
-
def
|
30
|
-
@
|
27
|
+
def __create_private_root?
|
28
|
+
@__is_private_root || false
|
31
29
|
end
|
32
30
|
|
33
|
-
private :
|
31
|
+
private :__create_private_root=, :__create_private_root?
|
34
32
|
|
35
33
|
def after_initialize
|
36
34
|
super
|
@@ -39,6 +37,7 @@ module Spontaneous::Model::Page
|
|
39
37
|
|
40
38
|
def before_create
|
41
39
|
place_in_page_tree
|
40
|
+
set_slug_from_dynamic_value
|
42
41
|
super
|
43
42
|
end
|
44
43
|
|
@@ -69,29 +68,37 @@ module Spontaneous::Model::Page
|
|
69
68
|
# because otherwise the slug would always take on the title fields
|
70
69
|
# default value.
|
71
70
|
def before_save
|
72
|
-
|
73
|
-
|
74
|
-
set_slug_from_title(title)
|
75
|
-
end
|
71
|
+
if !new? && (title = fields[title_field_name])
|
72
|
+
set_slug_from_title(title)
|
76
73
|
end
|
77
74
|
fix_generated_slug_conflicts
|
78
75
|
super
|
79
76
|
end
|
80
77
|
|
78
|
+
def set_slug_from_dynamic_value
|
79
|
+
if (title = fields[title_field_name]) && title.prototype.dynamic_default?
|
80
|
+
set_slug_from_title!(title)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
81
84
|
# Syncing the slug with the title is made more difficult because the field
|
82
85
|
# update mechanism works differently from the more direct, console version.
|
83
86
|
# This is called by the field updater before re-serializing each modified field.
|
84
87
|
def before_save_field(field)
|
85
|
-
set_slug_from_title(field) if (field.name ==
|
88
|
+
set_slug_from_title(field) if (field.name == title_field_name)
|
86
89
|
super
|
87
90
|
end
|
88
91
|
|
89
92
|
def set_slug_from_title(title)
|
90
93
|
if title.modified? and !title.blank? and has_generated_slug?
|
91
|
-
|
94
|
+
set_slug_from_title!(title)
|
92
95
|
end
|
93
96
|
end
|
94
97
|
|
98
|
+
def set_slug_from_title!(title)
|
99
|
+
self.slug = title.value
|
100
|
+
end
|
101
|
+
|
95
102
|
def sync_slug_to_title
|
96
103
|
self.slug = title.unprocessed_value
|
97
104
|
end
|
@@ -100,17 +107,12 @@ module Spontaneous::Model::Page
|
|
100
107
|
self.class.is_default_slug?(slug)
|
101
108
|
end
|
102
109
|
|
103
|
-
def after_save
|
104
|
-
super
|
105
|
-
check_for_path_changes
|
106
|
-
end
|
107
|
-
|
108
110
|
def generate_default_slug
|
109
111
|
self.class.generate_default_slug
|
110
112
|
end
|
111
113
|
|
112
114
|
def is_conflicting_slug?(slug)
|
113
|
-
siblings.reject { |s| s.root? }.compact.map(&:slug).include?(slug)
|
115
|
+
siblings(true).reject { |s| s.root? }.compact.map(&:slug).include?(slug)
|
114
116
|
end
|
115
117
|
|
116
118
|
def parent=(parent)
|
@@ -121,8 +123,8 @@ module Spontaneous::Model::Page
|
|
121
123
|
|
122
124
|
def place_in_page_tree
|
123
125
|
if parent_id.nil?
|
124
|
-
if
|
125
|
-
|
126
|
+
if __create_private_root? || content_model.has_root?
|
127
|
+
make_private_root
|
126
128
|
else
|
127
129
|
make_root
|
128
130
|
end
|
@@ -137,33 +139,53 @@ module Spontaneous::Model::Page
|
|
137
139
|
self[:ancestor_path] = ""
|
138
140
|
end
|
139
141
|
|
140
|
-
def
|
142
|
+
def make_private_root
|
141
143
|
raise Spontaneous::AnonymousRootException.new if slug.blank?
|
142
144
|
self[:path] = "##{slug}"
|
143
145
|
self[:ancestor_path] = ""
|
144
146
|
end
|
145
147
|
|
146
148
|
def ancestor_path
|
147
|
-
(self[:ancestor_path] || "").split(ANCESTOR_SEP).map { |id| id.to_i }
|
149
|
+
(self[:ancestor_path] || "").split(Spontaneous::Model::ANCESTOR_SEP).map { |id| id.to_i }
|
148
150
|
end
|
149
151
|
|
150
|
-
def
|
152
|
+
def is_public_root?
|
151
153
|
path == Spontaneous::SLASH
|
152
154
|
end
|
153
155
|
|
154
|
-
alias_method :
|
156
|
+
alias_method :root?, :is_public_root?
|
157
|
+
alias_method :is_root?, :is_public_root?
|
158
|
+
|
159
|
+
# Returns the root of the tree this page belongs to, which in the case
|
160
|
+
# of pages in an private tree will not be the same as the site's
|
161
|
+
# root/home page
|
162
|
+
def tree_root
|
163
|
+
content_model::Page.get(visibility_path_ids.first)
|
164
|
+
end
|
165
|
+
|
166
|
+
def is_private_root?
|
167
|
+
return false unless parent_id.nil?
|
168
|
+
return false if root?
|
169
|
+
path[0] == '#'
|
170
|
+
end
|
171
|
+
|
172
|
+
def in_private_tree?
|
173
|
+
tree_root = self.tree_root
|
174
|
+
return is_private_root? if tree_root.nil?
|
175
|
+
tree_root.is_private_root?
|
176
|
+
end
|
155
177
|
|
156
178
|
|
157
179
|
def update_path
|
158
180
|
self.path = calculate_path
|
159
181
|
if parent
|
160
|
-
self[:ancestor_path] = parent.ancestor_path.push(parent.id).join(ANCESTOR_SEP)
|
182
|
+
self[:ancestor_path] = parent.ancestor_path.push(parent.id).join(Spontaneous::Model::ANCESTOR_SEP)
|
161
183
|
end
|
162
184
|
end
|
163
185
|
|
164
186
|
|
165
187
|
def calculate_path
|
166
|
-
calculate_path_with_slug(
|
188
|
+
calculate_path_with_slug(slug)
|
167
189
|
end
|
168
190
|
|
169
191
|
def calculate_path_with_slug(slug)
|
@@ -174,12 +196,29 @@ module Spontaneous::Model::Page
|
|
174
196
|
end
|
175
197
|
end
|
176
198
|
|
199
|
+
class SlugChange
|
200
|
+
attr_reader :old_value, :new_value
|
201
|
+
def initialize(origin, old_value, new_value)
|
202
|
+
@origin, @old_value, @new_value = origin, old_value, new_value
|
203
|
+
end
|
204
|
+
|
205
|
+
def propagate
|
206
|
+
return if @old_value == @new_value
|
207
|
+
@origin.force_path_changes
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
included do
|
212
|
+
cascading_change :slug do |origin, old_value, new_value|
|
213
|
+
SlugChange.new(origin, old_value, new_value)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
177
217
|
# slugs can be max 64 characters long
|
178
218
|
def slug=(s)
|
179
219
|
if (new_slug = fit_slug_to_length(s, 64)) != slug
|
180
|
-
|
181
|
-
|
182
|
-
self.update_path
|
220
|
+
super(new_slug)
|
221
|
+
update_path
|
183
222
|
end
|
184
223
|
end
|
185
224
|
|
@@ -195,28 +234,18 @@ module Spontaneous::Model::Page
|
|
195
234
|
|
196
235
|
protected :fit_slug_to_length
|
197
236
|
|
198
|
-
def check_for_path_changes(force = false)
|
199
|
-
if @__slug_changed || force
|
200
|
-
@__slug_changed = false
|
201
|
-
children.each do |child|
|
202
|
-
child.propagate_path_changes
|
203
|
-
end
|
204
|
-
aliases.each do |link|
|
205
|
-
link.propagate_path_changes if link.page?
|
206
|
-
end
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
237
|
def force_path_changes
|
211
|
-
|
238
|
+
children.each do |child|
|
239
|
+
child.propagate_path_changes
|
240
|
+
end
|
241
|
+
aliases.each do |link|
|
242
|
+
link.propagate_path_changes if link.page?
|
243
|
+
end
|
212
244
|
end
|
213
245
|
|
214
246
|
def propagate_path_changes
|
215
|
-
|
216
|
-
|
217
|
-
@__ignore_page_modification = true
|
218
|
-
self.update_path
|
219
|
-
self.save
|
247
|
+
update_path
|
248
|
+
save
|
220
249
|
children.each do |child|
|
221
250
|
child.propagate_path_changes
|
222
251
|
end
|