spontaneous 0.2.0.beta4 → 0.2.0.beta5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +39 -0
- data/Gemfile +11 -6
- data/Readme.markdown +136 -69
- data/application/css/core.css.scss +27 -7
- data/application/css/editing.css.scss +4 -26
- data/application/css/schema_error.css.scss +22 -0
- data/application/js/content.js +11 -3
- data/application/js/edit_panel.js +1 -4
- data/application/js/field/file.js +17 -0
- data/application/js/field/image.js +30 -21
- data/application/js/field/string.js +4 -1
- data/application/js/field_preview.js +21 -16
- data/application/js/publish.js +6 -6
- data/application/js/types.js +5 -13
- data/application/js/views.js +2 -2
- data/application/js/views/box_view.js +3 -2
- data/application/js/views/page_piece_view.js +1 -1
- data/application/js/views/piece_view.js +1 -1
- data/application/views/schema_modification_error.html.erb +13 -3
- data/db/migrations/20131104101935_site_must_publish_all.rb +14 -0
- data/lib/spontaneous.rb +0 -1
- data/lib/spontaneous/box_style.rb +15 -9
- data/lib/spontaneous/capistrano/deploy.rb +13 -1
- data/lib/spontaneous/change.rb +11 -13
- data/lib/spontaneous/cli.rb +5 -2
- data/lib/spontaneous/cli/assets.rb +7 -1
- data/lib/spontaneous/cli/console.rb +7 -1
- data/lib/spontaneous/cli/content.rb +35 -0
- data/lib/spontaneous/cli/fields.rb +3 -2
- data/lib/spontaneous/cli/generate.rb +5 -2
- data/lib/spontaneous/cli/server.rb +12 -8
- data/lib/spontaneous/cli/site.rb +12 -12
- data/lib/spontaneous/cli/user.rb +28 -14
- data/lib/spontaneous/collections/box_set.rb +4 -4
- data/lib/spontaneous/collections/field_set.rb +4 -4
- data/lib/spontaneous/collections/prototype_set.rb +12 -4
- data/lib/spontaneous/data_mapper.rb +11 -7
- data/lib/spontaneous/data_mapper/content_model.rb +8 -0
- data/lib/spontaneous/data_mapper/content_model/associations.rb +1 -1
- data/lib/spontaneous/data_mapper/dataset.rb +14 -2
- data/lib/spontaneous/data_mapper/scope.rb +33 -13
- data/lib/spontaneous/facet.rb +4 -0
- data/lib/spontaneous/field.rb +12 -12
- data/lib/spontaneous/field/base.rb +27 -22
- data/lib/spontaneous/field/boolean.rb +4 -4
- data/lib/spontaneous/field/date.rb +2 -2
- data/lib/spontaneous/field/file.rb +24 -18
- data/lib/spontaneous/field/html.rb +1 -1
- data/lib/spontaneous/field/image.rb +6 -19
- data/lib/spontaneous/field/location.rb +1 -1
- data/lib/spontaneous/field/long_string.rb +3 -3
- data/lib/spontaneous/field/markdown.rb +3 -3
- data/lib/spontaneous/field/select.rb +2 -2
- data/lib/spontaneous/field/string.rb +2 -2
- data/lib/spontaneous/field/tags.rb +2 -2
- data/lib/spontaneous/field/update.rb +21 -20
- data/lib/spontaneous/field/webvideo.rb +6 -6
- data/lib/spontaneous/field/webvideo/fallback.rb +2 -2
- data/lib/spontaneous/field/webvideo/vimeo.rb +7 -7
- data/lib/spontaneous/generators/site.rb +2 -2
- data/lib/spontaneous/generators/site/Gemfile.tt +5 -1
- data/lib/spontaneous/layout.rb +2 -2
- data/lib/spontaneous/media.rb +1 -0
- data/lib/spontaneous/media/file.rb +6 -5
- data/lib/spontaneous/media/image/attributes.rb +4 -0
- data/lib/spontaneous/media/image/renderable.rb +4 -4
- data/lib/spontaneous/media/store.rb +22 -0
- data/lib/spontaneous/{storage → media/store}/backend.rb +1 -1
- data/lib/spontaneous/{storage → media/store}/cloud.rb +1 -1
- data/lib/spontaneous/{storage → media/store}/local.rb +1 -1
- data/lib/spontaneous/media/temp_file.rb +1 -1
- data/lib/spontaneous/model.rb +10 -7
- data/lib/spontaneous/model/action.rb +7 -0
- data/lib/spontaneous/model/action/clean.rb +87 -0
- data/lib/spontaneous/model/box/allowed_types.rb +15 -1
- data/lib/spontaneous/model/core.rb +10 -0
- data/lib/spontaneous/model/core/aliases.rb +1 -1
- data/lib/spontaneous/model/core/content_groups.rb +1 -1
- data/lib/spontaneous/model/core/fields.rb +1 -1
- data/lib/spontaneous/model/core/modifications.rb +2 -2
- data/lib/spontaneous/model/core/page_search.rb +4 -0
- data/lib/spontaneous/model/core/publishing.rb +4 -17
- data/lib/spontaneous/model/core/render.rb +4 -4
- data/lib/spontaneous/model/core/styles.rb +2 -2
- data/lib/spontaneous/model/core/visibility.rb +6 -2
- data/lib/spontaneous/model/page.rb +6 -2
- data/lib/spontaneous/model/page/controllers.rb +55 -17
- data/lib/spontaneous/model/page/formats.rb +12 -7
- data/lib/spontaneous/model/page/layouts.rb +2 -2
- data/lib/spontaneous/model/page/locks.rb +4 -1
- data/lib/spontaneous/model/page/page_tree.rb +40 -6
- data/lib/spontaneous/output.rb +14 -52
- data/lib/spontaneous/output/context.rb +11 -39
- data/lib/spontaneous/output/context/navigation.rb +31 -0
- data/lib/spontaneous/output/format.rb +15 -19
- data/lib/spontaneous/output/renderable.rb +99 -0
- data/lib/spontaneous/output/store.rb +24 -0
- data/lib/spontaneous/output/store/backend.rb +52 -0
- data/lib/spontaneous/output/store/file.rb +77 -0
- data/lib/spontaneous/output/store/moneta.rb +117 -0
- data/lib/spontaneous/output/store/revision.rb +34 -0
- data/lib/spontaneous/output/store/store.rb +15 -0
- data/lib/spontaneous/output/store/transaction.rb +44 -0
- data/lib/spontaneous/output/template/engine.rb +17 -7
- data/lib/spontaneous/output/template/renderer.rb +66 -40
- data/lib/spontaneous/page_lock.rb +5 -7
- data/lib/spontaneous/page_piece.rb +2 -2
- data/lib/spontaneous/permissions/user.rb +14 -7
- data/lib/spontaneous/plugins/application/features.rb +8 -4
- data/lib/spontaneous/plugins/application/state.rb +12 -6
- data/lib/spontaneous/prototypes/box_prototype.rb +9 -10
- data/lib/spontaneous/prototypes/field_prototype.rb +66 -15
- data/lib/spontaneous/publishing/immediate.rb +30 -26
- data/lib/spontaneous/rack.rb +12 -7
- data/lib/spontaneous/rack/back.rb +43 -37
- data/lib/spontaneous/rack/back/base.rb +4 -4
- data/lib/spontaneous/rack/back/changes.rb +2 -2
- data/lib/spontaneous/rack/back/file.rb +16 -24
- data/lib/spontaneous/rack/back/map.rb +5 -5
- data/lib/spontaneous/rack/back/preview.rb +3 -4
- data/lib/spontaneous/rack/back/schema.rb +1 -1
- data/lib/spontaneous/rack/back/site.rb +6 -7
- data/lib/spontaneous/rack/front.rb +19 -16
- data/lib/spontaneous/rack/middleware/authenticate.rb +3 -3
- data/lib/spontaneous/rack/middleware/reloader.rb +3 -2
- data/lib/spontaneous/rack/middleware/scope.rb +25 -19
- data/lib/spontaneous/rack/page_controller.rb +164 -13
- data/lib/spontaneous/rack/public.rb +23 -62
- data/lib/spontaneous/rack/static.rb +2 -3
- data/lib/spontaneous/schema.rb +27 -8
- data/lib/spontaneous/schema/schema_modification.rb +9 -1
- data/lib/spontaneous/schema/uid.rb +2 -2
- data/lib/spontaneous/schema/uid_map.rb +3 -2
- data/lib/spontaneous/search/database.rb +2 -2
- data/lib/spontaneous/search/field.rb +5 -3
- data/lib/spontaneous/search/index.rb +12 -7
- data/lib/spontaneous/search/results.rb +5 -3
- data/lib/spontaneous/server.rb +2 -2
- data/lib/spontaneous/site.rb +10 -3
- data/lib/spontaneous/site/features.rb +26 -6
- data/lib/spontaneous/site/helpers.rb +9 -12
- data/lib/spontaneous/site/level.rb +7 -9
- data/lib/spontaneous/site/map.rb +9 -11
- data/lib/spontaneous/site/paths.rb +5 -5
- data/lib/spontaneous/site/publishing.rb +83 -80
- data/lib/spontaneous/site/schema.rb +1 -7
- data/lib/spontaneous/site/search.rb +8 -18
- data/lib/spontaneous/site/selectors.rb +60 -54
- data/lib/spontaneous/site/state.rb +36 -30
- data/lib/spontaneous/site/storage.rb +10 -16
- data/lib/spontaneous/state.rb +8 -0
- data/lib/spontaneous/style.rb +32 -33
- data/lib/spontaneous/version.rb +1 -1
- data/spontaneous.gemspec +22 -21
- data/test/fixtures/public/templates/layouts/default.html.cut +1 -1
- data/test/fixtures/public/templates/layouts/default.pdf.cut +1 -1
- data/test/fixtures/public/templates/layouts/default.rss.cut +1 -1
- data/test/fixtures/search/config/indexes.rb +1 -1
- data/test/fixtures/serialisation/class_hash.yaml.erb +13 -1
- data/test/fixtures/serialisation/root_hash.yaml.erb +10 -0
- data/test/functional/test_application.rb +20 -24
- data/test/functional/test_back.rb +26 -27
- data/test/functional/test_cli.rb +146 -0
- data/test/functional/test_front.rb +287 -216
- data/test/functional/test_user_manager.rb +1 -1
- data/test/test_helper.rb +15 -11
- data/test/unit/test_alias.rb +32 -25
- data/test/unit/test_asset_bundler.rb +1 -1
- data/test/unit/test_assets.rb +34 -33
- data/test/unit/test_authentication.rb +1 -1
- data/test/unit/test_boxes.rb +16 -2
- data/test/unit/test_changesets.rb +23 -11
- data/test/unit/test_content.rb +15 -0
- data/test/unit/test_context.rb +139 -0
- data/test/unit/test_controllers.rb +374 -0
- data/test/{experimental → unit}/test_crypt.rb +0 -0
- data/test/unit/test_datamapper.rb +260 -237
- data/test/unit/test_datamapper_content.rb +42 -12
- data/test/{experimental → unit}/test_features.rb +85 -3
- data/test/unit/test_fields.rb +117 -42
- data/test/unit/test_formats.rb +11 -1
- data/test/unit/test_generators.rb +2 -2
- data/test/unit/test_helpers.rb +7 -8
- data/test/unit/test_images.rb +39 -2
- data/test/unit/test_layouts.rb +14 -12
- data/test/unit/test_media.rb +32 -23
- data/test/unit/test_output_store.rb +342 -0
- data/test/unit/test_page.rb +8 -1
- data/test/unit/test_permissions.rb +11 -7
- data/test/unit/test_plugins.rb +3 -3
- data/test/unit/test_prototype_set.rb +8 -1
- data/test/unit/test_publishing.rb +67 -54
- data/test/unit/test_render.rb +91 -38
- data/test/unit/test_revisions.rb +4 -4
- data/test/unit/test_schema.rb +109 -84
- data/test/unit/test_search.rb +42 -42
- data/test/unit/test_serialisation.rb +3 -2
- data/test/unit/test_site.rb +39 -27
- data/test/unit/test_storage.rb +9 -6
- data/test/unit/test_styles.rb +25 -32
- data/test/unit/test_templates.rb +8 -4
- metadata +89 -54
- data/lib/spontaneous/model/page/request.rb +0 -105
- data/lib/spontaneous/storage.rb +0 -22
data/lib/spontaneous/rack.rb
CHANGED
@@ -21,6 +21,7 @@ module Spontaneous
|
|
21
21
|
# Rack env params
|
22
22
|
ACTIVE_USER = "spot.user".freeze
|
23
23
|
ACTIVE_KEY = "spot.key".freeze
|
24
|
+
SITE = "spot.site".freeze
|
24
25
|
RENDERER = "spot.renderer".freeze
|
25
26
|
REVISION = "spot.revision".freeze
|
26
27
|
CSRF_VALID = "spot.csrf_valid".freeze
|
@@ -36,12 +37,12 @@ module Spontaneous
|
|
36
37
|
include Constants
|
37
38
|
|
38
39
|
class << self
|
39
|
-
def application
|
40
|
+
def application(site)
|
40
41
|
case Spontaneous.mode
|
41
42
|
when :back
|
42
|
-
Back.application
|
43
|
+
Back.application(site)
|
43
44
|
when :front
|
44
|
-
Front.application
|
45
|
+
Front.application(site)
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
@@ -49,12 +50,12 @@ module Spontaneous
|
|
49
50
|
Site.config.port
|
50
51
|
end
|
51
52
|
|
52
|
-
def make_front_controller(controller_class)
|
53
|
-
Spontaneous::Rack::Front.make_controller(controller_class)
|
53
|
+
def make_front_controller(controller_class, site)
|
54
|
+
Spontaneous::Rack::Front.make_controller(controller_class, site)
|
54
55
|
end
|
55
56
|
|
56
|
-
def make_back_controller(controller_class)
|
57
|
-
Spontaneous::Rack::Back.make_controller(controller_class)
|
57
|
+
def make_back_controller(controller_class, site)
|
58
|
+
Spontaneous::Rack::Back.make_controller(controller_class, site)
|
58
59
|
end
|
59
60
|
end
|
60
61
|
|
@@ -62,6 +63,10 @@ module Spontaneous
|
|
62
63
|
include Constants
|
63
64
|
|
64
65
|
set :environment, Proc.new { Spontaneous.environment }
|
66
|
+
|
67
|
+
def site
|
68
|
+
@site ||= env[Spontaneous::Rack::SITE]
|
69
|
+
end
|
65
70
|
end
|
66
71
|
|
67
72
|
autoload :Assets, 'spontaneous/rack/assets'
|
@@ -27,16 +27,9 @@ module Spontaneous
|
|
27
27
|
include Spontaneous::Rack::Constants
|
28
28
|
include Spontaneous::Rack::Middleware
|
29
29
|
|
30
|
-
def self.make_controller(
|
31
|
-
|
32
|
-
|
33
|
-
use Scope::Edit
|
34
|
-
use Authenticate::Init
|
35
|
-
use Authenticate::Edit
|
36
|
-
use CSRF::Header
|
37
|
-
use CSRF::Verification
|
38
|
-
run controller_class
|
39
|
-
end
|
30
|
+
def self.make_controller(app, site)
|
31
|
+
app.helpers Helpers if app.respond_to?(:helpers)
|
32
|
+
app
|
40
33
|
end
|
41
34
|
|
42
35
|
def self.api_handlers
|
@@ -53,80 +46,93 @@ module Spontaneous
|
|
53
46
|
["/shard", File::Sharded]]
|
54
47
|
end
|
55
48
|
|
56
|
-
def self.editing_app
|
49
|
+
def self.editing_app(site)
|
57
50
|
::Rack::Builder.app do
|
58
|
-
use Scope::Edit
|
51
|
+
use Scope::Edit, site
|
59
52
|
use ApplicationAssets
|
60
53
|
use UnsupportedBrowser
|
61
|
-
use Authenticate::Init
|
54
|
+
use Authenticate::Init, site
|
62
55
|
use Login
|
63
|
-
# Everything after this handler requires authentication
|
64
|
-
use Authenticate::Edit
|
56
|
+
use Authenticate::Edit # Everything after this handler requires authentication
|
65
57
|
use CSRF::Header
|
66
58
|
# Schema has to come before Reloader because we need to be able to
|
67
59
|
# present the conflict resolution interface without running through
|
68
60
|
# the schema validation step
|
69
61
|
map("/schema") { run Schema }
|
70
|
-
use Reloader
|
62
|
+
use Reloader, site
|
71
63
|
use Index
|
72
|
-
# Everything after this middleware requires a valid CSRF token
|
73
|
-
use CSRF::Verification
|
74
|
-
|
64
|
+
use CSRF::Verification # Everything after this middleware requires a valid CSRF token
|
75
65
|
Back.api_handlers.each do |path, app|
|
76
|
-
map(path)
|
66
|
+
map(path) { run app }
|
77
67
|
end
|
78
68
|
run lambda { |env| [ 404, {}, ["Not Found"] ] }
|
79
69
|
end
|
80
70
|
end
|
81
71
|
|
82
72
|
|
83
|
-
def self.preview_app
|
73
|
+
def self.preview_app(site)
|
84
74
|
::Rack::Builder.app do
|
85
75
|
use ::Rack::Lint if Spontaneous.development?
|
86
|
-
use Scope::Preview
|
87
|
-
use Authenticate::Init
|
76
|
+
use Scope::Preview, site
|
77
|
+
use Authenticate::Init, site
|
88
78
|
# Preview authentication redirects to /@spontaneous rather than
|
89
|
-
# showing a login screen. This way if you go to
|
79
|
+
# showing a login screen. This way if you go to the root of the site
|
90
80
|
# as an unauthorised user (say for the first time) you will get sent
|
91
81
|
# to the editing interface wrapper rather than being presented with
|
92
82
|
# the preview site.
|
93
83
|
use Authenticate::Preview
|
94
84
|
use CSRF::Header
|
95
85
|
map("/assets") { run SiteAssets.new }
|
96
|
-
use Spontaneous::Rack::Static, :
|
97
|
-
|
98
|
-
|
99
|
-
|
86
|
+
use Spontaneous::Rack::Static, root: Spontaneous.root / "public", urls: %w[/], try: ['.html', 'index.html', '/index.html']
|
87
|
+
use Reloader, site
|
88
|
+
# inject the front controllers into the preview so that this is a
|
89
|
+
# full duplicate of the live site
|
90
|
+
site.front.middleware.each do |args, block|
|
91
|
+
use *args, &block
|
92
|
+
end
|
93
|
+
site.front_controllers.each do |namespace, controller_class|
|
94
|
+
map namespace do
|
95
|
+
run controller_class
|
96
|
+
end
|
97
|
+
end
|
100
98
|
run Preview
|
101
99
|
end
|
102
100
|
end
|
103
101
|
|
104
|
-
def self.application
|
102
|
+
def self.application(site)
|
105
103
|
app = ::Rack::Builder.new do
|
106
|
-
|
107
|
-
map(namespace)
|
108
|
-
|
104
|
+
site.back_controllers.each do |namespace, controller|
|
105
|
+
map(namespace) do
|
106
|
+
use Scope::Edit, site
|
107
|
+
use Authenticate::Init, site
|
108
|
+
use Authenticate::Edit
|
109
|
+
use CSRF::Header
|
110
|
+
use CSRF::Verification
|
111
|
+
run controller
|
112
|
+
end
|
113
|
+
end
|
109
114
|
|
110
115
|
# Make all the files available under plugin_name/public/**
|
111
116
|
# available under the URL /plugin_name/**
|
112
117
|
# This needs to be handled by the asset system
|
113
118
|
# so that /assets/<plugin_name>/file.css is properly found
|
114
119
|
# and processed through sprockets
|
115
|
-
|
120
|
+
site.plugins.each do |plugin|
|
116
121
|
root = plugin.paths.expanded(:public)
|
122
|
+
|
117
123
|
map "/#{plugin.file_namespace}" do
|
118
|
-
use Spontaneous::Rack::CSS, :
|
124
|
+
use Spontaneous::Rack::CSS, root: root
|
119
125
|
run ::Rack::File.new(root)
|
120
126
|
end
|
121
|
-
end if
|
127
|
+
end if site
|
122
128
|
|
123
129
|
map "/media" do
|
124
130
|
use ::Rack::Lint
|
125
131
|
run Spontaneous::Rack::CacheableFile.new(Spontaneous.media_dir)
|
126
132
|
end
|
127
133
|
|
128
|
-
map(NAMESPACE) { run Spontaneous::Rack::Back.editing_app }
|
129
|
-
map("/") { run Spontaneous::Rack::Back.preview_app }
|
134
|
+
map(NAMESPACE) { run Spontaneous::Rack::Back.editing_app(site) }
|
135
|
+
map("/") { run Spontaneous::Rack::Back.preview_app(site) }
|
130
136
|
end
|
131
137
|
end
|
132
138
|
end
|
@@ -6,13 +6,13 @@ module Spontaneous::Rack
|
|
6
6
|
set :views, Proc.new { Spontaneous.application_dir + '/views' }
|
7
7
|
|
8
8
|
def content_model
|
9
|
-
|
9
|
+
site.model
|
10
10
|
end
|
11
11
|
|
12
|
-
def update_fields(
|
12
|
+
def update_fields(content, field_data)
|
13
13
|
return unless field_data
|
14
|
-
Spontaneous::Field.update_asynchronously(
|
15
|
-
json(
|
14
|
+
Spontaneous::Field.update_asynchronously(site, content, field_data, user)
|
15
|
+
json(content)
|
16
16
|
end
|
17
17
|
|
18
18
|
def content_for_request(lock = false)
|
@@ -5,14 +5,14 @@ module Spontaneous::Rack::Back
|
|
5
5
|
end
|
6
6
|
|
7
7
|
get '/?' do
|
8
|
-
json(Spontaneous::Change)
|
8
|
+
json(Spontaneous::Change.export(site))
|
9
9
|
end
|
10
10
|
|
11
11
|
post '/?' do
|
12
12
|
ids = params[:page_ids]
|
13
13
|
halt 400 if ids.blank? || ids.empty?
|
14
14
|
pages = ids.map(&:to_i)
|
15
|
-
|
15
|
+
site.publish_pages(pages)
|
16
16
|
json({})
|
17
17
|
end
|
18
18
|
end
|
@@ -9,7 +9,7 @@ module Spontaneous::Rack::Back
|
|
9
9
|
forbidden! unless target.field_writable?(user, field.name)
|
10
10
|
# version = params[:version].to_i
|
11
11
|
# if version == field.version
|
12
|
-
Spontaneous::Field.set_asynchronously(field, file, user)
|
12
|
+
Spontaneous::Field.set_asynchronously(site, field, file, user)
|
13
13
|
json(field.export(user))
|
14
14
|
# else
|
15
15
|
# errors = [[field.schema_id.to_s, [field.version, field.conflicted_value]]]
|
@@ -28,7 +28,7 @@ module Spontaneous::Rack::Back
|
|
28
28
|
instance = type.new
|
29
29
|
box.insert(position, instance)
|
30
30
|
field = instance.field_for_mime_type(file[:type])
|
31
|
-
Spontaneous::Field.set_asynchronously(field, file, user)
|
31
|
+
Spontaneous::Field.set_asynchronously(site, field, file, user)
|
32
32
|
content.save
|
33
33
|
json({
|
34
34
|
:position => position,
|
@@ -71,20 +71,6 @@ module Spontaneous::Rack::Back
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
def replace_with_shard(target, target_id)
|
75
|
-
field = target.fields.sid(params[:field])
|
76
|
-
forbidden! unless target.field_writable?(user, field.name)
|
77
|
-
# version = params[:version].to_i
|
78
|
-
# if version == field.version
|
79
|
-
Spontaneous::Media.combine_shards(params[:shards]) do |combined|
|
80
|
-
Spontaneous::Field.set_asynchronously(field, {
|
81
|
-
:filename => params[:filename],
|
82
|
-
:tempfile => combined
|
83
|
-
}, user)
|
84
|
-
end
|
85
|
-
json(field.export(user))
|
86
|
-
end
|
87
|
-
|
88
74
|
# TODO: remove duplication here
|
89
75
|
post '/:id/:box_id' do
|
90
76
|
content_for_request(true) do |content, box|
|
@@ -96,15 +82,9 @@ module Spontaneous::Rack::Back
|
|
96
82
|
box.insert(position, instance)
|
97
83
|
field = instance.field_for_mime_type(params[:mime_type])
|
98
84
|
Spontaneous::Media.combine_shards(params[:shards]) do |combined|
|
99
|
-
|
100
|
-
|
101
|
-
:tempfile => combined
|
102
|
-
}, user)
|
85
|
+
tempfile = { :filename => params[:filename], :tempfile => combined }
|
86
|
+
Spontaneous::Field.set_asynchronously(site, field, tempfile, user)
|
103
87
|
content.save
|
104
|
-
# field.value = {
|
105
|
-
# :filename => params[:filename],
|
106
|
-
# :tempfile => combined
|
107
|
-
# }
|
108
88
|
end
|
109
89
|
json({
|
110
90
|
:position => position,
|
@@ -113,6 +93,18 @@ module Spontaneous::Rack::Back
|
|
113
93
|
end
|
114
94
|
end
|
115
95
|
end
|
96
|
+
|
97
|
+
def replace_with_shard(target, target_id)
|
98
|
+
field = target.fields.sid(params[:field])
|
99
|
+
forbidden! unless target.field_writable?(user, field.name)
|
100
|
+
# version = params[:version].to_i
|
101
|
+
# if version == field.version
|
102
|
+
Spontaneous::Media.combine_shards(params[:shards]) do |combined|
|
103
|
+
tempfile = { :filename => params[:filename], :tempfile => combined }
|
104
|
+
Spontaneous::Field.set_asynchronously(site, field, tempfile, user)
|
105
|
+
end
|
106
|
+
json(field.export(user))
|
107
|
+
end
|
116
108
|
end
|
117
109
|
end
|
118
110
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Spontaneous::Rack::Back
|
2
2
|
class Map < Base
|
3
3
|
get '/?:id?' do
|
4
|
-
last_modified(
|
5
|
-
map =
|
4
|
+
last_modified(site.modified_at)
|
5
|
+
map = site.map(params[:id])
|
6
6
|
if map
|
7
7
|
json(map)
|
8
8
|
else
|
@@ -11,13 +11,13 @@ module Spontaneous::Rack::Back
|
|
11
11
|
end
|
12
12
|
|
13
13
|
get '/path*' do
|
14
|
-
last_modified(
|
14
|
+
last_modified(site.modified_at)
|
15
15
|
if content_model::Page.count == 0
|
16
16
|
406
|
17
17
|
else
|
18
18
|
path = params[:splat].first
|
19
|
-
page =
|
20
|
-
json
|
19
|
+
page = site[path]
|
20
|
+
json site.map(page.id)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -2,19 +2,18 @@ module Spontaneous::Rack::Back
|
|
2
2
|
class Preview < Base
|
3
3
|
include Spontaneous::Rack::Public
|
4
4
|
|
5
|
-
|
6
5
|
# In preview mode we want to find pages even if they're
|
7
6
|
# invisible.
|
8
7
|
def find_page_by_path(path)
|
9
|
-
|
10
|
-
|
8
|
+
site.model.scope do
|
9
|
+
site.by_path(path)
|
11
10
|
end
|
12
11
|
end
|
13
12
|
|
14
13
|
# Redirect to the edit UI if a preview page is being accessed directly
|
15
14
|
def ensure_edit_preview(path)
|
16
15
|
referer = env['HTTP_REFERER']
|
17
|
-
development_preview = Spontaneous.development? &&
|
16
|
+
development_preview = Spontaneous.development? && site.model::Page.has_root?
|
18
17
|
return true if development_preview || referer || params.key?('preview')
|
19
18
|
home = find_page_by_path(path)
|
20
19
|
# Need to handle the site initialisation where there is no homepage
|
@@ -1,22 +1,21 @@
|
|
1
1
|
module Spontaneous::Rack::Back
|
2
2
|
class Site < Base
|
3
|
-
SS = Spontaneous::Site
|
4
3
|
|
5
4
|
get '/?' do
|
6
5
|
json({
|
7
|
-
:
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
6
|
+
types: site.schema.export(user),
|
7
|
+
roots: site.roots(user),
|
8
|
+
user: user.export,
|
9
|
+
services: (site.config.services || [])
|
11
10
|
})
|
12
11
|
end
|
13
12
|
|
14
13
|
get '/home' do
|
15
|
-
json
|
14
|
+
json site.home
|
16
15
|
end
|
17
16
|
|
18
17
|
post '/home' do
|
19
|
-
forbidden! unless
|
18
|
+
forbidden! unless site.home.nil?
|
20
19
|
type = content_model.schema.to_class(params[:type])
|
21
20
|
root = type.create(:title => "Home")
|
22
21
|
json({:id => root.id})
|
@@ -7,41 +7,40 @@ module Spontaneous
|
|
7
7
|
module Front
|
8
8
|
include Spontaneous::Rack::Middleware
|
9
9
|
|
10
|
-
def self.make_controller(controller_class)
|
11
|
-
|
12
|
-
use Scope::Front
|
13
|
-
run controller_class
|
14
|
-
end
|
10
|
+
def self.make_controller(controller_class, site)
|
11
|
+
controller_class
|
15
12
|
end
|
16
13
|
|
17
|
-
def self.front_app
|
14
|
+
def self.front_app(site)
|
18
15
|
::Rack::Builder.app do
|
19
|
-
use Scope::Front
|
20
|
-
use Reloader if Spontaneous.development?
|
16
|
+
use Scope::Front, site
|
17
|
+
use Reloader, site if Spontaneous.development?
|
21
18
|
run Server.new
|
22
19
|
end
|
23
20
|
end
|
24
21
|
|
25
|
-
def self.application
|
22
|
+
def self.application(site)
|
26
23
|
app = ::Rack::Builder.new do
|
27
|
-
use Spontaneous::Rack::Static, :
|
28
|
-
|
29
|
-
|
24
|
+
use Spontaneous::Rack::Static, root: Spontaneous.revision_dir / "public", urls: %w[/], try: ['.html', 'index.html', '/index.html']
|
25
|
+
|
26
|
+
Spontaneous.instance.front.middleware.each do |args, block|
|
27
|
+
use *args, &block
|
28
|
+
end
|
30
29
|
|
31
30
|
Spontaneous.instance.front_controllers.each do |namespace, controller_class|
|
32
31
|
map namespace do
|
33
32
|
run controller_class
|
34
33
|
end
|
35
|
-
end
|
34
|
+
end
|
36
35
|
|
37
36
|
# Make all the files available under plugin_name/public/**
|
38
37
|
# available under the URL /plugin_name/**
|
39
38
|
# Only used in preview mode
|
40
|
-
|
39
|
+
site.plugins.each do |plugin|
|
41
40
|
map "/#{plugin.name}" do
|
42
41
|
run ::Rack::File.new(plugin.paths.expanded(:public))
|
43
42
|
end
|
44
|
-
end
|
43
|
+
end
|
45
44
|
|
46
45
|
map "/rev" do
|
47
46
|
run Spontaneous::Rack::CacheableFile.new(Spontaneous.revision_dir / "rev")
|
@@ -56,7 +55,7 @@ module Spontaneous
|
|
56
55
|
end
|
57
56
|
|
58
57
|
map "/" do
|
59
|
-
run Spontaneous::Rack::Front.front_app
|
58
|
+
run Spontaneous::Rack::Front.front_app(site)
|
60
59
|
end
|
61
60
|
end
|
62
61
|
end
|
@@ -72,6 +71,10 @@ module Spontaneous
|
|
72
71
|
|
73
72
|
render_path(@request.path_info)
|
74
73
|
end
|
74
|
+
|
75
|
+
def site
|
76
|
+
@site ||= env[Spontaneous::Rack::SITE]
|
77
|
+
end
|
75
78
|
end
|
76
79
|
end
|
77
80
|
end
|