pageflow 15.1.0.beta2 → 15.1.0.beta3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of pageflow might be problematic. Click here for more details.

Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +141 -1
  3. data/README.md +3 -6
  4. data/admins/pageflow/entry.rb +1 -1
  5. data/app/assets/javascripts/pageflow/dist/editor.js +1241 -1281
  6. data/app/assets/javascripts/pageflow/dist/react-client.js +3 -3
  7. data/app/assets/javascripts/pageflow/dist/react-server.js +2 -2
  8. data/app/assets/javascripts/pageflow/dist/ui.js +241 -57
  9. data/app/assets/javascripts/pageflow/editor/base.js +0 -20
  10. data/app/assets/javascripts/pageflow/editor/vendor.js +16 -0
  11. data/app/assets/stylesheets/pageflow/admin/embedded_index_table.scss +5 -1
  12. data/app/controllers/concerns/pageflow/controller_delegation.rb +31 -0
  13. data/app/controllers/concerns/pageflow/entry_password_protection.rb +4 -4
  14. data/app/controllers/pageflow/editor/entries_controller.rb +35 -0
  15. data/app/controllers/pageflow/editor/file_import_controller.rb +1 -1
  16. data/app/controllers/pageflow/editor/files_controller.rb +1 -1
  17. data/app/controllers/pageflow/entries_controller.rb +29 -71
  18. data/app/controllers/pageflow/revisions_controller.rb +16 -5
  19. data/app/helpers/pageflow/common_entry_seed_helper.rb +9 -24
  20. data/app/helpers/pageflow/config_helper.rb +25 -3
  21. data/app/helpers/pageflow/editor/config_helper.rb +12 -0
  22. data/app/helpers/pageflow/editor/entries_helper.rb +10 -0
  23. data/app/helpers/pageflow/editor/files_helper.rb +24 -0
  24. data/app/helpers/pageflow/entries_helper.rb +5 -4
  25. data/app/helpers/pageflow/entry_json_seed_helper.rb +1 -0
  26. data/app/helpers/pageflow/files_helper.rb +14 -13
  27. data/app/helpers/pageflow/page_types_helper.rb +4 -1
  28. data/app/helpers/pageflow/render_json_helper.rb +30 -5
  29. data/app/models/concerns/pageflow/auto_generated_perma_id.rb +16 -0
  30. data/app/models/concerns/pageflow/feature_target.rb +3 -3
  31. data/app/models/pageflow/draft_entry.rb +3 -0
  32. data/app/models/pageflow/home_button.rb +3 -1
  33. data/app/models/pageflow/page.rb +1 -6
  34. data/app/models/pageflow/published_entry.rb +1 -0
  35. data/app/models/pageflow/revision.rb +3 -0
  36. data/app/models/pageflow/storyline.rb +0 -2
  37. data/app/views/admin/entries/_links.html.arb +1 -1
  38. data/app/views/admin/features/_form.html.erb +1 -1
  39. data/app/views/components/pageflow/admin/add_membership_button.rb +13 -1
  40. data/app/views/layouts/pageflow/application.html.erb +3 -19
  41. data/app/views/layouts/pageflow/editor.html.erb +18 -0
  42. data/app/views/pageflow/admin/accounts/_cannot_add_account.html.erb +0 -0
  43. data/app/views/pageflow/admin/entries/_cannot_add_user.html.erb +5 -0
  44. data/app/views/pageflow/admin/users/_cannot_add.html.erb +8 -0
  45. data/app/views/pageflow/admin/users/_cannot_add_account.html.erb +0 -0
  46. data/app/views/pageflow/admin/users/_cannot_add_entry.html +0 -0
  47. data/app/views/pageflow/{config/_editor_seeds.json.jbuilder → editor/config/_seeds.json.jbuilder} +3 -2
  48. data/app/views/pageflow/editor/entries/seed.json.erb +5 -4
  49. data/app/views/pageflow/{entries/edit.html.erb → editor/entries/show.html.erb} +5 -9
  50. data/app/views/pageflow/{entries → editor/entries}/show.json.jbuilder +0 -0
  51. data/app/views/pageflow/entries/{show.css.erb → stylesheet.css.erb} +0 -0
  52. data/app/views/pageflow/entry_json_seed/_entry.json.jbuilder +2 -8
  53. data/config/initializers/entry_types.rb +4 -0
  54. data/config/initializers/features.rb +0 -10
  55. data/config/initializers/help_entries.rb +0 -8
  56. data/config/locales/de.yml +4 -0
  57. data/config/locales/en.yml +4 -0
  58. data/config/routes.rb +10 -5
  59. data/db/migrate/20191202145757_create_pageflow_scrolled_sections.rb +21 -0
  60. data/db/migrate/20191202150657_create_pageflow_scrolled_chapters.rb +11 -0
  61. data/db/migrate/20191202154723_create_pageflow_scrolled_content_elements.rb +21 -0
  62. data/db/migrate/20191219143450_add_position_to_content_elements.rb +5 -0
  63. data/db/migrate/20191220100946_create_pageflow_scrolled_storylines.rb +24 -0
  64. data/entry_types/paged/app/assets/javascripts/pageflow_paged/dist/editor.js +9805 -114
  65. data/entry_types/paged/app/assets/javascripts/pageflow_paged/editor.js +7 -0
  66. data/entry_types/paged/app/assets/stylesheets/pageflow_paged/editor.scss +1 -0
  67. data/entry_types/paged/app/controllers/concerns/pageflow_paged/without_controller_namespace_partial_path_prefix.rb +21 -0
  68. data/entry_types/paged/app/controllers/pageflow_paged/application_controller.rb +25 -0
  69. data/entry_types/paged/app/controllers/pageflow_paged/editor/entries_controller.rb +17 -0
  70. data/entry_types/paged/app/controllers/pageflow_paged/entries_controller.rb +25 -0
  71. data/{app/views/layouts/pageflow → entry_types/paged/app/views/layouts/pageflow_paged}/_ie_include_tags.html.erb +0 -0
  72. data/{app/views/layouts/pageflow → entry_types/paged/app/views/layouts/pageflow_paged}/_loading_spinner_inline_script.html.erb +0 -0
  73. data/entry_types/paged/app/views/layouts/pageflow_paged/application.html.erb +33 -0
  74. data/entry_types/paged/app/views/pageflow_paged/chapters/_chapter.html.erb +7 -0
  75. data/entry_types/paged/app/views/pageflow_paged/editor/entries/_body.html.erb +4 -0
  76. data/entry_types/paged/app/views/pageflow_paged/editor/entries/_head.html.erb +12 -0
  77. data/entry_types/paged/app/views/pageflow_paged/editor/entries/_indicators_seed.html.erb +3 -0
  78. data/entry_types/paged/app/views/pageflow_paged/editor/entries/_seed.json.jbuilder +0 -0
  79. data/entry_types/paged/app/views/pageflow_paged/editor/entries/partials.html.erb +3 -0
  80. data/{app/views/pageflow → entry_types/paged/app/views/pageflow_paged}/entries/_entry.html.erb +7 -5
  81. data/{app/views/pageflow → entry_types/paged/app/views/pageflow_paged}/entries/_header.html.erb +0 -0
  82. data/{app/views/pageflow → entry_types/paged/app/views/pageflow_paged}/entries/_ie8_hint.html.erb +0 -0
  83. data/{app/views/pageflow → entry_types/paged/app/views/pageflow_paged}/entries/_indicators.html.erb +0 -0
  84. data/{app/views/pageflow → entry_types/paged/app/views/pageflow_paged}/entries/_multimedia_alert.html.erb +0 -0
  85. data/{app/views/pageflow → entry_types/paged/app/views/pageflow_paged}/entries/_non_js_hint.html.erb +0 -0
  86. data/entry_types/paged/app/views/pageflow_paged/entries/_overview.html.erb +1 -0
  87. data/{app/views/pageflow → entry_types/paged/app/views/pageflow_paged}/entries/_skip_links.html.erb +0 -0
  88. data/{app/views/pageflow → entry_types/paged/app/views/pageflow_paged}/entries/overview/_chapter.html.erb +3 -1
  89. data/{app/views/pageflow → entry_types/paged/app/views/pageflow_paged}/entries/overview/_entry.html.erb +1 -1
  90. data/{app/views/pageflow → entry_types/paged/app/views/pageflow_paged}/entries/overview/_page.html.erb +0 -0
  91. data/{app/views/pageflow → entry_types/paged/app/views/pageflow_paged}/entries/show.html.erb +3 -3
  92. data/{app/views/pageflow → entry_types/paged/app/views/pageflow_paged}/pages/_page.html.erb +1 -1
  93. data/entry_types/paged/config/initializers/features.rb +16 -0
  94. data/entry_types/paged/config/initializers/page_types.rb +16 -0
  95. data/entry_types/paged/config/routes.rb +3 -0
  96. data/entry_types/paged/lib/pageflow_paged.rb +19 -0
  97. data/entry_types/paged/lib/pageflow_paged/configuration.rb +16 -0
  98. data/entry_types/paged/lib/pageflow_paged/engine.rb +7 -0
  99. data/entry_types/paged/lib/pageflow_paged/plugin.rb +8 -0
  100. data/entry_types/scrolled/app/assets/stylesheets/pageflow_scrolled/editor.scss +1 -0
  101. data/entry_types/scrolled/app/controllers/pageflow_scrolled/editor/chapters_controller.rb +56 -0
  102. data/entry_types/scrolled/app/controllers/pageflow_scrolled/editor/content_elements_controller.rb +61 -0
  103. data/entry_types/scrolled/app/controllers/pageflow_scrolled/editor/entries_controller.rb +8 -0
  104. data/entry_types/scrolled/app/controllers/pageflow_scrolled/editor/sections_controller.rb +59 -0
  105. data/entry_types/scrolled/app/controllers/pageflow_scrolled/entries_controller.rb +10 -0
  106. data/entry_types/scrolled/app/helpers/pageflow_scrolled/editor/seed_html_helper.rb +21 -0
  107. data/entry_types/scrolled/app/helpers/pageflow_scrolled/entry_json_seed_helper.rb +33 -0
  108. data/entry_types/scrolled/app/models/pageflow_scrolled/chapter.rb +40 -0
  109. data/entry_types/scrolled/app/models/pageflow_scrolled/content_element.rb +17 -0
  110. data/entry_types/scrolled/app/models/pageflow_scrolled/section.rb +26 -0
  111. data/entry_types/scrolled/app/models/pageflow_scrolled/storyline.rb +39 -0
  112. data/entry_types/scrolled/app/views/pageflow_scrolled/chapters/_chapter.json.jbuilder +8 -0
  113. data/entry_types/scrolled/app/views/pageflow_scrolled/content_elements/_content_element.json.jbuilder +9 -0
  114. data/entry_types/scrolled/app/views/pageflow_scrolled/editor/entries/_body.html.erb +1 -0
  115. data/entry_types/scrolled/app/views/pageflow_scrolled/editor/entries/_head.html.erb +12 -0
  116. data/entry_types/scrolled/app/views/pageflow_scrolled/editor/entries/_seed.json.jbuilder +1 -0
  117. data/entry_types/scrolled/app/views/pageflow_scrolled/entries/show.html.erb +22 -0
  118. data/entry_types/scrolled/app/views/pageflow_scrolled/entry_json_seed/_entry.json.jbuilder +35 -0
  119. data/entry_types/scrolled/app/views/pageflow_scrolled/sections/_section.json.jbuilder +8 -0
  120. data/entry_types/scrolled/config/routes.rb +23 -0
  121. data/entry_types/scrolled/lib/generators/pageflow_scrolled/install/install_generator.rb +34 -0
  122. data/entry_types/scrolled/lib/pageflow_scrolled.rb +19 -0
  123. data/entry_types/scrolled/lib/pageflow_scrolled/configuration.rb +6 -0
  124. data/entry_types/scrolled/lib/pageflow_scrolled/plugin.rb +16 -0
  125. data/entry_types/scrolled/lib/pageflow_scrolled/seeds.rb +133 -0
  126. data/entry_types/scrolled/spec/factories/chapters.rb +12 -0
  127. data/entry_types/scrolled/spec/factories/content_elements.rb +36 -0
  128. data/entry_types/scrolled/spec/factories/sections.rb +26 -0
  129. data/entry_types/scrolled/spec/factories/storylines.rb +12 -0
  130. data/entry_types/scrolled/spec/fixtures/image.jpg +0 -0
  131. data/lib/generators/pageflow/active_admin_initializer/active_admin_initializer_generator.rb +1 -1
  132. data/lib/generators/pageflow/assets/assets_generator.rb +2 -2
  133. data/lib/pageflow/built_in_page_types_plugin.rb +5 -3
  134. data/lib/pageflow/built_in_widget_types_plugin.rb +38 -12
  135. data/lib/pageflow/configuration.rb +76 -15
  136. data/lib/pageflow/editor_controller.rb +44 -0
  137. data/lib/pageflow/engine.rb +2 -3
  138. data/lib/pageflow/entries_controller_env_helper.rb +44 -0
  139. data/lib/pageflow/entry_type.rb +19 -2
  140. data/lib/pageflow/entry_type_configuration.rb +44 -0
  141. data/lib/pageflow/entry_types.rb +22 -0
  142. data/lib/pageflow/feature.rb +11 -5
  143. data/lib/pageflow/file_importers.rb +2 -2
  144. data/lib/pageflow/file_type.rb +3 -2
  145. data/lib/pageflow/file_types.rb +23 -3
  146. data/lib/pageflow/global_config_api.rb +11 -4
  147. data/lib/pageflow/page_types.rb +30 -0
  148. data/lib/pageflow/partial_editor_fragment_renderer.rb +37 -0
  149. data/lib/pageflow/revision_component.rb +2 -5
  150. data/lib/pageflow/revision_components.rb +18 -0
  151. data/lib/pageflow/version.rb +1 -1
  152. data/lib/pageflow/widget_type.rb +3 -0
  153. data/lib/pageflow/widget_types.rb +1 -1
  154. data/spec/factories/draft_entries.rb +11 -0
  155. data/spec/factories/published_entries.rb +17 -0
  156. data/vendor/assets/javascripts/dash.all.min.js +0 -1
  157. metadata +146 -29
  158. data/app/views/pageflow/chapters/_chapter.html.erb +0 -5
  159. data/app/views/pageflow/editor/entries/_indicators_seed.html.erb +0 -3
  160. data/app/views/pageflow/entries/_overview.html.erb +0 -1
  161. data/app/views/pageflow/entries/partials.html.erb +0 -3
  162. data/config/initializers/page_type_helpers.rb +0 -8
