Class: Tipsy::Handler::SassHandler::Importer
- Inherits:
-
Object
- Object
- Tipsy::Handler::SassHandler::Importer
- Defined in:
- lib/tipsy/handler/sass/importer.rb
Constant Summary collapse
- GLOB =
/\*|\[.+\]/
- PARTIAL =
/^_/
- HAS_EXTENSION =
/\.css(.s[ac]ss)?$/
- SASS_EXTENSIONS =
{ ".css.sass" => :sass, ".css.scss" => :scss, ".sass" => :sass, ".scss" => :scss }
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
- #find(name, options) ⇒ Object
- #find_relative(name, base, options) ⇒ Object
-
#initialize(context) ⇒ Importer
constructor
A new instance of Importer.
- #key(name, options) ⇒ Object
- #mtime(name, options) ⇒ Object
- #render_with_engine(data, pathname, options = {}) ⇒ Object
- #resolve(name, base_pathname = nil) ⇒ Object
- #resolve_sass_path(name, options = {}, relative = false) ⇒ Object
- #sass_file?(filename) ⇒ Boolean
- #syntax(filename) ⇒ Object
Constructor Details
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
21 22 23 |
# File 'lib/tipsy/handler/sass/importer.rb', line 21 def context @context end |
Instance Method Details
#find(name, options) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/tipsy/handler/sass/importer.rb', line 67 def find(name, ) if pathname = resolve(name) context.depend_on(pathname) if sass_file?(pathname) render_with_engine(pathname.read, pathname) else render_with_engine(@resolver.process(pathname), pathname) end else nil end end |
#find_relative(name, base, options) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/tipsy/handler/sass/importer.rb', line 53 def find_relative(name, base, ) base_pathname = Pathname.new(base) if pathname = resolve(name, base_pathname.dirname) context.depend_on(pathname) if sass_file?(pathname) render_with_engine(pathname.read, pathname) else render_with_engine(@resolver.process(pathname), pathname) end else nil end end |
#key(name, options) ⇒ Object
86 87 88 |
# File 'lib/tipsy/handler/sass/importer.rb', line 86 def key(name, ) ["Sprockets:" + File.dirname(File.(name)), File.basename(name)] end |
#mtime(name, options) ⇒ Object
80 81 82 83 84 |
# File 'lib/tipsy/handler/sass/importer.rb', line 80 def mtime(name, ) if pathname = resolve_sass_path(name, ) pathname.mtime end end |
#render_with_engine(data, pathname, options = {}) ⇒ Object
39 40 41 |
# File 'lib/tipsy/handler/sass/importer.rb', line 39 def render_with_engine(data, pathname, = {}) ::Sass::Engine.new(data, .merge(:filename => pathname.to_s, :importer => self, :syntax => syntax(pathname))) end |
#resolve(name, base_pathname = nil) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/tipsy/handler/sass/importer.rb', line 43 def resolve(name, base_pathname = nil) name = Pathname.new(name) if base_pathname && base_pathname.to_s.size > 0 root = Pathname.new(context.root_path) name = base_pathname.relative_path_from(root).join(name) end partial_name = name.dirname.join("_#{name.basename}") @resolver.resolve(name) || @resolver.resolve(partial_name) end |
#resolve_sass_path(name, options = {}, relative = false) ⇒ Object
90 91 92 93 |
# File 'lib/tipsy/handler/sass/importer.rb', line 90 def resolve_sass_path(name, = {}, relative = false) prefix = ( relative === false ? "" : "./" ) (context.resolve("#{prefix}#{name}", ) || context.resolve("#{prefix}_#{name}", )) end |
#sass_file?(filename) ⇒ Boolean
28 29 30 31 |
# File 'lib/tipsy/handler/sass/importer.rb', line 28 def sass_file?(filename) filename = filename.to_s SASS_EXTENSIONS.keys.any?{|ext| filename[ext]} end |
#syntax(filename) ⇒ Object
33 34 35 36 37 |
# File 'lib/tipsy/handler/sass/importer.rb', line 33 def syntax(filename) filename = filename.to_s SASS_EXTENSIONS.each {|ext, syntax| return syntax if filename[(ext.size+2)..-1][ext]} nil end |