From fa7fbe61861519f729c12456e66d96e660310af0 Mon Sep 17 00:00:00 2001 From: Yuri Pimenov Date: Tue, 31 Dec 2013 18:36:42 +0200 Subject: [PATCH 1/9] Route definitions for rails4 --- lib/themes_for_rails/routes.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/themes_for_rails/routes.rb b/lib/themes_for_rails/routes.rb index d52301b..95a05eb 100644 --- a/lib/themes_for_rails/routes.rb +++ b/lib/themes_for_rails/routes.rb @@ -6,11 +6,12 @@ def themes_for_rails theme_dir = ThemesForRails.config.themes_routes_dir constraints = { :theme => /[\w\.]*/ } - match "#{theme_dir}/:theme/stylesheets/*asset" => 'themes_for_rails/assets#stylesheets', + + get "#{theme_dir}/:theme/stylesheets/*asset" => 'themes_for_rails/assets#stylesheets', :as => :base_theme_stylesheet, :constraints => constraints - match "#{theme_dir}/:theme/javascripts/*asset" => 'themes_for_rails/assets#javascripts', + get "#{theme_dir}/:theme/javascripts/*asset" => 'themes_for_rails/assets#javascripts', :as => :base_theme_javascript, :constraints => constraints - match "#{theme_dir}/:theme/images/*asset" => 'themes_for_rails/assets#images', + get "#{theme_dir}/:theme/images/*asset" => 'themes_for_rails/assets#images', :as => :base_theme_image, :constraints => constraints end From 7701ef4c28dfb2058c287ce2d9381b74b19d8d96 Mon Sep 17 00:00:00 2001 From: Yuri Pimenov Date: Thu, 2 Jan 2014 12:26:50 +0200 Subject: [PATCH 2/9] Debug --- lib/themes_for_rails/assets_controller.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/themes_for_rails/assets_controller.rb b/lib/themes_for_rails/assets_controller.rb index efbd38c..4eb2d96 100644 --- a/lib/themes_for_rails/assets_controller.rb +++ b/lib/themes_for_rails/assets_controller.rb @@ -28,6 +28,11 @@ def handle_asset(prefix) end def find_themed_asset(asset_name, asset_theme, asset_type, &block) + puts asset_name + puts asset_theme + puts asset_type + raise 'x' + if asset_type == 'stylesheets' path = asset_stylesheets_path(asset_name, asset_theme, asset_type) else From 458b99a0bd924b0fa4c5575ed87bf02fdabfc597 Mon Sep 17 00:00:00 2001 From: Yuri Pimenov Date: Thu, 2 Jan 2014 17:29:10 +0200 Subject: [PATCH 3/9] Handle assets with sprockets --- lib/themes_for_rails.rb | 2 +- lib/themes_for_rails/common_methods.rb | 13 ++++++++++++- lib/themes_for_rails/railtie.rb | 4 ++-- lib/themes_for_rails/routes.rb | 13 ++++++------- lib/themes_for_rails/url_helpers.rb | 23 +++++++++++++++++++++-- 5 files changed, 42 insertions(+), 13 deletions(-) diff --git a/lib/themes_for_rails.rb b/lib/themes_for_rails.rb index 09a97a9..b68774e 100644 --- a/lib/themes_for_rails.rb +++ b/lib/themes_for_rails.rb @@ -53,7 +53,7 @@ def already_configured_in_sass?(sass_dir) require 'themes_for_rails/url_helpers' require 'themes_for_rails/action_view' -require 'themes_for_rails/assets_controller' +#require 'themes_for_rails/assets_controller' require 'themes_for_rails/action_controller' require 'themes_for_rails/action_mailer' require 'themes_for_rails/railtie' diff --git a/lib/themes_for_rails/common_methods.rb b/lib/themes_for_rails/common_methods.rb index c7fe876..bec080e 100644 --- a/lib/themes_for_rails/common_methods.rb +++ b/lib/themes_for_rails/common_methods.rb @@ -24,6 +24,7 @@ def set_theme(name) self.theme_name = name if valid_theme? add_theme_view_path + add_theme_sprockets_path end end @@ -62,5 +63,15 @@ def theme_view_path_for(theme_name) def theme_asset_path_for(theme_name) interpolate(ThemesForRails.config.assets_dir, theme_name) end + + protected + + def add_theme_sprockets_path + unless Rails.application.assets.paths.include?(theme_asset_path) + Rails.application.assets.prepend_path File.join(theme_asset_path, 'stylesheets') + end + puts Rails.application.assets.paths.inspect + end + end -end \ No newline at end of file +end diff --git a/lib/themes_for_rails/railtie.rb b/lib/themes_for_rails/railtie.rb index 276446d..d64576f 100644 --- a/lib/themes_for_rails/railtie.rb +++ b/lib/themes_for_rails/railtie.rb @@ -10,7 +10,7 @@ class Railtie < ::Rails::Railtie end # Adding theme stylesheets path to sass, automatically. - ThemesForRails.add_themes_path_to_sass if ThemesForRails.config.use_sass? + #ThemesForRails.add_themes_path_to_sass if ThemesForRails.config.use_sass? ActiveSupport.on_load(:action_view) do include ThemesForRails::ActionView @@ -29,4 +29,4 @@ class Railtie < ::Rails::Railtie load "tasks/themes_for_rails.rake" end end -end \ No newline at end of file +end diff --git a/lib/themes_for_rails/routes.rb b/lib/themes_for_rails/routes.rb index 95a05eb..8950541 100644 --- a/lib/themes_for_rails/routes.rb +++ b/lib/themes_for_rails/routes.rb @@ -5,14 +5,13 @@ module Routes def themes_for_rails theme_dir = ThemesForRails.config.themes_routes_dir constraints = { :theme => /[\w\.]*/ } - - get "#{theme_dir}/:theme/stylesheets/*asset" => 'themes_for_rails/assets#stylesheets', - :as => :base_theme_stylesheet, :constraints => constraints - get "#{theme_dir}/:theme/javascripts/*asset" => 'themes_for_rails/assets#javascripts', - :as => :base_theme_javascript, :constraints => constraints - get "#{theme_dir}/:theme/images/*asset" => 'themes_for_rails/assets#images', - :as => :base_theme_image, :constraints => constraints +# get "#{theme_dir}/:theme/stylesheets/*asset" => 'themes_for_rails/assets#stylesheets', +# :as => :base_theme_stylesheet, :constraints => constraints +# get "#{theme_dir}/:theme/javascripts/*asset" => 'themes_for_rails/assets#javascripts', +# :as => :base_theme_javascript, :constraints => constraints +# get "#{theme_dir}/:theme/images/*asset" => 'themes_for_rails/assets#images', +# :as => :base_theme_image, :constraints => constraints end end diff --git a/lib/themes_for_rails/url_helpers.rb b/lib/themes_for_rails/url_helpers.rb index 43dbc47..541d607 100644 --- a/lib/themes_for_rails/url_helpers.rb +++ b/lib/themes_for_rails/url_helpers.rb @@ -9,7 +9,19 @@ module UrlHelpers :current_theme_javascript_path, :current_theme_image_path end - + + def base_theme_stylesheet_path(args) + base_theme_asset_path('stylesheets', args) + end + + def base_theme_javascript_path(args) + base_theme_asset_path('javascripts', args) + end + + def base_theme_image_path(args) + base_theme_asset_path('images', args) + end + def current_theme_stylesheet_path(asset) base_theme_stylesheet_path(:theme => self.theme_name, :asset => "#{asset}.css") end @@ -23,5 +35,12 @@ def current_theme_image_path(asset) base_theme_image_path(:theme => self.theme_name, :asset => "#{image}.#{extension}") end + protected + + def base_theme_asset_path(asset, args) + theme_dir = ThemesForRails.config.themes_routes_dir + File.join('/themes', args[:theme], asset, args[:asset]) + end + end -end \ No newline at end of file +end From 80977dfa9b410024f09f09dd5e366c3e780fa39d Mon Sep 17 00:00:00 2001 From: Yuri Pimenov Date: Thu, 2 Jan 2014 18:37:36 +0200 Subject: [PATCH 4/9] Forgotten javascripts and images path --- lib/themes_for_rails/assets_controller.rb | 5 ----- lib/themes_for_rails/common_methods.rb | 9 +++++---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/themes_for_rails/assets_controller.rb b/lib/themes_for_rails/assets_controller.rb index 4eb2d96..efbd38c 100644 --- a/lib/themes_for_rails/assets_controller.rb +++ b/lib/themes_for_rails/assets_controller.rb @@ -28,11 +28,6 @@ def handle_asset(prefix) end def find_themed_asset(asset_name, asset_theme, asset_type, &block) - puts asset_name - puts asset_theme - puts asset_type - raise 'x' - if asset_type == 'stylesheets' path = asset_stylesheets_path(asset_name, asset_theme, asset_type) else diff --git a/lib/themes_for_rails/common_methods.rb b/lib/themes_for_rails/common_methods.rb index bec080e..6416136 100644 --- a/lib/themes_for_rails/common_methods.rb +++ b/lib/themes_for_rails/common_methods.rb @@ -67,10 +67,11 @@ def theme_asset_path_for(theme_name) protected def add_theme_sprockets_path - unless Rails.application.assets.paths.include?(theme_asset_path) - Rails.application.assets.prepend_path File.join(theme_asset_path, 'stylesheets') - end - puts Rails.application.assets.paths.inspect + ['stylesheets', 'javascripts', 'images'].each do |kind| + path = File.join(theme_asset_path, kind) + unless Rails.application.assets.paths.include?(path) + Rails.application.assets.prepend_path path + end end end From 081386d491eeb0af7101b2ad4ce739b8dd1ab568 Mon Sep 17 00:00:00 2001 From: Yuri Pimenov Date: Thu, 2 Jan 2014 18:43:21 +0200 Subject: [PATCH 5/9] Fix syntax error --- lib/themes_for_rails/common_methods.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/themes_for_rails/common_methods.rb b/lib/themes_for_rails/common_methods.rb index 6416136..743687d 100644 --- a/lib/themes_for_rails/common_methods.rb +++ b/lib/themes_for_rails/common_methods.rb @@ -72,6 +72,7 @@ def add_theme_sprockets_path unless Rails.application.assets.paths.include?(path) Rails.application.assets.prepend_path path end + end end end From 37aa64bddcd2c9f096950688e5628bef23bb67e3 Mon Sep 17 00:00:00 2001 From: Yuri Pimenov Date: Tue, 21 Jan 2014 17:20:31 +0200 Subject: [PATCH 6/9] Crash on production: TypeError (can't modify immutable index): sprockets (2.10.1) lib/sprockets/index.rb:81:in `expire_index!' sprockets (2.10.1) lib/sprockets/base.rb:103:in `prepend_path' --- lib/themes_for_rails/common_methods.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/themes_for_rails/common_methods.rb b/lib/themes_for_rails/common_methods.rb index 743687d..9f54d3d 100644 --- a/lib/themes_for_rails/common_methods.rb +++ b/lib/themes_for_rails/common_methods.rb @@ -24,7 +24,7 @@ def set_theme(name) self.theme_name = name if valid_theme? add_theme_view_path - add_theme_sprockets_path + #add_theme_sprockets_path end end From ac9ee63770e431ec3d95f96dedc190a0c472a10c Mon Sep 17 00:00:00 2001 From: Yuri Pimenov Date: Tue, 19 Jan 2016 15:45:01 +0200 Subject: [PATCH 7/9] If you are working on a gem, then DO NOT check in your Gemfile.lock. --- .gitignore | 3 ++ Gemfile.lock | 91 ---------------------------------------------------- 2 files changed, 3 insertions(+), 91 deletions(-) delete mode 100644 Gemfile.lock diff --git a/.gitignore b/.gitignore index 7fa29ee..ad019ae 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,6 @@ spec/dummy/db/*.sqlite3 spec/dummy/log/test.log .svn *.gem + +# http://stackoverflow.com/questions/4151495/should-gemfile-lock-be-included-in-gitignore +Gemfile.lock diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 039bfde..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,91 +0,0 @@ -PATH - remote: . - specs: - themes_for_rails (0.5.1) - rails (>= 3.0.0) - -GEM - remote: http://rubygems.org/ - specs: - abstract (1.0.0) - actionmailer (3.0.11) - actionpack (= 3.0.11) - mail (~> 2.2.19) - actionpack (3.0.11) - activemodel (= 3.0.11) - activesupport (= 3.0.11) - builder (~> 2.1.2) - erubis (~> 2.6.6) - i18n (~> 0.5.0) - rack (~> 1.2.1) - rack-mount (~> 0.6.14) - rack-test (~> 0.5.7) - tzinfo (~> 0.3.23) - activemodel (3.0.11) - activesupport (= 3.0.11) - builder (~> 2.1.2) - i18n (~> 0.5.0) - activerecord (3.0.11) - activemodel (= 3.0.11) - activesupport (= 3.0.11) - arel (~> 2.0.10) - tzinfo (~> 0.3.23) - activeresource (3.0.11) - activemodel (= 3.0.11) - activesupport (= 3.0.11) - activesupport (3.0.11) - arel (2.0.10) - builder (2.1.2) - contest (0.1.2) - erubis (2.6.6) - abstract (>= 1.0.0) - i18n (0.5.0) - json (1.6.5) - mail (2.2.19) - activesupport (>= 2.3.6) - i18n (>= 0.4.0) - mime-types (~> 1.16) - treetop (~> 1.4.8) - mime-types (1.17.2) - mocha (0.9.12) - polyglot (0.3.3) - rack (1.2.5) - rack-mount (0.6.14) - rack (>= 1.0.0) - rack-test (0.5.7) - rack (>= 1.0) - rails (3.0.11) - actionmailer (= 3.0.11) - actionpack (= 3.0.11) - activerecord (= 3.0.11) - activeresource (= 3.0.11) - activesupport (= 3.0.11) - bundler (~> 1.0) - railties (= 3.0.11) - railties (3.0.11) - actionpack (= 3.0.11) - activesupport (= 3.0.11) - rake (>= 0.8.7) - rdoc (~> 3.4) - thor (~> 0.14.4) - rake (0.9.2.2) - rdoc (3.12) - json (~> 1.4) - sqlite3 (1.3.5) - test-unit (2.2.0) - thor (0.14.6) - treetop (1.4.10) - polyglot - polyglot (>= 0.3.1) - tzinfo (0.3.31) - -PLATFORMS - ruby - -DEPENDENCIES - contest - mocha - rails (= 3.0.11) - sqlite3 - test-unit - themes_for_rails! From 03f8e0423cea6ba744af42846dfb3249d58a655c Mon Sep 17 00:00:00 2001 From: Yuri Pimenov Date: Tue, 19 Jan 2016 16:07:01 +0200 Subject: [PATCH 8/9] Fix missing helper-method --- lib/themes_for_rails/url_helpers.rb | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/themes_for_rails/url_helpers.rb b/lib/themes_for_rails/url_helpers.rb index 541d607..7a9ea11 100644 --- a/lib/themes_for_rails/url_helpers.rb +++ b/lib/themes_for_rails/url_helpers.rb @@ -3,6 +3,7 @@ module ThemesForRails module UrlHelpers extend ActiveSupport::Concern + include AbstractController::Helpers included do helper_method :current_theme_stylesheet_path, @@ -10,17 +11,17 @@ module UrlHelpers :current_theme_image_path end - def base_theme_stylesheet_path(args) - base_theme_asset_path('stylesheets', args) - end + #def base_theme_stylesheet_path(args) + # base_theme_asset_path('stylesheets', args) + #end - def base_theme_javascript_path(args) - base_theme_asset_path('javascripts', args) - end + #def base_theme_javascript_path(args) + # base_theme_asset_path('javascripts', args) + #end - def base_theme_image_path(args) - base_theme_asset_path('images', args) - end + #def base_theme_image_path(args) + # base_theme_asset_path('images', args) + #end def current_theme_stylesheet_path(asset) base_theme_stylesheet_path(:theme => self.theme_name, :asset => "#{asset}.css") @@ -37,10 +38,10 @@ def current_theme_image_path(asset) protected - def base_theme_asset_path(asset, args) - theme_dir = ThemesForRails.config.themes_routes_dir - File.join('/themes', args[:theme], asset, args[:asset]) - end + #def base_theme_asset_path(asset, args) + # theme_dir = ThemesForRails.config.themes_routes_dir + # File.join('/themes', args[:theme], asset, args[:asset]) + #end end end From 38474f75bed3fa753bda91e59a6bed17eab10b59 Mon Sep 17 00:00:00 2001 From: Yuri Pimenov Date: Tue, 19 Jan 2016 16:09:40 +0200 Subject: [PATCH 9/9] Get back those strange methods --- lib/themes_for_rails/url_helpers.rb | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/themes_for_rails/url_helpers.rb b/lib/themes_for_rails/url_helpers.rb index 7a9ea11..1010288 100644 --- a/lib/themes_for_rails/url_helpers.rb +++ b/lib/themes_for_rails/url_helpers.rb @@ -11,17 +11,17 @@ module UrlHelpers :current_theme_image_path end - #def base_theme_stylesheet_path(args) - # base_theme_asset_path('stylesheets', args) - #end + def base_theme_stylesheet_path(args) + base_theme_asset_path('stylesheets', args) + end - #def base_theme_javascript_path(args) - # base_theme_asset_path('javascripts', args) - #end + def base_theme_javascript_path(args) + base_theme_asset_path('javascripts', args) + end - #def base_theme_image_path(args) - # base_theme_asset_path('images', args) - #end + def base_theme_image_path(args) + base_theme_asset_path('images', args) + end def current_theme_stylesheet_path(asset) base_theme_stylesheet_path(:theme => self.theme_name, :asset => "#{asset}.css") @@ -38,10 +38,10 @@ def current_theme_image_path(asset) protected - #def base_theme_asset_path(asset, args) - # theme_dir = ThemesForRails.config.themes_routes_dir - # File.join('/themes', args[:theme], asset, args[:asset]) - #end + def base_theme_asset_path(asset, args) + theme_dir = ThemesForRails.config.themes_routes_dir + File.join('/themes', args[:theme], asset, args[:asset]) + end end end