Skip to content

Commit bd3b0cf

Browse files
committed
improving tests, using proper sass output styles, support sass style
1 parent c29bcc2 commit bd3b0cf

File tree

8 files changed

+143
-191
lines changed

8 files changed

+143
-191
lines changed

lib/sassc/rails.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
require_relative "rails/version"
2+
3+
require "sassc"
24
require_relative "rails/functions"
35
require_relative "rails/importer"
46
require_relative "rails/template"

lib/sassc/rails/functions.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require "sprockets/sass_template"
2-
require "sassc"
32

43
module Sprockets
54
class SassTemplate

lib/sassc/rails/importer.rb

Lines changed: 9 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,16 @@ def import_for(original_path, parent_path, full_path, options)
2626
end
2727
end
2828

29-
class ERBExtension < Extension
30-
def initialize(postfix)
31-
super
29+
class SassERBExtension < Extension
30+
def import_for(original_path, parent_path, full_path, options)
31+
template = Tilt::ERBTemplate.new(full_path)
32+
parsed_erb = template.render(options[:sprockets][:context], {})
33+
parsed_scss = SassC::Sass2Scss.convert(parsed_erb)
34+
SassC::Importer::Import.new(full_path, source: parsed_scss)
3235
end
36+
end
3337

38+
class ERBExtension < Extension
3439
def import_for(original_path, parent_path, full_path, options)
3540
template = Tilt::ERBTemplate.new(full_path)
3641
parsed_erb = template.render(options[:sprockets][:context], {})
@@ -43,42 +48,13 @@ def import_for(original_path, parent_path, full_path, options)
4348
Extension.new(".sass"),
4449
CSSExtension.new,
4550
ERBExtension.new(".scss.erb"),
46-
ERBExtension.new(".sass.erb"),
51+
SassERBExtension.new(".sass.erb"),
4752
ERBExtension.new(".css.erb"),
4853
]
4954

5055
PREFIXS = [ "", "_" ]
5156

5257
def imports(path, parent_path)
53-
# should return an Import, or array of Imports.
54-
# Import.new(path)
55-
56-
# Imports can usually be passed with only a path. However,
57-
# when parsing ERB we need to return the import like this:
58-
# Import.new(path, source: parsed_erb)
59-
# in this case, the path is just for reference, i don't believe it
60-
# gets used.
61-
62-
# the parent path is basically the file that's calling the
63-
# @import function. This necessary when we need to do an import
64-
# relative to the folder that the import function is being called from.
65-
66-
# for the filename, it looks like libsass can properly resolve
67-
# filenames without extensions provided that the actual file has
68-
# a .sass or .scss filename.
69-
70-
# it CANNOT resolve a .css file unless you explicitly pass the
71-
# filename with the .css extension.
72-
73-
# lets ignore globbing for now.
74-
75-
# for ERB parsing, check out the sass-rails importer below, it looks pretty
76-
# simple
77-
78-
# check out
79-
# https://github.com/sass/sass/blob/stable/lib/sass/importers/filesystem.rb
80-
# for reference
81-
8258
parent_dir, _ = File.split(parent_path)
8359
specified_dir, specified_file = File.split(path)
8460

