Skip to content

rails 4 beta support #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@ end
appraise "rails32" do
gem "rails", "~> 3.2"
gem "sass-rails"
end
end

appraise "rails40" do
gem "rails", :github => "rails/rails"
gem "journey", :github => "rails/journey"
gem "active_record_deprecated_finders", :github => "rails/active_record_deprecated_finders"
gem "sass-rails", :github => "rails/sass-rails"
gem "sprockets-rails", :github => "rails/sprockets-rails"
end

25 changes: 25 additions & 0 deletions gemfiles/rails40.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rb-fsevent", :require=>false
gem "ruby_gntp", :require=>false
gem "guard"
gem "guard-test"
gem "rails", :github=>"rails/rails"
gem "journey", :github=>"rails/journey"
gem "active_record_deprecated_finders", :github=>"rails/active_record_deprecated_finders"
gem "sass-rails", :github=>"rails/sass-rails"
gem "sprockets-rails", :github=>"rails/sprockets-rails"

group :assets do
gem "compass"
gem "compass-rails", :path=>".."
end
group :test do
gem "mocha"
gem "appraisal", :git=>"git://github.com/scottdavis/appraisal.git"
gem "rainbow"
end

gemspec :path=>"../"
16 changes: 13 additions & 3 deletions lib/compass-rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

module CompassRails

RAILS_4 = %r{^4.0}
RAILS_32 = %r{^3.2}
RAILS_31 = %r{^3.1}
RAILS_23 = %r{^2.3}
Expand All @@ -21,9 +22,13 @@ def load_rails
end
#load the rails config
require "#{rails_config_path}/config/application.rb"
if rails31? || rails32?
if rails31? || rails32? || rails4?
require 'sass-rails'
require 'sprockets/railtie'
if rails4?
require 'sprockets-rails'
else
require 'sprockets/railtie'
end
require 'rails/engine'
@app ||= ::Rails.application.initialize!(:assets)
end
Expand Down Expand Up @@ -98,6 +103,11 @@ def rails32?
rails_version =~ RAILS_32
end

def rails4?
return false unless defined?(::Rails)
rails_version =~ RAILS_4
end

def rails2?
rails_version =~ RAILS_23
end
Expand All @@ -114,7 +124,7 @@ def configuration
load_rails unless rails2?
config = Compass::Configuration::Data.new('rails')
config.extend(Configuration::Default)
if (rails31? || rails32?)
if (rails31? || rails32? || rails4?)
if asset_pipeline_enabled?
require "compass-rails/configuration/3_1"
config.extend(Configuration::Rails3_1)
Expand Down
4 changes: 2 additions & 2 deletions lib/compass-rails/patches.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if CompassRails.rails31? || CompassRails.rails32?
if CompassRails.rails31? || CompassRails.rails32? || CompassRails.rails4?
unless CompassRails.rails_loaded?
CompassRails.load_rails
end
require 'compass-rails/patches/importer'
end
end
34 changes: 25 additions & 9 deletions lib/compass-rails/patches/static_compiler.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
require 'sprockets/static_compiler'

module Sprockets
class StaticCompiler
cattr_accessor :generated_sprites
self.generated_sprites = {}
def write_manifest_with_sprites(manifest)
write_manifest_without_sprites(manifest.merge(self.class.generated_sprites))
if CompassRails.rails4?
require 'sprockets/rails/static_compiler'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this no longer exists in sprockets-rails.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any suggestions what to do about this? It's causing errors for me.

module Sprockets
module Rails
class StaticCompiler
cattr_accessor :generated_sprites
self.generated_sprites = {}
def write_manifest_with_sprites(manifest)
write_manifest_without_sprites(manifest.merge(self.class.generated_sprites))
end
alias_method_chain :write_manifest, :sprites
end
end
end
else
require 'sprockets/static_compiler'
module Sprockets
class StaticCompiler
cattr_accessor :generated_sprites
self.generated_sprites = {}
def write_manifest_with_sprites(manifest)
write_manifest_without_sprites(manifest.merge(self.class.generated_sprites))
end
alias_method_chain :write_manifest, :sprites
end
alias_method_chain :write_manifest, :sprites
end
end

4 changes: 2 additions & 2 deletions lib/compass-rails/railties.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
if defined?(::Rails)
if CompassRails.rails2?
require "compass-rails/railties/2_3"
elsif CompassRails.rails31? || CompassRails.rails32?
elsif CompassRails.rails31? || CompassRails.rails32? || CompassRails.rails4?
require "compass-rails/railties/3_1"
elsif CompassRails.rails3?
require "compass-rails/railties/3_0"
else
$stderr.puts "Unsupported rails environment for compass"
end
end
end
2 changes: 1 addition & 1 deletion test/helpers/file_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ def replace(destination, regexp, string)

