Skip to content

Asset pipeline support - #1

Open
saharvey wants to merge 8 commits into
mainfrom
asset-pipeline-support
Open

Asset pipeline support#1
saharvey wants to merge 8 commits into
mainfrom
asset-pipeline-support

Conversation

@saharvey

Copy link
Copy Markdown
Collaborator

What's this PR do?

Adds CDN support to lookbook_asset_path so Lookbook's pre-built CSS/JS/image assets can be served from a host app's CDN in production, instead of only via the gem's built-in Rack::Static
middleware.

Also fixes the icon component to route its SVG sprite through that same helper instead of a hardcoded path.

Why is it needed?

Host apps that serve assets from a CDN had no way to get Lookbook's own assets onto that CDN, they were only ever served from the gem's in-process middleware, which doesn't work once a host app is actually accessed through a CDN in front of the app.

Where should the reviewer start?

Start with app/helpers/lookbook/application_helper.rb where lookbook_asset_path is the core of this change (CDN URL vs. middleware fallback), and once that logic makes sense, lib/tasks/lookbook_assets.rake (how the assets actually get onto disk for deploy) and the icon component's use of the same helper both follow naturally from it.

How should this be manually tested?

This is on staging 2: https://stg-02.studiosity.com/connect/admin/lookbook/inspect/button/warning

Screenshots (if appropriate)

CleanShot 2569-07-14 at 15 52 42


private

def middleware_path(file, version)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would suggest adding a lookbook_ prefix given this will still bleed into the view helper method space (or, despite the ABC increase, simply inline it. Not perfect.. but less pollution to the views

Comment thread lib/tasks/lookbook_assets.rake Outdated
# Hook into assets:precompile so this runs automatically during deployment
if Rake::Task.task_defined?('assets:precompile')
Rake::Task['assets:precompile'].enhance do
Rake::Task['lookbook:copy_assets'].invoke

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this also be wrapped in the same guard as above. ie

if Rails.application.config.action_controller.respond_to?(:asset_host) &&
     Rails.application.config.action_controller.asset_host.present?

Comment thread Gemfile.lock
css_parser
htmlbeautifier (~> 1.3)
htmlentities (~> 4.3.4)
htmlentities (~> 4.3)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this intentional?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this happened upstream, not sure why the lock file wasn't updated

632d8fa

<%= render_component_tag :i, style: "height: #{size_rems}; width: #{size_rems}; #{@html_attrs[:style]}", class: "icon-stroke-#{stroke}" do %>
<svg>
<use href="/lookbook-assets/img/lucide-sprite.svg#<%= @icon_name %>"></use>
<use href="<%= sprite_path %>#<%= @icon_name %>"></use>

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use lookbook_asset_path instead of hardcoding the path

Comment thread Gemfile.lock
css_parser
htmlbeautifier (~> 1.3)
htmlentities (~> 4.3.4)
htmlentities (~> 4.3)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this happened upstream, not sure why the lock file wasn't updated

632d8fa

@abrom abrom left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants