scrivito_sdk 1.0.0 → 1.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/README.md +1 -1
  4. data/app/controllers/scrivito/legacy_redirect_controller.rb +11 -0
  5. data/app/controllers/scrivito/objs_controller.rb +15 -5
  6. data/app/controllers/scrivito/webservice_controller.rb +4 -3
  7. data/app/controllers/scrivito/workspaces_controller.rb +24 -29
  8. data/app/helpers/scrivito_helper.rb +82 -37
  9. data/app/views/scrivito/objs/binary_no_cache.json.jbuilder +1 -0
  10. data/app/views/scrivito/objs/search.json.jbuilder +5 -5
  11. data/app/views/scrivito/webservice/error.json.jbuilder +2 -2
  12. data/config/ca-bundle.crt +1 -1
  13. data/config/precedence_routes.rb +51 -48
  14. data/config/routes.rb +1 -14
  15. data/lib/assets/javascripts/scrivito_ui.js +2447 -266
  16. data/lib/assets/stylesheets/scrivito.css +1 -1
  17. data/lib/assets/stylesheets/scrivito_ui.css +1 -1
  18. data/lib/generators/scrivito/install/install_generator.rb +12 -0
  19. data/lib/generators/scrivito/install/templates/config/initializers/scrivito.rb +3 -0
  20. data/lib/scrivito/attribute_definition.rb +13 -1
  21. data/lib/scrivito/attribute_deserializer.rb +4 -4
  22. data/lib/scrivito/attribute_value_renderer.rb +79 -0
  23. data/lib/scrivito/backend/obj_data_cache.rb +15 -15
  24. data/lib/scrivito/backend/obj_data_from_rest.rb +1 -21
  25. data/lib/scrivito/backend/obj_query.rb +2 -2
  26. data/lib/scrivito/basic_obj.rb +17 -6
  27. data/lib/scrivito/binary.rb +13 -5
  28. data/lib/scrivito/cache/chainable.rb +10 -5
  29. data/lib/scrivito/cache/file_store.rb +4 -0
  30. data/lib/scrivito/cache/ram_store.rb +4 -0
  31. data/lib/scrivito/child_list_tag.rb +16 -14
  32. data/lib/scrivito/client_error.rb +10 -0
  33. data/lib/scrivito/cms_backend.rb +66 -291
  34. data/lib/scrivito/cms_data_cache.rb +7 -9
  35. data/lib/scrivito/cms_dispatch_controller.rb +1 -10
  36. data/lib/scrivito/cms_field_tag.rb +2 -1
  37. data/lib/scrivito/cms_rest_api.rb +2 -0
  38. data/lib/scrivito/cms_routing.rb +26 -22
  39. data/lib/scrivito/configuration.rb +38 -0
  40. data/lib/scrivito/connection_manager.rb +69 -0
  41. data/lib/scrivito/controller_actions.rb +2 -2
  42. data/lib/scrivito/controller_helper.rb +2 -2
  43. data/lib/scrivito/date_attribute.rb +4 -1
  44. data/lib/scrivito/deprecation.rb +5 -4
  45. data/lib/scrivito/editing_context.rb +2 -2
  46. data/lib/scrivito/errors.rb +17 -0
  47. data/lib/scrivito/image_tag.rb +2 -2
  48. data/lib/scrivito/link_parser.rb +10 -5
  49. data/lib/scrivito/meta_data_collection.rb +11 -0
  50. data/lib/scrivito/obj_collection.rb +1 -1
  51. data/lib/scrivito/obj_facet_value.rb +19 -7
  52. data/lib/scrivito/obj_params_parser.rb +43 -14
  53. data/lib/scrivito/obj_search_builder.rb +1 -2
  54. data/lib/scrivito/obj_search_enumerator/batch.rb +22 -0
  55. data/lib/scrivito/obj_search_enumerator/batch_iterator.rb +36 -0
  56. data/lib/scrivito/obj_search_enumerator/query_executor.rb +35 -0
  57. data/lib/scrivito/obj_search_enumerator.rb +218 -93
  58. data/lib/scrivito/obj_update_params_parser.rb +1 -0
  59. data/lib/scrivito/preset_routes.rb +25 -0
  60. data/lib/scrivito/revision.rb +13 -11
  61. data/lib/scrivito/route.rb +62 -0
  62. data/lib/scrivito/routing_extensions.rb +92 -0
  63. data/lib/scrivito/sdk_engine.rb +4 -0
  64. data/lib/scrivito/task.rb +77 -0
  65. data/lib/scrivito/type_computer.rb +3 -3
  66. data/lib/scrivito/ui_config.rb +4 -0
  67. data/lib/scrivito/user.rb +24 -18
  68. data/lib/scrivito/workspace/publish_checker.rb +2 -3
  69. data/lib/scrivito/workspace.rb +38 -6
  70. data/lib/scrivito/workspace_data.rb +0 -14
  71. metadata +14 -10
  72. data/lib/scrivito/content_service.rb +0 -121
  73. data/lib/scrivito/content_state.rb +0 -109
  74. data/lib/scrivito/content_state_caching.rb +0 -47
  75. data/lib/scrivito/content_state_visitor.rb +0 -19
  76. data/lib/scrivito/obj_data_from_service.rb +0 -63
  77. data/lib/scrivito/workspace_data_from_service.rb +0 -43
