compass-rails 1.0.3 → 1.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,4 @@
1
1
  require 'sprockets/static_compiler'
2
-
3
2
  module Sprockets
4
3
  class StaticCompiler
5
4
  cattr_accessor :generated_sprites
@@ -10,3 +9,4 @@ module Sprockets
10
9
  alias_method_chain :write_manifest, :sprites
11
10
  end
12
11
  end
12
+
@@ -1,11 +1,11 @@
1
1
  if defined?(::Rails)
2
- if CompassRails.rails2?
3
- require "compass-rails/railties/2_3"
4
- elsif CompassRails.rails31? || CompassRails.rails32?
2
+ if CompassRails.rails31? || CompassRails.rails32?
5
3
  require "compass-rails/railties/3_1"
6
4
  elsif CompassRails.rails3?
7
5
  require "compass-rails/railties/3_0"
6
+ elsif CompassRails.rails4?
7
+ require "compass-rails/railties/4_0"
8
8
  else
9
9
  $stderr.puts "Unsupported rails environment for compass"
10
10
  end
11
- end
11
+ end
@@ -88,12 +88,16 @@ module CompassRails
88
88
  class Railtie < Rails::Railtie
89
89
 
90
90
  initializer "compass.initialize_rails", :group => :all do |app|
91
- require 'compass-rails/patches/3_1'
92
- # Configure compass for use within rails, and provide the project configuration
93
- # that came via the rails boot process.
94
- CompassRails.check_for_double_boot!
95
- Compass.discover_extensions!
96
- CompassRails.configure_rails!(app)
91
+ if CompassRails.asset_pipeline_enabled?
92
+ require 'compass-rails/patches/3_1'
93
+ # Configure compass for use within rails, and provide the project configuration
94
+ # that came via the rails boot process.
95
+ CompassRails.check_for_double_boot!
96
+ Compass.discover_extensions!
97
+ CompassRails.configure_rails!(app)
98
+ else
99
+ CompassRails.initialize!(app.config.compass)
100
+ end
97
101
  end
98
102
  end
99
103
  end
@@ -0,0 +1,102 @@
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
+ Compass.add_configuration(:rails)
35
+ Compass.add_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.digest && # if digesting is enabled
60
+ caller.grep(%r{/sprockets/rails/task.rb}).any? && #OMG HAX - check if we're being precompiled
61
+ Compass.configuration.generated_images_path[Compass.configuration.images_path.to_s] # if the generated images path is not in the assets images directory, we don't have to do these backflips
62
+
63
+ # Clear entries in Hike::Index for this sprite's directory.
64
+ # This makes sure the asset can be found by find_assets
65
+ Rails.application.assets.send(:trail).instance_variable_get(:@entries).delete(File.dirname(filename))
66
+
67
+ pathname = Pathname.new(filename)
68
+ logical_path = pathname.relative_path_from(Pathname.new(Compass.configuration.images_path))
69
+ asset = Rails.application.assets.find_asset(logical_path)
70
+ target = File.join(Rails.public_path, Rails.application.config.assets.prefix, asset.digest_path)
71
+
72
+ # Adds the asset to the manifest file.
73
+
74
+ manifest = ActionView::Base.assets_manifest
75
+ manifest.assets[logical_path.to_s] = asset.digest_path
76
+
77
+
78
+ # Adds the fingerprinted asset to the public directory
79
+ FileUtils.mkdir_p File.dirname(target)
80
+ asset.write_to target
81
+
82
+ end
83
+ end
84
+ data
85
+ end
86
+ @compass
87
+ end
88
+ end
89
+
90
+ module CompassRails
91
+ class Railtie < Rails::Railtie
92
+
93
+ initializer "compass.initialize_rails", :group => :all do |app|
94
+ require 'compass-rails/patches/4_0'
95
+ # Configure compass for use within rails, and provide the project configuration
96
+ # that came via the rails boot process.
97
+ CompassRails.check_for_double_boot!
98
+ Compass.discover_extensions!
99
+ CompassRails.configure_rails!(app)
100
+ end
101
+ end
102
+ end
@@ -1,5 +1,5 @@
1
1
  module CompassRails
2
2
  unless defined?(::CompassRails::VERSION)
3
- VERSION = "1.0.3"
3
+ VERSION = "1.1.0.pre"
4
4
  end
5
5
  end
