Skip to content

Commit 507ad40

Browse files
committed
initial
0 parents  commit 507ad40

File tree

227 files changed

+4747
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+4747
-0
lines changed

.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/.bundle/
2+
/.yardoc
3+
/Gemfile.lock
4+
/_yardoc/
5+
/coverage/
6+
/doc/
7+
/pkg/
8+
/spec/reports/
9+
/tmp/
10+
*.bundle
11+
*.so
12+
*.o
13+
*.a
14+
mkmf.log
15+
vendor

Gemfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
# Specify your gem's dependencies in sassc-rails.gemspec
4+
gemspec

LICENSE.txt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2015 Ryan Boland
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.

README.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Sassc::Rails
2+
3+
WIP.
4+
5+
## Installation
6+
7+
Add this line to your application's Gemfile:
8+
9+
```ruby
10+
gem 'sassc-rails'
11+
```
12+
13+
And then execute:
14+
15+
$ bundle
16+
17+
Or install it yourself as:
18+
19+
$ gem install sassc-rails
20+
21+
## Usage
22+
23+
TODO: Write usage instructions here
24+
25+
## Contributing
26+
27+
1. Fork it ( https://github.com/[my-github-username]/sassc-rails/fork )
28+
2. Create your feature branch (`git checkout -b my-new-feature`)
29+
3. Commit your changes (`git commit -am 'Add some feature'`)
30+
4. Push to the branch (`git push origin my-new-feature`)
31+
5. Create a new Pull Request

Rakefile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require "bundler/gem_tasks"
2+
3+
task :test do
4+
$LOAD_PATH.unshift('lib', 'test')
5+
Dir.glob('./test/**/*_test.rb') { |f| require f }
6+
end

lib/sassc-rails.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
begin
2+
require "sass-rails"
3+
Sass::Rails.send(:remove_const, :Railtie)
4+
rescue LoadError
5+
end
6+
7+
require_relative "sassc/rails"
8+

lib/sassc/rails.rb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#module Sass
2+
# module Rails
3+
# autoload :Logger, 'sass/rails/logger'
4+
# end
5+
#end
6+
#
7+
require_relative "rails/version"
8+
#require_relative "rails/helpers"
9+
#require_relative "rails/importer"
10+
require_relative "rails/template"
11+
require_relative "rails/railtie"

lib/sassc/rails/functions.rb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require 'sprockets/sass_functions'
2+
3+
module Sprockets
4+
module SassFunctions
5+
def asset_data_url(path)
6+
Sass::Script::String.new("url(" + sprockets_context.asset_data_uri(path.value) + ")")
7+
end
8+
end
9+
end
10+
11+
::Sass::Script::Functions.send :include, Sprockets::SassFunctions

lib/sassc/rails/importer.rb

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
require 'active_support/deprecation/reporting'
2+
require 'sass'
3+
require 'sprockets/sass_importer'
4+
require 'tilt'
5+
6+
module Sass
7+
module Rails
8+
class SassImporter < Sass::Importers::Filesystem
9+
module Globbing
10+
GLOB = /(\A|\/)(\*|\*\*\/\*)\z/
11+
12+
def find_relative(name, base, options)
13+
if options[:sprockets] && m = name.match(GLOB)
14+
path = name.sub(m[0], "")
15+
base = File.expand_path(path, File.dirname(base))
16+
glob_imports(base, m[2], options)
17+
else
18+
super
19+
end
20+
end
21+
22+
def find(name, options)
23+
# globs must be relative
24+
return if name =~ GLOB
25+
super
26+
end
27+
28+
private
29+
def glob_imports(base, glob, options)
30+
contents = ""
31+
context = options[:sprockets][:context]
32+
each_globbed_file(base, glob, context) do |filename|
33+
next if filename == options[:filename]
34+
contents << "@import #{filename.inspect};\n"
35+
end
36+
return nil if contents == ""
37+
Sass::Engine.new(contents, options.merge(
38+
:filename => base,
39+
:importer => self,
40+
:syntax => :scss
41+
))
42+
end
43+
44+
def each_globbed_file(base, glob, context)
45+
raise ArgumentError unless glob == "*" || glob == "**/*"
46+
47+
exts = extensions.keys.map { |ext| Regexp.escape(".#{ext}") }.join("|")
48+
sass_re = Regexp.compile("(#{exts})$")
49+
50+
context.depend_on(base)
51+
52+
Dir["#{base}/#{glob}"].sort.each do |path|
53+
if File.directory?(path)
54+
context.depend_on(path)
55+
elsif sass_re =~ path
56+
yield path
57+
end
58+
end
59+
end
60+
end
61+
62+
module ERB
63+
def extensions
64+
{
65+
'css.erb' => :scss_erb,
66+
'scss.erb' => :scss_erb,
67+
'sass.erb' => :sass_erb
68+
}.merge(super)
69+
end
70+
71+
def erb_extensions
72+
{
73+
:scss_erb => :scss,
74+
:sass_erb => :sass
75+
}
76+
end
77+
78+
def find_relative(*args)
79+
process_erb_engine(super)
80+
end
81+
82+
def find(*args)
83+
process_erb_engine(super)
84+
end
85+
86+
private
87+
def process_erb_engine(engine)
88+
if engine && engine.options[:sprockets] && syntax = erb_extensions[engine.options[:syntax]]
89+
template = Tilt::ERBTemplate.new(engine.options[:filename])
90+
contents = template.render(engine.options[:sprockets][:context], {})
91+
92+
Sass::Engine.new(contents, engine.options.merge(:syntax => syntax))
93+
else
94+
engine
95+
end
96+
end
97+
end
98+
99+
module Deprecated
100+
def extensions
101+
{
102+
'css.scss' => :scss,
103+
'css.sass' => :sass,
104+
'css.scss.erb' => :scss_erb,
105+
'css.sass.erb' => :sass_erb
106+
}.merge(super)
107+
end
108+
109+
def find_relative(*args)
110+
deprecate_extra_css_extension(super)
111+
end
112+
113+
def find(*args)
114+
deprecate_extra_css_extension(super)
115+
end
116+
117+
private
118+
def deprecate_extra_css_extension(engine)
119+
if engine && filename = engine.options[:filename]
120+
if filename.end_with?('.css.scss')
121+
msg = "Extra .css in SCSS file is unnecessary. Rename #{filename} to #{filename.sub('.css.scss', '.scss')}."
122+
elsif filename.end_with?('.css.sass')
123+
msg = "Extra .css in SASS file is unnecessary. Rename #{filename} to #{filename.sub('.css.sass', '.sass')}."
124+
elsif filename.end_with?('.css.scss.erb')
125+
msg = "Extra .css in SCSS/ERB file is unnecessary. Rename #{filename} to #{filename.sub('.css.scss.erb', '.scss.erb')}."
126+
elsif filename.end_with?('.css.sass.erb')
127+
msg = "Extra .css in SASS/ERB file is unnecessary. Rename #{filename} to #{filename.sub('.css.sass.erb', '.sass.erb')}."
128+
end
129+
130+
ActiveSupport::Deprecation.warn(msg) if msg
131+
end
132+
133+
engine
134+
end
135+
end
136+
137+
include Deprecated
138+
include ERB
139+
include Globbing
140+
141+
# Allow .css files to be @import'd
142+
def extensions
143+
{ 'css' => :scss }.merge(super)
144+
end
145+
end
146+
end
147+
end

lib/sassc/rails/logger.rb

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require 'sass/logger'
2+
3+
module Sass
4+
module Rails
5+
class Logger < Sass::Logger::Base
6+
def _log(level, message)
7+
8+
case level
9+
when :trace, :debug
10+
::Rails.logger.debug message
11+
when :warn
12+
::Rails.logger.warn message
13+
when :error
14+
::Rails.logger.error message
15+
when :info
16+
::Rails.logger.info message
17+
end
18+
end
19+
end
20+
end
21+
end

lib/sassc/rails/railtie.rb

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
require 'active_support/core_ext/class/attribute'
2+
require 'sprockets/railtie'
3+
4+
module SassC::Rails
5+
class Railtie < ::Rails::Railtie
6+
config.sass = ActiveSupport::OrderedOptions.new
7+
8+
# Establish static configuration defaults
9+
# Emit scss files during stylesheet generation of scaffold
10+
config.sass.preferred_syntax = :scss
11+
# Write sass cache files for performance
12+
config.sass.cache = true
13+
# Read sass cache files for performance
14+
config.sass.read_cache = true
15+
# Display line comments above each selector as a debugging aid
16+
config.sass.line_comments = true
17+
# Initialize the load paths to an empty array
18+
config.sass.load_paths = []
19+
# Send Sass logs to Rails.logger
20+
#config.sass.logger = Sass::Rails::Logger.new
21+
22+
# Set the default stylesheet engine
23+
# It can be overridden by passing:
24+
# --stylesheet_engine=sass
25+
# to the rails generate command
26+
config.app_generators.stylesheet_engine config.sass.preferred_syntax
27+
28+
if config.respond_to?(:annotations)
29+
config.annotations.register_extensions("scss", "sass") { |annotation| /\/\/\s*(#{annotation}):?\s*(.*)$/ }
30+
end
31+
32+
# Remove the sass middleware if it gets inadvertently enabled by applications.
33+
config.after_initialize do |app|
34+
app.config.middleware.delete(Sass::Plugin::Rack) if defined?(Sass::Plugin::Rack)
35+
end
36+
37+
initializer :setup_sass, group: :all do |app|
38+
# Only emit one kind of syntax because though we have registered two kinds of generators
39+
syntax = app.config.sass.preferred_syntax.to_sym
40+
alt_syntax = syntax == :sass ? "scss" : "sass"
41+
app.config.generators.hide_namespace alt_syntax
42+
43+
# Override stylesheet engine to the preferred syntax
44+
config.app_generators.stylesheet_engine syntax
45+
46+
# Set the sass cache location
47+
config.sass.cache_location = File.join(Rails.root, "tmp/cache/sass")
48+
49+
# Establish configuration defaults that are evironmental in nature
50+
if config.sass.full_exception.nil?
51+
# Display a stack trace in the css output when in development-like environments.
52+
config.sass.full_exception = app.config.consider_all_requests_local
53+
end
54+
55+
if app.assets
56+
app.assets.register_engine '.sass', SassC::Rails::SassTemplate
57+
app.assets.register_engine '.scss', SassC::Rails::SassTemplate
58+
59+
app.assets.context_class.class_eval do
60+
class_attribute :sass_config
61+
self.sass_config = app.config.sass
62+
end
63+
end
64+
65+
#Sass.logger = app.config.sass.logger
66+
end
67+
68+
initializer :setup_compression, group: :all do |app|
69+
unless Rails.env.development?
70+
app.config.assets.css_compressor ||= :sass
71+
else
72+
# Use expanded output instead of the sass default of :nested unless specified
73+
app.config.sass.style ||= :expanded
74+
end
75+
end
76+
end
77+
end

0 commit comments

Comments
 (0)