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,154 @@
|
|
1
|
+
|
2
|
+
module Spontaneous::Publishing
|
3
|
+
module Steps
|
4
|
+
class InvalidStepException < Spontaneous::Error
|
5
|
+
def initialize(step)
|
6
|
+
super("Unknown/invalid step #{step.inspect}")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
class InvalidProgressException < Spontaneous::Error
|
10
|
+
def initialize(progress)
|
11
|
+
super("Unknown/invalid progress #{progress.inspect}")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.new(steps = [], progress = [], &block)
|
16
|
+
Steps.new(steps, progress, &block)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.minimal
|
20
|
+
new do
|
21
|
+
run :activate_revision
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.rerender
|
26
|
+
new do
|
27
|
+
run :render_revision
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.default
|
32
|
+
new do
|
33
|
+
CORE_STEPS.each do |step|
|
34
|
+
run step
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.register_step(step_class)
|
40
|
+
registered_steps[step_class.to_sym] = step_class
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.registered_steps
|
44
|
+
@registered_steps ||= {}
|
45
|
+
end
|
46
|
+
|
47
|
+
class DSL
|
48
|
+
def initialize(steps, &block)
|
49
|
+
@steps = steps
|
50
|
+
instance_eval(&block) if block
|
51
|
+
end
|
52
|
+
|
53
|
+
def notify(progress, *args)
|
54
|
+
@steps.add_progress(validate_progress(make_progress(progress, args)))
|
55
|
+
end
|
56
|
+
|
57
|
+
alias_method :log, :notify
|
58
|
+
|
59
|
+
def run(step)
|
60
|
+
@steps.add_step(validate_step(make_step(step)))
|
61
|
+
end
|
62
|
+
|
63
|
+
def validate_progress(progress)
|
64
|
+
raise InvalidProgressException.new(progress) unless progress && is_progress?(progress)
|
65
|
+
progress
|
66
|
+
end
|
67
|
+
|
68
|
+
def make_progress(progress, args)
|
69
|
+
return progress if is_progress?(progress)
|
70
|
+
progress_class = case progress
|
71
|
+
when Symbol
|
72
|
+
Spontaneous::Publishing::Progress.registered[progress]
|
73
|
+
else
|
74
|
+
raise InvalidProgressException.new(progress)
|
75
|
+
end
|
76
|
+
return nil if progress_class.nil?
|
77
|
+
progress_class.new(*args)
|
78
|
+
end
|
79
|
+
|
80
|
+
def is_progress?(obj)
|
81
|
+
[:start, :stage, :step, :log, :done].all? { |method| obj.respond_to?(method) }
|
82
|
+
end
|
83
|
+
|
84
|
+
def validate_step(step)
|
85
|
+
raise InvalidStepException.new(step) unless step && step.respond_to?(:call)
|
86
|
+
step
|
87
|
+
end
|
88
|
+
|
89
|
+
def make_step(step)
|
90
|
+
return step if step.respond_to?(:call)
|
91
|
+
case step
|
92
|
+
when Symbol
|
93
|
+
Spontaneous::Publishing::Steps.registered_steps[step]
|
94
|
+
else
|
95
|
+
raise InvalidStepException.new(step)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
class Steps
|
101
|
+
attr_reader :steps, :progress
|
102
|
+
|
103
|
+
def initialize(steps = [], progress = [], &block)
|
104
|
+
@steps, @progress = steps, progress
|
105
|
+
DSL.new(self, &block)
|
106
|
+
end
|
107
|
+
|
108
|
+
def add_progress(reporter)
|
109
|
+
progress << reporter
|
110
|
+
end
|
111
|
+
|
112
|
+
def add_step(step)
|
113
|
+
steps << step
|
114
|
+
end
|
115
|
+
|
116
|
+
def run(site, revision, pages, progress)
|
117
|
+
@steps.each do |step|
|
118
|
+
progress.add(step.count(site, revision)) if step.respond_to?(:count)
|
119
|
+
end
|
120
|
+
|
121
|
+
@steps.each do |step|
|
122
|
+
step.call(site, revision, pages, progress)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def to_a
|
127
|
+
steps
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
CORE_STEPS = [
|
132
|
+
:create_revision_directory,
|
133
|
+
:render_revision,
|
134
|
+
:generate_search_indexes,
|
135
|
+
:copy_static_files,
|
136
|
+
:generate_rackup_file,
|
137
|
+
:activate_revision,
|
138
|
+
:write_revision_file,
|
139
|
+
:archive_old_revisions
|
140
|
+
].freeze
|
141
|
+
|
142
|
+
CORE_PROGRESS = [:browser, :stdout].freeze
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
require 'spontaneous/publishing/steps/base_step'
|
147
|
+
require 'spontaneous/publishing/steps/create_revision_directory'
|
148
|
+
require 'spontaneous/publishing/steps/render_revision'
|
149
|
+
require 'spontaneous/publishing/steps/generate_search_indexes'
|
150
|
+
require 'spontaneous/publishing/steps/copy_static_files'
|
151
|
+
require 'spontaneous/publishing/steps/generate_rackup_file'
|
152
|
+
require 'spontaneous/publishing/steps/activate_revision'
|
153
|
+
require 'spontaneous/publishing/steps/write_revision_file'
|
154
|
+
require 'spontaneous/publishing/steps/archive_old_revisions'
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Spontaneous::Publishing::Steps
|
2
|
+
class ActivateRevision < BaseStep
|
3
|
+
|
4
|
+
def count
|
5
|
+
2
|
6
|
+
end
|
7
|
+
|
8
|
+
def call
|
9
|
+
save_state
|
10
|
+
@progress.stage("activating revision")
|
11
|
+
set_published_revision
|
12
|
+
symlink_revision(revision)
|
13
|
+
end
|
14
|
+
|
15
|
+
def rollback
|
16
|
+
@site.send(:set_published_revision, @state.published_revision)
|
17
|
+
if @linked
|
18
|
+
symlink_path(@linked)
|
19
|
+
else
|
20
|
+
FileUtils.rm(@site.revision_dir) if File.exist?(@site.revision_dir)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def set_published_revision
|
25
|
+
@site.send(:set_published_revision, revision)
|
26
|
+
@progress.step(1, "published revision => #{revision}")
|
27
|
+
end
|
28
|
+
|
29
|
+
def symlink_revision(r)
|
30
|
+
path = @site.revision_dir(r)
|
31
|
+
symlink_path(path)
|
32
|
+
@progress.step(1, %(symlinking "revisions/current" => "#{path}"))
|
33
|
+
end
|
34
|
+
|
35
|
+
def symlink_path(path)
|
36
|
+
system("ln -nsf #{path} #{@site.revision_dir}")
|
37
|
+
end
|
38
|
+
|
39
|
+
def save_state
|
40
|
+
@state = @site.state
|
41
|
+
link = Pathname.new(@site.revision_dir)
|
42
|
+
@linked = link.realpath.to_s if link.exist?
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Spontaneous::Publishing::Steps
|
2
|
+
class ArchiveOldRevisions < BaseStep
|
3
|
+
KEEP_REVISIONS = 8
|
4
|
+
|
5
|
+
def count
|
6
|
+
1
|
7
|
+
end
|
8
|
+
|
9
|
+
def call
|
10
|
+
@progress.stage("archiving old revisions")
|
11
|
+
@site.model.cleanup_revisions(revision, keep_revisions)
|
12
|
+
@progress.step(1)
|
13
|
+
end
|
14
|
+
|
15
|
+
def rollback
|
16
|
+
end
|
17
|
+
|
18
|
+
def keep_revisions
|
19
|
+
@site.config.keep_revisions || KEEP_REVISIONS
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Spontaneous::Publishing::Steps
|
2
|
+
class BaseStep
|
3
|
+
|
4
|
+
def self.to_sym
|
5
|
+
name.demodulize.underscore.to_sym
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.count(site, revision, pages, progress = Spontaneous::Publishing::Progress::Silent.new)
|
9
|
+
new(site, revision, pages, progress).count
|
10
|
+
end
|
11
|
+
|
12
|
+
# create, run & return an instance that does the actual work
|
13
|
+
def self.call(site, revision, pages, progress = Spontaneous::Publishing::Progress::Silent.new)
|
14
|
+
new(site, revision, pages, progress).tap do |instance|
|
15
|
+
begin
|
16
|
+
instance.call
|
17
|
+
rescue Exception => e
|
18
|
+
instance.rollback #if instance.respond_to?(:rollback)
|
19
|
+
raise
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.inherited(subclass)
|
25
|
+
Spontaneous::Publishing::Steps.register_step(subclass)
|
26
|
+
end
|
27
|
+
|
28
|
+
attr_reader :revision, :site, :progress
|
29
|
+
|
30
|
+
def initialize(site, revision, pages, progress)
|
31
|
+
@site, @revision, @pages, @progress = site, revision, pages, progress
|
32
|
+
end
|
33
|
+
|
34
|
+
# Does the actual work
|
35
|
+
def call
|
36
|
+
# implement in subclasses
|
37
|
+
end
|
38
|
+
|
39
|
+
# Should return the number of steps we're going to make
|
40
|
+
def count
|
41
|
+
# implement in subclasses
|
42
|
+
end
|
43
|
+
|
44
|
+
# Undo what we did in #call in case of exceptions
|
45
|
+
def rollback
|
46
|
+
# implement in subclasses
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Spontaneous::Publishing::Steps
|
2
|
+
class CopyStaticFiles < BaseStep
|
3
|
+
|
4
|
+
def count
|
5
|
+
facets.length
|
6
|
+
end
|
7
|
+
|
8
|
+
def call
|
9
|
+
@progress.stage("copying files")
|
10
|
+
ensure_public_dir
|
11
|
+
facets.each do |facet|
|
12
|
+
copy_facet(facet)
|
13
|
+
@progress.step(1, "from #{facet.name.inspect}")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def rollback
|
18
|
+
FileUtils.rm_r(revision_public) if File.exists?(revision_public)
|
19
|
+
end
|
20
|
+
|
21
|
+
def ensure_public_dir
|
22
|
+
dir = revision_public
|
23
|
+
end
|
24
|
+
|
25
|
+
def copy_facet(facet)
|
26
|
+
sources(facet).each do |dir|
|
27
|
+
copy_files(facet, dir)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def copy_files(facet, dir)
|
32
|
+
files(dir).each do |source, path|
|
33
|
+
copy_file(facet, source, path)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def copy_file(facet, source, path)
|
38
|
+
dest = File.join([revision_public, facet.file_namespace, path].compact)
|
39
|
+
dir = File.dirname(dest)
|
40
|
+
FileUtils.mkdir_p(dir) unless File.exist?(dir)
|
41
|
+
link_file(source, dest)
|
42
|
+
end
|
43
|
+
|
44
|
+
def link_file(source, dest)
|
45
|
+
src_dev = File::stat(source).dev
|
46
|
+
dst_dev = File::stat(File.dirname(dest)).dev
|
47
|
+
if (src_dev == dst_dev)
|
48
|
+
FileUtils.ln(source, dest, :force => true)
|
49
|
+
else
|
50
|
+
FileUtils.cp(source, dest)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def files(dir)
|
55
|
+
Dir["#{dir}/**/*"]
|
56
|
+
.reject {|path| ::File.directory?(path) }
|
57
|
+
.map { |path| [path, Pathname.new(path).relative_path_from(dir).to_s] }
|
58
|
+
end
|
59
|
+
|
60
|
+
def revision_public
|
61
|
+
@public_dest ||= Pathname.new(Spontaneous.revision_dir(revision) / 'public').tap do |path|
|
62
|
+
FileUtils.mkdir_p(path) unless File.exists?(path)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def facets
|
67
|
+
@site.facets
|
68
|
+
end
|
69
|
+
|
70
|
+
def sources(facet)
|
71
|
+
facet.paths.expanded(:public).map { |dir| Pathname.new(dir) }.select(&:exist?).map(&:realpath)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Should be called *after* the revision
|
2
|
+
module Spontaneous::Publishing::Steps
|
3
|
+
class CreateRevisionDirectory < BaseStep
|
4
|
+
|
5
|
+
def call
|
6
|
+
@progress.stage("creating revision directory")
|
7
|
+
FileUtils.mkdir_p(path / "tmp")
|
8
|
+
@progress.step(count, path)
|
9
|
+
end
|
10
|
+
|
11
|
+
def count
|
12
|
+
1
|
13
|
+
end
|
14
|
+
|
15
|
+
# This is the reason for the existance of this step: cleaning up when it's gone wrong
|
16
|
+
def rollback
|
17
|
+
FileUtils.rm_r(path) if File.exist?(path)
|
18
|
+
end
|
19
|
+
|
20
|
+
def path
|
21
|
+
@site.revision_dir(revision)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Spontaneous::Publishing::Steps
|
2
|
+
class GenerateRackupFile < BaseStep
|
3
|
+
|
4
|
+
def call
|
5
|
+
@progress.stage("create server config")
|
6
|
+
File.open(config_path, "w:UTF-8") do |file|
|
7
|
+
file.write(config)
|
8
|
+
end
|
9
|
+
@progress.step(count, config_path.inspect)
|
10
|
+
end
|
11
|
+
|
12
|
+
def count
|
13
|
+
1
|
14
|
+
end
|
15
|
+
|
16
|
+
def rollback
|
17
|
+
FileUtils.rm(config_path) if File.exists?(config_path)
|
18
|
+
end
|
19
|
+
|
20
|
+
def config_path
|
21
|
+
(@site.revision_dir(revision) / "config.ru").tap do |path|
|
22
|
+
dir = File.dirname(path)
|
23
|
+
FileUtils.mkdir_p(dir) unless File.directory?(dir)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def path
|
28
|
+
@path ||= Pathname.new(@site.root).realpath.to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
def config
|
32
|
+
path = Pathname.new(Spontaneous.root).realpath.to_s
|
33
|
+
rackup = "config/front.ru"
|
34
|
+
|
35
|
+
template = (<<-RACKUP).gsub(/^ +/, '')
|
36
|
+
# This is an automatically generated file *DO NOT EDIT*
|
37
|
+
# To configure your Rack application make your changes in
|
38
|
+
# '#{path}/#{rackup}'
|
39
|
+
|
40
|
+
# Set the revision to display
|
41
|
+
ENV["#{Spontaneous::SPOT_REVISION_NUMBER}"] = "#{revision}"
|
42
|
+
ENV["#{Spontaneous::SPOT_ROOT}"] = "#{path}"
|
43
|
+
|
44
|
+
# Change to the absolute path of our application and load the Rack config
|
45
|
+
root = "#{path}"
|
46
|
+
Dir.chdir(root)
|
47
|
+
eval(::File.read("#{rackup}"), binding, ::File.join(root, "#{rackup}"), __LINE__)
|
48
|
+
RACKUP
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Spontaneous::Publishing::Steps
|
2
|
+
class GenerateSearchIndexes < BaseStep
|
3
|
+
|
4
|
+
def call
|
5
|
+
return if indexes.empty?
|
6
|
+
@progress.stage("indexing")
|
7
|
+
@site.indexer(revision) do |indexer|
|
8
|
+
@site.pages.each do |page|
|
9
|
+
indexer << page
|
10
|
+
@progress.step(1, page.path.inspect)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def count
|
16
|
+
return 0 if indexes.empty?
|
17
|
+
@site.pages.count
|
18
|
+
end
|
19
|
+
|
20
|
+
def indexes
|
21
|
+
site.indexes
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|