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,6 @@
1
+ module PageflowScrolled
2
+ # Configuration options for scrolled entry type
3
+ class Configuration
4
+ include Pageflow::EntryTypeConfiguration
5
+ end
6
+ end
@@ -0,0 +1,16 @@
1
+ module PageflowScrolled
2
+ # @api private
3
+ class Plugin < Pageflow::Plugin
4
+ def configure(config)
5
+ config.entry_types.register(PageflowScrolled.entry_type)
6
+
7
+ config.for_entry_type(PageflowScrolled.entry_type) do |c|
8
+ c.file_types.register(Pageflow::BuiltInFileType.image)
9
+ c.file_types.register(Pageflow::BuiltInFileType.video)
10
+ c.file_types.register(Pageflow::BuiltInFileType.audio)
11
+
12
+ c.revision_components.register(Storyline)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,133 @@
1
+ require 'uri'
2
+
3
+ module PageflowScrolled
4
+ # Following the DSL for seeding the database with Pageflow
5
+ # models, this adds a method to also seed a PageflowScrolled Entry configuration.
6
+ # Usage: See pageflow/seeds.rb
7
+ module Seeds
8
+ # Create a sample scrolled {Entry} with one section, based on the PageflowNext
9
+ # presentation example if no scrolled entry with that title exists in the given account.
10
+ #
11
+ # @param [Hash] attributes attributes to override defaults
12
+ # @option attributes [Account] :account required
13
+ # @option attributes [String] :title required
14
+ # @option attributes [Array] :chapters required
15
+ # An array of chapter configurations, each containing a key "sections"
16
+ # which lists the separate sections of each chapter.
17
+ # Each section has a "foreground"-key
18
+ # under which an array of content_element configurations is stored.
19
+ # Each content_element configuration must provide a "type"-attribute
20
+ # to determine the React component used to render this content element.
21
+ # @option attributes [Hash] :image_files A hash mapping image
22
+ # names used in properties like `backdrop.image` to urls.
23
+ # @yield [entry] a block to be called before the entry is saved
24
+ # @return [Entry] newly created entry
25
+ def sample_scrolled_entry(attributes)
26
+ entry = Pageflow::Entry.where(type_name: 'scrolled')
27
+ .where(attributes.slice(:account, :title))
28
+ .first
29
+
30
+ if entry.nil?
31
+ entry = Pageflow::Entry.create!(type_name: 'scrolled',
32
+ **attributes.except(:chapters,
33
+ :image_files)) do |created_entry|
34
+ created_entry.theming = attributes.fetch(:account).default_theming
35
+
36
+ say_creating_scrolled_entry(created_entry)
37
+ yield(created_entry) if block_given?
38
+ end
39
+
40
+ image_files_by_name = create_image_files(Pageflow::DraftEntry.new(entry),
41
+ attributes.fetch(:image_files, {}))
42
+
43
+ attributes[:chapters].each_with_index do |chapter_config, i|
44
+ create_chapter(entry, chapter_config, i, image_files_by_name)
45
+ end
46
+ end
47
+
48
+ entry
49
+ end
50
+
51
+ private
52
+
53
+ def say(text)
54
+ puts(text) unless Rails.env.test?
55
+ end
56
+
57
+ def say_creating_scrolled_entry(entry)
58
+ say(" sample scrolled entry '#{entry.title}'\n")
59
+ end
60
+
61
+ def create_image_files(draft_entry, image_file_data_by_name)
62
+ image_file_data_by_name.transform_values do |data|
63
+ say(" creating image file from #{data['url']}")
64
+
65
+ draft_entry.create_file!(Pageflow::BuiltInFileType.image,
66
+ state: 'processed',
67
+ attachment: URI.parse(data['url']),
68
+ configuration: data['configuration'])
69
+ end
70
+ end
71
+
72
+ def create_chapter(entry, chapter_config, position, image_files_by_name)
73
+ section_configs = chapter_config.delete('sections') || []
74
+ chapter = Chapter.create!(
75
+ revision: entry.draft,
76
+ configuration: {
77
+ title: chapter_config['title'],
78
+ summary: chapter_config['summary']
79
+ },
80
+ position: position
81
+ )
82
+
83
+ section_configs.each_with_index do |section_config, i|
84
+ create_section(chapter, section_config, i, image_files_by_name)
85
+ end
86
+ end
87
+
88
+ def create_section(chapter, section_config, position, image_files_by_name)
89
+ content_element_configs = section_config.delete('foreground') || []
90
+
91
+ rewrite_file_references!(section_config['backdrop'],
92
+ ['image', 'imageMobile'],
93
+ image_files_by_name)
94
+
95
+ section = Section.create!(chapter: chapter,
96
+ configuration: section_config,
97
+ position: position)
98
+
99
+ content_element_configs.each_with_index do |content_element_config, i|
100
+ create_content_element(section, content_element_config, i, image_files_by_name)
101
+ end
102
+ end
103
+
104
+ def create_content_element(section, content_element_config, position, image_files_by_name)
105
+ if %w[stickyImage inlineImage].include?(content_element_config['type'])
106
+ rewrite_file_references!(content_element_config['props'], ['id'], image_files_by_name)
107
+ end
108
+
109
+ section.content_elements.create!(
110
+ type_name: content_element_config['type'],
111
+ configuration: content_element_config['props'],
112
+ position: position
113
+ )
114
+ end
115
+
116
+ def rewrite_file_references!(hash, keys, image_files_by_name)
117
+ return unless hash
118
+
119
+ keys.each do |key|
120
+ next unless hash[key]
121
+ next if non_image_reference?(hash[key])
122
+
123
+ hash[key] = image_files_by_name.fetch(hash[key]).perma_id
124
+ end
125
+ end
126
+
127
+ def non_image_reference?(value)
128
+ value.starts_with?('#') ||
129
+ value.starts_with?('video') ||
130
+ value.starts_with?('beforeAfter')
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,12 @@
1
+ module PageflowScrolled
2
+ FactoryBot.define do
3
+ factory :scrolled_chapter, class: Chapter do
4
+ revision
5
+ configuration do
6
+ {
7
+ title: 'chapter title'
8
+ }
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,36 @@
1
+ module PageflowScrolled
2
+ FactoryBot.define do
3
+ factory :content_element, class: ContentElement do
4
+ section
5
+
6
+ transient do
7
+ revision { nil }
8
+ end
9
+
10
+ before(:create) do |content_element, evaluator|
11
+ if evaluator.revision
12
+ chapter = create(:scrolled_chapter, revision: evaluator.revision)
13
+ content_element.section = create(:section, chapter: chapter)
14
+ end
15
+ end
16
+ end
17
+
18
+ trait :heading do
19
+ type_name { 'heading' }
20
+ configuration do
21
+ {
22
+ children: 'A headline'
23
+ }
24
+ end
25
+ end
26
+
27
+ trait :text_block do
28
+ type_name { 'textBlock' }
29
+ configuration do
30
+ {
31
+ children: 'Some sample text with <b>HTML</b>'
32
+ }
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,26 @@
1
+ module PageflowScrolled
2
+ FactoryBot.define do
3
+ factory :section, class: Section do
4
+ chapter { create(:scrolled_chapter) }
5
+ configuration do
6
+ {
7
+ transition: 'scroll',
8
+ fullHeight: true,
9
+ backdrop: {
10
+ image: 'darkPattern'
11
+ }
12
+ }
13
+ end
14
+
15
+ transient do
16
+ revision { nil }
17
+ end
18
+
19
+ before(:create) do |section, evaluator|
20
+ if evaluator.revision
21
+ section.chapter = create(:scrolled_chapter, revision: evaluator.revision)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ module PageflowScrolled
2
+ FactoryBot.define do
3
+ factory :scrolled_storyline, class: Storyline do
4
+ revision
5
+ configuration do
6
+ {
7
+ main: true
8
+ }
9
+ end
10
+ end
11
+ end
12
+ end
@@ -7,7 +7,7 @@ module Pageflow
7
7
 