@@ -50,4 +50,4 @@ module CompassRails
50
50
 
51
51
  end
52
52
  end
53
- end
53
+ end
@@ -5,32 +5,32 @@ module CompassRails
5
5
  include FileHelper
6
6
  include DebugHelper
7
7
  include CommandHelper
8
+ RAILS_4_0 = "4.0"
8
9
  RAILS_3_2 = "3.2"
9
10
  RAILS_3_1 = "3.1"
10
11
  RAILS_3 = "3.0"
11
- RAILS_2 = "2.3"
12
12
 
13
13
  WORKING_DIR = File.join(ROOT_PATH, 'rails-temp')
14
14
 
15
15
  GEMFILES = {
16
+ RAILS_4_0 => GEMFILES_DIR.join("rails40.gemfile").to_s,
16
17
  RAILS_3_2 => GEMFILES_DIR.join("rails32.gemfile").to_s,
17
18
  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
19
+ RAILS_3 => GEMFILES_DIR.join("rails3.gemfile").to_s
20
20
  }
21
-
22
- GENERTOR_OPTIONS = {
21
+
22
+ GENERATOR_OPTIONS = {
23
+ RAILS_4_0 => ['-q', '-G', '-O', '--skip-bundle'],
23
24
  RAILS_3_2 => ['-q', '-G', '-O', '--skip-bundle'],
24
25
  RAILS_3_1 => ['-q', '-G', '-O', '--skip-bundle'],
25
- RAILS_3 => ['-q', '-G', '-O', '--skip-bundle'],
26
- RAILS_2 => ['-q']
26
+ RAILS_3 => ['-q', '-G', '-O', '--skip-bundle']
27
27
  }
28
-
28
+
29
29
  GENERATOR_COMMAND = {
30
+ RAILS_4_0 => 'new',
30
31
  RAILS_3_2 => 'new',
31
32
  RAILS_3_1 => 'new',
32
- RAILS_3 => 'new',
33
- RAILS_2 => ''
33
+ RAILS_3 => 'new'
34
34
  }
35
35
 
36
36
  def rails_command(options, version)
@@ -42,24 +42,23 @@ module CompassRails
42
42
  # with the rails libraries. This will allow testing against multiple versions of rails
43
43
  # by manipulating the load path.
44
44
  def generate_rails_app(name, version, options=[])
45
- options += GENERTOR_OPTIONS[version]
45
+ options += GENERATOR_OPTIONS[version]
46
46
  rails_command([GENERATOR_COMMAND[version], name, *options], version)
47
47
  end
48
48
 
49
- def within_rails_app(named, version, &block)
49
+ def within_rails_app(named, version, asset_pipeline_enabled = true, &block)
50
50
  dir = "#{named}-#{version}"
51
51
  rm_rf File.join(WORKING_DIR, dir)
52
52
  mkdir_p WORKING_DIR
53
53
  cd(WORKING_DIR) do
54
- generate_rails_app(dir, version)
54
+ generate_rails_app(dir, version, asset_pipeline_enabled ? [] : ["-S"])
55
55
  cd(dir) do
56
- yield RailsProject.new(File.join(WORKING_DIR, dir), version)
56
+ yield RailsProject.new(File.join(WORKING_DIR, dir), version, asset_pipeline_enabled)
57
57
  end
58
58
  end
59
59
  rm_rf File.join(WORKING_DIR, dir)
60
60
  end
61
-
62
61
 
63
62
  end
64
63
  end
65
- end
64
+ end
@@ -16,16 +16,16 @@ module CompassRails
16
16
  BOOT_FILE = 'config/boot.rb'
17
17
 
18
18
 
19
- attr_reader :directory, :version
19
+ attr_reader :directory, :version, :asset_pipeline_enabled
20
20
 
21
- def initialize(directory, version)
21
+ def initialize(directory, version, asset_pipeline_enabled = true)
22
22
  @directory = Pathname.new(directory)
23
23
  @version = version
24
- configure_for_bundler!
24
+ @asset_pipeline_enabled = asset_pipeline_enabled
25
25
  end
26
26
 
27
27
  ## FILE METHODS
28
-
28
+
29
29
  def to_s
30
30
  directory_name
31
31
  end
@@ -39,10 +39,9 @@ module CompassRails
39
39
  end
40
40
 
41
41
  def screen_file
42
- case version
43
- when RAILS_3_1, RAILS_3_2
42
+ if asset_pipeline_enabled
44
43
  return directory.join('app', 'assets', 'stylesheets', 'screen.css.scss')
45
- when RAILS_2, RAILS_3
44
+ else
46
45
  return directory.join('app', 'assets', 'stylesheets','screen.scss')
47
46
  end
48
47
  end
@@ -65,10 +64,6 @@ module CompassRails
65
64
  directory.join(APPLICATION_FILE).exist?
66
65
  end
67
66
 
68
- def rails2?
69
- directory.join(BOOT_FILE).exist? && !directory.join(APPLICATION_FILE).exist?
70
- end
71
-
72
67
  def boots?
73
68
  string = 'THIS IS MY RANDOM AWESOME TEST STRING'
74
69
  test_string = "puts \"#{string}\""
@@ -82,12 +77,7 @@ module CompassRails
82
77
  end
83
78
 
84
79
  def runner(string)
85
- case version
86
- when RAILS_3_1, RAILS_3, RAILS_3_2
87
- rails_command(['runner', "'#{string}'"], version)
88
- when RAILS_2
89
- run_command("script/runner '#{string}'", GEMFILES[version])
90
- end
80
+ rails_command(['runner', "'#{string}'"], version)
91
81
  end
92
82
 
93
83
  # COMPASS METHODS
@@ -110,57 +100,13 @@ module CompassRails
110
100
  else
111
101
  "\n config.#{property} = '#{value}'\n"
112
102
  end
113
- inject_into_file(directory.join(APPLICATION_FILE), value, :after, '# Enable the asset pipeline')
103
+ inject_into_file(directory.join(APPLICATION_FILE), value, :after, 'class Application < Rails::Application')
114
104
  end
115
105
 
116
106
  ## GEM METHODS
117
107
 
118
108
  def configure_for_bundler!
119
- return if [RAILS_3_1, RAILS_3, RAILS_3_2].include?(version)
120
- bundle = <<-BUNDLER
121
- class Rails::Boot
122
- def run
123
- load_initializer
124
-
125
- Rails::Initializer.class_eval do
126
- def load_gems
127
- @bundler_loaded ||= Bundler.require :default, Rails.env
128
- end
129
- end
130
-
131
- Rails::Initializer.run(:set_load_path)
132
- end
133
- end
134
- BUNDLER
135
- inject_into_file(directory.join('config/boot.rb'), bundle, :before, 'Rails.boot!')
136
-
137
- touch directory.join('config/preinitializer.rb')
138
- preinit = <<-PREINIT
139
- begin
140
- require "rubygems"
141
- require "bundler"
142
- rescue LoadError
143
- raise "Could not load the bundler gem. Install it with `gem install bundler`."
144
- end
145
-
146
- if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.24")
147
- raise RuntimeError, "Your bundler version is too old for Rails 2.3." +
148
- "Run `gem install bundler` to upgrade."
149
- end
150
-
151
- begin
152
- # Set up load paths for all bundled gems
153
- ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__)
154
- Bundler.setup
155
- rescue Bundler::GemNotFound
156
- raise RuntimeError, "Bundler couldn't find some gems." +
157
- "Did you run `bundle install`?"
158
- end
159
- PREINIT
160
- inject_at_bottom(directory.join('config/preinitializer.rb'), preinit)
161
-
162
- touch directory.join('Gemfile')
163
-
109
+ Rails.logger.warn("This method is deprecated") && return
164
110
  end
