Skip to content

Commit

Permalink
Add admin_stylesheets
Browse files Browse the repository at this point in the history
Additional stylesheets to be included in the Alchemy admin UI

== Example

    # config/initializers/alchemy.rb
    Alchemy.admin_stylesheets << "alchemy/devise/admin.css"
  • Loading branch information
tvdeyen committed Feb 4, 2025
1 parent eeb8502 commit 8538e2a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
4 changes: 3 additions & 1 deletion app/views/layouts/alchemy/admin.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
<%= stylesheet_link_tag('alchemy/custom-properties', media: 'screen', 'data-turbo-track' => true) %>
<%= stylesheet_link_tag('alchemy/admin', media: 'screen', 'data-turbo-track' => true) %>
<%= stylesheet_link_tag('alchemy/admin/print', media: 'print', 'data-turbo-track' => true) %>
<%= stylesheet_link_tag('alchemy/admin/custom', 'data-turbo-track' => true) %>
<% Alchemy.admin_stylesheets.each do |stylesheet| %>
<%= stylesheet_link_tag(stylesheet, 'data-turbo-track' => true) %>
<% end %>
<%= yield :stylesheets %>
<script>
// Global Alchemy JavaScript object.
Expand Down
14 changes: 14 additions & 0 deletions lib/alchemy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ def self.admin_importmaps
}])
end

# Additional stylesheets to be included in the Alchemy admin UI
#
# == Example
#
# # lib/alchemy/devise/engine.rb
# initializer "alchemy.devise.stylesheets", before: "alchemy.admin_stylesheets" do
# Alchemy.admin_stylesheets << "alchemy/devise/admin.css"
# end
#
# @return [Set<String>]
def self.admin_stylesheets
@_admin_stylesheets ||= Set.new(["alchemy/admin/custom.css"])
end

# Define page publish targets
#
# A publish target is a ActiveJob that gets performed
Expand Down
12 changes: 10 additions & 2 deletions lib/alchemy/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,19 @@ class Engine < Rails::Engine
end
end

initializer "alchemy.assets" do
initializer "alchemy.assets" do |app|
if defined?(Sprockets)
require_relative "../non_stupid_digest_assets"
NonStupidDigestAssets.whitelist += [/^tinymce\//]
Rails.application.config.assets.precompile << "alchemy_manifest.js"
app.config.assets.precompile << "alchemy_manifest.js"

Check warning on line 23 in lib/alchemy/engine.rb

View check run for this annotation

Codecov / codecov/patch

lib/alchemy/engine.rb#L23

Added line #L23 was not covered by tests
end
end

initializer "alchemy.admin_stylesheets" do |app|
if defined?(Sprockets)
Alchemy.admin_stylesheets.each do |stylesheet|
app.config.assets.precompile << stylesheet

Check warning on line 30 in lib/alchemy/engine.rb

View check run for this annotation

Codecov / codecov/patch

lib/alchemy/engine.rb#L29-L30

Added lines #L29 - L30 were not covered by tests
end
end
end

Expand Down
4 changes: 0 additions & 4 deletions lib/generators/alchemy/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ def copy_yml_files

def install_assets
copy_file "custom.css", app_assets_path.join("stylesheets/alchemy/admin/custom.css")
sprockets_manifest = Rails.root.join("app/assets/config/manifest.js")
if File.exist?(sprockets_manifest)
append_to_file sprockets_manifest, "//= link alchemy/admin/custom.css\n"
end
end

def copy_demo_views
Expand Down
1 change: 0 additions & 1 deletion spec/dummy/app/assets/config/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
//= link_tree ../images
//= link tinymce/langs/de.js
//= link_tree ../builds
//= link alchemy/admin/custom.css

0 comments on commit 8538e2a

Please sign in to comment.