8
8
  def configure_active_admin_load_path
9
9
  prepend_to_file 'config/initializers/active_admin.rb' do
10
- "ActiveAdmin.application.load_paths.unshift(Pageflow.active_admin_load_path)\n\n"
10
+ "ActiveAdmin.application.load_paths += [Pageflow.active_admin_load_path]\n\n"
11
11
  end
12
12
  end
13
13
 
@@ -16,8 +16,8 @@ module Pageflow
16
16
 
17
17
  template 'components.js', 'app/assets/javascripts/components.js'
18
18
 
19
- append_to_file 'app/assets/javascripts/active_admin.js.coffee' do
20
- "#= require pageflow/admin\n"
19
+ append_to_file 'app/assets/javascripts/active_admin.js' do
20
+ "//= require pageflow/admin\n"
21
21
  end
22
22
 
23
23
  append_to_file 'app/assets/stylesheets/active_admin.scss' do
@@ -1,9 +1,11 @@
1
1
  module Pageflow
2
2
  class BuiltInPageTypesPlugin < Plugin
3
3
  def configure(config)
4
- config.page_types.register(BuiltInPageType.plain)
5
- config.page_types.register(BuiltInPageType.video)
6
- config.page_types.register(BuiltInPageType.audio)
4
+ config.for_entry_type(PageflowPaged.entry_type) do |entry_type_config|
5
+ entry_type_config.page_types.register(BuiltInPageType.plain)
6
+ entry_type_config.page_types.register(BuiltInPageType.video)
7
+ entry_type_config.page_types.register(BuiltInPageType.audio)
8
+ end
7
9
  end
