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
@@ -0,0 +1,186 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'delegate'
|
3
|
+
require 'simultaneous'
|
4
|
+
|
5
|
+
module Spontaneous::Publishing
|
6
|
+
module Progress
|
7
|
+
class Duration < DelegateClass(Float)
|
8
|
+
def to_s
|
9
|
+
d = self.to_f
|
10
|
+
h, r = _factor(d, 3600)
|
11
|
+
m, _ = _factor(r, 60)
|
12
|
+
s = (d - (h*3600 + m * 60)).round(2)
|
13
|
+
"%02dh %02dm %02.2fs" % [h, m,s]
|
14
|
+
end
|
15
|
+
|
16
|
+
def _factor(d, f)
|
17
|
+
[d.to_i/f, d.to_i%f]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.registered
|
22
|
+
@registered ||= {}
|
23
|
+
end
|
24
|
+
|
25
|
+
class Progress
|
26
|
+
def self.register(klass, *names)
|
27
|
+
names.each do |name|
|
28
|
+
Spontaneous::Publishing::Progress.registered[name] = klass
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Silent < Progress
|
34
|
+
attr_reader :total, :stage
|
35
|
+
|
36
|
+
register self, :silent, :none
|
37
|
+
|
38
|
+
def initialize
|
39
|
+
@total = 0
|
40
|
+
@position = 0
|
41
|
+
@stage = ""
|
42
|
+
@start = Time.now
|
43
|
+
end
|
44
|
+
|
45
|
+
def start(total_steps)
|
46
|
+
@total = total_steps
|
47
|
+
end
|
48
|
+
|
49
|
+
def stage(name)
|
50
|
+
@stage = name
|
51
|
+
end
|
52
|
+
|
53
|
+
def current_stage
|
54
|
+
@stage
|
55
|
+
end
|
56
|
+
|
57
|
+
def step(n = 1, msg = "")
|
58
|
+
@position += n
|
59
|
+
end
|
60
|
+
|
61
|
+
def log(message)
|
62
|
+
end
|
63
|
+
|
64
|
+
def error(exception)
|
65
|
+
end
|
66
|
+
|
67
|
+
def done
|
68
|
+
end
|
69
|
+
|
70
|
+
def percentage
|
71
|
+
((@position.to_f / @total.to_f) * 100).round(2)
|
72
|
+
end
|
73
|
+
|
74
|
+
def position
|
75
|
+
@position
|
76
|
+
end
|
77
|
+
|
78
|
+
def duration
|
79
|
+
Duration.new(Time.now - @start)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class Log < Silent
|
84
|
+
register self, :log
|
85
|
+
|
86
|
+
def initialize(io = $stdout, label = "Publish")
|
87
|
+
super()
|
88
|
+
# don't call close on stdout or stderr
|
89
|
+
@closable = !((io == STDOUT) || (io == STDERR))
|
90
|
+
@logger = Logger.new(io, File::APPEND)
|
91
|
+
@logger.formatter = proc do |severity, datetime, progname, msg|
|
92
|
+
pct = ("%03.2f" % [percentage]).rjust(6, " ")
|
93
|
+
"#{label}:#{severity}: [#{datetime.strftime('%Y-%m-%d %H:%M:%S.%3N')}] #{duration} #{pct}% #{current_stage} #{msg}\n"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def log(message)
|
98
|
+
super
|
99
|
+
logger.info(message)
|
100
|
+
end
|
101
|
+
|
102
|
+
def step(n = 1, msg = "")
|
103
|
+
super
|
104
|
+
@logger.info("#{msg}")
|
105
|
+
end
|
106
|
+
|
107
|
+
def error(exception)
|
108
|
+
super
|
109
|
+
msg = [exception.to_s].concat(exception.backtrace).join("\n")
|
110
|
+
@logger.error(msg)
|
111
|
+
end
|
112
|
+
|
113
|
+
def done
|
114
|
+
@logger.close if @closable
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
class Stdout < Log
|
119
|
+
register self, :stdout
|
120
|
+
|
121
|
+
def initialize
|
122
|
+
super($stdout)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
class Simultaneous < Silent
|
127
|
+
register self, :simultaneous, :browser
|
128
|
+
|
129
|
+
def stage(name)
|
130
|
+
super
|
131
|
+
send_event
|
132
|
+
end
|
133
|
+
|
134
|
+
def step(n = 1, msg = "")
|
135
|
+
super
|
136
|
+
send_event
|
137
|
+
end
|
138
|
+
|
139
|
+
def send_event(stage = current_stage, percentage = percentage)
|
140
|
+
::Simultaneous.send_event('publish_progress', {:state => stage, :progress => percentage}.to_json)
|
141
|
+
rescue Errno::ECONNREFUSED
|
142
|
+
rescue Errno::ENOENT
|
143
|
+
end
|
144
|
+
|
145
|
+
def error(exception)
|
146
|
+
super
|
147
|
+
send_event("aborting", "*")
|
148
|
+
end
|
149
|
+
|
150
|
+
def done
|
151
|
+
super
|
152
|
+
send_event("complete", "*")
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
class Multi < Progress
|
157
|
+
def initialize(*outputs)
|
158
|
+
@outputs = outputs
|
159
|
+
end
|
160
|
+
|
161
|
+
def log(message)
|
162
|
+
@outputs.each { |progress| progress.log(message) }
|
163
|
+
end
|
164
|
+
|
165
|
+
def start(total_steps)
|
166
|
+
@outputs.each { |progress| progress.start(total_steps) }
|
167
|
+
end
|
168
|
+
|
169
|
+
def stage(name)
|
170
|
+
@outputs.each { |progress| progress.stage(name) }
|
171
|
+
end
|
172
|
+
|
173
|
+
def step(n = 1, msg = "")
|
174
|
+
@outputs.each { |progress| progress.step(n, msg) }
|
175
|
+
end
|
176
|
+
|
177
|
+
def error(exception)
|
178
|
+
@outputs.each { |progress| progress.error(exception) }
|
179
|
+
end
|
180
|
+
|
181
|
+
def done
|
182
|
+
@outputs.each { |progress| progress.done }
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
|
2
|
+
module Spontaneous::Publishing
|
3
|
+
class Publish
|
4
|
+
attr_reader :site, :revision, :actions
|
5
|
+
|
6
|
+
def initialize(site, revision, actions)
|
7
|
+
@site, @revision, @actions = site, revision, actions
|
8
|
+
end
|
9
|
+
|
10
|
+
def publish_pages(modified_pages)
|
11
|
+
pages = normalise_page_list(modified_pages)
|
12
|
+
if all_pages?(pages) || all_modified_pages?(pages)
|
13
|
+
publish_all
|
14
|
+
else
|
15
|
+
pages = Spontaneous::Change.include_dependencies(pages)
|
16
|
+
publish(pages)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def publish_all
|
21
|
+
publish(nil)
|
22
|
+
end
|
23
|
+
|
24
|
+
def publish(pages)
|
25
|
+
model.database.transaction do
|
26
|
+
publish!(pages)
|
27
|
+
end
|
28
|
+
rescue Exception => e
|
29
|
+
abort_publish(e)
|
30
|
+
raise
|
31
|
+
end
|
32
|
+
|
33
|
+
def publish!(pages)
|
34
|
+
start_publish
|
35
|
+
model.publish(revision, pages) do
|
36
|
+
run_pipeline(pages)
|
37
|
+
end
|
38
|
+
finish_publish
|
39
|
+
end
|
40
|
+
|
41
|
+
def run_pipeline(pages)
|
42
|
+
model.scope(revision, true) do
|
43
|
+
run_pipeline!(pages)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def run_pipeline!(pages)
|
48
|
+
pages ||= all_unpublished_pages
|
49
|
+
pipeline.run(site, revision, pages, progress)
|
50
|
+
end
|
51
|
+
|
52
|
+
def pipeline
|
53
|
+
@pipeline ||= Pipeline.new(actions.steps)
|
54
|
+
end
|
55
|
+
|
56
|
+
def start_publish
|
57
|
+
progress.log("Publishing revision #{revision}")
|
58
|
+
# when working with multiple instances it's possible to rollback the revision number
|
59
|
+
# leaving behind old revisions > the current published_revision.
|
60
|
+
model.delete_revision(revision)
|
61
|
+
site.send(:pending_revision=, revision)
|
62
|
+
end
|
63
|
+
|
64
|
+
def finish_publish
|
65
|
+
S::PublishedRevision.create(:revision => revision, :published_at => Time.now)
|
66
|
+
site.send(:pending_revision=, nil)
|
67
|
+
site.must_publish_all!(false)
|
68
|
+
progress.done
|
69
|
+
end
|
70
|
+
|
71
|
+
def abort_publish(e)
|
72
|
+
S::PublishedRevision.filter(:revision => revision).delete
|
73
|
+
site.send(:pending_revision=, nil)
|
74
|
+
progress.error(e)
|
75
|
+
end
|
76
|
+
|
77
|
+
def model
|
78
|
+
@site.model
|
79
|
+
end
|
80
|
+
|
81
|
+
def progress
|
82
|
+
@progress ||= Progress::Multi.new(*actions.progress)
|
83
|
+
end
|
84
|
+
|
85
|
+
def normalise_page_list(pages)
|
86
|
+
pages = pages.flatten.map { |c|
|
87
|
+
c.is_a?(model::Page) ? c.reload : model::Page[c]
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
def all_unpublished_pages
|
92
|
+
@all_unpublished_pages ||= Spontaneous::Change.unpublished_pages(@site)
|
93
|
+
end
|
94
|
+
|
95
|
+
def all_pages
|
96
|
+
site.pages
|
97
|
+
end
|
98
|
+
|
99
|
+
def all_pages?(pages)
|
100
|
+
(all_pages - pages).empty?
|
101
|
+
end
|
102
|
+
|
103
|
+
def all_modified_pages?(pages)
|
104
|
+
(all_unpublished_pages - pages).empty?
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Spontaneous::Publishing
|
2
|
+
class Rerender < Publish
|
3
|
+
def initialize(site, revision, actions)
|
4
|
+
@site, @revision, @actions = site, revision, actions
|
5
|
+
end
|
6
|
+
|
7
|
+
def rerender
|
8
|
+
model.scope(revision, true) do
|
9
|
+
pipeline.run(site, revision, [], progress)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def progress
|
14
|
+
@progress ||= Progress::Stdout.new
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,6 +1,31 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
module Spontaneous::Publishing
|
4
|
+
def self.create_content_table(db, source_table, dest_table_name)
|
5
|
+
# sqlite doesn't like it if you create a table with no columns
|
6
|
+
# so hard-code the id column (but don't make it a pk because the
|
7
|
+
# unique constraint isn't useful at this stage)
|
8
|
+
schema = db.schema(source_table).dup.delete_if { |col, opts| col == :id }
|
9
|
+
db.create_table(dest_table_name) do
|
10
|
+
integer :id
|
11
|
+
end
|
12
|
+
db.alter_table(dest_table_name) do
|
13
|
+
schema.each do |column, column_opts|
|
14
|
+
opts = column_opts.dup
|
15
|
+
type = opts.delete(:db_type)
|
16
|
+
case column
|
17
|
+
when :id
|
18
|
+
opts.delete(:default)
|
19
|
+
end
|
20
|
+
add_column column, type#, opts
|
21
|
+
end
|
22
|
+
end
|
23
|
+
nil
|
24
|
+
rescue => e
|
25
|
+
db.drop_table(dest_table_name) rescue nil
|
26
|
+
raise
|
27
|
+
end
|
28
|
+
|
4
29
|
class Revision
|
5
30
|
class InvalidRevision < Spontaneous::Error; end
|
6
31
|
|
@@ -23,24 +48,24 @@ module Spontaneous::Publishing
|
|
23
48
|
sync_revision
|
24
49
|
set_revision_timestamps
|
25
50
|
set_revision_version
|
51
|
+
set_revision_content_hash
|
26
52
|
@revision.complete
|
27
53
|
@revision.scope do
|
28
54
|
yield if block_given?
|
29
55
|
end
|
30
56
|
set_source_timestamps
|
31
|
-
|
57
|
+
set_source_content_hash
|
58
|
+
rescue Exception => e # Want to catch everything, including the "uncatchable"
|
32
59
|
@revision.delete
|
33
|
-
raise
|
60
|
+
raise
|
34
61
|
end
|
35
62
|
end
|
36
63
|
|
37
64
|
protected
|
38
65
|
|
39
66
|
def create_revision
|
40
|
-
db.
|
41
|
-
|
42
|
-
AS #{source_dataset.select_sql}
|
43
|
-
SQL
|
67
|
+
Spontaneous::Publishing.create_content_table(db, source_dataset.first_source, @revision.table)
|
68
|
+
@revision.copy_dataset(source_dataset, @revision.table)
|
44
69
|
end
|
45
70
|
|
46
71
|
def source_dataset
|
@@ -48,6 +73,8 @@ module Spontaneous::Publishing
|
|
48
73
|
end
|
49
74
|
|
50
75
|
def copy_indexes
|
76
|
+
pk = @revision.model.primary_key
|
77
|
+
db.add_index(@revision.table, Array(pk), unique: true)
|
51
78
|
indexes = db.indexes(@revision.content_table)
|
52
79
|
indexes.each do |name, options|
|
53
80
|
columns = options.delete(:columns)
|
@@ -59,6 +86,18 @@ module Spontaneous::Publishing
|
|
59
86
|
# To be overwritten in Patch subclass
|
60
87
|
end
|
61
88
|
|
89
|
+
def set_source_content_hash
|
90
|
+
set_content_hash(@revision.content_dataset)
|
91
|
+
end
|
92
|
+
|
93
|
+
def set_revision_content_hash
|
94
|
+
set_content_hash(@revision.dataset)
|
95
|
+
end
|
96
|
+
|
97
|
+
def set_content_hash(dataset)
|
98
|
+
filter_dataset(dataset).update(published_content_hash: :content_hash, content_hash_changed: false)
|
99
|
+
end
|
100
|
+
|
62
101
|
def set_revision_timestamps
|
63
102
|
set_timestamps(@revision.dataset)
|
64
103
|
end
|
@@ -83,11 +122,11 @@ module Spontaneous::Publishing
|
|
83
122
|
end
|
84
123
|
|
85
124
|
def published_dataset(ds)
|
86
|
-
ds
|
125
|
+
filter_dataset(ds)
|
87
126
|
end
|
88
127
|
|
89
128
|
def first_published_dataset(ds)
|
90
|
-
ds.filter(:first_published_at => nil)
|
129
|
+
filter_dataset(ds.filter(:first_published_at => nil))
|
91
130
|
end
|
92
131
|
|
93
132
|
def set_revision_version
|
@@ -105,6 +144,10 @@ module Spontaneous::Publishing
|
|
105
144
|
def revision
|
106
145
|
@revision.revision
|
107
146
|
end
|
147
|
+
|
148
|
+
def filter_dataset(ds)
|
149
|
+
ds
|
150
|
+
end
|
108
151
|
end
|
109
152
|
|
110
153
|
class Patcher < Generator
|
@@ -126,15 +169,7 @@ module Spontaneous::Publishing
|
|
126
169
|
end
|
127
170
|
end
|
128
171
|
|
129
|
-
def
|
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)
|
172
|
+
def filter_dataset(ds)
|
138
173
|
ds.filter(:id => @modified.map(&:id))
|
139
174
|
end
|
140
175
|
end
|
@@ -211,7 +246,7 @@ module Spontaneous::Publishing
|
|
211
246
|
model.mapper.revision_table?(table)
|
212
247
|
end
|
213
248
|
|
214
|
-
attr_reader :revision
|
249
|
+
attr_reader :model, :revision
|
215
250
|
|
216
251
|
def initialize(model, revision)
|
217
252
|
@model, @revision = model, revision
|