Skip to content
Browse files

Let users switch the compilers in a simpler manner, change version nu…

…mber.
  • Loading branch information...
1 parent 7741431 commit af37599ed1b8b56ee7fb888a3f06aab8373d1dd2 @Sutto committed
Showing with 55 additions and 13 deletions.
  1. +6 −4 README.md
  2. +14 −7 lib/barista.rb
  3. +11 −0 lib/barista/compiler.rb
  4. +2 −2 lib/barista/version.rb
  5. +22 −0 lib/generators/barista_install/templates/initializer.rb
View
10 README.md
@@ -1,6 +1,8 @@
# Barista #
-Barista is a rails plugin that transparently compiles CoffeeScript to JavaScript, by running the `coffee` compiler with Node.js. When a `.coffee` file is changed and the page is refreshed, it delays sending the `.js` file until it's been regenerated from the newly modified CoffeeScript. This way, you can refresh immediately after saving the `.coffee` file, and not worry about an old `.js` file being sent to the browser (as often happens when using `coffee --watch`).
+Barista is a rails plugin that transparently compiles CoffeeScript to JavaScript. When a `.coffee` file is changed and the page is refreshed, it delays sending the `.js` file until it's been regenerated from the newly modified CoffeeScript. This way, you can refresh immediately after saving the `.coffee` file, and not worry about an old `.js` file being sent to the browser (as often happens when using `coffee --watch`).
+
+Barista supports using `therubyracer` when installed or, by default, the node.js version of CoffeeScript via the `coffee` executable.
Barista is very, very similar to [bistro\_car](http://github.com/jnicklas/bistro_car) (infact, credit where credit is due - it shares similar
code / is almost a fork).
@@ -29,9 +31,9 @@ Barista require rails 3+ (but patches for Rails 2 will be accepted.)
## Frameworks ##
-One of the other main features Barista adds (over bistro\_car) is frameworks similar
-to Compass. The idea being, you add coffeescripts at runtime from gems etc. To do this,
-in your gem just have a coffeescript directory and then in you gem add the following code:
+One of the other main features Barista adds (over other tools) is frameworks similar
+to Compass. The idea being, you add coffee scripts at runtime from gems etc. To do this,
+in your gem just have a `coffeescript` directory and then in you gem add the following code:
Barista::Framework.register 'name', 'full-path-to-directory' if defined?(Barista::Framework)
View
21 lib/barista.rb
@@ -136,14 +136,20 @@ def debug(message)
Rails.logger.debug "[Barista] #{message}" if defined?(Rails.logger) && Rails.logger
end
- # By default, only add it in dev / test
- def add_filter?
- defined?(Rails) && (Rails.env.test? || Rails.env.development?)
+ def verbose?
+ @verbose ||= (defined?(Rails) && (Rails.env.test? || Rails.env.development?))
end
-
- def add_preamble?
- defined?(Rails) && (Rails.env.test? || Rails.env.development?)
+
+ def verbose!
+ self.verbose = true
end
+
+ def verbose=(value)
+ @verbose = !!value
+ end
+
+ alias add_filter? verbose?
+ alias add_preamble? verbose?
def no_wrap?
defined?(@no_wrap) && @no_wrap
@@ -160,7 +166,8 @@ def no_wrap=(value)
end
alias bare= no_wrap=
- delegate :bin_path, :bin_path=, :js_path, :js_path=, :to => Compiler
+ delegate :bin_path, :bin_path=, :js_path, :js_path=, :compiler, :compiler=,
+ :compiler_klass, :compiler_klass=, :to => Compiler
end
View
11 lib/barista/compiler.rb
@@ -13,6 +13,17 @@ def self.compilers
[Compilers::Native, Compilers::Node]
end
+ def self.compiler=(value)
+ name = "Barista::Compilers::#{value.to_s.classify}".constantize
+ self.compiler_klass = name
+ rescue
+ self.compiler_klass = nil
+ end
+
+ def self.compiler
+ compiler_klass.name.underscore.gsub("barista/compilers/", '').to_sym
+ end
+
def self.compiler_klass
@compiler_klass ||= compilers.detect(&:available?)
end
View
4 lib/barista/version.rb
@@ -1,8 +1,8 @@
module Barista
module Version
MAJOR = 0
- MINOR = 5
- PATCH = 1
+ MINOR = 6
+ PATCH = 0
STRING = [MAJOR, MINOR, PATCH].join(".")
end
end
View
22 lib/generators/barista_install/templates/initializer.rb
@@ -7,6 +7,8 @@
# Change the output root, causing Barista to compile into public/coffeescripts
# c.output_root = Rails.root.join("public", "coffeescripts")
+ # Set the compiler
+
# Disable wrapping in a closure:
# c.no_wrap = true
# ... or ...
@@ -33,4 +35,24 @@
# c.on_compilation_error { |path, output| puts "Barista: Compilation of #{path} failed with:\n#{output}" }
# c.on_compilation_with_warning { |path, output| puts "Barista: Compilation of #{path} had a warning:\n#{output}" }
+ # Turn off preambles and exceptions on failure
+
+ # c.verbose = false
+
+ # Or, make sure it is always on
+ # c.verbose!
+
+ # Changing the compiler
+
+ # To use a customer compiler class:
+ # c.compiler_klass = MyAwesomeCompilerClass
+ # c.compiler = :null # Barista::Compilers::Null
+
+ # To switch between the built in compilers:
+ # c.compiler = :native
+ # or...
+ # c.compiler = :node
+
+ # The default compiler is auto detected.
+
end

0 comments on commit af37599

Please sign in to comment.
Something went wrong with that request. Please try again.