Permalink
Browse files

Expose the output_root option

  • Loading branch information...
1 parent 21147fb commit 151a5a06fbacb0d23609dd3b4e6123e450f13ec9 @Sutto committed Apr 18, 2011
Showing with 35 additions and 10 deletions.
  1. +1 −0 README.md
  2. +5 −0 lib/barista.rb
  3. +19 −6 lib/barista/framework.rb
  4. +10 −4 lib/generators/barista/install/templates/initializer.rb
View
@@ -146,6 +146,7 @@ and `#option!` (to set the value to true):
* `root` – The folder path to read CoffeeScripts from. (Defaults to `app/coffeescripts`.)
* `output_root` – The folder to write compiled JS files to. (Defaults to `public/javascripts`.)
* `change_output_prefix!` – Method to change the output prefix for a framework.
+* `change_output_root!` - Method to change the output root for a given framework.
* `verbose` – Whether or not Barista will add a preamble to files.
* `js_path` – Path to the pure-JavaScript compiler.
* `env` – The application environment. (Defaults to `Rails.env`.)
View
@@ -195,6 +195,11 @@ def change_output_prefix!(framework, prefix = nil)
framework.output_prefix = prefix if framework
end
+ def change_output_root!(framework, root)
+ framework = Barista::Framework[framework] unless framework.is_a?(Barista::Framework)
+ framework.output_root = root if framework
+ end
+
def each_framework(include_default = false, &blk)
Framework.all(include_default).each(&blk)
end
View
@@ -41,8 +41,13 @@ def self.full_path_for(script)
nil
end
- def self.register(name, root)
- (@all ||= []) << self.new(:name => name, :root => root)
+ def self.register(name, options = nil)
+ if options.is_a?(Hash)
+ framework = self.new(options.merge(:name => name))
+ else
+ framework = self.new(:name => name, :root => root)
+ end
+ (@all ||= []) << framework
end
def self.[](name)
@@ -63,10 +68,10 @@ def initialize(options, root = nil, output_prefix = nil)
end
# actually setup the framework.
check_options! options, :name, :root
- @name = options[:name].to_s
- @output_prefix = options[:output_prefix]
- @framework_root = File.expand_path(options[:root].to_s)
- @output_root = options[:output_root] && Pathname(options[:output_root])
+ @name = options[:name].to_s
+ @output_prefix = options[:output_prefix]
+ @framework_root = File.expand_path(options[:root].to_s)
+ self.output_root = options[:output_root]
end
def coffeescripts
@@ -112,6 +117,14 @@ def output_root
@output_root || Barista.output_root
end
+ def output_root=(value)
+ if value.nil?
+ @output_root = nil
+ else
+ @output_root = Pathname(value.to_s)
+ end
+ end
+
def output_path_for(file, format = 'js')
# Strip the leading slashes
file = file.to_s.gsub(/^\/+/, '')
@@ -10,12 +10,14 @@
# Disable auto compile, use generated file directly:
# c.auto_compile = false
- # Set the compiler
+ # Add a new framework:
+
+ # c.register :tests, :root => Rails.root.join('test', 'coffeescript'), :output_prefix => 'test'
# Disable wrapping in a closure:
- # c.no_wrap = true
+ # c.bare = true
# ... or ...
- # c.no_wrap!
+ # c.bare!
# Change the output root for a framework:
@@ -24,13 +26,17 @@
# or for all frameworks...
# c.each_framework do |framework|
- # c.change_output_prefix! framework.name, "vendor/#{framework.name}"
+ # c.change_output_prefix! framework, "vendor/#{framework.name}"
# end
# or, prefix the path for the app files:
# c.change_output_prefix! :default, 'my-app-name'
+ # or, change the directory the framework goes into full stop:
+
+ # c.change_output_prefix! :tests, Rails.root.join('spec', 'javascripts')
+
# or, hook into the compilation:
# c.before_compilation { |path| puts "Barista: Compiling #{path}" }

0 comments on commit 151a5a0

Please sign in to comment.