165
111
 
166
112
  def bundle
@@ -183,4 +129,4 @@ module CompassRails
183
129
  end
184
130
  end
185
131
  end
186
- end
132
+ end
@@ -4,13 +4,13 @@ class Rails3Test < Test::Unit::TestCase
4
4
  RAILS_VERSION = RAILS_3
5
5
 
6
6
  def test_rails_app_created
7
- within_rails_app('test_railtie', RAILS_VERSION) do |project|
7
+ within_rails_app('test_railtie', RAILS_VERSION, false) do |project|
8
8
  assert project.boots?
9
9
  end
10
10
  end
11
11
 
12
12
  def test_installs_compass
13
- within_rails_app('test_railtie', RAILS_VERSION) do |project|
13
+ within_rails_app('test_railtie', RAILS_VERSION, false) do |project|
14
14
  project.run_compass('init')
15
15
  assert project.has_config?
16
16
  assert project.has_screen_file?
@@ -19,7 +19,7 @@ class Rails3Test < Test::Unit::TestCase
19
19
  end
20
20
 
21
21
  def test_compass_compile
22
- within_rails_app('test_railtie', RAILS_VERSION) do |project|
22
+ within_rails_app('test_railtie', RAILS_VERSION, false) do |project|
23
23
  project.run_compass('init')
