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,355 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module Spontaneous::Publishing
|
4
|
+
class Revision
|
5
|
+
class InvalidRevision < Spontaneous::Error; end
|
6
|
+
|
7
|
+
class Generator
|
8
|
+
# Both revision & source_revision should be instances of Revision
|
9
|
+
def initialize(revision)
|
10
|
+
@revision = revision
|
11
|
+
end
|
12
|
+
|
13
|
+
def run
|
14
|
+
@revision.transaction do
|
15
|
+
create
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def create
|
20
|
+
begin
|
21
|
+
create_revision
|
22
|
+
copy_indexes
|
23
|
+
sync_revision
|
24
|
+
set_revision_timestamps
|
25
|
+
set_revision_version
|
26
|
+
@revision.complete
|
27
|
+
@revision.scope do
|
28
|
+
yield if block_given?
|
29
|
+
end
|
30
|
+
set_source_timestamps
|
31
|
+
rescue ::Exception => e
|
32
|
+
@revision.delete
|
33
|
+
raise e
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
protected
|
38
|
+
|
39
|
+
def create_revision
|
40
|
+
db.run(<<-SQL)
|
41
|
+
CREATE TABLE #{db.literal(@revision.table)}
|
42
|
+
AS #{source_dataset.select_sql}
|
43
|
+
SQL
|
44
|
+
end
|
45
|
+
|
46
|
+
def source_dataset
|
47
|
+
@revision.content_dataset
|
48
|
+
end
|
49
|
+
|
50
|
+
def copy_indexes
|
51
|
+
indexes = db.indexes(@revision.content_table)
|
52
|
+
indexes.each do |name, options|
|
53
|
+
columns = options.delete(:columns)
|
54
|
+
db.add_index(@revision.table, columns, options)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def sync_revision
|
59
|
+
# To be overwritten in Patch subclass
|
60
|
+
end
|
61
|
+
|
62
|
+
def set_revision_timestamps
|
63
|
+
set_timestamps(@revision.dataset)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Update the timestamps on the :content table
|
67
|
+
#
|
68
|
+
# Only do this once we're sure the
|
69
|
+
# publish has completed successfully as they are used
|
70
|
+
# to track which pages need publishing
|
71
|
+
def set_source_timestamps
|
72
|
+
set_timestamps(@revision.content_dataset)
|
73
|
+
end
|
74
|
+
|
75
|
+
def set_timestamps(ds)
|
76
|
+
published_dataset(ds).update({
|
77
|
+
:last_published_at => Sequel.datetime_class.now
|
78
|
+
})
|
79
|
+
first_published_dataset(ds).update({
|
80
|
+
:first_published_at => Sequel.datetime_class.now,
|
81
|
+
:first_published_revision => revision
|
82
|
+
})
|
83
|
+
end
|
84
|
+
|
85
|
+
def published_dataset(ds)
|
86
|
+
ds
|
87
|
+
end
|
88
|
+
|
89
|
+
def first_published_dataset(ds)
|
90
|
+
ds.filter(:first_published_at => nil)
|
91
|
+
end
|
92
|
+
|
93
|
+
def set_revision_version
|
94
|
+
@revision.dataset.update(:revision => revision)
|
95
|
+
end
|
96
|
+
|
97
|
+
def mapper
|
98
|
+
@revision.mapper
|
99
|
+
end
|
100
|
+
|
101
|
+
def db
|
102
|
+
@revision.db
|
103
|
+
end
|
104
|
+
|
105
|
+
def revision
|
106
|
+
@revision.revision
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
class Patcher < Generator
|
111
|
+
def initialize(revision, modified)
|
112
|
+
super(revision)
|
113
|
+
# pages should be published in depth order because it's
|
114
|
+
# possible to be publishing a child of
|
115
|
+
# a page that's never been published
|
116
|
+
@modified = modified.sort { |m1, m2| m1.depth <=> m2.depth }
|
117
|
+
end
|
118
|
+
|
119
|
+
def source_dataset
|
120
|
+
@revision.previous.history_dataset
|
121
|
+
end
|
122
|
+
|
123
|
+
def sync_revision
|
124
|
+
@modified.each do |m|
|
125
|
+
m.sync_to_revision(revision, true)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def published_dataset(ds)
|
130
|
+
filter_ids(super)
|
131
|
+
end
|
132
|
+
|
133
|
+
def first_published_dataset(ds)
|
134
|
+
filter_ids(super)
|
135
|
+
end
|
136
|
+
|
137
|
+
def filter_ids(ds)
|
138
|
+
ds.filter(:id => @modified.map(&:id))
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def self.create(model, revision, &block)
|
143
|
+
new(model, revision).create(&block)
|
144
|
+
end
|
145
|
+
|
146
|
+
def self.patch(model, revision, modified, &block)
|
147
|
+
new(model, revision).patch(modified, &block)
|
148
|
+
end
|
149
|
+
|
150
|
+
def self.exists?(model, revision)
|
151
|
+
new(model, revision).table_exists?
|
152
|
+
end
|
153
|
+
|
154
|
+
def self.delete(model, revision)
|
155
|
+
return if revision.nil?
|
156
|
+
new(model, revision).delete
|
157
|
+
end
|
158
|
+
|
159
|
+
def self.delete_all(model)
|
160
|
+
revisions = tables(model).
|
161
|
+
map { |table| revision_from_table(model, table) }.
|
162
|
+
map { |r| new(model, r) }
|
163
|
+
|
164
|
+
# Don't call the full #delete because it is much more efficient
|
165
|
+
# to delete the contents of the revision tables in a single
|
166
|
+
# command rather than revision by revision
|
167
|
+
revisions.each(&:delete_table)
|
168
|
+
history_dataset(model).delete
|
169
|
+
archive_dataset(model).delete
|
170
|
+
end
|
171
|
+
|
172
|
+
def self.cleanup(model, current_revision, keep_revisions)
|
173
|
+
current = table(model, current_revision)
|
174
|
+
tables = tables(model).reject { |t| t == current }
|
175
|
+
tables.each do |table|
|
176
|
+
model.database.drop_table(table)
|
177
|
+
end
|
178
|
+
history_dataset(model) { revision <= (current_revision - keep_revisions) }.delete
|
179
|
+
end
|
180
|
+
|
181
|
+
def self.history_dataset(model, revision = nil, &block)
|
182
|
+
_filter_dataset(model.mapper.revision_history_dataset, revision, &block)
|
183
|
+
end
|
184
|
+
|
185
|
+
def self.archive_dataset(model, revision = nil, &block)
|
186
|
+
_filter_dataset(model.mapper.revision_archive_dataset, revision, &block)
|
187
|
+
end
|
188
|
+
|
189
|
+
def self._filter_dataset(ds, revision, &block)
|
190
|
+
return ds.filter(&block) if revision.nil?
|
191
|
+
ds.filter(:revision => revision, &block)
|
192
|
+
end
|
193
|
+
|
194
|
+
def self.revision_from_table(model, table)
|
195
|
+
model.mapper.revision_from_table(table)
|
196
|
+
end
|
197
|
+
|
198
|
+
def self.tables(model)
|
199
|
+
mapper = model.mapper
|
200
|
+
model.database.tables.select { |t| mapper.revision_table?(t) }.sort
|
201
|
+
end
|
202
|
+
|
203
|
+
def self.table(model, revision = nil)
|
204
|
+
new(model, revision).table
|
205
|
+
end
|
206
|
+
|
207
|
+
def self.table?(model, table)
|
208
|
+
model.mapper.revision_table?(table)
|
209
|
+
end
|
210
|
+
|
211
|
+
attr_reader :revision
|
212
|
+
|
213
|
+
def initialize(model, revision)
|
214
|
+
@model, @revision = model, revision
|
215
|
+
end
|
216
|
+
|
217
|
+
def create(&block)
|
218
|
+
validate!
|
219
|
+
generator = Generator.new(self)
|
220
|
+
generator.create(&block)
|
221
|
+
self
|
222
|
+
end
|
223
|
+
|
224
|
+
def patch(modified, &block)
|
225
|
+
return create(&block) if must_publish_all?(modified)
|
226
|
+
validate!
|
227
|
+
modified = Array(modified).map { |m|
|
228
|
+
m.is_a?(@model) ? m.reload : @model.get(m)
|
229
|
+
}
|
230
|
+
patcher = Patcher.new(self, modified)
|
231
|
+
patcher.create(&block)
|
232
|
+
self
|
233
|
+
end
|
234
|
+
|
235
|
+
def must_publish_all?(modified)
|
236
|
+
Array(modified).empty? || !previous.revision_exists?
|
237
|
+
end
|
238
|
+
|
239
|
+
def validate!
|
240
|
+
raise InvalidRevision, "Revision '#{@revision.inspect}' is not > 0" if !creatable?
|
241
|
+
end
|
242
|
+
|
243
|
+
def creatable?
|
244
|
+
!@revision.nil? && (@revision > 0)
|
245
|
+
end
|
246
|
+
|
247
|
+
def delete
|
248
|
+
return self unless creatable?
|
249
|
+
delete_table
|
250
|
+
history_dataset.delete
|
251
|
+
archive_dataset.delete
|
252
|
+
self
|
253
|
+
end
|
254
|
+
|
255
|
+
def delete_table
|
256
|
+
database.drop_table?(table)
|
257
|
+
end
|
258
|
+
|
259
|
+
def table_exists?
|
260
|
+
database.tables.include?(table)
|
261
|
+
end
|
262
|
+
|
263
|
+
def revision_exists?
|
264
|
+
return false if @revision.nil?
|
265
|
+
history_dataset.count > 0
|
266
|
+
end
|
267
|
+
|
268
|
+
def exists?
|
269
|
+
revision_exists?
|
270
|
+
end
|
271
|
+
|
272
|
+
def unarchive
|
273
|
+
return if revision_exists?
|
274
|
+
copy_dataset(archive_dataset, history_table)
|
275
|
+
end
|
276
|
+
|
277
|
+
def mapper
|
278
|
+
@model.mapper
|
279
|
+
end
|
280
|
+
|
281
|
+
def database
|
282
|
+
@model.database
|
283
|
+
end
|
284
|
+
|
285
|
+
alias_method :db, :database
|
286
|
+
|
287
|
+
def transaction
|
288
|
+
database.transaction do
|
289
|
+
@model.with_editable do
|
290
|
+
yield
|
291
|
+
end
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
def scope
|
296
|
+
@model.with_revision(@revision) do
|
297
|
+
yield
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
def complete
|
302
|
+
copy_to(history_table)
|
303
|
+
copy_to(archive_table)
|
304
|
+
end
|
305
|
+
|
306
|
+
def copy_to(dest_table)
|
307
|
+
copy_dataset(dataset, dest_table)
|
308
|
+
end
|
309
|
+
|
310
|
+
def copy_dataset(ds, dest_table)
|
311
|
+
db.run("INSERT INTO #{db.literal(dest_table)} #{ds.select_sql}")
|
312
|
+
end
|
313
|
+
|
314
|
+
def previous
|
315
|
+
revision = (@revision.nil? || @revision <= 1) ? nil : @revision - 1
|
316
|
+
Revision.new(@model, revision)
|
317
|
+
end
|
318
|
+
|
319
|
+
def table
|
320
|
+
mapper.revision_table(@revision)
|
321
|
+
end
|
322
|
+
|
323
|
+
def dataset
|
324
|
+
db[table]
|
325
|
+
end
|
326
|
+
|
327
|
+
def content_table
|
328
|
+
mapper.base_table
|
329
|
+
end
|
330
|
+
|
331
|
+
def content_dataset
|
332
|
+
db[content_table]
|
333
|
+
end
|
334
|
+
|
335
|
+
def history_table
|
336
|
+
mapper.revision_history_table
|
337
|
+
end
|
338
|
+
|
339
|
+
def history_dataset(&block)
|
340
|
+
_dataset(history_table, &block)
|
341
|
+
end
|
342
|
+
|
343
|
+
def archive_table
|
344
|
+
mapper.revision_archive_table
|
345
|
+
end
|
346
|
+
|
347
|
+
def archive_dataset(&block)
|
348
|
+
_dataset(history_table, &block)
|
349
|
+
end
|
350
|
+
|
351
|
+
def _dataset(table, &block)
|
352
|
+
db[table].filter(:revision => @revision, &block)
|
353
|
+
end
|
354
|
+
end
|
355
|
+
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require 'simultaneous'
|
4
3
|
|
5
4
|
module Spontaneous
|
6
5
|
module Publishing
|
@@ -11,62 +10,24 @@ module Spontaneous
|
|
11
10
|
:publish
|
12
11
|
end
|
13
12
|
|
14
|
-
def self.spot_binary
|
15
|
-
::Spontaneous.config.spontaneous_binary || default_spot_binary
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.default_spot_binary
|
19
|
-
(Pathname.new(Spontaneous.gem_dir) + "bin/spot").expand_path.to_s
|
20
|
-
end
|
21
|
-
|
22
13
|
def self.register_task
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
logfile = "#{site_root}/log/publish.log"
|
27
|
-
# TODO: make nice value configurable
|
14
|
+
task = "site publish"
|
15
|
+
niceness = Spontaneous::Site.config.publish_niceness || 15
|
16
|
+
logfile = "log/publish.log"
|
28
17
|
task_options = {
|
29
18
|
:niceness => niceness,
|
30
|
-
:logfile
|
31
|
-
:pwd => site_root
|
32
|
-
}
|
33
|
-
|
34
|
-
task_params = {
|
35
|
-
"site" => site_root,
|
36
|
-
"logfile" => logfile,
|
37
|
-
"environment" => Spontaneous.env
|
38
|
-
}
|
39
|
-
env = {
|
40
|
-
"SPOT_SERVER" => server_address
|
19
|
+
:logfile => logfile
|
41
20
|
}
|
42
|
-
|
21
|
+
task_params = {}
|
22
|
+
Spontaneous::Simultaneous.register(task_name, task, task_options, task_params)
|
43
23
|
end
|
44
24
|
|
45
|
-
def self.simultaneous_setup
|
46
|
-
::Simultaneous.client_mode = :async
|
47
|
-
::Simultaneous.connection = ::Spontaneous.config.simultaneous_connection
|
48
|
-
::Simultaneous.domain = ::Spontaneous.config.site_domain
|
49
|
-
end
|
50
|
-
|
51
|
-
def self.server_address
|
52
|
-
Spontaneous.config.server_connection || "#{ ::Spontaneous.config.host || "127.0.0.1" }:#{::Spontaneous.config.port}"
|
53
|
-
end
|
54
|
-
|
55
|
-
simultaneous_setup
|
56
25
|
register_task
|
57
26
|
|
58
|
-
# def self.status
|
59
|
-
# FAF.get_status(task_name)
|
60
|
-
# end
|
61
|
-
|
62
|
-
# def self.status=(status)
|
63
|
-
# FAF.set_status(task_name, status)
|
64
|
-
# end
|
65
|
-
|
66
27
|
attr_reader :revision
|
67
28
|
|
68
|
-
def initialize(revision)
|
69
|
-
@revision = revision
|
29
|
+
def initialize(revision, content_model)
|
30
|
+
@revision, @content_model = revision, content_model
|
70
31
|
end
|
71
32
|
|
72
33
|
def task_name
|
@@ -74,11 +35,11 @@ module Spontaneous
|
|
74
35
|
end
|
75
36
|
|
76
37
|
def publish_pages(page_list)
|
77
|
-
::Simultaneous.fire(task_name, {"pages" => page_list})
|
38
|
+
Spontaneous::Simultaneous.fire(task_name, {"pages" => page_list})
|
78
39
|
end
|
79
40
|
|
80
41
|
def publish_all
|
81
|
-
::Simultaneous.fire(task_name)
|
42
|
+
Spontaneous::Simultaneous.fire(task_name)
|
82
43
|
end
|
83
44
|
end # Simultaneous
|
84
45
|
end # Publishing
|
@@ -6,6 +6,7 @@ module Spontaneous
|
|
6
6
|
autoload :Threaded, "spontaneous/publishing/threaded"
|
7
7
|
autoload :Simultaneous, "spontaneous/publishing/simultaneous"
|
8
8
|
autoload :EventClient, "spontaneous/publishing/event_client"
|
9
|
+
autoload :Revision, "spontaneous/publishing/revision"
|
9
10
|
end # Publishing
|
10
11
|
end # Spontaneous
|
11
12
|
|
@@ -15,10 +15,8 @@ module Spontaneous
|
|
15
15
|
def call(env)
|
16
16
|
status = headers = body = nil
|
17
17
|
env[Rack::RENDERER] = @renderer
|
18
|
-
Content.
|
19
|
-
|
20
|
-
status, headers, body = @app.call(env)
|
21
|
-
end
|
18
|
+
Spontaneous::Content.with_published do
|
19
|
+
status, headers, body = @app.call(env)
|
22
20
|
end
|
23
21
|
[status, headers.merge(POWERED_BY), body]
|
24
22
|
end
|