Skip to content

Commit

Permalink
Use Rails app root to join paths
Browse files Browse the repository at this point in the history
Without that it is not always ensured that the path is
the hosts apps root path.
  • Loading branch information
tvdeyen committed May 8, 2020
1 parent afb1787 commit 94a0123
Showing 1 changed file with 36 additions and 16 deletions.
52 changes: 36 additions & 16 deletions lib/generators/alchemy/install/install_generator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require "rails"
require "rails/generators"

module Alchemy
module Generators
Expand All @@ -14,41 +14,41 @@ class InstallGenerator < ::Rails::Generators::Base
source_root File.expand_path("files", __dir__)

def copy_config
copy_file "#{config_path}/config.yml", "config/alchemy/config.yml"
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", "config/alchemy/#{file}.yml"
template "#{__dir__}/templates/#{file}.yml.tt", app_config_path.join("alchemy", "#{file}.yml")
end
end

def install_assets
copy_file "all.js", "vendor/assets/javascripts/alchemy/admin/all.js"
copy_file "all.css", "vendor/assets/stylesheets/alchemy/admin/all.css"
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/layouts/application.html.erb"
copy_file "article.scss", "app/assets/stylesheets/alchemy/elements/article.scss"
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/stylesheets/application.css")
insert_into_file "app/assets/stylesheets/application.css", stylesheet_require,
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/stylesheets/application.css", "/*\n#{stylesheet_require} */\n"
create_file app_assets_path.join("stylesheets", "application.css"), "/*\n#{stylesheet_require} */\n"
end

copy_file "_article.html.erb", "app/views/alchemy/elements/_article.html.erb"
copy_file "_standard.html.erb", "app/views/alchemy/page_layouts/_standard.html.erb"
copy_file "alchemy.en.yml", "config/locales/alchemy.en.yml"
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", "config/initializers/dragonfly.rb"
template "#{__dir__}/templates/dragonfly.rb.tt", app_config_path.join("initializers", "dragonfly.rb")
end

def install_gutentag_migrations
Expand All @@ -57,8 +57,28 @@ def install_gutentag_migrations

private

def config_path
@_config_path ||= File.expand_path("../../../../../config/alchemy", __dir__)
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
Expand Down

0 comments on commit 94a0123

Please sign in to comment.