@@ -1,109 +0,0 @@
1
- module Scrivito
2
-
3
- # This class represents a single instance of a content state.
4
- # Basically a content state has three important characteristics: cache with obj datas,
5
- # changes representing changed objs and ways they has been changed and an ancestor content state.
6
- class ContentState < Struct.new(:content_state_id, :changes, :changes_index, :from_content_state_id)
7
- class << self
8
- private :new
9
-
10
- # Creates a new content state with given changes and ancestor (optional).
11
- def create(attributes)
12
- new(attributes).tap do |content_state|
13
- content_state.index_changes!
14
- CmsDataCache.write_content_state(content_state.content_state_id, content_state.to_hash)
15
- end
16
- end
17
-
18
- # Finds a previously saved content state.
19
- # Returns nil if not found.
20
- def find(content_state_id)
21
- if content_state_data = CmsDataCache.read_content_state(content_state_id)
22
- new(content_state_data)
23
- end
24
- end
25
-
26
- # Fetches an existing workspace.
27
- # If not found creates a new one and returns it.
28
- def find_or_create(content_state_id)
29
- find(content_state_id) || create(content_state_id: content_state_id)
30
- end
31
- end
32
-
33
- def initialize(attributes)
34
- super(*attributes.symbolize_keys.values_at(:content_state_id, :changes, :changes_index,
35
- :from_content_state_id))
36
- end
37
-
38
- # Stores arbitrary data in cache.
39
- # Cache key is build from given index and key.
40
- def save_obj_data(index, key, data)
41
- CmsDataCache.write_obj_data(content_state_id, index, key, data)
42
- end
43
-
44
- # Fetches previously stored arbitrary data from cache.
45
- # Returns nil if nothing found.
46
- # Cache key is build from given index and key.
47
- def find_obj_data(index, key)
48
- CmsDataCache.read_obj_data(content_state_id, index, key)
49
- end
50
-
51
- # Fetches and caches the ancestor.
52
- # Returns nil if there is no ancestor.
53
- def from_content_state
54
- @from_content_state ||= self.class.find(from_content_state_id)
55
- end
56
-
57
- # Determines whether given data is still up-to-date for given index and key.
58
- def has_changes_for?(index, key, data)
59
- case index
60
- when 'id'
61
- id_index.include?(key)
62
- when 'path'
63
- path_index.include?(key) || data.first && id_index.include?(data.first['_id'].first)
64
- when 'ppath'
65
- ppath_index.include?(key) || data.find { |d| id_index.include?(d['_id'].first) }
66
- end
67
- end
68
-
69
- # Computes for a given changes feed a set of access-efficient indexes.
70
- def index_changes!
71
- id_index, path_index, ppath_index = Set.new, Set.new, Set.new
72
- if changes.present?
73
- changes.each do |hash|
74
- id_index.add(hash['id'])
75
- if path = hash['modified_path']
76
- path_index.add(path)
77
- ppath_index.add(ParentPath.of(path)) if path != '/'
78
- end
79
- end
80
- end
81
- self.changes = nil
82
- self.changes_index = {'id' => id_index, 'path' => path_index, 'ppath' => ppath_index}
83
- end
84
-
85
- # Returns a hash representation of a content state for serialization purpose.
86
- def to_hash
87
- {
88
- content_state_id: content_state_id,
89
- changes_index: changes_index,
90
- from_content_state_id: from_content_state_id
91
- }
92
- end
93
-
94
- private
95
-
96
- def id_index
97
- @id_index ||= changes_index['id']
98
- end
99
-
100
- def path_index
101
- @path_index ||= changes_index['path']
102
- end
103
-
104
- def ppath_index
105
- @ppath_index ||= changes_index['ppath']
106
- end
107
- end
108
-
109
- end
@@ -1,47 +0,0 @@
1
- module Scrivito
2
-
3
- # This module provides advances auto-invalidating caching mechanism for storing obj data.
4
- #
5
- # To keep it up-to-date its caches and changes should be updated periodically
6
- # Its changes should be updated every time a new workspace data has been fetched.
7
- # Its caches should be updated every time a new obj data has been fetched.
8
- module ContentStateCaching
9
- class << self
10
- # How deep should a content state chain be inspected. Default depth is 20.
11
- attr_accessor :cache_lookup_depth
12
-
13
- # At which lookup depth to copy a hit found in an ancestor content state
14
- # to the current content state's cache. Default depth is 5.
15
- attr_accessor :cache_replication_depth
16
-
17
- # Updates caches with data from given workspace.
18
- # Should be called every time a new OBJ data has been fetched.
19
- def store_obj_data(content_state, index, key, data)
20
- content_state.save_obj_data(index, key, data) if content_state
21
- end
22
-
23
- # Fetches up-to-date obj data for given workspace, index and key.
24
- # Returns nil if no up-to-date data found.
25
- def find_obj_data(current_content_state , index, key)
26
- if index == 'permalink'
27
- current_content_state.find_obj_data(index, key)
28
- else
29
- visitor = ContentStateVisitor.new(current_content_state)
30
- cache_lookup_depth.times do |depth|
31
- return unless content_state = visitor.visit_next
32
- if hit = content_state.find_obj_data(index, key)
33
- visitor.visited_except_current.each { |cs| return if cs.has_changes_for?(index, key, hit) }
34
- current_content_state.save_obj_data(index, key, hit) if depth >= cache_replication_depth
35
- return hit
36
- end
37
- end
38
- nil
39
- end
40
- end
41
- end
42
-
43
- self.cache_replication_depth = 5
44
- self.cache_lookup_depth = 20
45
- end
46
-
47
- end
@@ -1,19 +0,0 @@
1
- module Scrivito
2
- class ContentStateVisitor
3
- def initialize(start_content_state)
4
- @next_content_state, @visited = start_content_state, []
5
- end
6
-
7
- def visit_next
8
- if content_state = @next_content_state
9
- @visited << content_state
10
- @next_content_state = content_state.from_content_state
11
- content_state
12
- end
13
- end
14
-
15
- def visited_except_current
16
- @visited[0..-2]
17
- end
18
- end
19
- end
@@ -1,63 +0,0 @@
1
- module Scrivito
2
-
3
- class ObjDataFromService < ObjData
4
- def initialize(data)
5
- @data = data
6
- end
7
-
8
- def raw_value_and_type_of(attribute_name)
9
- return [value_of_widget_pool, nil] if attribute_name == '_widget_pool'
10
- if value_and_type = @data[attribute_name]
11
- value, type = value_and_type
12
- value = convert_value(value, type)
13
- [value, type]
14
- else
15
- [nil, nil]
16
- end
17
- end
18
-
19
- def convert_value(value, type)
20
- case type
21
- when 'html' then convert_text_links(value)
22
- else value
23
- end
24
- end
25
-
26
- def attribute_names
27
- @data.keys
28
- end
29
-
30
- def to_h
31
- @data.to_h
32
- end
33
-
34
- private
35
-
36
- def convert_text_links(value)
37
- text_links_conversion.convert(value)
38
- end
39
-
40
- def text_links_conversion
41
- @text_links_conversion = TextLinkConversion.new(text_links_map)
42
- end
43
-
44
- def text_links_map
45
- text_links = @data["_text_links"]
46
- return nil unless text_links
47
-
48
- text_links.first.each_with_object({}) do |link, map|
49
- map[link["link_id"]] = TextLink.new(link)
50
- end
51
- end
52
-
53
- def value_of_widget_pool
54
- if widget_pool = @data['_widget_pool']
55
- widget_pool.first.dup.tap do |hash|
56
- hash.each_pair do |widget_id, raw_widget_data|
57
- hash[widget_id] = self.class.new(raw_widget_data)
58
- end
59
- end
60
- end
61
- end
62
- end
63
- end
@@ -1,43 +0,0 @@
1
- module Scrivito
2
-
3
- class WorkspaceDataFromService < WorkspaceData
4
- class << self
5
- # Fetches a workspace data previously store in cache storage.
6
- # Returns nil if not found.
7
- def find_from_cache(id)
8
- if data = CmsDataCache.read_workspace_data(id)
9
- new(data)
10
- end
11
- end
12
- end
13
-
14
- data_attr_reader :diff
15
-
16
- def changes
17
- diff && diff['changes']
18
- end
19
-
20
- def from_content_state_id
21
- diff && diff['from_content_state_id']
22
- end
23
-
24
- def to_content_state_id
25
- diff && diff['to_content_state_id']
26
- end
27
-
28
- # Serializes and stores a workspace data in cache storage.
29
- # Also creates an appropriate content state if needed.
30
- def store_in_cache_and_create_content_state
31
- create_content_state if content_state_id
32
- store_in_cache
33
- end
34
-
35
- private
36
-
37
- def create_content_state
38
- ContentState.create(content_state_id: to_content_state_id, changes: changes,
39
- from_content_state_id: from_content_state_id)
40
- end
41
- end
42
-
43
- end # module Scrivito