Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Rails] image_url() now integrates with the rails asset handling code…
… when stylesheets are generated within the rails container. This causes your rails configuration for cache busting and asset hosts to be picked up when generating your stylesheets. Unfortunately, all that code runs within the context of a controller, so the stylesheets have to be generated during first request to use this functionality.
- Loading branch information
1 parent
ccc2823
commit 9981681
Showing
7 changed files
with
95 additions
and
6 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
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,3 +1,5 @@ | ||
# If we're running inside Rails | ||
require File.join(File.dirname(__FILE__), 'app_integration', 'rails') if defined?(ActionController::Base) | ||
|
||
# If we're running inside Merb | ||
require File.join(File.dirname(__FILE__), 'app_integration', 'merb') if defined?(Merb::Plugins) |
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,12 @@ | ||
unless defined?(Compass::RAILS_LOADED) | ||
Compass::RAILS_LOADED = true | ||
require File.join(File.dirname(__FILE__), 'rails', 'action_controller') | ||
require File.join(File.dirname(__FILE__), 'rails', 'sass_plugin') | ||
require File.join(File.dirname(__FILE__), 'rails', 'image_url') | ||
# Wierd that this has to be re-included to pick up sub-modules. Ruby bug? | ||
class Sass::Script::Functions::EvaluationContext | ||
include Sass::Script::Functions | ||
private | ||
include ActionView::Helpers::AssetTagHelper | ||
end | ||
end |
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,15 @@ | ||
# :stopdoc: | ||
module ActionController | ||
class Base | ||
def process_with_compass(*args) | ||
Sass::Plugin.rails_controller = self | ||
begin | ||
process_without_compass(*args) | ||
ensure | ||
Sass::Plugin.rails_controller = nil | ||
end | ||
end | ||
alias_method_chain :process, :compass | ||
end | ||
end | ||
# :startdoc: |
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,14 @@ | ||
module Compass::SassExtensions::Functions::ImageUrl | ||
def image_url_with_rails_integration(path) | ||
if @controller = Sass::Plugin.rails_controller | ||
begin | ||
Sass::Script::String.new "url(#{image_path(path.value)})" | ||
ensure | ||
@controller = nil | ||
end | ||
else | ||
image_url_without_rails_integration(path) | ||
end | ||
end | ||
alias_method_chain :image_url, :rails_integration | ||
end |
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,5 @@ | ||
module Sass::Plugin | ||
class << self | ||
attr_accessor :rails_controller | ||
end | ||
end |
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,20 @@ | ||
# XXX This file isn't in use at the moment, but will be used to help test | ||
# XXX deep rails integration of compass features. | ||
need_gems = false | ||
|
||
# allows testing with edge Rails by creating a test/rails symlink | ||
RAILS_ROOT = linked_rails = File.dirname(__FILE__) + '/rails' | ||
RAILS_ENV = 'test' | ||
|
||
if File.exists?(linked_rails) && !$:.include?(linked_rails + '/activesupport/lib') | ||
puts "[ using linked Rails ]" | ||
$:.unshift linked_rails + '/activesupport/lib' | ||
$:.unshift linked_rails + '/actionpack/lib' | ||
else | ||
need_gems = true | ||
end | ||
|
||
require 'rubygems' if need_gems | ||
|
||
require 'action_controller' | ||
require 'action_view' |