From 10be8c0073b67dcfb7925996e81c2e717f8b499e Mon Sep 17 00:00:00 2001 From: elijah Date: Thu, 14 Nov 2013 02:19:03 -0800 Subject: added support for easier customizations via "config/customization" directory --- config/application.rb | 6 ++++++ config/customization/README.md | 27 +++++++++++++++++++++++++++ config/initializers/customization.rb | 31 +++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 config/customization/README.md create mode 100644 config/initializers/customization.rb (limited to 'config') diff --git a/config/application.rb b/config/application.rb index 8587ffc..8cf7e30 100644 --- a/config/application.rb +++ b/config/application.rb @@ -85,5 +85,11 @@ module LeapWeb # Set to false in order to see asset requests in the log config.quiet_assets = true + + ## + ## CUSTOMIZATION + ## see initializers/customization.rb + ## + config.paths['app/views'].unshift "config/customization/views" end end diff --git a/config/customization/README.md b/config/customization/README.md new file mode 100644 index 0000000..9c3e434 --- /dev/null +++ b/config/customization/README.md @@ -0,0 +1,27 @@ +Customizing LEAP Webapp +============================================ + +By default, this directory is empty. Any file you place here will override the default files for the application. + +For example: + + stylesheets/ -- overrides files Rails.root/app/assets/stylesheets + tail.scss -- included before all others + head.scss -- included after all others + + public/ -- overrides files in Rails.root/public + favicon.ico -- custom favicon + img/ -- customary directory to put images in + + views/ -- overrides files Rails.root/app/views + home/ + index.html.haml -- this file is what shows up on the home page + + locales/ -- overrides files in Rails.root/config/locales + en.yml -- overrides for English + de.yml -- overrides for German + and so on... + +For most changes, the web application must be restarted after any changes are made to the customization directory. + +Sometimes a `rake tmp:clear` and a rails restart is required to pick up a new stylesheet. diff --git a/config/initializers/customization.rb b/config/initializers/customization.rb new file mode 100644 index 0000000..a2f6f88 --- /dev/null +++ b/config/initializers/customization.rb @@ -0,0 +1,31 @@ +# +# When deploying, common customizations can be dropped in config/customizations. This initializer makes this work. +# +customization_directory = "#{Rails.root}/config/customization" + +# +# Set customization views as the first view path +# +# Rails.application.config.paths['app/views'].unshift "config/customization/views" +# (For some reason, this does not work here. See application.rb for where this is actually called.) + +# +# Set customization stylesheets as the first asset path +# +# (This cannot go in application.rb, because the default paths +# haven't been loaded yet, as far as I can tell) +# +Rails.application.config.assets.paths.unshift "#{customization_directory}/stylesheets" + +# +# Copy files to public +# +if Dir.exists?("#{customization_directory}/public") + require 'fileutils' + FileUtils.cp_r("#{customization_directory}/public/.", "#{Rails.root}/public") +end + +# +# Add I18n path +# +Rails.application.config.i18n.load_path += Dir["#{customization_directory}/locales/*.{rb,yml,yaml}"] -- cgit v1.2.3 From 84682ee6261967935d16fbeae1190af26420563e Mon Sep 17 00:00:00 2001 From: elijah Date: Thu, 14 Nov 2013 15:50:22 -0800 Subject: ensure that we only copy files when running restarting the app, not every time a rake task is run (especially since some rake tasks get run as root!) --- config/initializers/customization.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'config') diff --git a/config/initializers/customization.rb b/config/initializers/customization.rb index a2f6f88..08da518 100644 --- a/config/initializers/customization.rb +++ b/config/initializers/customization.rb @@ -20,7 +20,7 @@ Rails.application.config.assets.paths.unshift "#{customization_directory}/styles # # Copy files to public # -if Dir.exists?("#{customization_directory}/public") +if !defined?(RAKE) && Dir.exists?("#{customization_directory}/public") require 'fileutils' FileUtils.cp_r("#{customization_directory}/public/.", "#{Rails.root}/public") end -- cgit v1.2.3 From 4193a94b4cc5b5cabbace8311562c0ca88a79f74 Mon Sep 17 00:00:00 2001 From: elijah Date: Fri, 15 Nov 2013 00:25:40 -0800 Subject: fix problem with custom scss files and precompiling assets in production mode. --- config/application.rb | 2 +- config/initializers/customization.rb | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'config') diff --git a/config/application.rb b/config/application.rb index 8cf7e30..2c9c55a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -78,7 +78,7 @@ module LeapWeb # Enable the asset pipeline config.assets.enabled = true - config.assets.initialize_on_precompile = false + config.assets.initialize_on_precompile = true # don't change this (see customization.rb) # Version of your assets, change this if you want to expire all your assets config.assets.version = '1.0' diff --git a/config/initializers/customization.rb b/config/initializers/customization.rb index 08da518..bc9c834 100644 --- a/config/initializers/customization.rb +++ b/config/initializers/customization.rb @@ -12,8 +12,13 @@ customization_directory = "#{Rails.root}/config/customization" # # Set customization stylesheets as the first asset path # -# (This cannot go in application.rb, because the default paths -# haven't been loaded yet, as far as I can tell) +# Some notes: +# +# * This cannot go in application.rb, as far as I can tell. In application.rb, the default paths +# haven't been loaded yet, so the path we add will always end up at the end unless we add it here. +# +# * For this to work, config.assets.initialize_on_precompile MUST be set to true, otherwise +# this initializer will never get called in production mode when the assets are precompiled. # Rails.application.config.assets.paths.unshift "#{customization_directory}/stylesheets" -- cgit v1.2.3