compass-rails4 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7d5f44af415e24ca4e7e9910cc8029b39eb5c19a
4
+ data.tar.gz: 72e11724e86e814f53244976d9840cada95cb2b9
5
+ SHA512:
6
+ metadata.gz: 18b9e656b02c272e77f1066e962460902ec1a64fd6860ec2f30356839aecde476264909e50e50755e4495e44f1e74e4ff7b086b0356b1d509a4cdcb85cc0a605
7
+ data.tar.gz: 36b3100a75f3cfec7c00c5fd0bd894f8915fc1b4b342593a1dfefccb31afc087064532f5445588d54c0d4988c5fae79912d9a87e5ba4849b05028314fa49b40c
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in compass-rails4.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2011 Scott Davis
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/compass-rails4/version', __FILE__)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.authors = ["Tomas Brazys"]
6
+ spec.email = ["tomas.brazys@gmail.com"]
7
+ spec.description = %q{Integrate Compass into Rails 4.0.}
8
+ spec.summary = %q{Adaptation of original compass-rails to work with Rails 4.}
9
+ spec.homepage = "https://github.com/deees/compass-rails4"
10
+
11
+ # spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ spec.files = `git ls-files`.split("\n")
13
+ # spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+
15
+ spec.name = "compass-rails4"
16
+ spec.require_paths = ["lib"]
17
+ spec.version = CompassRails4::VERSION
18
+ spec.license = "MIT"
19
+
20
+ spec.add_dependency 'compass', '~> 0.13.alpha.12'
21
+ spec.add_dependency 'railties', '~> 4.0.0'
22
+
23
+ spec.add_development_dependency 'rake'
24
+ end
@@ -0,0 +1,164 @@
1
+ require "compass-rails4/version"
2
+ require "compass-rails4/configuration"
3
+
4
+ module CompassRails4
5
+
6
+ RAILS_4 = %r{^4.[0|1]}
7
+
8
+ extend self
9
+
10
+ def load_rails
11
+ return if rails_loaded?
12
+
13
+ rails_config_path = Dir.pwd
14
+ until File.exists?(File.join(rails_config_path, 'config', 'environment.rb')) do
15
+ raise 'Rails application not found' if rails_config_path == '/'
16
+ rails_config_path = File.join(rails_config_path, '..')
17
+ end
18
+
19
+ require "#{rails_config_path}/config/environment"
20
+ end
21
+
22
+ def app
23
+ ::Rails.application
24
+ end
25
+
26
+ def rails_config
27
+ app.config
28
+ end
29
+
30
+ def sass_config
31
+ load_rails
32
+ rails_config.sass
33
+ end
34
+
35
+ def sprockets
36
+ load_rails
37
+ @sprockets ||= app.assets
38
+ end
39
+
40
+ def context
41
+ load_rails
42
+ @context ||= sprockets.context_class
43
+ end
44
+
45
+ def rails?
46
+ defined?(::Rails)
47
+ end
48
+
49
+ def rails_loaded?
50
+ rails? && app
51
+ end
52
+
53
+ def rails_version
54
+ rails_spec = Gem.loaded_specs["railties"]
55
+ raise "You have to require Rails before compass" unless rails_spec
56
+ rails_spec.version.to_s
57
+ end
58
+
59
+ def rails4?
60
+ rails? && version_match(RAILS_4)
61
+ end
62
+
63
+ def version_match(version)
64
+ !(rails_version =~ version).nil?
65
+ end
66
+
67
+ def booted!
68
+ CompassRails4.const_set(:BOOTED, true)
69
+ end
70
+
71
+ def booted?
72
+ defined?(CompassRails4::BOOTED) && CompassRails4::BOOTED
73
+ end
74
+
75
+ def configuration
76
+ load_rails
77
+ config = Compass::Configuration::Data.new('rails')
78
+ config.extend(Configuration::Default)
79
+ if asset_pipeline_enabled?
80
+ require "compass-rails4/configuration/asset_pipeline"
81
+ config.extend(Configuration::AssetPipeline)
82
+ end
83
+ config
84
+ end
85
+
86
+ def env
87
+ env_production? ? :production : :development
88
+ end
89
+
90
+ def prefix
91
+ rails_config.assets.prefix
92
+ end
93
+
94
+ def env_production?
95
+ rails? && ::Rails.env.production?
96
+ end
97
+
98
+ def root
99
+ @root ||= rails? ? ::Rails.root : Pathname.new(Dir.pwd)
100
+ end
101
+
102
+ def check_for_double_boot!
103
+ if booted?
104
+ Compass::Util.compass_warn("Warning: Compass was booted twice. Compass-rails4 has got your back; please remove your compass initializer.")
105
+ else
106
+ booted!
107
+ end
108
+ end
109
+
110
+ def configure_rails!(app)
111
+ return unless app.config.respond_to?(:sass)
112
+ sass_config = app.config.sass
113
+ compass_config = app.config.compass
114
+
115
+ sass_config.load_paths.concat(compass_config.sass_load_paths)
116
+
117
+ { :output_style => :style,
118
+ :line_comments => :line_comments,
119
+ :cache => :cache,
120
+ :disable_warnings => :quiet,
121
+ :preferred_syntax => :preferred_syntax
122
+ }.each do |compass_option, sass_option|
123
+ set_maybe sass_config, compass_config, sass_option, compass_option
124
+ end
125
+ if compass_config.sass_options
126
+ compass_config.sass_options.each do |config, value|
127
+ sass_config.send("#{config}=", value)
128
+ end
129
+ end
130
+ end
131
+
132
+ def boot_config
133
+ config = if (config_file = Compass.detect_configuration_file) && (config_data = Compass.configuration_for(config_file))
134
+ config_data
135
+ else
136
+ Compass::Configuration::Data.new("compass_rails_boot")
137
+ end
138
+ config.top_level.project_type = :rails
139
+ config
140
+ end
141
+
142
+ def asset_pipeline_enabled?
143
+ return false unless rails_loaded?
144
+ return false if !rails_config.respond_to?(:assets)
145
+
146
+ rails_config.assets.enabled != false
147
+ end
148
+
149
+ private
150
+
151
+ # sets the sass config value only if the corresponding compass-based setting
152
+ # has been explicitly set by the user.
153
+ def set_maybe(sass_config, compass_config, sass_option, compass_option)
154
+ if compass_value = compass_config.send(:"#{compass_option}_without_default")
155
+ sass_config.send(:"#{sass_option}=", compass_value)
156
+ end
157
+ end
158
+
159
+ end
160
+
161
+ require "compass-rails4/railtie"
162
+
163
+ Compass::AppIntegration.register(:rails, "::CompassRails4")
164
+ Compass.add_configuration(CompassRails4.boot_config)
@@ -0,0 +1 @@
1
+ require "compass-rails4/configuration/default"
@@ -0,0 +1,51 @@
1
+ module CompassRails4
2
+ module Configuration
3
+ module AssetPipeline
4
+
5
+ def default_images_dir
6
+ File.join("app", "assets", "images")
7
+ end
8
+
9
+ def default_fonts_dir
10
+ File.join("app", "assets", "fonts")
11
+ end
12
+
13
+ def default_javascripts_dir
14
+ File.join("app", "assets", "javascripts")
15
+ end
16
+
17
+ def default_css_dir
18
+ File.join('public', CompassRails4.prefix)
19
+ end
20
+
21
+ def default_http_path
22
+ File.join(CompassRails4.prefix)
23
+ end
24
+
25
+ def default_http_images_path
26
+ "#{top_level.http_path}"
27
+ end
28
+
29
+ def default_http_javascripts_path
30
+ "#{top_level.http_path}"
31
+ end
32
+
33
+ def default_http_fonts_path
34
+ "#{top_level.http_path}"
35
+ end
36
+
37
+ def default_http_stylesheets_path
38
+ "#{top_level.http_path}"
39
+ end
40
+
41
+ def default_preferred_syntax
42
+ CompassRails4.sass_config.preferred_syntax rescue nil
43
+ end
44
+
45
+ def default_sprite_load_path
46
+ CompassRails4.sprockets.paths
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,75 @@
1
+ module CompassRails4
2
+ module Configuration
3
+ module Default
4
+
5
+ def project_type_without_default
6
+ :rails
7
+ end
8
+
9
+ def default_sass_dir
10
+ File.join("app", "assets", "stylesheets")
11
+ end
12
+
13
+ def default_css_dir
14
+ File.join("public", "stylesheets")
15
+ end
16
+
17
+ def default_images_dir
18
+ File.join("public", "images")
19
+ end
20
+
21
+ def default_fonts_dir
22
+ File.join("public", "fonts")
23
+ end
24
+
25
+ def default_javascripts_dir
26
+ File.join("public", "javascripts")
27
+ end
28
+
29
+ def default_http_images_path
30
+ # Relies on the fact that this will be loaded after the "normal"
31
+ # defaults, so that method_missing finds http_root_relative
32
+ http_root_relative "images"
33
+ end
34
+
35
+ def default_http_generated_images_path
36
+ # Relies on the fact that this will be loaded after the "normal"
37
+ # defaults, so that method_missing finds http_root_relative
38
+ http_root_relative "images"
39
+ end
40
+
41
+ def default_http_javascripts_path
42
+ http_root_relative "javascripts"
43
+ end
44
+
45
+ def default_http_fonts_path
46
+ http_root_relative "fonts"
47
+ end
48
+
49
+ def default_http_stylesheets_path
50
+ http_root_relative "stylesheets"
51
+ end
52
+
53
+ def default_extensions_dir
54
+ File.join("vendor", "plugins", "compass_extensions")
55
+ end
56
+
57
+ def default_cache_dir
58
+ File.join("tmp", "sass-cache")
59
+ end
60
+
61
+ def default_project_path
62
+ project_path = CompassRails4.root
63
+ end
64
+
65
+ def default_http_path
66
+ "/" # XXX Where is/was this stored in the Rails config?
67
+ end
68
+
69
+ def default_environment
70
+ CompassRails4.env
71
+ end
72
+
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,30 @@
1
+ require 'compass-rails4/patches/compass'
2
+ require 'compass-rails4/patches/sass_importer'
3
+ require 'compass-rails4/patches/sprite_importer'
4
+
5
+ module Sass::Script::Functions
6
+ def generated_image_url(path, only_path = nil)
7
+ cachebust_generated_images
8
+ asset_url(path)
9
+ end
10
+
11
+ def cachebust_generated_images
12
+ generated_images_path = CompassRails4.root.join(Compass.configuration.generated_images_dir).to_s
13
+ sprockets_entries = CompassRails4.sprockets.send(:trail).index.instance_variable_get(:@entries)
14
+ sprockets_entries.delete(generated_images_path) if sprockets_entries.has_key? generated_images_path
15
+ end
16
+
17
+ def asset_url(path)
18
+ context = CompassRails4.context.new(CompassRails4.sprockets, path.value, path.value)
19
+ Sass::Script::String.new("url(" + context.asset_path(path.value) + ")")
20
+ end
21
+ end
22
+
23
+ module Sass::Script::Functions
24
+ include Compass::RailsImageFunctionPatch
25
+ end
26
+
27
+ # Wierd that this has to be re-included to pick up sub-modules. Ruby bug?
28
+ class Sass::Script::Functions::EvaluationContext
29
+ include Sass::Script::Functions
30
+ end
@@ -0,0 +1,12 @@
1
+ module Compass::RailsImageFunctionPatch
2
+ private
3
+
4
+ def image_path_for_size(image_file)
5
+ begin
6
+ file = CompassRails4.sprockets.find_asset(image_file)
7
+ return file
8
+ rescue ::Sprockets::FileOutsidePaths
9
+ return super(image_file)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,40 @@
1
+ module CompassRails4
2
+ module SassTemplate
3
+
4
+ def self.included(base)
5
+ base.class_eval do
6
+ alias_method_chain :evaluate, :compass_rails
7
+ end
8
+ end
9
+
10
+ def evaluate_with_compass_rails(context, locals, &block)
11
+ # Use custom importer that knows about Sprockets Caching
12
+ cache_store = Sprockets::SassCacheStore.new(context.environment)
13
+ paths = context.environment.paths.map { |path| CompassRails4::SpriteImporter.new(context, path) }
14
+ paths += context.environment.paths.map { |path| Sprockets::SassImporter.new(context, path) }
15
+ paths += CompassRails4.sass_config.load_paths
16
+
17
+ options = CompassRails4.sass_config.merge( {
18
+ :filename => eval_file,
19
+ :line => line,
20
+ :syntax => syntax,
21
+ :cache_store => cache_store,
22
+ :importer => Sprockets::SassImporter.new(context, context.pathname),
23
+ :load_paths => paths,
24
+ :sprockets => {
25
+ :context => context,
26
+ :environment => context.environment
27
+ }
28
+ })
29
+
30
+ ::Sass::Engine.new(data, options).render
31
+ rescue ::Sass::SyntaxError => e
32
+ # Annotates exception message with parse line number
33
+ context.__LINE__ = e.sass_backtrace.first[:line]
34
+ raise e
35
+ end
36
+ end
37
+ end
38
+
39
+ Sprockets::ScssTemplate.send(:include, CompassRails4::SassTemplate)
40
+ Sprockets::SassTemplate.send(:include, CompassRails4::SassTemplate)
@@ -0,0 +1,26 @@
1
+ module CompassRails4
2
+ class SpriteImporter < Compass::SpriteImporter
3
+ attr_reader :context, :root
4
+
5
+ def initialize(context, root)
6
+ @context = context
7
+ @root = root
8
+ end
9
+
10
+ def find(uri, options)
11
+ if old = super(uri, options)
12
+ self.class.files(uri).each do |file|
13
+ relative_path = Pathname.new(file).relative_path_from(Pathname.new(root))
14
+ begin
15
+ pathname = context.resolve(relative_path)
16
+ context.depend_on_asset(pathname)
17
+ rescue Sprockets::FileNotFound
18
+
19
+ end
20
+ end
21
+ end
22
+
23
+ old
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,56 @@
1
+ unless CompassRails4.rails4?
2
+ $stderr.puts "Unsupported rails environment for compass"
3
+ exit 1
4
+ end
5
+
6
+ class Rails::Railtie::Configuration
7
+ # Adds compass configuration accessor to the application configuration.
8
+ #
9
+ # If a configuration file for compass exists, it will be read in and
10
+ # the project's configuration values will already be set on the config
11
+ # object.
12
+ #
13
+ # For example:
14
+ #
15
+ # module MyApp
16
+ # class Application < Rails::Application
17
+ # config.compass.line_comments = !Rails.env.production?
18
+ # config.compass.fonts_dir = "app/assets/fonts"
19
+ # end
20
+ # end
21
+ #
22
+ # It is suggested that you create a compass configuration file if you
23
+ # want a quicker boot time when using the compass command line tool.
24
+ #
25
+ # For more information on available configuration options see:
26
+ # http://compass-style.org/help/tutorials/configuration-reference/
27
+ def compass
28
+ @compass ||= begin
29
+ data = if (config_file = Compass.detect_configuration_file) && (config_data = Compass.configuration_for(config_file))
30
+ config_data
31
+ else
32
+ Compass::Configuration::Data.new("rails_config")
33
+ end
34
+ data.project_type = :rails # Forcing this makes sure all the rails defaults will be loaded.
35
+
36
+ Compass.add_configuration(:rails)
37
+ Compass.add_configuration(data)
38
+
39
+ data
40
+ end
41
+ @compass
42
+ end
43
+ end
44
+
45
+ module CompassRails4
46
+ class Railtie < ::Rails::Railtie
47
+ initializer "compass.initialize_rails", :group => :all do |app|
48
+ require 'compass-rails4/patches'
49
+ # Configure compass for use within rails, and provide the project configuration
50
+ # that came via the rails boot process.
51
+ CompassRails4.check_for_double_boot!
52
+ Compass.discover_extensions!
53
+ CompassRails4.configure_rails!(app)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,5 @@
1
+ module CompassRails4
2
+ unless defined?(::CompassRails4::VERSION)
3
+ VERSION = "0.0.1" #based on 1.1.3
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: compass-rails4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tomas Brazys
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: compass
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.13.alpha.12
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.13.alpha.12
27
+ - !ruby/object:Gem::Dependency
28
+ name: railties
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 4.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 4.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Integrate Compass into Rails 4.0.
56
+ email:
57
+ - tomas.brazys@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - LICENSE
66
+ - Rakefile
67
+ - compass-rails4.gemspec
68
+ - lib/compass-rails4.rb
69
+ - lib/compass-rails4/configuration.rb
70
+ - lib/compass-rails4/configuration/asset_pipeline.rb
71
+ - lib/compass-rails4/configuration/default.rb
72
+ - lib/compass-rails4/patches.rb
73
+ - lib/compass-rails4/patches/compass.rb
74
+ - lib/compass-rails4/patches/sass_importer.rb
75
+ - lib/compass-rails4/patches/sprite_importer.rb
76
+ - lib/compass-rails4/railtie.rb
77
+ - lib/compass-rails4/version.rb
78
+ homepage: https://github.com/deees/compass-rails4
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.0.6
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Adaptation of original compass-rails to work with Rails 4.
102
+ test_files: []