8
10
  end
9
11
  end
@@ -1,33 +1,59 @@
1
1
  module Pageflow
2
+ # @api private
2
3
  class BuiltInWidgetTypesPlugin < Plugin
3
4
  def configure(config)
4
- config.widget_types.register(Pageflow::BuiltInWidgetType.default_slideshow_mode,
5
- default: true)
5
+ config.for_entry_type(PageflowPaged.entry_type) do |entry_type_config|
6
+ slideshow_mode(entry_type_config)
7
+ loading_spinner(entry_type_config)
8
+ navigation(entry_type_config)
9
+ player_controls(entry_type_config)
10
+ cookie_notice(entry_type_config)
11
+ background_media_control(entry_type_config)
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def slideshow_mode(config)
18
+ config.widget_types.register(BuiltInWidgetType.default_slideshow_mode, default: true)
6
19
 
7
20
  config.features.register('phone_horizontal_slideshow_mode') do |feature_config|
8
- feature_config.widget_types.register(Pageflow::BuiltInWidgetType
9
- .phone_horizontal_slideshow_mode)
21
+ feature_config.widget_types.register(BuiltInWidgetType.phone_horizontal_slideshow_mode)
10
22
  end
23
+ end
11
24
 
25
+ def loading_spinner(config)
12
26
  config.widget_types.register_widget_defaults('loading_spinner',
13
27
  'blur_strength' => 50,
14
28
  'remove_logo' => false,
15
29
  'invert' => false)
16
- config.widget_types.register(Pageflow::BuiltInWidgetType.classic_loading_spinner,
17
- default: true)
30
+
31
+ config.widget_types.register(BuiltInWidgetType.classic_loading_spinner, default: true)
18
32
 
19
33
  config.features.register('title_loading_spinner') do |feature_config|
20
- feature_config.widget_types.register(Pageflow::BuiltInWidgetType.media_loading_spinner)
21
- feature_config.widget_types.register(Pageflow::BuiltInWidgetType.title_loading_spinner)
34
+ feature_config.widget_types.register(BuiltInWidgetType.media_loading_spinner)
35
+ feature_config.widget_types.register(BuiltInWidgetType.title_loading_spinner)
22
36
  end