@@ -0,0 +1,44 @@
1
+ module Pageflow
2
+ # Concern that can be included in entry type specific controllers
3
+ # that extend the REST interface used by the editor. Handles
4
+ # authentication, entry lookup, authorization and edit locking.
5
+ #
6
+ # @since 15.1
7
+ module EditorController
8
+ extend ActiveSupport::Concern
9
+
10
+ include EditLocking
11
+
12
+ included do
13
+ before_action :authenticate_user!
14
+
15
+ before_action do
16
+ begin
17
+ @entry = DraftEntry.find(params[:entry_id])
18
+ rescue ActiveRecord::RecordNotFound
19
+ head :not_found
20
+ end
21
+ end
22
+
23
+ before_action do
24
+ begin
25
+ Ability.new(current_user).authorize!(:update, @entry.to_model)
26
+ rescue CanCan::AccessDenied
27
+ head :forbidden
28
+ end
29
+ end
30
+
31
+ before_action :verify_edit_lock
32
+
33
+ before_action do
34
+ head :bad_request if params[:entry_type] && @entry.entry_type.name != params[:entry_type]
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def verify_edit_lock
41
+ verify_edit_lock!(@entry)
42
+ end
43
+ end
44
+ end
@@ -111,15 +111,14 @@ module Pageflow
111
111
  end