end
end
end
end
7 changes: 5 additions & 2 deletions test/helpers/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module RailsHelpers
include FileHelper
include DebugHelper
include CommandHelper
RAILS_4_0 = "4.0"
RAILS_3_2 = "3.2"
RAILS_3_1 = "3.1"
RAILS_3 = "3.0"
Expand All @@ -13,20 +14,23 @@ module RailsHelpers
WORKING_DIR = File.join(ROOT_PATH, 'rails-temp')

GEMFILES = {
RAILS_4_0 => GEMFILES_DIR.join("rails40.gemfile").to_s,
RAILS_3_2 => GEMFILES_DIR.join("rails32.gemfile").to_s,
RAILS_3_1 => GEMFILES_DIR.join("rails31.gemfile").to_s,
RAILS_3 => GEMFILES_DIR.join("rails3.gemfile").to_s,
RAILS_2 => GEMFILES_DIR.join("rails2.gemfile").to_s
}

GENERTOR_OPTIONS = {
RAILS_4_0 => ['-q', '-G', '-O', '--skip-bundle'],
RAILS_3_2 => ['-q', '-G', '-O', '--skip-bundle'],
RAILS_3_1 => ['-q', '-G', '-O', '--skip-bundle'],
RAILS_3 => ['-q', '-G', '-O', '--skip-bundle'],
RAILS_2 => ['-q']
}

GENERATOR_COMMAND = {
RAILS_4_0 => 'new',
RAILS_3_2 => 'new',
RAILS_3_1 => 'new',
RAILS_3 => 'new',
Expand Down Expand Up @@ -58,8 +62,7 @@ def within_rails_app(named, version, &block)
end
rm_rf File.join(WORKING_DIR, dir)
end


end
end
end
end
10 changes: 5 additions & 5 deletions test/helpers/rails_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def has_file?(file)

def screen_file
case version
when RAILS_3_1, RAILS_3_2
when RAILS_3_1, RAILS_3_2, RAILS_4_0
return directory.join('app', 'assets', 'stylesheets', 'screen.css.scss')
when RAILS_2, RAILS_3
return directory.join('app', 'assets', 'stylesheets','screen.scss')
Expand Down Expand Up @@ -83,7 +83,7 @@ def boots?

def runner(string)
case version
when RAILS_3_1, RAILS_3, RAILS_3_2
when RAILS_3_1, RAILS_3, RAILS_3_2, RAILS_4_0
rails_command(['runner', "'#{string}'"], version)
when RAILS_2
run_command("script/runner '#{string}'", GEMFILES[version])
Expand All @@ -110,13 +110,13 @@ def set_rails(property, value)
else
"\n config.#{property} = '#{value}'\n"
end
inject_into_file(directory.join(APPLICATION_FILE), value, :after, '# Enable the asset pipeline')
inject_into_file(directory.join(APPLICATION_FILE), value, :after, 'class Application < Rails::Application')
end

## GEM METHODS

def configure_for_bundler!
return if [RAILS_3_1, RAILS_3, RAILS_3_2].include?(version)
return if [RAILS_3_1, RAILS_3, RAILS_3_2, RAILS_4_0].include?(version)
bundle = <<-BUNDLER
class Rails::Boot
def run
Expand Down Expand Up @@ -183,4 +183,4 @@ def add_to_gemfile(name, requirements)
end
end
end
end
end
46 changes: 46 additions & 0 deletions test/integrations/rails_40_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require 'test_helper'
class Rails40Test < Test::Unit::TestCase
include CompassRails::Test::RailsHelpers
RAILS_VERSION = RAILS_4_0

def test_rails_app_created
within_rails_app('test_railtie', RAILS_VERSION) do |project|
assert project.boots?
end
end


def test_installs_compass
within_rails_app('test_railtie', RAILS_VERSION) do |project|
project.run_compass('init')
assert project.has_config?
assert project.has_screen_file?
assert project.has_compass_import?
end
end

def test_compass_compile
within_rails_app('test_railtie', RAILS_VERSION) do |project|
project.run_compass('init')
project.run_compass('compile')
assert project.directory.join('public/assets/screen.css').exist?
end
end

def test_install_blueprint
within_rails_app('test_railtie', RAILS_VERSION) do |project|
project.run_compass('init')
project.run_compass('install blueprint --force')
assert project.directory.join('app/assets/stylesheets/partials').directory?
end
end

def test_compass_preferred_syntax
within_rails_app('test_railtie', RAILS_VERSION) do |project|
project.set_rails('sass.preferred_syntax', :sass)
project.run_compass('init')
assert project.directory.join('app/assets/stylesheets/screen.css.sass').exist?
end
end

end