Skip to content

Commit

Permalink
Merge pull request #2083 from tf/additional-editor-stylesheet-packs
Browse files Browse the repository at this point in the history
Allow registering additional editor packs with stylesheets
  • Loading branch information
tf authored Feb 23, 2024
2 parents a390c00 + 0a62196 commit afe174f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
11 changes: 11 additions & 0 deletions entry_types/scrolled/app/helpers/pageflow_scrolled/packs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ def scrolled_editor_javascript_packs_tag(entry)
)
end

def scrolled_editor_stylesheet_packs_tag(entry)
stylesheet_pack_tag(
*scrolled_editor_stylesheet_packs(entry),
media: 'all'
)
end

def scrolled_frontend_packs(entry, widget_scope:)
['pageflow-scrolled-frontend'] +
scrolled_additional_frontend_packs(entry, widget_scope) +
Expand All @@ -34,6 +41,10 @@ def scrolled_editor_packs(entry)
scrolled_frontend_widget_type_packs(entry, :editor)
end

def scrolled_editor_stylesheet_packs(entry)
Pageflow.config_for(entry).additional_editor_packs.stylesheet_paths
end

private

def scrolled_additional_frontend_packs(entry, widget_scope)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@

<%= scrolled_webpack_public_path_script_tag %>
<%= scrolled_editor_javascript_packs_tag(entry) %>
<%= scrolled_editor_stylesheet_packs_tag(entry) %>
11 changes: 8 additions & 3 deletions entry_types/scrolled/lib/pageflow_scrolled/additional_packs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def initialize

# content_element_type_names option only takes effect for frontend
# packs.
def register(path, content_element_type_names: [])
@packs << AdditionalPack.new(path, content_element_type_names)
def register(path, content_element_type_names: [], stylesheet: false)
@packs << AdditionalPack.new(path, content_element_type_names, stylesheet)
end

# @api private
Expand All @@ -24,6 +24,11 @@ def paths
@packs.map(&:path)
end

# @api private
def stylesheet_paths
@packs.select(&:stylesheet).map(&:path)
end

# @api private
def paths_for_content_element_types(type_names)
@packs.reject { |pack|
Expand All @@ -33,6 +38,6 @@ def paths_for_content_element_types(type_names)
end

# @api private
AdditionalPack = Struct.new(:path, :content_element_type_names)
AdditionalPack = Struct.new(:path, :content_element_type_names, :stylesheet)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -247,5 +247,36 @@ module PageflowScrolled
expect(result).to include('pageflow-scrolled/widgets/customNavigation')
end
end

describe 'scrolled_editor_stylesheet_packs' do
it 'empty by default' do
entry = create(:published_entry, type_name: 'scrolled')

result = helper.scrolled_editor_stylesheet_packs(entry)

expect(result).to eq([])
end

it 'includes additional editor packs in editor with stylesheet option' do
pageflow_configure do |config|
config.for_entry_type(PageflowScrolled.entry_type) do |entry_type_config|
entry_type_config.additional_editor_packs.register(
'pageflow-scrolled/only-js'
)

entry_type_config.additional_editor_packs.register(
'pageflow-scrolled/extra-editor',
stylesheet: true
)
end
end

entry = create(:published_entry, type_name: 'scrolled')

result = helper.scrolled_editor_stylesheet_packs(entry)

expect(result).to eq(['pageflow-scrolled/extra-editor'])
end
end
end
end

0 comments on commit afe174f

Please sign in to comment.