compass-rails 1.0.0.rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +18 -0
- data/.travis.yml +5 -0
- data/Appraisals +17 -0
- data/Gemfile +22 -0
- data/Guardfile +9 -0
- data/LICENSE +22 -0
- data/README.md +191 -0
- data/Rakefile +34 -0
- data/compass-rails.gemspec +21 -0
- data/gemfiles/rails2.gemfile +21 -0
- data/gemfiles/rails2.gemfile.lock +87 -0
- data/gemfiles/rails3.gemfile +21 -0
- data/gemfiles/rails3.gemfile.lock +134 -0
- data/gemfiles/rails31.gemfile +22 -0
- data/gemfiles/rails31.gemfile.lock +151 -0
- data/gemfiles/rails32.gemfile +22 -0
- data/gemfiles/rails32.gemfile.lock +148 -0
- data/lib/compass-rails.rb +207 -0
- data/lib/compass-rails/configuration.rb +1 -0
- data/lib/compass-rails/configuration/3_1.rb +51 -0
- data/lib/compass-rails/configuration/default.rb +75 -0
- data/lib/compass-rails/installer.rb +30 -0
- data/lib/compass-rails/patches.rb +6 -0
- data/lib/compass-rails/patches/3_1.rb +28 -0
- data/lib/compass-rails/patches/importer.rb +26 -0
- data/lib/compass-rails/patches/sprite_importer.rb +38 -0
- data/lib/compass-rails/railties.rb +11 -0
- data/lib/compass-rails/railties/2_3.rb +56 -0
- data/lib/compass-rails/railties/3_0.rb +48 -0
- data/lib/compass-rails/railties/3_1.rb +90 -0
- data/lib/compass-rails/version.rb +5 -0
- data/lib/compass/app_integration/rails.rb +10 -0
- data/test/fixtures/.gitkeep +0 -0
- data/test/helpers/command_helper.rb +120 -0
- data/test/helpers/debug_helper.rb +12 -0
- data/test/helpers/file_helper.rb +53 -0
- data/test/helpers/rails_helper.rb +65 -0
- data/test/helpers/rails_project.rb +186 -0
- data/test/integrations/.gitkeep +0 -0
- data/test/integrations/rails3_test.rb +37 -0
- data/test/integrations/rails_23_test.rb +28 -0
- data/test/integrations/rails_31_test.rb +47 -0
- data/test/integrations/rails_32_test.rb +46 -0
- data/test/test_helper.rb +15 -0
- data/test/units/.gitkeep +0 -0
- metadata +160 -0
@@ -0,0 +1,11 @@
|
|
1
|
+
if defined?(::Rails)
|
2
|
+
if CompassRails.rails2?
|
3
|
+
require "compass-rails/railties/2_3"
|
4
|
+
elsif CompassRails.rails31? || CompassRails.rails32?
|
5
|
+
require "compass-rails/railties/3_1"
|
6
|
+
elsif CompassRails.rails3?
|
7
|
+
require "compass-rails/railties/3_0"
|
8
|
+
else
|
9
|
+
$stderr.puts "Unsupported rails environment for compass"
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#rails 2.x doesn't have railties so gona do this the long way
|
2
|
+
require "sass/plugin/rack" #unless defined?(Sass::Plugin::Rack)
|
3
|
+
|
4
|
+
module ActionController
|
5
|
+
class Base
|
6
|
+
def process_with_compass(*args)
|
7
|
+
Sass::Plugin.rails_controller = self
|
8
|
+
begin
|
9
|
+
process_without_compass(*args)
|
10
|
+
ensure
|
11
|
+
Sass::Plugin.rails_controller = nil
|
12
|
+
end
|
13
|
+
end
|
14
|
+
alias_method_chain :process, :compass
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
module Sass::Plugin
|
20
|
+
class << self
|
21
|
+
attr_accessor :rails_controller
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module Compass::SassExtensions::Functions::Urls::ImageUrl
|
26
|
+
def image_url_with_rails_integration(path, only_path = Sass::Script::Bool.new(false), cache_buster = Sass::Script::Bool.new(true))
|
27
|
+
if (@controller = Sass::Plugin.rails_controller) && @controller.respond_to?(:request) && @controller.request
|
28
|
+
begin
|
29
|
+
if only_path.to_bool
|
30
|
+
Sass::Script::String.new image_path(path.value)
|
31
|
+
else
|
32
|
+
Sass::Script::String.new "url(#{image_path(path.value)})"
|
33
|
+
end
|
34
|
+
ensure
|
35
|
+
@controller = nil
|
36
|
+
end
|
37
|
+
else
|
38
|
+
image_url_without_rails_integration(path, only_path, cache_buster)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
alias_method_chain :image_url, :rails_integration
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
class Sass::Script::Functions::EvaluationContext
|
46
|
+
include Sass::Script::Functions
|
47
|
+
private
|
48
|
+
include ActionView::Helpers::AssetTagHelper
|
49
|
+
end
|
50
|
+
|
51
|
+
unless Compass.detect_configuration_file.nil?
|
52
|
+
Compass.add_configuration(CompassRails.configuration)
|
53
|
+
CompassRails.initialize!
|
54
|
+
else
|
55
|
+
CompassRails.initialize!(CompassRails.configuration)
|
56
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#3.0.11
|
2
|
+
require 'compass'
|
3
|
+
require 'rails'
|
4
|
+
|
5
|
+
class Rails::Railtie::Configuration
|
6
|
+
# Adds compass configuration accessor to the application configuration.
|
7
|
+
#
|
8
|
+
# If a configuration file for compass exists, it will be read in and
|
9
|
+
# the project's configuration values will already be set on the config
|
10
|
+
# object.
|
11
|
+
#
|
12
|
+
# For example:
|
13
|
+
#
|
14
|
+
# module MyApp
|
15
|
+
# class Application < Rails::Application
|
16
|
+
# config.compass.line_comments = !Rails.env.production?
|
17
|
+
# config.compass.fonts_dir = "app/assets/fonts"
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# It is suggested that you create a compass configuration file if you
|
22
|
+
# want a quicker boot time when using the compass command line tool.
|
23
|
+
#
|
24
|
+
# For more information on available configuration options see:
|
25
|
+
# http://compass-style.org/help/tutorials/configuration-reference/
|
26
|
+
def compass
|
27
|
+
@compass ||= begin
|
28
|
+
data = if (config_file = Compass.detect_configuration_file) && (config_data = Compass.configuration_for(config_file))
|
29
|
+
config_data
|
30
|
+
else
|
31
|
+
Compass::Configuration::Data.new("project")
|
32
|
+
end
|
33
|
+
data.project_type = :rails # Forcing this makes sure all the rails defaults will be loaded.
|
34
|
+
data
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
module CompassRails
|
40
|
+
class Railtie < Rails::Railtie
|
41
|
+
|
42
|
+
initializer "compass.initialize_rails" do |app|
|
43
|
+
# Configure compass for use within rails, and provide the project configuration
|
44
|
+
# that came via the rails boot process.
|
45
|
+
CompassRails.initialize!(app.config.compass)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
#3.1.3
|
2
|
+
require 'compass'
|
3
|
+
require 'rails/railtie'
|
4
|
+
|
5
|
+
class Rails::Railtie::Configuration
|
6
|
+
# Adds compass configuration accessor to the application configuration.
|
7
|
+
#
|
8
|
+
# If a configuration file for compass exists, it will be read in and
|
9
|
+
# the project's configuration values will already be set on the config
|
10
|
+
# object.
|
11
|
+
#
|
12
|
+
# For example:
|
13
|
+
#
|
14
|
+
# module MyApp
|
15
|
+
# class Application < Rails::Application
|
16
|
+
# config.compass.line_comments = !Rails.env.production?
|
17
|
+
# config.compass.fonts_dir = "app/assets/fonts"
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# It is suggested that you create a compass configuration file if you
|
22
|
+
# want a quicker boot time when using the compass command line tool.
|
23
|
+
#
|
24
|
+
# For more information on available configuration options see:
|
25
|
+
# http://compass-style.org/help/tutorials/configuration-reference/
|
26
|
+
def compass
|
27
|
+
@compass ||= begin
|
28
|
+
data = if (config_file = Compass.detect_configuration_file) && (config_data = Compass.configuration_for(config_file))
|
29
|
+
config_data
|
30
|
+
else
|
31
|
+
Compass::Configuration::Data.new("rails_config")
|
32
|
+
end
|
33
|
+
data.project_type = :rails # Forcing this makes sure all the rails defaults will be loaded.
|
34
|
+
data.inherit_from!(Compass.configuration) #force this
|
35
|
+
Compass.add_project_configuration(data)
|
36
|
+
Compass.configuration.on_sprite_saved do |filename|
|
37
|
+
# This is a huge hack based on reading through the sprockets internals.
|
38
|
+
# Sprockets needs an API for adding assets during precompilation.
|
39
|
+
# At a minimum sprockets should provide this API:
|
40
|
+
#
|
41
|
+
# #filename is a path in the asset source directory
|
42
|
+
# Rails.application.assets.new_asset!(filename)
|
43
|
+
#
|
44
|
+
# # logical_path is how devs refer to it, data is the contents of it.
|
45
|
+
# Rails.application.assets.new_asset!(logical_path, data)
|
46
|
+
#
|
47
|
+
# I would also like to select one of the above calls based on whether
|
48
|
+
# the user is precompiling or not:
|
49
|
+
#
|
50
|
+
# Rails.application.assets.precompiling? #=> true or false
|
51
|
+
#
|
52
|
+
# But even the above is not an ideal API. The issue is that compass sprites need to
|
53
|
+
# avoid generation if the sprite file is already generated (which can be quite time
|
54
|
+
# consuming). To do this, compass has it's own uniqueness hash based on the user's
|
55
|
+
# inputs instead of being based on the file contents. So if we could provide our own
|
56
|
+
# hash or some metadata that is opaque to sprockets that could be read from the
|
57
|
+
# asset's attributes, we could avoid cluttering the assets directory with generated
|
58
|
+
# sprites and always just use the logical_path + data version of the api.
|
59
|
+
if Rails.application.config.assets.digests.try(:any?)
|
60
|
+
asset = Rails.application.assets.find_asset(filename)
|
61
|
+
pathname = Pathname.new(filename)
|
62
|
+
logical_path = filename[(Compass.configuration.generated_images_path.length+1)..-1]
|
63
|
+
# Force the asset into the cache so find_asset will find it.
|
64
|
+
cached_assets = Rails.application.assets.instance_variable_get("@assets")
|
65
|
+
cached_assets[logical_path] = cached_assets[filename] = asset
|
66
|
+
|
67
|
+
target = Pathname.new(File.join(Rails.public_path, Rails.application.config.assets.prefix))
|
68
|
+
asset = Rails.application.assets.find_asset(logical_path)
|
69
|
+
filename = target.join(asset.digest_path)
|
70
|
+
asset.write_to(filename)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
data
|
74
|
+
end
|
75
|
+
@compass
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
module CompassRails
|
80
|
+
class Railtie < Rails::Railtie
|
81
|
+
|
82
|
+
initializer "compass.initialize_rails", :group => :all do |app|
|
83
|
+
# Configure compass for use within rails, and provide the project configuration
|
84
|
+
# that came via the rails boot process.
|
85
|
+
CompassRails.check_for_double_boot!
|
86
|
+
Compass.discover_extensions!
|
87
|
+
CompassRails.configure_rails!(app)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Compass
|
2
|
+
module AppIntegration
|
3
|
+
module Rails
|
4
|
+
extend self
|
5
|
+
def initialize!
|
6
|
+
Compass::Util.compass_warn("WARNING: Please remove the call to Compass::AppIntegration::Rails.initialize! from #{caller[0].sub(/:.*$/,'')};\nWARNING: This is done automatically now. If this is default compass initializer you can just remove the file.")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
File without changes
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'appraisal'
|
2
|
+
require 'appraisal/command'
|
3
|
+
module Kernal
|
4
|
+
module Captures
|
5
|
+
def capture_output
|
6
|
+
buffer = []
|
7
|
+
real_stdout, $stdout = $stdout, StringIO.new
|
8
|
+
buffer << yield
|
9
|
+
buffer << $stdout.string
|
10
|
+
return buffer.join
|
11
|
+
ensure
|
12
|
+
$stdout = real_stdout
|
13
|
+
end
|
14
|
+
|
15
|
+
def capture_all_output
|
16
|
+
capture_output do
|
17
|
+
capture_warning do
|
18
|
+
yield
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def capture_warning
|
25
|
+
buffer = []
|
26
|
+
real_stderr, $stderr = $stderr, StringIO.new
|
27
|
+
buffer << yield
|
28
|
+
buffer << $stderr.string
|
29
|
+
return buffer.join
|
30
|
+
ensure
|
31
|
+
$stderr = real_stderr
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
include Kernal::Captures
|
37
|
+
|
38
|
+
module CompassRails
|
39
|
+
module Test
|
40
|
+
module CommandHelper
|
41
|
+
include DebugHelper
|
42
|
+
GEMFILES_DIR = Pathname.new(ROOT_PATH).join('gemfiles')
|
43
|
+
BUNDLER_COMMAND = 'bundle'
|
44
|
+
|
45
|
+
def run_command(command, gemfile=nil)
|
46
|
+
debug("Running: #{command} with gemfile: #{gemfile}".foreground(:cyan))
|
47
|
+
capture_all_output { CompassRails::Test::CommandRunner.new(command, gemfile).run }
|
48
|
+
end
|
49
|
+
|
50
|
+
def bundle(gemfile=nil)
|
51
|
+
run_command(BUNDLER_COMMAND, gemfile)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Executes commands with a clean environment
|
59
|
+
class CompassRails::Test::CommandRunner
|
60
|
+
BUNDLER_ENV_VARS = %w(RUBYOPT BUNDLE_PATH BUNDLE_BIN_PATH BUNDLE_GEMFILE).freeze
|
61
|
+
|
62
|
+
def self.from_args(gemfile)
|
63
|
+
command = ([$0] + ARGV.slice(1, ARGV.size)).join(' ')
|
64
|
+
new(command, gemfile)
|
65
|
+
end
|
66
|
+
|
67
|
+
def initialize(command, gemfile = nil)
|
68
|
+
@original_env = {}
|
69
|
+
@gemfile = gemfile
|
70
|
+
if command =~ /^bundle/
|
71
|
+
@command = command
|
72
|
+
else
|
73
|
+
@command = "bundle exec #{command}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def run
|
78
|
+
announce
|
79
|
+
with_clean_env do
|
80
|
+
%x{#{@command}}
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def exec
|
85
|
+
announce
|
86
|
+
with_clean_env { Kernel.exec(@command) }
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def with_clean_env
|
92
|
+
unset_bundler_env_vars
|
93
|
+
ENV['BUNDLE_GEMFILE'] = @gemfile
|
94
|
+
yield
|
95
|
+
ensure
|
96
|
+
restore_env
|
97
|
+
end
|
98
|
+
|
99
|
+
def announce
|
100
|
+
return
|
101
|
+
if @gemfile
|
102
|
+
puts ">> BUNDLE_GEMFILE=#{@gemfile} #{@command}"
|
103
|
+
else
|
104
|
+
puts ">> #{@command}"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def unset_bundler_env_vars
|
109
|
+
BUNDLER_ENV_VARS.each do |key|
|
110
|
+
@original_env[key] = ENV[key]
|
111
|
+
ENV[key] = nil
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def restore_env
|
116
|
+
@original_env.each { |key, value| ENV[key] = value }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module CompassRails
|
2
|
+
module Test
|
3
|
+
module FileHelper
|
4
|
+
include DebugHelper
|
5
|
+
|
6
|
+
def mkdir_p(dir)
|
7
|
+
debug("Creating Directory: #{dir}".foreground(:green))
|
8
|
+
::FileUtils.mkdir_p dir
|
9
|
+
assert File.directory?(dir), "mkdir_p: #{dir} failed"
|
10
|
+
end
|
11
|
+
|
12
|
+
def rm_rf(path)
|
13
|
+
debug("Removing: #{path}".foreground(:red))
|
14
|
+
::FileUtils.rm_rf(path)
|
15
|
+
assert !File.directory?(path), "rm_rf: #{path} failed"
|
16
|
+
end
|
17
|
+
|
18
|
+
def cd(path, &block)
|
19
|
+
debug("Entered: #{path}".foreground(:yellow))
|
20
|
+
Dir.chdir(path, &block)
|
21
|
+
end
|
22
|
+
|
23
|
+
def inject_at_bottom(file_name, string)
|
24
|
+
content = File.read(file_name)
|
25
|
+
content = "#{content}#{string}"
|
26
|
+
File.open(file_name, 'w') { |file| file << content }
|
27
|
+
end
|
28
|
+
|
29
|
+
def touch(file)
|
30
|
+
debug("Touching File: #{file}".foreground(:green))
|
31
|
+
::FileUtils.touch(file)
|
32
|
+
end
|
33
|
+
|
34
|
+
def inject_into_file(file_name, replacment, position, anchor)
|
35
|
+
case position
|
36
|
+
when :after
|
37
|
+
replace(file_name, Regexp.escape(anchor), "#{anchor}#{replacment}")
|
38
|
+
when :before
|
39
|
+
replace(file_name, Regexp.escape(anchor), "#{replacment}#{anchor}")
|
40
|
+
else
|
41
|
+
raise Compass::FilesystemConflict.new("You need to specify :before or :after")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def replace(destination, regexp, string)
|
46
|
+
content = File.read(destination)
|
47
|
+
content.gsub!(Regexp.new(regexp), string)
|
48
|
+
File.open(destination, 'wb') { |file| file.write(content) }
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
|
2
|
+
module CompassRails
|
3
|
+
module Test
|
4
|
+
module RailsHelpers
|
5
|
+
include FileHelper
|
6
|
+
include DebugHelper
|
7
|
+
include CommandHelper
|
8
|
+
RAILS_3_2 = "3.2"
|
9
|
+
RAILS_3_1 = "3.1"
|
10
|
+
RAILS_3 = "3.0"
|
11
|
+
RAILS_2 = "2.3"
|
12
|
+
|
13
|
+
WORKING_DIR = File.join(ROOT_PATH, 'rails-temp')
|
14
|
+
|
15
|
+
GEMFILES = {
|
16
|
+
RAILS_3_2 => GEMFILES_DIR.join("rails32.gemfile").to_s,
|
17
|
+
RAILS_3_1 => GEMFILES_DIR.join("rails31.gemfile").to_s,
|
18
|
+
RAILS_3 => GEMFILES_DIR.join("rails3.gemfile").to_s,
|
19
|
+
RAILS_2 => GEMFILES_DIR.join("rails2.gemfile").to_s
|
20
|
+
}
|
21
|
+
|
22
|
+
GENERTOR_OPTIONS = {
|
23
|
+
RAILS_3_2 => ['-q', '-G', '-O', '--skip-bundle'],
|
24
|
+
RAILS_3_1 => ['-q', '-G', '-O', '--skip-bundle'],
|
25
|
+
RAILS_3 => ['-q', '-G', '-O', '--skip-bundle'],
|
26
|
+
RAILS_2 => ['-q']
|
27
|
+
}
|
28
|
+
|
29
|
+
GENERATOR_COMMAND = {
|
30
|
+
RAILS_3_2 => 'new',
|
31
|
+
RAILS_3_1 => 'new',
|
32
|
+
RAILS_3 => 'new',
|
33
|
+
RAILS_2 => ''
|
34
|
+
}
|
35
|
+
|
36
|
+
def rails_command(options, version)
|
37
|
+
debug("Running Rails command with: rails #{options.join(' ')}".foreground(:cyan))
|
38
|
+
run_command("rails #{options.join(' ')}", GEMFILES[version])
|
39
|
+
end
|
40
|
+
|
41
|
+
# Generate a rails application without polluting our current set of requires
|
42
|
+
# with the rails libraries. This will allow testing against multiple versions of rails
|
43
|
+
# by manipulating the load path.
|
44
|
+
def generate_rails_app(name, version, options=[])
|
45
|
+
options += GENERTOR_OPTIONS[version]
|
46
|
+
rails_command([GENERATOR_COMMAND[version], name, *options], version)
|
47
|
+
end
|
48
|
+
|
49
|
+
def within_rails_app(named, version, &block)
|
50
|
+
dir = "#{named}-#{version}"
|
51
|
+
rm_rf File.join(WORKING_DIR, dir)
|
52
|
+
mkdir_p WORKING_DIR
|
53
|
+
cd(WORKING_DIR) do
|
54
|
+
generate_rails_app(dir, version)
|
55
|
+
cd(dir) do
|
56
|
+
yield RailsProject.new(File.join(WORKING_DIR, dir), version)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
rm_rf File.join(WORKING_DIR, dir)
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|