112
112
  end
113
113
 
114
- # Precompile additional assets. pageflow/editor.* has to be
115
- # provided by the main app.
114
+ # Precompile additional assets.
116
115
  initializer 'pageflow.assets.precompile' do |app|
117
116
  app.config.assets.precompile += %w(
118
- pageflow/editor.js pageflow/editor.css
119
117
  pageflow/application_with_simulated_media_queries.css
120
118
  pageflow/print_view.css
121
119
  pageflow/lt_ie9.js pageflow/lt_ie9.css pageflow/ie9.js pageflow/ie9.css
122
120
  pageflow/vendor.js
121
+ pageflow/editor/vendor.js
123
122
  video-js.swf vjs.eot vjs.svg vjs.ttf vjs.woff
124
123
  )
125
124
 
@@ -0,0 +1,44 @@
1
+ module Pageflow
2
+ # A helper module that can be included in an entry type's frontend
3
+ # app to access the {PublishedEntry}.
4
+ #
5
+ # @since 15.1
6
+ module EntriesControllerEnvHelper
7
+ module_function
8
+
9
+ # Read the {PublishedEntry} from the request env. It will be
10
+ # placed there by the Pageflow engine before delegating to the
11
+ # entry type's frontend app.
12
+ #
13
+ # Use {EntriesControllerTestHelper} to set up the request
14
+ # environment in controller tests.
15
+ def get_published_entry_from_env(env = request.env)
16
+ EntriesControllerEnvHelper.get_pageflow_hash(env)['published_entry']
17
+ end
18
+
19
+ # Returns `:preview` if a signed in user is currently viewing the
20
+ # entry via the preview feature. Returns `:published` if the entry
21
+ # is rendered on a publicly available site. The information will
22
+ # be placed in the request env by the Pageflow engine before
23
+ # delegating to the entry type's frontend app.
24
+ #
25
+ # Use {EntriesControllerTestHelper} to set up the request
26
+ # environment in controller tests.
27
+ def get_entry_mode_from_env(env = request.env)
28
+ EntriesControllerEnvHelper.get_pageflow_hash(env)['entry_mode']
29
+ end
30
+
31
+ # @api private
32
+ def self.add_entry_info_to_env(env, entry:, mode: nil)
33
+ env['pageflow'] = {'published_entry' => entry, 'entry_mode' => mode}
34
+ end
35
+
36
+ # @api private
37
+ def self.get_pageflow_hash(env)
38
+ env.fetch('pageflow') do
39
+ throw('Missing pageflow key in request env. Use Pageflow::EntriesControllerTestHelper ' \
40
+ 'to set it in controller tests.')
41
+ end
42
+ end
43
+ end
44
+ end
@@ -4,11 +4,28 @@ module Pageflow
4
4
  # @since 15.1
