scrivito_sdk 0.41.1 → 0.42.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/scrivito/workspaces_controller.rb +12 -1
- data/config/ca-bundle.crt +1 -1
- data/lib/assets/javascripts/scrivito_ui.js +8 -0
- data/lib/assets/stylesheets/scrivito_sdk.css +1 -1
- data/lib/assets/stylesheets/scrivito_ui.css +1 -1
- data/lib/scrivito/attribute_content.rb +104 -0
- data/lib/scrivito/attribute_definition.rb +38 -0
- data/lib/scrivito/attribute_definition_collection.rb +41 -0
- data/lib/scrivito/class_collection.rb +27 -0
- data/lib/scrivito/client_config.rb +2 -1
- data/lib/scrivito/model_library.rb +118 -0
- data/lib/scrivito/sdk_engine.rb +7 -1
- data/lib/scrivito/user.rb +3 -2
- data/lib/scrivito/workspace_data.rb +19 -0
- data/lib/scrivito/workspace_data_from_rest_api.rb +6 -0
- data/lib/scrivito/workspace_data_from_service.rb +1 -14
- data/lib/scrivito_sdk.rb +94 -0
- metadata +8 -2
data/lib/scrivito/sdk_engine.rb
CHANGED
@@ -6,7 +6,13 @@ require 'net/http/post/multipart'
|
|
6
6
|
|
7
7
|
module ::Scrivito
|
8
8
|
class SdkEngine < Rails::Engine
|
9
|
-
config.to_prepare
|
9
|
+
config.to_prepare do
|
10
|
+
Scrivito::Configuration.to_prepare
|
11
|
+
|
12
|
+
unless Rails.application.config.cache_classes
|
13
|
+
Scrivito.models.clear_cache
|
14
|
+
end
|
15
|
+
end
|
10
16
|
|
11
17
|
# make sure our exceptions cause an adequate error page and http status code
|
12
18
|
config.action_dispatch.rescue_responses.merge!("Scrivito::ResourceNotFound" => :not_found)
|
data/lib/scrivito/user.rb
CHANGED
@@ -108,8 +108,9 @@ module Scrivito
|
|
108
108
|
|
109
109
|
def can?(verb, workspace)
|
110
110
|
assert_valid_verb(verb)
|
111
|
-
verb == :read && workspace.published? ||
|
112
|
-
|
111
|
+
verb == :read && workspace.published? ||
|
112
|
+
can_always?(verb, :workspace) ||
|
113
|
+
verb != :create && owner_of?(workspace) && !can_never?(verb, :workspace)
|
113
114
|
end
|
114
115
|
|
115
116
|
def can_always?(verb, subject)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Scrivito
|
2
|
+
class WorkspaceData
|
3
|
+
class << self
|
4
|
+
private
|
5
|
+
|
6
|
+
def data_attr_reader(attr_name)
|
7
|
+
define_method(attr_name) { @data[attr_name.to_s] }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
data_attr_reader :id
|
12
|
+
data_attr_reader :title
|
13
|
+
data_attr_reader :memberships
|
14
|
+
|
15
|
+
def initialize(data)
|
16
|
+
@data = data
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Scrivito
|
2
2
|
|
3
|
-
class WorkspaceDataFromService
|
3
|
+
class WorkspaceDataFromService < WorkspaceData
|
4
4
|
class << self
|
5
5
|
# Fetches a workspace data previously store in cache storage.
|
6
6
|
# Returns nil if not found.
|
@@ -9,26 +9,13 @@ class WorkspaceDataFromService
|
|
9
9
|
new(data)
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def data_attr_reader(attr_name)
|
16
|
-
define_method(attr_name) { @data[attr_name.to_s] }
|
17
|
-
end
|
18
12
|
end
|
19
13
|
|
20
|
-
data_attr_reader :id
|
21
|
-
data_attr_reader :title
|
22
14
|
data_attr_reader :revision_id
|
23
15
|
data_attr_reader :content_state_id
|
24
16
|
data_attr_reader :base_revision_id
|
25
17
|
data_attr_reader :base_content_state_id
|
26
18
|
data_attr_reader :diff
|
27
|
-
data_attr_reader :memberships
|
28
|
-
|
29
|
-
def initialize(data)
|
30
|
-
@data = data
|
31
|
-
end
|
32
19
|
|
33
20
|
def content_state
|
34
21
|
@content_state ||= ContentState.find_or_create(content_state_id) if content_state_id
|
data/lib/scrivito_sdk.rb
CHANGED
@@ -18,6 +18,100 @@ module Scrivito
|
|
18
18
|
yield Configuration
|
19
19
|
end
|
20
20
|
|
21
|
+
#
|
22
|
+
# Configures which models Scrivito assumes as pages and widgets.
|
23
|
+
#
|
24
|
+
# @api private
|
25
|
+
#
|
26
|
+
# In order to display a page class selection dialog and a widget class selection dialog, Scrivito
|
27
|
+
# needs to know which page models and widget models are available. That models can be defined in
|
28
|
+
# the Rails application itself or in 3rd-party gems.
|
29
|
+
#
|
30
|
+
# Scrivito will automatically assume all the classes descending from {Scrivito::BasicObj}, whose
|
31
|
+
# class names are ending with +Page+ are pages (e.g. +MyPage+, +HomePage+, +BlogPostPage+ etc.).
|
32
|
+
# It will also automatically assume all the classes descending from {Scrivito::BasicWidget}, whose
|
33
|
+
# class names are ending with +Widget+ are widgets (e.g. +TextWidget+, +ImageWdidget+ etc.).
|
34
|
+
#
|
35
|
+
# Scrivito will recursively scan for such models in all directories from
|
36
|
+
# {Scrivito::ModelLibrary#paths Scrivito.models.paths}, which is an array of strings.
|
37
|
+
# It by default includes the directory +app/models+ of the Rails application. For example it will
|
38
|
+
# find following page and widget models:
|
39
|
+
#
|
40
|
+
# +app/models/my_page.rb+
|
41
|
+
#
|
42
|
+
# +app/models/my_widget.rb+
|
43
|
+
#
|
44
|
+
# +app/models/my_namespace/my_other_page.rb+
|
45
|
+
#
|
46
|
+
# +app/models/my_namespace/my_other_widget.rb+
|
47
|
+
#
|
48
|
+
# +app/models/my_namespace/my_other_namespace/my_other_special_page.rb+
|
49
|
+
#
|
50
|
+
# +app/models/my_namespace/my_other_namespace/my_other_special_widget.rb+
|
51
|
+
#
|
52
|
+
# Also {Scrivito::ModelLibrary#paths Scrivito.models.paths} will include all directories ending
|
53
|
+
# with +app/models+ of any available Rails engine, as long as that directory is included in the
|
54
|
+
# autoload paths of Rails (which is the default). For example it will find following page and
|
55
|
+
# widget models in an engine:
|
56
|
+
#
|
57
|
+
# +/../some_engine/app/models/my_page.rb+
|
58
|
+
#
|
59
|
+
# +/../some_engine/app/models/my_widget.rb+
|
60
|
+
#
|
61
|
+
# +/../some_engine/app/models/my_namespace/my_other_page.rb+
|
62
|
+
#
|
63
|
+
# +/../some_engine/app/models/my_namespace/my_other_widget.rb+
|
64
|
+
#
|
65
|
+
# +/../some_engine/app/models/my_namespace/my_other_namespace/my_other_special_page.rb+
|
66
|
+
#
|
67
|
+
# +/../some_engine/app/models/my_namespace/my_other_namespace/my_other_special_widget.rb+
|
68
|
+
#
|
69
|
+
# You can add custom directories to scan for models and register single page and widget models
|
70
|
+
# with {Scrivito::ModelLibrary#define Scrivito.models.define} (see examples below).
|
71
|
+
#
|
72
|
+
# The loaded pages can be inspected with {Scrivito::ModelLibrary#pages Scrivito.models.pages},
|
73
|
+
# which will return a {Scrivito::ClassCollection} containing all available pages.
|
74
|
+
# The loaded widgets can be inspected with {Scrivito::ModelLibrary#widgets Scrivito.models.widgets},
|
75
|
+
# which will return a {Scrivito::ClassCollection} containing all available widgets.
|
76
|
+
#
|
77
|
+
# The scan results are cached. If +Rails.application.config.cache_classes+ is +false+, then the
|
78
|
+
# cache will be cleared on every request. Otherwise the cache will be kept between the requests.
|
79
|
+
# You can clear the cache with {Scrivito::ModelLibrary#clear_cache Scrivito.models.clear_cache}.
|
80
|
+
#
|
81
|
+
# @example Register a custom path
|
82
|
+
# Scrivito.models.define do
|
83
|
+
# paths << Rails.root + 'lib/special_models'
|
84
|
+
# end
|
85
|
+
#
|
86
|
+
# @example Register pages and widgets with inconvenient names
|
87
|
+
# Scrivito.models.define do
|
88
|
+
# page 'MyCrazyPageModel'
|
89
|
+
# page 'MyOtherCrazyPageModel1', 'MyOtherCrazyPageModel2'
|
90
|
+
#
|
91
|
+
# widget 'MyCrazyWidgetModel'
|
92
|
+
# widget 'MyOtherCrazyWidgetModel1', 'MyOtherCrazyWidgetModel2'
|
93
|
+
# end
|
94
|
+
#
|
95
|
+
# @example Iterate over available pages
|
96
|
+
# Scrivito.models.pages.each do |page_class|
|
97
|
+
# puts page_class.name
|
98
|
+
# end
|
99
|
+
# #=> "MyPage"
|
100
|
+
# #=> "MyOtherPage"
|
101
|
+
# # ...
|
102
|
+
#
|
103
|
+
# @example Iterate over available widgets
|
104
|
+
# Scrivito.models.widgets.each do |widget_class|
|
105
|
+
# puts widget_class.name
|
106
|
+
# end
|
107
|
+
# #=> "MyWidget"
|
108
|
+
# #=> "MyOtherWidget"
|
109
|
+
# # ...
|
110
|
+
#
|
111
|
+
def self.models
|
112
|
+
@models ||= ModelLibrary.new
|
113
|
+
end
|
114
|
+
|
21
115
|
def self.autoload_all_sources
|
22
116
|
source_files = Dir.glob(File.expand_path("../scrivito/*.rb", __FILE__)).map do |file|
|
23
117
|
File.basename(file)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scrivito_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.42.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Infopark AG
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -256,6 +256,8 @@ files:
|
|
256
256
|
- lib/scrivito/attribute.rb
|
257
257
|
- lib/scrivito/attribute_collection.rb
|
258
258
|
- lib/scrivito/attribute_content.rb
|
259
|
+
- lib/scrivito/attribute_definition.rb
|
260
|
+
- lib/scrivito/attribute_definition_collection.rb
|
259
261
|
- lib/scrivito/backend_error.rb
|
260
262
|
- lib/scrivito/basic_obj.rb
|
261
263
|
- lib/scrivito/basic_widget.rb
|
@@ -267,6 +269,7 @@ files:
|
|
267
269
|
- lib/scrivito/cache_garbage_collector.rb
|
268
270
|
- lib/scrivito/cache_middleware.rb
|
269
271
|
- lib/scrivito/child_list_tag.rb
|
272
|
+
- lib/scrivito/class_collection.rb
|
270
273
|
- lib/scrivito/client_config.rb
|
271
274
|
- lib/scrivito/client_error.rb
|
272
275
|
- lib/scrivito/cms_backend.rb
|
@@ -314,6 +317,7 @@ files:
|
|
314
317
|
- lib/scrivito/migrations/migrator.rb
|
315
318
|
- lib/scrivito/migrations/workspace_lock.rb
|
316
319
|
- lib/scrivito/model_identity.rb
|
320
|
+
- lib/scrivito/model_library.rb
|
317
321
|
- lib/scrivito/modification.rb
|
318
322
|
- lib/scrivito/named_link.rb
|
319
323
|
- lib/scrivito/network_error.rb
|
@@ -348,6 +352,8 @@ files:
|
|
348
352
|
- lib/scrivito/widget_tag.rb
|
349
353
|
- lib/scrivito/workspace.rb
|
350
354
|
- lib/scrivito/workspace/publish_checker.rb
|
355
|
+
- lib/scrivito/workspace_data.rb
|
356
|
+
- lib/scrivito/workspace_data_from_rest_api.rb
|
351
357
|
- lib/scrivito/workspace_data_from_service.rb
|
352
358
|
- lib/scrivito/workspace_selection_middleware.rb
|
353
359
|
- lib/scrivito_sdk.rb
|