37
+
23
38
  config.features.enable_by_default('title_loading_spinner')
39
+ end
40
+
41
+ def navigation(config)
42
+ config.widget_types.register(BuiltInWidgetType.navigation, default: true)
43
+ config.widget_types.register(BuiltInWidgetType.mobile_navigation, default: true)
44
+ end
24
45
 
25
- config.widget_types.register(Pageflow::BuiltInWidgetType.navigation, default: true)
26
- config.widget_types.register(Pageflow::BuiltInWidgetType.mobile_navigation, default: true)
46
+ def player_controls(config)
27
47
  config.widget_types.register(Pageflow::BuiltInWidgetType.slim_player_controls)
28
48
  config.widget_types.register(Pageflow::BuiltInWidgetType.classic_player_controls, default: true)
29
- config.widget_types.register(Pageflow::BuiltInWidgetType.cookie_notice_bar)
30
- config.widget_types.register(Pageflow::BuiltInWidgetType.unmute_button, default: true)
49
+ end
50
+
51
+ def cookie_notice(config)
52
+ config.widget_types.register(BuiltInWidgetType.cookie_notice_bar)
53
+ end
54
+
55
+ def background_media_control(config)
56
+ config.widget_types.register(BuiltInWidgetType.unmute_button, default: true)
31
57
  end
32
58
  end
33
59
  end
@@ -52,11 +52,11 @@ module Pageflow
52
52
  #
53
53
  # @example
54
54
  #
55
- # Make a page type only available if a feature flag is set on the
55
+ # Make a widget type only available if a feature flag is set on the
56
56
  # entry or its account
57
57
  #
58
- # config.features.register('some_special_page_type' do |config
59
- # config.page_types.register(Pageflow::SomeSpecial.page_type)
58
+ # config.features.register('some_special_widget_type' do |config
59
+ # config.widget_types.register(Pageflow::SomeSpecial.widget_type)
60
60
  # end
61
61
  #
62
62
  # @since 0.9
@@ -95,15 +95,16 @@ module Pageflow
95
95
  # @since 15.1
96
96
  attr_reader :entry_types
97
97
 
98
- # Register new types of pages.
99
- # @return [PageTypes]
100
- # @since 0.9
101
- attr_reader :page_types
102
-
103
- # List of {FileType} instances provided by page types.
98
+ # List of {FileType} instances.
99
+ # Can be registered globally or provided by page types.
104
100
  # @return [FileTypes]
105
101
  attr_reader :file_types
106
102
 
103
+ # Used to register components whose current state must be
104
+ # persisted as part of a revision.
105
+ # @return [RevisionComponents]
106
+ attr_reader :revision_components
107
+
107
108
  # Used to register new types of widgets to be displayed in entries.
108
109
  # @return [WidgetTypes]
109
110
  attr_reader :widget_types
@@ -337,7 +338,9 @@ module Pageflow
337
338
  # @since 12.2
338
339
  attr_accessor :news
339
340
 
340
- def initialize
341
+ def initialize(target_type_name = nil)
342
+ @target_type_name = target_type_name
343
+
341
344
  @paperclip_attachments_version = 'v1'
342
345
  @paperclip_s3_root = 'main'
343
346
 
@@ -367,11 +370,13 @@ module Pageflow
367
370
  @quotas = Quotas.new
368
371
  @themes = Themes.new
369
372
  @entry_types = EntryTypes.new
370
- @page_types = PageTypes.new
371
- @file_types = FileTypes.new(page_types)
373
+ @entry_type_configs = {}
374
+ @entry_type_configure_blocks = Hash.new { |h, k| h[k] = [] }
375
+ @file_types = FileTypes.new
372
376
  @widget_types = WidgetTypes.new
373
377
  @file_importers = FileImporters.new