5
5
  class EntryType
6
6
  # @api private
7
- attr_reader :name
7
+ attr_reader :name, :frontend_app, :editor_fragment_renderer, :configuration, :editor_app
8
8
 
9
9
  # @param name [String] A unique name.
10
- def initialize(name:)
10
+ #
11
+ # @param frontend_app [#call] A rack app that renders the entry
12
+ # when not in the editor (i.e. preview and published entries).
13
+ #
14
+ # @param editor_fragment_renderer [PartialEditorFragmentRenderer]
15
+ # Inject content into editor HTML and JSON seed templates.
16
+ #
17
+ # @param configuration [Class] Class including
18
+ # {Pageflow::Configuration::EntryTypeConfiguration}.
19
+ #
20
+ # @param editor_app [#call] A rack app that extends the REST
21
+ # interface used by editor Backbone collections. Mounted at
22
+ # `/editor/entries/:id/<entry_type_name>/`
23
+ def initialize(name:, frontend_app:, editor_fragment_renderer:, configuration:, editor_app: nil)
11
24
  @name = name
25
+ @frontend_app = frontend_app
26
+ @editor_fragment_renderer = editor_fragment_renderer
27
+ @configuration = configuration
28
+ @editor_app = editor_app
12
29
  end
13
30
  end
14
31
  end