24
24
  project.run_compass('compile')
25
25
  assert project.directory.join('public/stylesheets/screen.css').exist?
@@ -27,7 +27,7 @@ class Rails3Test < Test::Unit::TestCase
27
27
  end
28
28
 
29
29
  def test_install_blueprint
30
- within_rails_app('test_railtie', RAILS_VERSION) do |project|
30
+ within_rails_app('test_railtie', RAILS_VERSION, false) do |project|
31
31
  project.run_compass('init')
32
32
  project.run_compass('install blueprint --force')
33
33
  assert project.directory.join('app/assets/stylesheets/partials').directory?
@@ -0,0 +1,37 @@
1
+ require 'test_helper'
2
+ class Rails32WithoutPipelineTest < Test::Unit::TestCase
3
+ include CompassRails::Test::RailsHelpers
4
+ RAILS_VERSION = RAILS_3_2
5
+
6
+ def test_rails_app_created
7
+ within_rails_app('test_railtie', RAILS_VERSION, false) do |project|
8
+ assert project.boots?
9
+ end
10
+ end
11
+
12
+ def test_installs_compass
13
+ within_rails_app('test_railtie', RAILS_VERSION, false) do |project|
14
+ project.run_compass('init')
15
+ assert project.has_config?
16
+ assert project.has_screen_file?
17
+ assert project.has_compass_import?
18
+ end
19
+ end
20
+
21
+ def test_compass_compile
22
+ within_rails_app('test_railtie', RAILS_VERSION, false) do |project|
23
+ project.run_compass('init')
24
+ project.run_compass('compile')
25
+ assert project.directory.join('public/stylesheets/screen.css').exist?
26
+ end
27
+ end
28
+
29
+ def test_install_blueprint
30
+ within_rails_app('test_railtie', RAILS_VERSION, false) do |project|
31
+ project.run_compass('init')
32
+ project.run_compass('install blueprint --force')
33
+ assert project.directory.join('app/assets/stylesheets/partials').directory?
34
+ end
35
+ end
36
+
37
+ end
@@ -1,7 +1,7 @@
1
1
  require 'test_helper'
2
- class Rails23Test < Test::Unit::TestCase
2
+ class Rails40Test < Test::Unit::TestCase
3
3
  include CompassRails::Test::RailsHelpers
4
- RAILS_VERSION = RAILS_2
4
+ RAILS_VERSION = RAILS_4_0
5
5
 
6
6
  def test_rails_app_created
7
7
  within_rails_app('test_railtie', RAILS_VERSION) do |project|
@@ -9,6 +9,7 @@ class Rails23Test < Test::Unit::TestCase
9
9
  end
10
10
  end
11
11
 
12
+
12
13
  def test_installs_compass
13
14
  within_rails_app('test_railtie', RAILS_VERSION) do |project|
14
15
  project.run_compass('init')
@@ -18,11 +19,28 @@ class Rails23Test < Test::Unit::TestCase
18
19
  end
19
20
  end
20
21
 
22
+ def test_compass_compile
23
+ within_rails_app('test_railtie', RAILS_VERSION) do |project|
24
+ project.run_compass('init')
25
+ project.run_compass('compile')
26
+ assert project.directory.join('public/assets/screen.css').exist?
27
+ end
28
+ end
29
+
21
30
  def test_install_blueprint
22
31
  within_rails_app('test_railtie', RAILS_VERSION) do |project|
32
+ project.run_compass('init')
23
33
  project.run_compass('install blueprint --force')
24
34
  assert project.directory.join('app/assets/stylesheets/partials').directory?
25
35
  end
26
36
  end
27
37
 
28
- end
38
+ def test_compass_preferred_syntax
39
+ within_rails_app('test_railtie', RAILS_VERSION) do |project|
40
+ project.set_rails('sass.preferred_syntax', :sass)
41
+ project.run_compass('init')
42
+ assert project.directory.join('app/assets/stylesheets/screen.css.sass').exist?
43
+ end
44
+ end
45
+
46
+ end