class Slinky::CompiledFile
Stores information about compiled files, including location, source file and last modified time
Attributes
last_compiled[R]
output_ext[R]
output_path[RW]
print_name[RW]
source[RW]
Public Class Methods
new(source, compiler, output_ext)
click to toggle source
Creates a new CompiledFile
, compiling the provided source file with the provided compiler class.
# File lib/slinky/compiled_file.rb, line 10 def initialize source, compiler, output_ext @source = source @compiler = compiler @last_compiled = Time.at(0) @output_ext = output_ext end
Public Instance Methods
build(path)
click to toggle source
# File lib/slinky/compiled_file.rb, line 17 def build path compiler_compile path, EM::DefaultDeferrable end
compile(&cb)
click to toggle source
Compiles the source file to a temporary location
# File lib/slinky/compiled_file.rb, line 22 def compile &cb path = @output_path || tmp_path @last_compiled = Time.now if @compiler.respond_to? :compile compiler_compile path, cb else compile_failed Exception.new("invalid compiler") cb.call @output_path, nil, nil, "invalid compiler" # compiler_command path, cb end end
compile_failed(e)
click to toggle source
# File lib/slinky/compiled_file.rb, line 76 def compile_failed e SlinkyError.raise BuildFailedError, "Compilation failed on #{name}: #{e}" end
compile_succeeded()
click to toggle source
# File lib/slinky/compiled_file.rb, line 72 def compile_succeeded $stdout.puts "Compiled #{name}".foreground(:green) end
compiler_compile(path, cb)
click to toggle source
# File lib/slinky/compiled_file.rb, line 34 def compiler_compile path, cb begin out = File.open @source do |f| @compiler.compile f.read, @source end compile_succeeded File.open(path, "w+") do |f| f.write out end rescue Exception compile_failed $! path = nil end cb.call((path ? path.to_s : nil), nil, nil, $!) end
file(&cb)
click to toggle source
Calls the supplied callback with the path of the compiled file, compiling the source file first if necessary.
# File lib/slinky/compiled_file.rb, line 82 def file &cb #if needs_update? compile &cb #else # cb.call @output_path, nil, nil, nil #end end
name()
click to toggle source
EM.system3 command do |stdout, stderr, status| if status.exitstatus != 0 compile_failed stderr.strip else compile_succeeded @output_path = path end cb.call(@output_path, status, stdout, stderr) end
end
# File lib/slinky/compiled_file.rb, line 68 def name @print_name || @source end
needs_update?()
click to toggle source
Returns whether the source file has changed since it was last compiled.
# File lib/slinky/compiled_file.rb, line 92 def needs_update? return true if @compiler.to_s.match "SassCompiler" File.new(source).mtime > @last_compiled rescue true end
Private Instance Methods
tmp_path()
click to toggle source
# File lib/slinky/compiled_file.rb, line 98 def tmp_path Tempfile.new("slinky").path + "." + @output_ext end