@@ -0,0 +1,44 @@
1
+ module Pageflow
2
+ # Include in entry type specific configuration classes.
3
+ #
4
+ # @since 15.1
5
+ module EntryTypeConfiguration
6
+ # @api private
7
+ def initialize(config, entry_type)
8
+ @config = config
9
+ @features = FeaturesDelegator.new(config, entry_type)
10
+ end
11
+
12
+ attr_reader :features
13
+
14
+ delegate :file_types, to: :@config
15
+ delegate :help_entries, to: :@config
16
+ delegate :hooks, to: :@config
17
+ delegate :revision_components, to: :@config
18
+ delegate :widget_types, to: :@config
19
+
20
+ def plugin(plugin)
21
+ plugin.configure(self)
22
+ end
23
+
24
+ # @api private
25
+ FeaturesDelegator = Struct.new(:config, :entry_type) do
26
+ def register(feature, &block)
27
+ return register(Feature.new(feature, &block)) if feature.is_a?(String)
28
+
29
+ entry_type_feature = Feature.new(
30
+ feature.name,
31
+ name_translation_key: feature.name_translation_key
32
+ ) do |feature_config|
33
+ feature_config.for_entry_type(entry_type, &feature.method(:enable))
34
+ end
35
+
36
+ config.features.register(entry_type_feature)
37
+ end
38
+
39
+ def enable_by_default(name)
40
+ config.features.enable_by_default(name)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -3,6 +3,8 @@ module Pageflow
3
3
  #
