Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate CSS entrypoint for Custom Admin CSS #3009

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/views/layouts/alchemy/admin.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<meta name="turbo-cache-control" content="no-cache">
<%= 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) %>
<%= yield :stylesheets %>
<script>
// Global Alchemy JavaScript object.
Expand Down
34 changes: 30 additions & 4 deletions lib/alchemy/upgrader/seven_point_three.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
# frozen_string_literal: true

require "fileutils"
require "thor"

module Alchemy
class Upgrader::SevenPointThree < Upgrader
def self.remove_admin_stylesheets
if File.exist? "vendor/assets/stylesheets/alchemy/admin/all.css"
log "Removing Alchemy admin stylesheets."
FileUtils.rm_f "vendor/assets/stylesheets/alchemy/admin/all.css"
include Thor::Base
include Thor::Actions

source_root Alchemy::Engine.root.join("lib/generators/alchemy/install/files")

class << self
def remove_admin_stylesheets
if File.exist? "vendor/assets/stylesheets/alchemy/admin/all.css"
log "Removing Alchemy admin stylesheets."
FileUtils.rm_f "vendor/assets/stylesheets/alchemy/admin/all.css"
end
end

def generate_custom_css_entrypoint
if File.exist? "app/assets/config/manifest.js"
log "Generating alchemy/admin/custom.css entrypoint file."
task.copy_file "custom.css", "app/assets/stylesheets/alchemy/admin/custom.css"
task.append_to_file "app/assets/config/manifest.js", "//= link alchemy/admin/custom.css\n"
todo(<<~TODO, "Custom styles have been moved to `app/assets/alchemy/admin/custom.css`")
Check the new `app/assets/alchemy/admin/custom.css` file for any custom styles you might
have added to the old `vendor/assets/stylesheets/alchemy/admin/all.css` file.
TODO
end
end

private

def task
@_task || new
end
end
end
Expand Down
1 change: 0 additions & 1 deletion lib/generators/alchemy/install/files/all.scss

This file was deleted.

4 changes: 4 additions & 0 deletions lib/generators/alchemy/install/files/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
* Edit this file to add custom styles to the Alchemy admin interface.
* This file will be loaded after the default Alchemy admin stylesheets.
*/
2 changes: 2 additions & 0 deletions lib/generators/alchemy/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def copy_yml_files

def install_assets
copy_file "all.js", app_vendor_assets_path.join("javascripts", "alchemy", "admin", "all.js")
copy_file "custom.css", app_assets_path.join("stylesheets/alchemy/admin/custom.css")
append_to_file Rails.root.join("app/assets/config/manifest.js"), "//= link alchemy/admin/custom.css\n"
end

def copy_demo_views
Expand Down
8 changes: 7 additions & 1 deletion lib/tasks/alchemy/upgrade.rake
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,19 @@ namespace :alchemy do

namespace "7.3" do
task "run" => [
"alchemy:upgrade:7.3:remove_admin_stylesheets"
"alchemy:upgrade:7.3:remove_admin_stylesheets",
"alchemy:upgrade:7.3:generate_custom_css_entrypoint"
]

desc "Remove alchemy admin stylesheets"
task remove_admin_stylesheets: [:environment] do
Alchemy::Upgrader::SevenPointThree.remove_admin_stylesheets
end

desc "Generate custom css entrypoint"
task generate_custom_css_entrypoint: [:environment] do
Alchemy::Upgrader::SevenPointThree.generate_custom_css_entrypoint
end
end
end
end
1 change: 1 addition & 0 deletions spec/dummy/app/assets/config/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
//= link_tree ../images
//= link tinymce/langs/de.js
//= link_tree ../builds
//= link alchemy/admin/custom.css
4 changes: 4 additions & 0 deletions spec/dummy/app/assets/stylesheets/alchemy/admin/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
* Edit this file to add custom styles to the Alchemy admin interface.
* This file will be loaded after the default Alchemy admin stylesheets.
*/