@@ -123,151 +99,3 @@ def load_paths
12399
end
124100
end
125101
end
126-
127-
#require 'active_support/deprecation/reporting'
128-
#require 'sass'
129-
#require 'sprockets/sass_importer'
130-
#require 'tilt'
131-
132-
# module Sass
133-
# module Rails
134-
# class SassImporter < Sass::Importers::Filesystem
135-
# module Globbing
136-
# GLOB = /(\A|\/)(\*|\*\*\/\*)\z/
137-
#
138-
# def find_relative(name, base, options)
139-
# if options[:sprockets] && m = name.match(GLOB)
140-
# path = name.sub(m[0], "")
141-
# base = File.expand_path(path, File.dirname(base))
142-
# glob_imports(base, m[2], options)
143-
# else
144-
# super
145-
# end
146-
# end
147-
#
148-
# def find(name, options)
149-
# # globs must be relative
150-
# return if name =~ GLOB
151-
# super
152-
# end
153-
#
154-
# private
155-
# def glob_imports(base, glob, options)
156-
# contents = ""
157-
# context = options[:sprockets][:context]
158-
# each_globbed_file(base, glob, context) do |filename|
159-
# next if filename == options[:filename]
160-
# contents << "@import #{filename.inspect};\n"
161-
# end
162-
# return nil if contents == ""
163-
# Sass::Engine.new(contents, options.merge(
164-
# :filename => base,
165-
# :importer => self,
166-
# :syntax => :scss
167-
# ))
168-
# end
169-
#
170-
# def each_globbed_file(base, glob, context)
171-
# raise ArgumentError unless glob == "*" || glob == "**/*"
172-
#
173-
# exts = extensions.keys.map { |ext| Regexp.escape(".#{ext}") }.join("|")
174-
# sass_re = Regexp.compile("(#{exts})$")
175-
#
176-
# context.depend_on(base)
177-
#
178-
# Dir["#{base}/#{glob}"].sort.each do |path|
179-
# if File.directory?(path)
180-
# context.depend_on(path)
181-
# elsif sass_re =~ path
182-
# yield path
183-
# end
184-
# end
185-
# end
186-
# end
187-
#
188-
# module ERB
189-
# def extensions
190-
# {
191-
# 'css.erb' => :scss_erb,
192-
# 'scss.erb' => :scss_erb,
193-
# 'sass.erb' => :sass_erb
194-
# }.merge(super)
195-
# end
196-
#
197-
# def erb_extensions
198-
# {
199-
# :scss_erb => :scss,
200-
# :sass_erb => :sass
201-
# }
202-
# end
203-
#
204-
# def find_relative(*args)
205-
# process_erb_engine(super)
206-
# end
207-
#
208-
# def find(*args)
209-
# process_erb_engine(super)
210-
# end
211-
#
212-
# private
213-
# def process_erb_engine(engine)
214-
# if engine && engine.options[:sprockets] && syntax = erb_extensions[engine.options[:syntax]]
215-
# template = Tilt::ERBTemplate.new(engine.options[:filename])
216-
# contents = template.render(engine.options[:sprockets][:context], {})
217-
#
218-
# Sass::Engine.new(contents, engine.options.merge(:syntax => syntax))
219-
# else
220-
# engine
221-
# end
222-
# end
223-
# end
224-
#
225-
# module Deprecated
226-
# def extensions
227-
# {
228-
# 'css.scss' => :scss,
229-
# 'css.sass' => :sass,
230-
# 'css.scss.erb' => :scss_erb,
231-
# 'css.sass.erb' => :sass_erb
232-
# }.merge(super)
233-
# end
234-
#
235-
# def find_relative(*args)
236-
# deprecate_extra_css_extension(super)
237-
# end
238-
#
239-
# def find(*args)
240-
# deprecate_extra_css_extension(super)
241-
# end
242-
#
243-
# private
244-
# def deprecate_extra_css_extension(engine)
245-
# if engine && filename = engine.options[:filename]
246-
# if filename.end_with?('.css.scss')
247-
# msg = "Extra .css in SCSS file is unnecessary. Rename #{filename} to #{filename.sub('.css.scss', '.scss')}."
248-
# elsif filename.end_with?('.css.sass')
249-
# msg = "Extra .css in SASS file is unnecessary. Rename #{filename} to #{filename.sub('.css.sass', '.sass')}."
250-
# elsif filename.end_with?('.css.scss.erb')
251-
# msg = "Extra .css in SCSS/ERB file is unnecessary. Rename #{filename} to #{filename.sub('.css.scss.erb', '.scss.erb')}."
252-
# elsif filename.end_with?('.css.sass.erb')
253-
# msg = "Extra .css in SASS/ERB file is unnecessary. Rename #{filename} to #{filename.sub('.css.sass.erb', '.sass.erb')}."
254-
# end
255-
#
256-
# ActiveSupport::Deprecation.warn(msg) if msg
257-
# end
258-
#
259-
# engine
260-
# end
261-
# end
262-
#
263-
# include Deprecated
264-
# include ERB
265-
# include Globbing
266-
#
267-
# # Allow .css files to be @import'd
268-
# def extensions
269-
# { 'css' => :scss }.merge(super)
270-
# end
271-
# end
272-
# end
273-
# end

lib/sassc/rails/railtie.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ class Railtie < ::Rails::Railtie
5353
end
5454

5555
initializer :setup_compression, group: :all do |app|
56+
app.config.assets.css_compressor = nil
57+
5658
if !Rails.env.development?
57-
app.config.assets.css_compressor ||= :sass
59+
app.config.sass.style = :compressed
5860
else
5961
# Use expanded output instead of the sass default of :nested unless specified
6062
app.config.sass.style ||= :expanded

sassc-rails.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ Gem::Specification.new do |spec|
2323
spec.add_development_dependency "rake", "~> 10.0"
2424
spec.add_development_dependency "minitest", "~> 5.5.1"
2525
spec.add_development_dependency 'rails'
26+
spec.add_development_dependency 'mocha'
2627

2728
# unfortunately we require sass for now, so that we can
2829
# reuse portions of the sprockets template
2930
spec.add_dependency 'sass'
3031

3132
spec.add_dependency 'tilt' # For ERB
3233

33-
spec.add_dependency "sassc", "0.0.10"
34+
spec.add_dependency "sassc", "1.0.0"
3435
spec.add_dependency 'railties'
3536
spec.add_dependency 'sprockets', '3.0.0.beta.6'
3637
end

test/dummy/app/assets/stylesheets/imports_test.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
@import "partials/without_css_ext";
88
@import "css_erb_handler";
99
@import "scss_erb_handler";
10-
// @import "sass_erb_handler";
10+
@import "sass_erb_handler";
1111
@import "css_scss_erb_handler";
12-
// @import "css_sass_erb_handler";
12+
@import "css_sass_erb_handler";
1313

1414
.main {
1515
color: yellow;
16-
// @include background-from-partial(red);
16+
@include background-from-partial(red);
1717
}
1818

1919
@include without-css-ext;

0 commit comments

Comments
 (0)