4
4
  # @since 15.1
5
5
  class EntryTypes
6
+ include Enumerable
7
+
6
8
  # @api private
7
9
  def initialize
8
10
  @entry_types_by_name = {}
@@ -21,5 +23,25 @@ module Pageflow
21
23
  raise "Unknown entry type with name #{name}."
22
24
  end
23
25
  end
26
+
27
+ # @api private
28
+ def each(&block)
29
+ @entry_types_by_name.values.each(&block)
30
+ end
31
+
32
+ # @api private
33
+ def routes(router)
34
+ each do |entry_type|
35
+ next unless entry_type.editor_app
36
+
37
+ router.instance_eval do
38
+ nested do
39
+ scope '/:entry_type', constraints: {entry_type: entry_type.name} do
40
+ mount entry_type.editor_app, at: '/'
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
24
46
  end
25
47
  end
@@ -9,12 +9,22 @@ module Pageflow
9
9
  # @return [String]
10
10
  attr_reader :name
11
11
 
12
+ # Translation key to represent the feature in the UI.
13
+ #
14
+ # @return [String]
15
+ attr_reader :name_translation_key
16
+
12
17
  # Create a block based feature.
13
18
  #
14
19
  # @param name [String] Unique identifyer of feature.
20
+ #
21
+ # @param name_translation_key [String] Translation key to
22
+ # represent the feature in the UI.
23
+ #
15
24
  # @yieldparam config [Configuration] The configuration object to manipulate.
