Skip to content

Commit

Permalink
Merge pull request #2003 from tf/rails-6-entry-types
Browse files Browse the repository at this point in the history
Fix scrolled specs for Rails 6
  • Loading branch information
tf authored Sep 18, 2023
2 parents 5ccd257 + b994fb7 commit f42e681
Show file tree
Hide file tree
Showing 16 changed files with 278 additions and 88 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,26 @@ jobs:
plugin-name: pageflow_scrolled
rspec-command: bin/rspec --tag ~js

- engine-name: pageflow_scrolled
ruby-version: 3.2
rails-version: "~> 6.1"
engine-directory: entry_types/scrolled
plugin-name: pageflow_scrolled
rspec-command: bin/rspec --tag ~js

- engine-name: pageflow_scrolled
ruby-version: 2.6
engine-directory: entry_types/scrolled
plugin-name: pageflow_scrolled
rspec-command: bin/rspec-with-retry-on-timeout --tag js

- engine-name: pageflow_scrolled
ruby-version: 3.2
rails-version: "~> 6.1"
engine-directory: entry_types/scrolled
plugin-name: pageflow_scrolled
rspec-command: bin/rspec-with-retry-on-timeout --tag js

env:
PAGEFLOW_RAILS_VERSION: ${{ matrix.rails-version }}

Expand Down Expand Up @@ -152,7 +166,7 @@ jobs:
- name: Precompile
working-directory: ${{ matrix.engine-directory }}
run: |
WEBPACKER_PRECOMPILE=false bin/rake app:assets:precompile
WEBPACKER_PRECOMPILE=false SHAKAPACKER_PRECOMPILE=false bin/rake app:assets:precompile
# Test

Expand Down
18 changes: 13 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,19 @@ end
# Required for XML serialization in Active Admin
gem 'activemodel-serializers-xml'

# Make webpacker available in specs. Host applications that want to
# use webpacker need to add it to their Gemfile themselves. Requiring
# webpacker in an engine file (like we normally do) would force all
# host application to install webpacker.
gem 'webpacker'
if Pageflow::RailsVersion.experimental?
# Make shakapacker available in specs. Host applications that want to
# use shakapacker need to add it to their Gemfile themselves. Requiring
# shakapacker in an engine file (like we normally do) would force all
# host application to install shakapacker.
gem 'shakapacker'
else
# Make webpacker available in specs. Host applications that want to
# use webpacker need to add it to their Gemfile themselves. Requiring
# webpacker in an engine file (like we normally do) would force all
# host application to install webpacker.
gem 'webpacker'
end

# Make tests fail on JS errors
gem 'capybara-chromedriver-logger', git: 'https://github.com/codevise/capybara-chromedriver-logger', branch: 'fix-selenium-4-deprecation', require: false
41 changes: 31 additions & 10 deletions entry_types/scrolled/app/helpers/pageflow_scrolled/packs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,43 @@ module PageflowScrolled
# @api private
module PacksHelper
def scrolled_frontend_javascript_packs_tag(entry, options)
javascript_packs_with_chunks_tag(
*scrolled_frontend_packs(entry, options)
)
if Pageflow::RailsVersion.experimental?
javascript_pack_tag(
*scrolled_frontend_packs(entry, **options),
defer: false
)
else
javascript_packs_with_chunks_tag(
*scrolled_frontend_packs(entry, **options)
)
end
end

def scrolled_frontend_stylesheet_packs_tag(entry, options)
stylesheet_packs_with_chunks_tag(
*scrolled_frontend_packs(entry, options),
media: 'all'
)
if Pageflow::RailsVersion.experimental?
stylesheet_pack_tag(
*scrolled_frontend_packs(entry, **options),
media: 'all'
)
else
stylesheet_packs_with_chunks_tag(
*scrolled_frontend_packs(entry, **options),
media: 'all'
)
end
end

