lib/barista.rb in barista-0.2.1 vs lib/barista.rb in barista-0.3.0
- old
+ new
@@ -1,50 +1,50 @@
require 'active_support'
require 'pathname'
module Barista
-
+
autoload :Compiler, 'barista/compiler'
autoload :Filter, 'barista/filter'
autoload :Framework, 'barista/framework'
-
+
class << self
-
+
def configure
yield self if block_given?
end
-
+
def root
@root ||= Rails.root.join("app", "coffeescripts")
end
-
+
def root=(value)
@root = Pathname(value.to_s)
Framework.default_framework = nil
end
-
+
def output_root
@output_root ||= Rails.root.join("public", "javascripts")
end
-
+
def output_root=(value)
@output_root = Pathname(value.to_s)
end
-
+
def compile_file!(file, force = false)
origin_path, framework = Framework.full_path_for(file)
return if origin_path.blank?
destination_path = self.output_path_for(file)
return unless force || Compiler.dirty?(origin_path, destination_path)
debug "Compiling #{file} from framework '#{framework.name}'"
FileUtils.mkdir_p File.dirname(destination_path)
- File.open(destination_path, "w+") do |f|
- f.write Compiler.compile(File.read(origin_path))
- end
- true
+ content = Compiler.compile(origin_path)
+ # Write the rendered content to file.
+ File.open(destination_path, "w+") { |f| f.write content }
+ content
rescue SystemCallError
- false
+ ""
end
def compile_all!(force = false)
debug "Compiling all coffeescripts"
Framework.exposed_coffeescripts.each do |coffeescript|
@@ -102,6 +102,6 @@
end
end
end
-end
\ No newline at end of file
+end