16
- def initialize(name, &block)
25
+ def initialize(name, name_translation_key: nil, &block)
17
26
  @name = name
27
+ @name_translation_key = name_translation_key || "pageflow.#{name}.feature_name"
18
28
  @block = block
19
29
  end
20
30
 
@@ -25,9 +35,5 @@ module Pageflow
25
35
  def enable(config)
26
36
  @block.call(config) if @block
27
37
  end
28
-
29
- def name_translation_key
30
- "pageflow.#{name}.feature_name"
31
- end
32
38
  end
33
39
  end
@@ -8,8 +8,8 @@ module Pageflow
8
8
  clear
9
9
  end
10
10
 
11
- def register(name, file_importer)
12
- @file_importers[name] = file_importer
11
+ def register(file_importer)
12
+ @file_importers[file_importer.name] = file_importer
13
13
  end
14
14
 
15
15
  def clear
@@ -58,12 +58,13 @@ module Pageflow
58
58
  #
59
59
  # @example
60
60
  #
61
- # Pageflow::FileType.new(model: Pageflow::Rainbow::File,
61
+ # Pageflow::FileType.new(model: 'Pageflow::Rainbow::File',
62
62
  # editor_partial: 'pageflow/rainbow/editor/files/file')
63
63
  #
64
64
  # @param [Hash] options
65
65
  # @option options [ActiveRecord::Base, String] :model
66
- # Required. Model representing the file, or name of that model.
66
+ # Required. Name of model representing the file. Model reference
67
+ # still works, but is deprecated
67
68
  # @option options [String] :partial
68
69
  # Optional. Path of a partial to include in json representations
69
70
  # of the file both inside the editor and published entries.
@@ -2,12 +2,20 @@ module Pageflow
2
2
  class FileTypes
3
3
  include Enumerable
4
4
 
5
- def initialize(page_types)
6
- @page_types = page_types
5
+ def initialize
6
+ @file_types = []
7
+ end
8
+
9
+ def register(file_type)
10
+ @file_types << file_type
11
+ end
12
+
13
+ def clear
14
+ @file_types = []
7
15
  end
8
16
 
9
17
  def each(&block)
10
- first_level_file_types = @page_types.map(&:file_types).flatten
18
+ first_level_file_types = trigger_lazy_loading_of_file_types
11
19
  lower_level_file_types = search_for_nested_file_types(first_level_file_types)
12
20
  (first_level_file_types + lower_level_file_types).uniq(&:model).each(&block)
13
21
  end
@@ -39,6 +47,18 @@ module Pageflow
39
47
 
40
48
  private
41
49
 
50
+ def trigger_lazy_loading_of_file_types
51
+ # To avoid dependency cycles due to autoloading for model
52
+ # references that are passed into FileType.new in some plugins,
53
+ # we allow registering as file types lambdas which resolve to a
54
+ # page type's file types. After some deprecation period, we
55
+ # could get rid of this and just set first_level_file_types to
56
+ # @file_types here.
57
+ @file_types.map { |file_type|
58
+ file_type.respond_to?(:call) ? file_type.call : file_type
59
+ }.flatten
60
+ end
61
+
42
62
  def search_for_nested_file_types(higher_level_file_types)