def scrolled_editor_javascript_packs_tag(entry)
javascript_packs_with_chunks_tag(
*scrolled_editor_packs(entry)
)
if Pageflow::RailsVersion.experimental?
javascript_pack_tag(
*scrolled_editor_packs(entry),
defer: false
)
else
javascript_packs_with_chunks_tag(
*scrolled_editor_packs(entry)
)
end
end

def scrolled_frontend_packs(entry, widget_scope:)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ def scrolled_theme_asset_path(theme,
theme_file_role: nil,
theme_file_style: :resized,
relative_url: false)
prefix = Pageflow::RailsVersion.experimental? ? 'static' : 'media'

path =
theme.files.dig(theme_file_role, theme_file_style) ||
asset_pack_path("media/pageflow-scrolled/themes/#{theme.name}/#{path}")
asset_pack_path("#{prefix}/pageflow-scrolled/themes/#{theme.name}/#{path}")

if relative_url
URI.parse(path).path
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<%= stylesheet_link_tag 'pageflow_paged/editor', media: 'all' %>
<%= stylesheet_packs_with_chunks_tag 'pageflow-scrolled-frontend' %>

<% if Pageflow::RailsVersion.experimental? %>
<%= stylesheet_pack_tag 'pageflow-scrolled-frontend' %>
<% else %>
<%= stylesheet_packs_with_chunks_tag 'pageflow-scrolled-frontend' %>
<% end %>

<%= scrolled_theme_properties_style_tag(entry.theme) %>
<%= scrolled_theme_stylesheet_pack_tags(entry.theme) %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,66 @@ def theme_plugin
end

def install_packages
run 'yarn add postcss-url@^8.0.0 @fontsource/source-sans-pro'
if Pageflow::RailsVersion.experimental?
run 'yarn add css-loader style-loader' \
' mini-css-extract-plugin css-minimizer-webpack-plugin' \
' postcss postcss-loader postcss-url' \
' @fontsource/source-sans-pro'
else
run 'yarn add postcss-url@^8.0.0 @fontsource/source-sans-pro'
end
end

def webpack_config
return unless Pageflow::RailsVersion.experimental?

gsub_file(
'config/webpack/webpack.config.js',
"const { generateWebpackConfig } = require('shakapacker')",
"const { generateWebpackConfig, merge, mergeWithRules } = require('shakapacker')"
)

gsub_file(
'config/webpack/webpack.config.js',
'const webpackConfig = generateWebpackConfig()',
<<~JS
const webpackConfig = merge(
generateWebpackConfig(),
require('pageflow/config/webpack5'),
require('pageflow-scrolled/config/webpack')
)
JS
)

gsub_file(
'config/webpack/webpack.config.js',
'module.exports = webpackConfig',
<<~JS
// Extend file rule to include mp3 extension
module.exports = mergeWithRules({
module: {
rules: {
test: 'replace',
type: 'match'
},
},
})(webpackConfig, {
module: {
rules: [
{
test: /\.(bmp|gif|jpe?g|png|tiff|ico|avif|webp|eot|otf|ttf|woff|woff2|svg|mp3)$/,
type: 'asset/resource'
}
]
}
})
JS
)
end

def webpack_environment
return if Pageflow::RailsVersion.experimental?

inject_into_file('config/webpack/environment.js',
before: "module.exports = environment\n") do
"environment.config.merge(require('pageflow/config/webpack'))\n" \
Expand All @@ -53,6 +109,8 @@ def webpack_environment
end

def webpacker_yml
return if Pageflow::RailsVersion.experimental?

gsub_file('config/webpacker.yml',
'extract_css: false',
'extract_css: true')
Expand All @@ -64,6 +122,8 @@ def webpacker_yml
end

def postcss_config
return if Pageflow::RailsVersion.experimental?

inject_into_file('postcss.config.js',
after: "require('postcss-import'),\n") do
" // Make relative urls in fontsource packages work\n" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def items_for_entry(entry, options)
entry.revision,
content_element_type_names
),
options
**options
)
end

Expand Down
Loading

0 comments on commit f42e681

Please sign in to comment.