374
378
  @help_entries = HelpEntries.new
379
+ @revision_components = RevisionComponents.new
375
380
 
376
381
  @thumbnail_styles = Defaults::THUMBNAIL_STYLES.dup
377
382
  @css_rendered_thumbnail_styles = Defaults::CSS_RENDERED_THUMBNAIL_STYLES.dup
@@ -421,6 +426,16 @@ module Pageflow
421
426
  plugin.configure(self)
422
427
  end
423
428
 
429
+ # Provide backwards compatibility as long as paged entry type has
430
+ # not been extracted completely. Prefer accessing entry type
431
+ # specific config via {#for_entry_type} for new code.
432
+ #
433
+ # @return {PageTypes}
434
+ # @since 0.7
435
+ def page_types
436
+ get_entry_type_config(PageflowPaged.entry_type).page_types
437
+ end
438
+
424
439
  # @deprecated Use `config.page_types.register` instead.
425
440
  def register_page_type(page_type)
426
441
  ActiveSupport::Deprecation.warn('Pageflow::Configuration#register_page_type is deprecated. Use config.page_types.register instead.', caller)
@@ -437,8 +452,28 @@ module Pageflow
437
452
  ActiveSupport::Deprecation.warn('Pageflow::Configuration#paperclip_filesystem_root is deprecated.', caller)
438
453
  end
439
454
 
440
- def revision_components
441
- page_types.map(&:revision_components).flatten.uniq
455
+ # Scope configuration to entries of a certain entry type or access
456
+ # entry type specific configuration. When building a configuration
457
+ # object for an entry, the passed block is only evaluated when
458
+ # types match. When building `Pageflow.config`, all
459
+ # `for_entry_type` blocks are evaluated.
460
+ #
461
+ # @param [EntryType] type
462
+ #
463
+ # @yieldparam [EntryTypeConfiguration] entry_type_config -
464
+ # Instance of configuration class passed as `configuration`
465
+ # option during registration of entry type.
466
+ #
467
+ # @since 15.1
468
+ def for_entry_type(type)
469
+ return if @target_type_name && @target_type_name != type.name
470
+
471
+ yield get_entry_type_config(type)
472
+ end
473
+
474
+ # @api private
475
+ def get_entry_type_config(type)
476
+ @entry_type_configs[type.name] ||= type.configuration.new(self, type)
442
477
  end
443
478
 
444
479
  # @api private
@@ -464,7 +499,7 @@ module Pageflow
464
499
 
465
500
  # Restricts the configuration interface to those parts which can
466
501
  # be used from inside features.
467
- class FeatureLevelConfiguration < Struct.new(:config)
502
+ FeatureLevelConfiguration = Struct.new(:config) do
468
503
  delegate :page_types, to: :config
469
504
  delegate :widget_types, to: :config
470
505
  delegate :help_entries, to: :config
@@ -472,6 +507,32 @@ module Pageflow
472
507
  delegate :admin_attributes_table_rows, to: :config
473
508
  delegate :themes, to: :config
474
509
  delegate :file_importers, to: :config
510
+
511
+ delegate :for_entry_type, to: :config
512
+ end
513
+
514
+ # @api private
515
+ class ConfigView
516
+ def initialize(config, entry_type)
517
+ @config = config
518
+ @entry_type_config = config.get_entry_type_config(entry_type)
519
+ end
520
+
521
+ def method_missing(method, *args)
522
+ if @config.respond_to?(method)
523
+ @config.send(method, *args)
524
+ elsif @entry_type_config.respond_to?(method)
525
+ @entry_type_config.send(method, *args)
526
+ else
527
+ super
528
+ end
529
+ end
530
+
531
+ def respond_to_missing?(method_name, include_private = false)
532
+ @config.respond_to?(method_name) ||
533
+ @entry_type_config.respond_to?(method_name) ||
534
+ super
535
+ end
475
536
  end
476
537
  end
477
538
  end