43
63
  higher_level_file_types.map { |file_type|
44
64
  file_type.nested_file_types +
@@ -44,9 +44,16 @@ module Pageflow
44
44
  # @return [Configuration]
45
45
  # @since 0.9
46
46
  def config_for(target)
47
- build_config do |config|
48
- config.enable_features(target.enabled_feature_names)
47
+ config = build_config(target.respond_to?(:type_name) && target.type_name) do |c|
48
+ c.enable_features(target.enabled_feature_names(c))
49
49
  end
50
+
51
+ if target.respond_to?(:type_name)
52
+ config = Configuration::ConfigView.new(config,
53
+ config.entry_types.find_by_name!(target.type_name))
54
+ end
55
+
56
+ config
50
57
  end
51
58
 
52
59
  # Register a block which shall be called after any configuration
@@ -99,8 +106,8 @@ module Pageflow
99
106
 
100
107
  private
101
108
 
102
- def build_config(&block)
103
- Configuration.new.tap do |config|
109
+ def build_config(target_type_name = nil)
110
+ Configuration.new(target_type_name).tap do |config|
104
111
  @configure_blocks ||= []
105
112
  @after_configure_blocks ||= []
106
113
 
@@ -32,10 +32,40 @@ module Pageflow
32
32
  @page_types.each(&block)
33
33
  end
34
34
 
35
+ def setup(config)
36
+ config.help_entries.register('pageflow.help_entries.page_types', priority: 10)
37
+ each do |page_type|
38
+ register_help_entries(config, page_type)
39
+ register_revision_components(config, page_type)
40
+ register_file_types(config, page_type)
41
+ end
42
+ end
43
+
35
44
  private
36
45
 
37
46
  def ensure_export_version_implemented(page_type)
38
47
  page_type.export_version
39
48
  end
49
+
50
+ def register_help_entries(config, page_type)
51
+ config.help_entries.register(page_type.help_entry_translation_key,
52
+ parent: 'pageflow.help_entries.page_types')
53
+ end
54
+
55
+ def register_revision_components(config, page_type)
56
+ page_type.revision_components.each do |component|
57
+ config.revision_components.register(component)
58
+ end
59
+ end
60
+
61
+ def register_file_types(config, page_type)
62
+ # After a deprecation period against initializing FileType with
63
+ # a model reference instead of a model name string, we could
64
+ # rewrite this to register the page type's file types one by one
65
+ # right here instead of lazily in FileTypes#each.
66
+ config.file_types.register(
67
+ -> { page_type.file_types }
68
+ )
69
+ end
40
70
  end
41
71
  end
@@ -0,0 +1,37 @@
1
+ module Pageflow
2
+ # Helper class to be used as `editor_fragment_renderer` of
3
+ # {EntryType} objects to render fragments from partials.
4
+ #
5
+ # @since 15.1
6
+ class PartialEditorFragmentRenderer
7
+ # Create object that implements methods required by
8
+ # `editor_fragment_renderer` of {EntryType}.
9
+ #
10
+ # @param controller [ActionController::Base] Renders partials in
11
+ # the context of this controller. The controller determines
12
+ # which helpers are available in the template
13
+ def initialize(controller)
14
+ @renderer = controller.renderer
15
+ end
16
+
17
+ def head_fragment(entry)
18
+ render('head', entry)
19
+ end
20
+
21
+ def body_fragment(entry)
22
+ render('body', entry)
23
+ end
24
+
25
+ def seed_fragment(entry)
26
+ render('seed', entry, format: :json)
27
+ end
28
+
29
+ private
30
+
31
+ def render(partial, entry, format: :html)
32
+ @renderer.render(partial: partial,
33
+ formats: format,
34
+ locals: {entry: entry})
35
+ end
36
+ end
37
+ end
@@ -12,8 +12,9 @@ module Pageflow
12
12
  class PermaIdGenerationAdvisoryLockTimeout < StandardError; end
13
13
 
14
14
  included do
15
+ include AutoGeneratedPermaId
16
+
15
17
  belongs_to :revision, class_name: 'Pageflow::Revision', touch: true
16
- before_save :ensure_perma_id
17
18
  end
18
19
 
19
20
  def copy_to(revision)
@@ -22,10 +23,6 @@ module Pageflow
22
23
  record.save!
23
24
  end
24
25
 
25
- def ensure_perma_id
26
- self.perma_id ||= (self.class.maximum(:perma_id) || 0) + 1
27
- end
28
-
29
26
  module ClassMethods
30
27
  # Recommended way to create revision components. Uses an
31
28
  # advisory lock to ensure concurrently created records are not