class SassBuddy
Pass either a file or a string containing scss and recieve a compiled string of css with or without style tags.
Attributes
additions[R]
container[R]
file[R]
manifest[R]
require_paths[R]
string[R]
Public Class Methods
new(opts)
click to toggle source
# File lib/sass-buddy.rb, line 9 def initialize(opts) @file = opts[:file] @string, = opts[:string] @container = opts[:container] @additions = opts[:additions] @require_paths = opts[:require_paths] @manifest = opts[:rev_manifest] ? get_manifest(opts[:rev_manifest]) : {} @syntax = opts[:sass] ? :sass : :scss end
Public Instance Methods
compile()
click to toggle source
# File lib/sass-buddy.rb, line 20 def compile revved(compiled_css) if compiled_css end
compile_html()
click to toggle source
# File lib/sass-buddy.rb, line 24 def compile_html "<style>#{revved(compiled_css)}</style>" if compiled_css end
Private Instance Methods
compiled_css()
click to toggle source
# File lib/sass-buddy.rb, line 42 def compiled_css SassC::Engine.new( stringed_additions + contents, syntax: @syntax, importer: ImportBuddy, filename: file, require_paths: require_paths ).render rescue SassC::SyntaxError false end
contents()
click to toggle source
# File lib/sass-buddy.rb, line 62 def contents @contents ||= begin scss = file ? File.open(file).read : string scss = "#{container} {#{scss}}" if container scss end end
get_manifest(file)
click to toggle source
# File lib/sass-buddy.rb, line 30 def get_manifest(file) JSON.parse(File.open(file).read) end
revved(css)
click to toggle source
# File lib/sass-buddy.rb, line 34 def revved(css) manifest.each do |k, v| css.gsub!(k, v) end css end
stringed_additions()
click to toggle source
# File lib/sass-buddy.rb, line 54 def stringed_additions return '' unless additions additions.inject('') do |out, (k, v)| out + "$#{k}:##{v};" end end