-
-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use rails root in install generator (#1822)
* Move generators out of rails folder * Use Rails app root to join paths Without that it is not always ensured that the path is the hosts apps root path. * Refactor elements generator naming validation
- Loading branch information
Showing
44 changed files
with
99 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# frozen_string_literal: true | ||
require "rails/generators" | ||
|
||
module Alchemy | ||
module Generators | ||
class InstallGenerator < ::Rails::Generators::Base | ||
desc "Installs Alchemy into your App." | ||
|
||
class_option :skip_demo_files, | ||
type: :boolean, | ||
default: false, | ||
desc: "Skip creation of demo element, page and application layout." | ||
|
||
source_root File.expand_path("files", __dir__) | ||
|
||
def copy_config | ||
copy_file "#{gem_config_path}/config.yml", app_config_path.join("alchemy", "config.yml") | ||
end | ||
|
||
def copy_yml_files | ||
%w(elements page_layouts menus).each do |file| | ||
template "#{__dir__}/templates/#{file}.yml.tt", app_config_path.join("alchemy", "#{file}.yml") | ||
end | ||
end | ||
|
||
def install_assets | ||
copy_file "all.js", app_vendor_assets_path.join("javascripts", "alchemy", "admin", "all.js") | ||
copy_file "all.css", app_vendor_assets_path.join("stylesheets", "alchemy", "admin", "all.css") | ||
end | ||
|
||
def copy_demo_views | ||
return if @options[:skip_demo_files] | ||
|
||
copy_file "application.html.erb", app_views_path.join("layouts", "application.html.erb") | ||
copy_file "article.scss", app_assets_path.join("stylesheets", "alchemy", "elements", "article.scss") | ||
|
||
stylesheet_require = " *= require_tree ./alchemy/elements\n" | ||
if File.exist?(app_assets_path.join("stylesheets", "application.css")) | ||
insert_into_file app_assets_path.join("stylesheets", "application.css"), stylesheet_require, | ||
before: " */" | ||
else | ||
create_file app_assets_path.join("stylesheets", "application.css"), "/*\n#{stylesheet_require} */\n" | ||
end | ||
|
||
copy_file "_article.html.erb", app_views_path.join("alchemy", "elements", "_article.html.erb") | ||
copy_file "_standard.html.erb", app_views_path.join("alchemy", "page_layouts", "_standard.html.erb") | ||
copy_file "alchemy.en.yml", app_config_path.join("locales", "alchemy.en.yml") | ||
end | ||
|
||
def copy_dragonfly_config | ||
template "#{__dir__}/templates/dragonfly.rb.tt", app_config_path.join("initializers", "dragonfly.rb") | ||
end | ||
|
||
def install_gutentag_migrations | ||
rake "gutentag:install:migrations" | ||
end | ||
|
||
private | ||
|
||
def gem_config_path | ||
@_config_path ||= File.expand_path("../../../../config/alchemy", __dir__) | ||
end | ||
|
||
def app_config_path | ||
@_app_config_path ||= app_root.join("config") | ||
end | ||
|
||
def app_views_path | ||
@_app_views_path ||= app_root.join("app", "views") | ||
end | ||
|
||
def app_assets_path | ||
@_app_assets_path ||= app_root.join("app", "assets") | ||
end | ||
|
||
def app_vendor_assets_path | ||
@_app_vendor_assets_path ||= app_root.join("vendor", "assets") | ||
end | ||
|
||
def app_root | ||
@_app_root ||= Rails.root | ||
end | ||
end | ||
end | ||
end |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../../../../lib/rails/generators/alchemy/install/files/all.js | ||
../../../../../../../lib/generators/alchemy/install/files/all.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../../../../../../../lib/rails/generators/alchemy/install/files/all.css | ||
../../../../../../../lib/generators/alchemy/install/files/all.css |