Skip to content

Commit

Permalink
Make use of the asset pipeline. refs lucasefe#54
Browse files Browse the repository at this point in the history
* Load and override action_view when asset digests are enabled.

* don't load asset_controller routes when asset pipeline is in use.
  • Loading branch information
jasherai committed Aug 9, 2012
1 parent 2e56895 commit bc7b7e3
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 6 deletions.
65 changes: 65 additions & 0 deletions lib/themes_for_rails/digested_action_view.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# encoding: utf-8
module ThemesForRails

module DigestedActionView

extend ActiveSupport::Concern

included do
include ThemesForRails::CommonMethods
end

def current_theme_stylesheet_path(asset)
digest_for_stylesheet("#{asset}.css", self.theme_name)
end

def current_theme_javascript_path(asset)
digest_for_javascript("#{asset}.js", self.theme_name)
end

def current_theme_image_path(asset)
image, extension = name_ext(asset)
digest_for_image("#{image}.#{extension}", self.theme_name)
end

def theme_stylesheet_path(asset, new_theme_name = self.theme_name)
digest_for_stylesheet("#{asset}.css", new_theme_name)
end

def theme_javascript_path(asset, new_theme_name = self.theme_name)
digest_for_javascript("#{asset}.js", new_theme_name)
end

def theme_image_path(asset, new_theme_name = self.theme_name)
image, extension = name_ext(asset)
digest_for_image("#{image}.#{extension}", new_theme_name)
end

def theme_image_tag(source, options = {})
image_tag(theme_image_path("#{source}", self.theme_name), options)
end

def theme_image_submit_tag(source, options = {})
image, extension = name_ext(source)
image_submit_tag(theme_image_path("#{image}.#{extension}", self.theme_name), options)
end

def theme_javascript_include_tag(*files)
options = files.extract_options!
options.merge!({ :type => "text/javascript" })
files_with_options = files.collect {|file| theme_javascript_path(file) }
files_with_options += [options]

javascript_include_tag(*files_with_options)
end

def theme_stylesheet_link_tag(*files)
options = files.extract_options!
options.merge!({ :type => "text/css" })
files_with_options = files.collect {|file| theme_stylesheet_path(file) }
files_with_options += [options]

stylesheet_link_tag(*files_with_options)
end
end
end
4 changes: 4 additions & 0 deletions lib/themes_for_rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class Railtie < ::Rails::Railtie

ActiveSupport.on_load(:action_view) do
include ThemesForRails::ActionView
if ThemesForRails.config.asset_digests_enabled?
require 'themes_for_rails/digested_action_view'
include ThemesForRails::DigestedActionView
end
end

ActiveSupport.on_load(:action_controller) do
Expand Down
15 changes: 9 additions & 6 deletions lib/themes_for_rails/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ 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',
:as => :base_theme_stylesheet, :constraints => constraints
match "#{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',
:as => :base_theme_image, :constraints => constraints
# Lets not pollute the routes if they aren't being used.
unless ThemesForRails.config.asset_digests_enabled?
match "#{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',
:as => :base_theme_javascript, :constraints => constraints
match "#{theme_dir}/:theme/images/*asset" => 'themes_for_rails/assets#images',
:as => :base_theme_image, :constraints => constraints
end
end

end
Expand Down

0 comments on commit bc7b7e3

Please sign in to comment.