barista 1.0.0 → 1.1.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +10 -17
- data/README.md +132 -63
- data/barista.gemspec +8 -8
- data/lib/barista.rb +19 -14
- data/lib/barista/compiler.rb +16 -6
- data/lib/barista/framework.rb +2 -2
- data/lib/barista/integration.rb +4 -9
- data/lib/barista/integration/sinatra.rb +4 -4
- data/lib/barista/rake_task.rb +69 -0
- data/lib/barista/tasks/barista.rake +5 -10
- data/lib/barista/version.rb +2 -2
- data/lib/generators/barista/install/templates/initializer.rb +26 -19
- metadata +33 -29
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,38 +1,31 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
barista (0.7.0.pre)
|
5
|
-
coffee-script (~> 2.1.1)
|
6
|
-
|
7
1
|
GEM
|
8
2
|
remote: http://rubygems.org/
|
9
3
|
specs:
|
10
4
|
coffee-script (2.1.1)
|
11
5
|
coffee-script-source
|
12
|
-
coffee-script-source (0.
|
6
|
+
coffee-script-source (1.0.1)
|
13
7
|
diff-lcs (1.1.2)
|
14
8
|
git (1.2.5)
|
15
|
-
jeweler (1.5.
|
9
|
+
jeweler (1.5.2)
|
16
10
|
bundler (~> 1.0.0)
|
17
11
|
git (>= 1.2.5)
|
18
12
|
rake
|
19
13
|
rake (0.8.7)
|
20
14
|
rr (1.0.2)
|
21
|
-
rspec (2.
|
22
|
-
rspec-core (~> 2.
|
23
|
-
rspec-expectations (~> 2.
|
24
|
-
rspec-mocks (~> 2.
|
25
|
-
rspec-core (2.
|
26
|
-
rspec-expectations (2.
|
15
|
+
rspec (2.5.0)
|
16
|
+
rspec-core (~> 2.5.0)
|
17
|
+
rspec-expectations (~> 2.5.0)
|
18
|
+
rspec-mocks (~> 2.5.0)
|
19
|
+
rspec-core (2.5.0)
|
20
|
+
rspec-expectations (2.5.0)
|
27
21
|
diff-lcs (~> 1.1.2)
|
28
|
-
rspec-mocks (2.
|
22
|
+
rspec-mocks (2.5.0)
|
29
23
|
|
30
24
|
PLATFORMS
|
31
25
|
ruby
|
32
26
|
|
33
27
|
DEPENDENCIES
|
34
|
-
|
35
|
-
coffee-script (~> 2.1.1)
|
28
|
+
coffee-script (~> 2.1)
|
36
29
|
jeweler (~> 1.0)
|
37
30
|
rr (~> 1.0)
|
38
31
|
rspec (~> 2.1)
|
data/README.md
CHANGED
@@ -1,34 +1,95 @@
|
|
1
|
-
# Barista
|
1
|
+
# Barista
|
2
2
|
|
3
3
|
Barista is a set of tools to make using [CoffeeScript](http://jashkenas.github.com/coffee-script/) in Rails 3, Rails 2 and Rack applications
|
4
|
-
easier. You can think of it as similar to [Compass]() but instead of
|
4
|
+
easier. You can think of it as similar to [Compass](http://compass-style.org/), but for CoffeeScript instead of [Sass](http://sass-lang.com/).
|
5
5
|
|
6
|
-
|
6
|
+
As an added bonus, Barista also gives:
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
* Automatic support for a `:coffeescript` filter in [Haml](http://haml-lang.com/) (when Haml is loaded before Barista) — automatically converting inline CoffeeScript to JavaScript for you.
|
9
|
+
* Where possible, support for `coffeescript_include_tag` and `coffeescript_tag`.
|
10
|
+
* When possible, instead of pre-compiling in development and test modes, Barista will embed CoffeeScript in the page for you.
|
11
|
+
* Support for Heroku via [therubyracer-heroku](https://github.com/aler/therubyracer-heroku) and either pre-compiled JS or, optionally, a lightweight Rack app that generates on request.
|
11
12
|
|
12
|
-
|
13
|
+
## Getting Started
|
13
14
|
|
15
|
+
Out of the box, Barista has semi-automatic support for Rails 3.0, Rails 2 (currently untested) and Sinatra. With a minimal amount of effort, you can also make it work in any Rack-based framework.
|
14
16
|
|
15
|
-
|
17
|
+
### Rails 3
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
Adding Barista to your Rails 3 application should as simple as adding two gems to your `Gemfile`, and running two commands. To get started, open up your `Gemfile` and add the following:
|
20
|
+
|
21
|
+
gem "json" # Only needed if on Ruby 1.8 / a platform that ships without JSON
|
22
|
+
gem "barista"
|
23
|
+
|
24
|
+
Next, you'll need to run the the following:
|
25
|
+
|
26
|
+
bundle install
|
27
|
+
rails g barista:install
|
28
|
+
|
29
|
+
This will install the gem into your application and will generate a file in `config/initializers/barista_config.rb` that contains a set of options to configure Barista options.
|
30
|
+
|
31
|
+
Place your CoffeeScripts in `app/coffeescripts` and Barista will automatically compile them on change into `public/javascripts`.
|
32
|
+
|
33
|
+
### Rails 2
|
34
|
+
|
35
|
+
Much like on Rails 3, Barista supports deep integration into Rails 2. The only thing missing (that is currently supported in the Rails 3 version) is built in support for generating a config file. If you're using bundler in your application, all you need to do is add:
|
36
|
+
|
37
|
+
gem "json" # Only needed if on Ruby 1.8 / a platform that ships without JSON
|
38
|
+
gem "barista"
|
39
|
+
|
40
|
+
To your `Gemfile`. If you're not using bundler, doing `gem install json barista` and requiring barista both in your application should be enough to get you started.
|
41
|
+
|
42
|
+
If you wish to change the barista configuration, take a look at the [Rails 3 initializer](https://github.com/Sutto/barista/blob/master/lib/generators/barista/install/templates/initializer.rb) and modify it to suite your application as needed.
|
43
|
+
|
44
|
+
### Sinatra
|
45
|
+
|
46
|
+
Adding Barista to a Sinatra application is a relatively straight forward affair. Like in Rails 2 and Rails 3, you first need to add and require the barista gem and (optionally, the json gem). Unlike Rails 2 and 3 (which set it up automatically), you must also register the extension in your application. So, in the scope of your app (either the top level scope or the `Sinatra::Application` subclass you're using), you then need to simple add:
|
47
|
+
|
48
|
+
register Barista::Integration::Sinatra
|
49
|
+
|
50
|
+
Which will automatically set up the Barista environment and other similar details (e.g. the automatic compilation filter). Since you don't have initializers like you do in Rails, you
|
51
|
+
can then simply run your `Barista.configure` call and block anywhere before your application starts serving requests.
|
52
|
+
|
53
|
+
### Other Rack-based Frameworks
|
54
|
+
|
55
|
+
Lastly, even though it is built out of the box to support Rails and Sinatra, Barista can also be used with any Rack-based framework. For proper integration, several things must be done. Namely, wherever you declare your middleware (e.g. in a `config.ru` file), you should register the two pieces of middleware barista uses. `Barista::Filter` should only be registered when
|
56
|
+
Barista performs compilation (e.g. in development mode) and `Barista::Server::Proxy` should be registered if you want it to support automatic serving of a `coffeescript.js` file and / or
|
57
|
+
on the fly (versus pre-request compilation) of CoffeeScripts.
|
22
58
|
|
59
|
+
For example, your `config.ru` may look like:
|
60
|
+
|
61
|
+
# Setup goes here...
|
62
|
+
use Barista::Filter if Barista.add_filter?
|
63
|
+
use Barista::Server::Proxy
|
64
|
+
run MyRackApplication
|
65
|
+
|
66
|
+
Next, you need to configure barista anywhere before your the above code is run. e.g by adding the following immediatly preceeding it:
|
67
|
+
|
68
|
+
# Barista (for CoffeeScript Support)
|
69
|
+
Barista.app_root = root
|
70
|
+
Barista.root = File.join(root, 'coffeescripts')
|
71
|
+
Barista.setup_defaults
|
72
|
+
barista_config = root + '/barista_config.rb'
|
73
|
+
require barista_config if File.exist?(barista_config)
|
74
|
+
|
75
|
+
Hence, if you'e using, for example, [serve](https://github.com/jlong/serve) users should have a `config.ru` that looks similar to [this example](https://github.com/YouthTree/site-design/blob/master/config.ru).
|
76
|
+
|
77
|
+
### A Quick Note on the JSON Gem
|
78
|
+
|
79
|
+
Barista indirectly requires the json gem via the coffee-script gem, but it isn't listed as a dependency for very
|
80
|
+
good reasons. If you encounter errors relating to `require 'json'`, Then you'll need to add either `gem 'json'`
|
81
|
+
or `gem 'json_pure'` to your Gemfile.
|
82
|
+
|
83
|
+
If you're already running Ruby 1.9, this will be unnecessary as JSON is shipped as part of the standard library.
|
23
84
|
|
24
85
|
## General Information
|
25
86
|
|
26
|
-
Barista transparently compiles CoffeeScript to JavaScript
|
87
|
+
Barista transparently compiles CoffeeScript to JavaScript. When a `.coffee` file is changed and the page is refreshed, Barista first regenerates all `.js` files whose `.coffee` sources have been recently changed. 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`).
|
27
88
|
|
28
|
-
Barista supports using `therubyracer` when installed or, by default, using either the `node` executable or `jsc` (on
|
29
|
-
no need for you to install the coffee
|
89
|
+
Barista supports using `therubyracer` when installed or, by default, using either the `node` executable or `jsc` (on OS X) to compile your scripts. There is
|
90
|
+
no need for you to install the coffee-script executable in Node as having Node itself, or any of the alternatives available, is enough.
|
30
91
|
|
31
|
-
When you want to deploy, you can simple run `rake barista:brew` to force the compilation of all JavaScripts
|
92
|
+
When you want to deploy, you can simple run `rake barista:brew` to force the compilation of all JavaScripts for the current application.
|
32
93
|
|
33
94
|
## In Practice
|
34
95
|
|
@@ -36,75 +97,82 @@ Barista not only supports compiling all JavaScripts on demand (via `rake barista
|
|
36
97
|
also ships with a simple Rack server app that will compile on demand for platforms such as Heroku, meaning you don't need write access
|
37
98
|
(although it is helpful).
|
38
99
|
|
39
|
-
If you're using Jammit, the precompilation phase (e.g. `rake barista:brew` before running
|
100
|
+
If you're using [Jammit](http://documentcloud.github.com/jammit/), the precompilation phase (e.g. `rake barista:brew` before running Jammit) will make it possible for your application
|
40
101
|
to automatically bundle not only normal JavaScripts but also your CoffeeScripts.
|
41
102
|
|
42
|
-
To add to your project, simply add
|
103
|
+
To add Barista to your project, simply add `gem 'barista', '~> 1.0'` to your Gemfile and run `bundle install`.
|
43
104
|
|
44
|
-
|
45
|
-
|
46
|
-
To your Gemfile and run bundle install.
|
47
|
-
|
48
|
-
Please note that for Jammit compatibility, in test and dev mode (by default) it will
|
105
|
+
Please note that for Jammit compatibility, in test and development mode (by default) it will
|
49
106
|
automatically compile all CoffeeScripts that have changed before rendering the page.
|
50
107
|
|
51
|
-
Barista works out of the box with Rails 3 (and theoretically, Rails 2)
|
108
|
+
Barista works out of the box with Rails 3 (and theoretically, Rails 2) — with support for Rack if
|
52
109
|
you're willing to set it up manually. More docs on how to set it up for other platforms
|
53
110
|
will be posted in the near future.
|
54
111
|
|
55
|
-
##
|
112
|
+
## Sinatra
|
113
|
+
|
114
|
+
To use Barista with [Sinatra](http://www.sinatrarb.com/), you'll need to first require the Barista gem in your application
|
115
|
+
and then add the following to your application scope (e.g. if you're using a custom class, there):
|
116
|
+
|
117
|
+
register Barista::Integration::Sinatra
|
118
|
+
|
119
|
+
This will automatically setup the filter as needed, setup a server proxy for the `coffee-script.js`
|
120
|
+
file and setup the defaults based on your applications environment
|
56
121
|
|
57
|
-
|
122
|
+
## Configuration
|
123
|
+
|
124
|
+
Please note that Barista lets you configure several options. To do this,
|
58
125
|
it's as simple as setting up an initializer with:
|
59
126
|
|
60
127
|
rails generate barista:install
|
61
|
-
|
128
|
+
|
62
129
|
Then editing `config/initializers/barista_config.rb`. The options available are:
|
63
130
|
|
64
131
|
### Boolean Options
|
65
132
|
|
66
|
-
All of these come in the form of `#option?` (to check
|
133
|
+
All of these come in the form of `#option?` (to check its status), `#option=(value)` (to set it)
|
67
134
|
and `#option!` (to set the value to true):
|
68
135
|
|
69
|
-
* `verbose`
|
70
|
-
* `bare`
|
71
|
-
* `add_filter`
|
72
|
-
* `add_preamble`
|
73
|
-
* `exception_on_error`
|
74
|
-
* `embedded_interpreter`
|
136
|
+
* `verbose` – Output debugging error messages. (Defaults to true in test / dev)
|
137
|
+
* `bare` – Don't wrap the compiled JS in a Closure.
|
138
|
+
* `add_filter` – Automatically add an around filter for processing changes. (Defaults to true in test / dev)
|
139
|
+
* `add_preamble` – Add a time + path preamble to compiled JS. (Defaults to true in test / dev)
|
140
|
+
* `exception_on_error` – Raise an exception on compilation errors (defaults to true)
|
141
|
+
* `embedded_interpreter` – Embeds coffeescript + link to coffee file instead of compiling for include tags and haml filters. (Defaults to true in test / dev)
|
142
|
+
* `auto_compile` – Automatically compile CoffeeScript to JS when CoffeeScript is newer than the generated JS file. After you turn it off, your server will use the generated JS file directly and won't depend on any CoffeeScript compilers. (Defaults is true)
|
75
143
|
|
76
144
|
### Path options
|
77
145
|
|
78
|
-
* `root`
|
79
|
-
* `output_root`
|
80
|
-
* `change_output_prefix!`
|
81
|
-
* `verbose`
|
82
|
-
* `js_path`
|
83
|
-
* `env`
|
84
|
-
* `app_root`
|
85
|
-
* `bin_path`
|
146
|
+
* `root` – The folder path to read CoffeeScripts from. (Defaults to `app/coffeescripts`.)
|
147
|
+
* `output_root` – The folder to write compiled JS files to. (Defaults to `public/javascripts`.)
|
148
|
+
* `change_output_prefix!` – Method to change the output prefix for a framework.
|
149
|
+
* `verbose` – Whether or not Barista will add a preamble to files.
|
150
|
+
* `js_path` – Path to the pure-JavaScript compiler.
|
151
|
+
* `env` – The application environment. (Defaults to `Rails.env`.)
|
152
|
+
* `app_root` – The application's root path.
|
153
|
+
* `bin_path` – The path to the `node` executable if non-standard and not using `therubyracer`.
|
86
154
|
* All of the hook methods mentioned below.
|
87
155
|
|
88
|
-
## Frameworks
|
156
|
+
## Frameworks
|
89
157
|
|
90
158
|
One of the other main features Barista adds (over other tools) is frameworks similar
|
91
|
-
to Compass. The idea being, you add
|
92
|
-
in your gem just have a `coffeescript` directory and then in
|
159
|
+
to Compass. The idea being, you add CoffeeScripts at runtime from gems etc. To do this,
|
160
|
+
in your gem just have a `coffeescript` directory and then in your gem add the following code:
|
93
161
|
|
94
162
|
Barista::Framework.register 'name', 'full-path-to-directory' if defined?(Barista::Framework)
|
95
|
-
|
163
|
+
|
96
164
|
For an example of this in practice, check out [bhm-google-maps](http://github.com/YouthTree/bhm-google-maps)
|
97
165
|
or, the currently-in-development, [shuriken](http://github.com/Sutto/shuriken). The biggest advantage of this
|
98
|
-
is you can then manage
|
166
|
+
is you can then manage JS dependencies using existing tools like Bundler.
|
99
167
|
|
100
168
|
In your `Barista.configure` block, you can also configure on a per-application basis the output directory
|
101
|
-
for individual frameworks (e.g. put shuriken into vendor/shuriken
|
169
|
+
for individual frameworks (e.g. put shuriken into `vendor/shuriken`, bhm-google-maps into `vendor/bhm-google-maps`):
|
102
170
|
|
103
171
|
Barista.configure do |c|
|
104
172
|
c.change_output_prefix! 'shuriken', 'vendor/shuriken'
|
105
173
|
c.change_output_prefix! 'bhm-google-maps', 'vendor/bhm-google-maps'
|
106
174
|
end
|
107
|
-
|
175
|
+
|
108
176
|
Alternatively, to prefix all, you can use `Barista.each_framework` (if you pass true, it includes the 'default' framework
|
109
177
|
which is your application root).
|
110
178
|
|
@@ -113,17 +181,17 @@ which is your application root).
|
|
113
181
|
c.change_output_prefix! framework.name, "vendor/#{framework.name}"
|
114
182
|
end
|
115
183
|
end
|
116
|
-
|
117
|
-
## Hooks ##
|
118
184
|
|
119
|
-
|
185
|
+
## Hooks
|
186
|
+
|
187
|
+
Barista lets you hook into the compilation at several stages, namely:
|
120
188
|
|
121
189
|
* before compilation
|
122
190
|
* after compilation
|
123
191
|
* after compilation fails
|
124
192
|
* after compilation complete
|
125
193
|
|
126
|
-
To hook into these hooks, you can
|
194
|
+
To hook into these hooks, you can do the following:
|
127
195
|
|
128
196
|
* `Barista.before_compilation { |path| puts "Barista: Compiling #{path}" }`
|
129
197
|
* `Barista.on_compilation { |path| puts "Barista: Successfully compiled #{path}" }`
|
@@ -135,20 +203,21 @@ These allow you to do things such as notify on compilation, automatically
|
|
135
203
|
perform compression post compilation and a variety of other cool things.
|
136
204
|
|
137
205
|
An excellent example of these hooks in use is [barista\_growl](http://github.com/TrevorBurnham/barista_growl),
|
138
|
-
by Trevor Burnham
|
206
|
+
by Trevor Burnham — a gem perfect for development purposes that automatically shows Growl messages
|
139
207
|
on compilation.
|
140
208
|
|
141
209
|
# Contributors / Credits
|
142
210
|
|
143
211
|
The following people have all contributed to Barista:
|
144
212
|
|
145
|
-
* [Xavier Shay](https://github.com/xaviershay)
|
146
|
-
* [einarmagnus](https://github.com/einarmagnus)
|
147
|
-
* [Matt Dean](https://github.com/trabian)
|
148
|
-
* [Trevor Burnham](https://github.com/TrevorBurnham)
|
149
|
-
* [Sean McCullough](https://github.com/mcculloughsean)
|
150
|
-
* [Ben Atkin](https://github.com/benatkin)
|
151
|
-
* [Ben Hoskings](https://github.com/benhoskings) Misc fixes, added preamble support.
|
213
|
+
* [Xavier Shay](https://github.com/xaviershay) – Added preamble text to generated text in verbose mode.
|
214
|
+
* [einarmagnus](https://github.com/einarmagnus) – Fixed jruby support.
|
215
|
+
* [Matt Dean](https://github.com/trabian) – Added `before_full_compilation` and `on_compilation_complete` hooks.
|
216
|
+
* [Trevor Burnham](https://github.com/TrevorBurnham) – Misc. documentation tweaks and hooks idea.
|
217
|
+
* [Sean McCullough](https://github.com/mcculloughsean) – Initial switch to support bare (vs. no\_wrap)
|
218
|
+
* [Ben Atkin](https://github.com/benatkin) – Docs work.
|
219
|
+
* [Ben Hoskings](https://github.com/benhoskings) – Misc. fixes, added preamble support.
|
220
|
+
* [Kim Joar Bekkelund](https://github.com/kjbekkelund) – Docs work.
|
152
221
|
|
153
222
|
Barista was originally heavily inspired by [Bistro Car](https://github.com/jnicklas/bistro_car), but has taken a few fundamentally
|
154
223
|
different approach in a few areas.
|
@@ -158,7 +227,7 @@ Barista builds upon the awesome [coffee-script](https://github.com/josh/ruby-cof
|
|
158
227
|
It's all possible thanks to [CoffeeScript](https://github.com/jashkenas/coffee-script) by Jeremy Ashkenas.
|
159
228
|
|
160
229
|
## Note on Patches/Pull Requests ##
|
161
|
-
|
230
|
+
|
162
231
|
1. Fork the project.
|
163
232
|
2. Make your feature addition or bug fix.
|
164
233
|
3. Add tests for it. This is important so I don't break it in a future version unintentionally.
|
data/barista.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{barista}
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.1.0.pre1"
|
9
9
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Darcy Laycock"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-04-18}
|
13
13
|
s.description = %q{Barista provides simple, integrated support for CoffeeScript in Rack and Rails applications.
|
14
14
|
|
15
15
|
Much like Compass does for Sass, It also provides Frameworks (bundleable code which can be shared via Gems).
|
@@ -45,6 +45,7 @@ For more details, please see the the README file bundled with it.}
|
|
45
45
|
"lib/barista/integration/rails2.rb",
|
46
46
|
"lib/barista/integration/rails3.rb",
|
47
47
|
"lib/barista/integration/sinatra.rb",
|
48
|
+
"lib/barista/rake_task.rb",
|
48
49
|
"lib/barista/server.rb",
|
49
50
|
"lib/barista/tasks/barista.rake",
|
50
51
|
"lib/barista/version.rb",
|
@@ -57,7 +58,7 @@ For more details, please see the the README file bundled with it.}
|
|
57
58
|
]
|
58
59
|
s.homepage = %q{http://github.com/Sutto/barista}
|
59
60
|
s.require_paths = ["lib"]
|
60
|
-
s.rubygems_version = %q{1.
|
61
|
+
s.rubygems_version = %q{1.6.2}
|
61
62
|
s.summary = %q{Simple, transparent coffeescript integration for Rails and Rack applications.}
|
62
63
|
s.test_files = [
|
63
64
|
"spec/barista_spec.rb",
|
@@ -65,22 +66,21 @@ For more details, please see the the README file bundled with it.}
|
|
65
66
|
]
|
66
67
|
|
67
68
|
if s.respond_to? :specification_version then
|
68
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
69
69
|
s.specification_version = 3
|
70
70
|
|
71
71
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
72
|
-
s.add_runtime_dependency(%q<coffee-script>, ["~> 2.1
|
72
|
+
s.add_runtime_dependency(%q<coffee-script>, ["~> 2.1"])
|
73
73
|
s.add_development_dependency(%q<jeweler>, ["~> 1.0"])
|
74
74
|
s.add_development_dependency(%q<rspec>, ["~> 2.1"])
|
75
75
|
s.add_development_dependency(%q<rr>, ["~> 1.0"])
|
76
76
|
else
|
77
|
-
s.add_dependency(%q<coffee-script>, ["~> 2.1
|
77
|
+
s.add_dependency(%q<coffee-script>, ["~> 2.1"])
|
78
78
|
s.add_dependency(%q<jeweler>, ["~> 1.0"])
|
79
79
|
s.add_dependency(%q<rspec>, ["~> 2.1"])
|
80
80
|
s.add_dependency(%q<rr>, ["~> 1.0"])
|
81
81
|
end
|
82
82
|
else
|
83
|
-
s.add_dependency(%q<coffee-script>, ["~> 2.1
|
83
|
+
s.add_dependency(%q<coffee-script>, ["~> 2.1"])
|
84
84
|
s.add_dependency(%q<jeweler>, ["~> 1.0"])
|
85
85
|
s.add_dependency(%q<rspec>, ["~> 2.1"])
|
86
86
|
s.add_dependency(%q<rr>, ["~> 1.0"])
|
data/lib/barista.rb
CHANGED
@@ -33,15 +33,15 @@ module Barista
|
|
33
33
|
def hooks
|
34
34
|
@hooks ||= Hooks.new
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def on_hook(name, *args, &blk)
|
38
38
|
hooks.on(name, *args, &blk)
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def invoke_hook(name, *args)
|
42
42
|
hooks.invoke(name, *args)
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
has_hook_method :on_compilation_error => :compilation_failed,
|
46
46
|
:on_compilation => :compiled,
|
47
47
|
:on_compilation_complete => :all_compiled,
|
@@ -51,15 +51,15 @@ module Barista
|
|
51
51
|
|
52
52
|
|
53
53
|
# Configuration - Tweak how you use Barista.
|
54
|
-
|
55
|
-
has_boolean_options :verbose, :bare, :add_filter, :add_preamble, :exception_on_error, :embedded_interpreter
|
54
|
+
|
55
|
+
has_boolean_options :verbose, :bare, :add_filter, :add_preamble, :exception_on_error, :embedded_interpreter, :auto_compile
|
56
56
|
has_delegate_methods Compiler, :bin_path, :bin_path=, :js_path, :js_path=
|
57
57
|
has_deprecated_methods :compiler, :compiler=, :compiler_klass, :compiler_klass=
|
58
|
-
|
58
|
+
|
59
59
|
def configure
|
60
60
|
yield self if block_given?
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
def env
|
64
64
|
@env ||= default_for_env
|
65
65
|
end
|
@@ -68,7 +68,7 @@ module Barista
|
|
68
68
|
@env = value.to_s.strip
|
69
69
|
@env = nil if @env == ''
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
def logger
|
73
73
|
@logger ||= default_for_logger
|
74
74
|
end
|
@@ -160,11 +160,16 @@ module Barista
|
|
160
160
|
def default_for_exception_on_error
|
161
161
|
true
|
162
162
|
end
|
163
|
-
|
163
|
+
|
164
164
|
def default_for_embedded_interpreter
|
165
|
-
|
165
|
+
false
|
166
|
+
end
|
167
|
+
|
168
|
+
def default_for_auto_compile
|
169
|
+
true
|
166
170
|
end
|
167
171
|
|
172
|
+
|
168
173
|
# Actual tasks on the barista module.
|
169
174
|
|
170
175
|
def compile_file!(file, force = false, silence_error = false)
|
@@ -183,7 +188,7 @@ module Barista
|
|
183
188
|
|
184
189
|
def change_output_prefix!(framework, prefix = nil)
|
185
190
|
framework = Barista::Framework[framework] unless framework.is_a?(Barista::Framework)
|
186
|
-
framework.output_prefix = prefix if framework
|
191
|
+
framework.output_prefix = prefix if framework
|
187
192
|
end
|
188
193
|
|
189
194
|
def each_framework(include_default = false, &blk)
|
@@ -195,16 +200,16 @@ module Barista
|
|
195
200
|
end
|
196
201
|
|
197
202
|
def debug(message)
|
198
|
-
logger.debug "[Barista] #{message}"
|
203
|
+
logger.debug "[Barista] #{message}" if logger
|
199
204
|
end
|
200
|
-
|
205
|
+
|
201
206
|
def setup_defaults
|
202
207
|
Barista::HamlFilter.setup
|
203
208
|
Barista::Compiler.setup_default_error_logger
|
204
209
|
end
|
205
210
|
|
206
211
|
end
|
207
|
-
|
212
|
+
|
208
213
|
# Setup integration by default.
|
209
214
|
Integration.setup
|
210
215
|
|
data/lib/barista/compiler.rb
CHANGED
@@ -23,7 +23,7 @@ module Barista
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def available?
|
26
|
-
CoffeeScript.engine
|
26
|
+
CoffeeScript.engine && CoffeeScript.engine.supported?
|
27
27
|
end
|
28
28
|
|
29
29
|
def check_availability!(silence = false)
|
@@ -39,16 +39,26 @@ module Barista
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def autocompile_file(file, force = false, silence_error = false)
|
42
|
-
# Ensure we have a coffeescript compiler available.
|
43
|
-
if !check_availability!(silence_error)
|
44
|
-
Barista.debug "The coffeescript compiler at '#{Compiler.bin_path}' is currently unavailable."
|
45
|
-
return nil
|
46
|
-
end
|
47
42
|
# Expand the path from the framework.
|
48
43
|
origin_path, framework = Framework.full_path_for(file)
|
49
44
|
return if origin_path.nil?
|
50
45
|
destination_path = framework.output_path_for(file)
|
46
|
+
|
47
|
+
# read file directly if auto_compile is disabled
|
48
|
+
if !Barista.auto_compile?
|
49
|
+
if File.exist?(destination_path)
|
50
|
+
return File.read(destination_path)
|
51
|
+
else
|
52
|
+
return nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
51
56
|
return File.read(destination_path) unless dirty?(origin_path, destination_path) || force
|
57
|
+
# Ensure we have a coffeescript compiler available.
|
58
|
+
if !check_availability!(silence_error)
|
59
|
+
Barista.debug "The coffeescript compiler at '#{Compiler.bin_path}' is currently unavailable."
|
60
|
+
return nil
|
61
|
+
end
|
52
62
|
Barista.debug "Compiling #{file} from framework '#{framework.name}'"
|
53
63
|
compiler = new(origin_path, :silence_error => silence_error, :output_path => destination_path)
|
54
64
|
content = compiler.to_js
|
data/lib/barista/framework.rb
CHANGED
@@ -20,7 +20,7 @@ module Barista
|
|
20
20
|
collection + fw.exposed_coffeescripts
|
21
21
|
end.uniq.sort_by { |f| f.length }
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def self.coffeescript_glob_paths
|
25
25
|
all(true).map { |fw| fw.coffeescript_glob_path }
|
26
26
|
end
|
@@ -65,7 +65,7 @@ module Barista
|
|
65
65
|
def coffeescripts
|
66
66
|
Dir[coffeescript_glob_path]
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
def coffeescript_glob_path
|
70
70
|
@coffeescript_glob_path ||= File.join(@framework_root, "**", "*.coffee")
|
71
71
|
end
|
data/lib/barista/integration.rb
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
module Barista
|
2
2
|
module Integration
|
3
|
-
|
3
|
+
|
4
4
|
autoload :Rails2, 'barista/integration/rails2'
|
5
5
|
autoload :Rails3, 'barista/integration/rails3'
|
6
6
|
autoload :Sinatra, 'barista/integration/sinatra'
|
7
|
-
|
7
|
+
|
8
8
|
def self.setup
|
9
9
|
setup_rails if defined?(Rails)
|
10
|
-
setup_sinatra if defined?(::Sinatra)
|
11
10
|
end
|
12
|
-
|
11
|
+
|
13
12
|
def self.setup_rails
|
14
13
|
case Rails::VERSION::MAJOR
|
15
14
|
when 3
|
@@ -19,10 +18,6 @@ module Barista
|
|
19
18
|
Rails2.setup
|
20
19
|
end
|
21
20
|
end
|
22
|
-
|
23
|
-
def self.setup_sinatra
|
24
|
-
::Sinatra::Base.register(Sinatra)
|
25
|
-
end
|
26
|
-
|
21
|
+
|
27
22
|
end
|
28
23
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Barista
|
2
2
|
module Integration
|
3
3
|
module Sinatra
|
4
|
-
|
4
|
+
|
5
5
|
def self.registered(app)
|
6
6
|
app.configure do |inner_app|
|
7
7
|
setup_defaults inner_app
|
@@ -9,15 +9,15 @@ module Barista
|
|
9
9
|
inner_app.use Barista::Server::Proxy
|
10
10
|
Barista.setup_defaults
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def self.setup_defaults(app)
|
16
16
|
Barista.configure do |c|
|
17
17
|
c.env = app.environment.to_s
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'barista' unless defined?(Barista)
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/tasklib'
|
4
|
+
|
5
|
+
module Barista
|
6
|
+
class RakeTask < ::Rake::TaskLib
|
7
|
+
|
8
|
+
attr_writer :namespace, :task_name
|
9
|
+
attr_writer :environment, :input_directory, :output_directory, :rails
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
yield self if block_given?
|
13
|
+
@namespace ||= :barista
|
14
|
+
@task_name ||= :brew
|
15
|
+
@task_name = @task_name.to_sym
|
16
|
+
@rails = defined?(Rails) if @rails.nil?
|
17
|
+
|
18
|
+
task_declaration = (@rails ? {@task_name => :environment} : @task_name)
|
19
|
+
|
20
|
+
namespace @namespace do
|
21
|
+
desc "Compiles all CoffeeScript sources to JavaScript"
|
22
|
+
task task_declaration do
|
23
|
+
setup_barista
|
24
|
+
check_availability
|
25
|
+
puts "Compiling all CoffeeScripts to their JavaScript equivalent."
|
26
|
+
Barista.compile_all! true, false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Proxy methods for rake tasks
|
32
|
+
|
33
|
+
def respond_to?(method, include_private = false)
|
34
|
+
super || Barista.respond_to?(method, include_private)
|
35
|
+
end
|
36
|
+
|
37
|
+
def method_missing(method, *args, &blk)
|
38
|
+
if Barista.respond_to?(method)
|
39
|
+
Barista.send method, *args, &blk
|
40
|
+
else
|
41
|
+
super
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def setup_barista
|
48
|
+
Barista.env = @environment if @environment
|
49
|
+
if @input_directory
|
50
|
+
Barista.root = File.expand_path(@input_directory, Dir.pwd)
|
51
|
+
end
|
52
|
+
if @output_directory
|
53
|
+
Barista.output_root = File.expand_path(@output_directory, Dir.pwd)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def check_availability
|
58
|
+
if !Barista::Compiler.available?
|
59
|
+
if Barista::Compiler.bin_path.nil?
|
60
|
+
$stderr.puts "CoffeeScript doesn't appear to be installed on this system and you're not using an embedded compiler."
|
61
|
+
else
|
62
|
+
$stderr.puts "'#{Barista::Compiler.bin_path}' was unavailable."
|
63
|
+
end
|
64
|
+
exit 1
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
@@ -1,12 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
desc "Compiles coffeescripts from app/coffeescripts into public/javascripts"
|
4
|
-
task :brew => :environment do
|
5
|
-
if !Barista::Compiler.available?
|
6
|
-
$stderr.puts "'#{Barista::Compiler.bin_path}' was unavailable."
|
7
|
-
exit 1
|
8
|
-
end
|
9
|
-
Barista.compile_all! true, false
|
10
|
-
end
|
1
|
+
require 'barista/rake_task'
|
11
2
|
|
3
|
+
Barista::RakeTask.new do |t|
|
4
|
+
t.namespace = :barista
|
5
|
+
t.task_name = :brew
|
6
|
+
t.rails = true
|
12
7
|
end
|
data/lib/barista/version.rb
CHANGED
@@ -1,49 +1,56 @@
|
|
1
1
|
# Configure barista.
|
2
2
|
Barista.configure do |c|
|
3
|
-
|
3
|
+
|
4
4
|
# Change the root to use app/scripts
|
5
5
|
# c.root = Rails.root.join("app", "scripts")
|
6
|
-
|
6
|
+
|
7
7
|
# Change the output root, causing Barista to compile into public/coffeescripts
|
8
8
|
# c.output_root = Rails.root.join("public", "coffeescripts")
|
9
|
-
|
9
|
+
#
|
10
|
+
# Disable auto compile, use generated file directly:
|
11
|
+
# c.auto_compile = false
|
12
|
+
|
10
13
|
# Set the compiler
|
11
|
-
|
14
|
+
|
12
15
|
# Disable wrapping in a closure:
|
13
16
|
# c.no_wrap = true
|
14
17
|
# ... or ...
|
15
18
|
# c.no_wrap!
|
16
|
-
|
19
|
+
|
17
20
|
# Change the output root for a framework:
|
18
|
-
|
21
|
+
|
19
22
|
# c.change_output_prefix! 'framework-name', 'output-prefix'
|
20
|
-
|
23
|
+
|
21
24
|
# or for all frameworks...
|
22
|
-
|
25
|
+
|
23
26
|
# c.each_framework do |framework|
|
24
27
|
# c.change_output_prefix! framework.name, "vendor/#{framework.name}"
|
25
28
|
# end
|
26
|
-
|
29
|
+
|
27
30
|
# or, prefix the path for the app files:
|
28
|
-
|
29
|
-
# c.change_output_prefix! :default, 'my-app-name'
|
30
|
-
|
31
|
+
|
32
|
+
# c.change_output_prefix! :default, 'my-app-name'
|
33
|
+
|
31
34
|
# or, hook into the compilation:
|
32
|
-
|
35
|
+
|
33
36
|
# c.before_compilation { |path| puts "Barista: Compiling #{path}" }
|
34
37
|
# c.on_compilation { |path| puts "Barista: Successfully compiled #{path}" }
|
35
38
|
# c.on_compilation_error { |path, output| puts "Barista: Compilation of #{path} failed with:\n#{output}" }
|
36
39
|
# c.on_compilation_with_warning { |path, output| puts "Barista: Compilation of #{path} had a warning:\n#{output}" }
|
37
|
-
|
38
|
-
# Turn off preambles and exceptions on failure
|
39
|
-
|
40
|
+
|
41
|
+
# Turn off preambles and exceptions on failure:
|
42
|
+
|
40
43
|
# c.verbose = false
|
41
|
-
|
44
|
+
|
42
45
|
# Or, make sure it is always on
|
43
46
|
# c.verbose!
|
44
|
-
|
47
|
+
|
45
48
|
# If you want to use a custom JS file, you can as well
|
46
49
|
# e.g. vendoring CoffeeScript in your application:
|
47
50
|
# c.js_path = Rails.root.join('public', 'javascripts', 'coffee-script.js')
|
48
|
-
|
51
|
+
|
52
|
+
# Make helpers and the HAML filter output coffee-script instead of the compiled JS.
|
53
|
+
# Used in combination with the coffeescript_interpreter_js helper in Rails.
|
54
|
+
# c.embedded_interpreter = true
|
55
|
+
|
49
56
|
end
|
metadata
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barista
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 1923831963
|
5
|
+
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
-
|
10
|
-
|
10
|
+
- pre
|
11
|
+
- 1
|
12
|
+
version: 1.1.0.pre1
|
11
13
|
platform: ruby
|
12
14
|
authors:
|
13
15
|
- Darcy Laycock
|
@@ -15,30 +17,27 @@ autorequire:
|
|
15
17
|
bindir: bin
|
16
18
|
cert_chain: []
|
17
19
|
|
18
|
-
date: 2011-
|
20
|
+
date: 2011-04-18 00:00:00 +08:00
|
19
21
|
default_executable:
|
20
22
|
dependencies:
|
21
23
|
- !ruby/object:Gem::Dependency
|
22
|
-
prerelease: false
|
23
24
|
type: :runtime
|
24
|
-
|
25
|
-
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
26
|
none: false
|
27
27
|
requirements:
|
28
28
|
- - ~>
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
hash:
|
30
|
+
hash: 1
|
31
31
|
segments:
|
32
32
|
- 2
|
33
33
|
- 1
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
- !ruby/object:Gem::Dependency
|
34
|
+
version: "2.1"
|
35
|
+
version_requirements: *id001
|
36
|
+
name: coffee-script
|
38
37
|
prerelease: false
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
39
|
type: :development
|
40
|
-
|
41
|
-
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
41
|
none: false
|
43
42
|
requirements:
|
44
43
|
- - ~>
|
@@ -48,12 +47,12 @@ dependencies:
|
|
48
47
|
- 1
|
49
48
|
- 0
|
50
49
|
version: "1.0"
|
51
|
-
|
52
|
-
|
50
|
+
version_requirements: *id002
|
51
|
+
name: jeweler
|
53
52
|
prerelease: false
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
54
|
type: :development
|
55
|
-
|
56
|
-
version_requirements: &id003 !ruby/object:Gem::Requirement
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
56
|
none: false
|
58
57
|
requirements:
|
59
58
|
- - ~>
|
@@ -63,12 +62,12 @@ dependencies:
|
|
63
62
|
- 2
|
64
63
|
- 1
|
65
64
|
version: "2.1"
|
66
|
-
|
67
|
-
|
65
|
+
version_requirements: *id003
|
66
|
+
name: rspec
|
68
67
|
prerelease: false
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
69
|
type: :development
|
70
|
-
|
71
|
-
version_requirements: &id004 !ruby/object:Gem::Requirement
|
70
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
72
71
|
none: false
|
73
72
|
requirements:
|
74
73
|
- - ~>
|
@@ -78,7 +77,9 @@ dependencies:
|
|
78
77
|
- 1
|
79
78
|
- 0
|
80
79
|
version: "1.0"
|
81
|
-
|
80
|
+
version_requirements: *id004
|
81
|
+
name: rr
|
82
|
+
prerelease: false
|
82
83
|
description: |-
|
83
84
|
Barista provides simple, integrated support for CoffeeScript in Rack and Rails applications.
|
84
85
|
|
@@ -118,6 +119,7 @@ files:
|
|
118
119
|
- lib/barista/integration/rails2.rb
|
119
120
|
- lib/barista/integration/rails3.rb
|
120
121
|
- lib/barista/integration/sinatra.rb
|
122
|
+
- lib/barista/rake_task.rb
|
121
123
|
- lib/barista/server.rb
|
122
124
|
- lib/barista/tasks/barista.rake
|
123
125
|
- lib/barista/version.rb
|
@@ -148,16 +150,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
150
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
151
|
none: false
|
150
152
|
requirements:
|
151
|
-
- - "
|
153
|
+
- - ">"
|
152
154
|
- !ruby/object:Gem::Version
|
153
|
-
hash:
|
155
|
+
hash: 25
|
154
156
|
segments:
|
155
|
-
-
|
156
|
-
|
157
|
+
- 1
|
158
|
+
- 3
|
159
|
+
- 1
|
160
|
+
version: 1.3.1
|
157
161
|
requirements: []
|
158
162
|
|
159
163
|
rubyforge_project:
|
160
|
-
rubygems_version: 1.
|
164
|
+
rubygems_version: 1.6.2
|
161
165
|
signing_key:
|
162
166
|
specification_version: 3
|
163
167
|
summary: Simple, transparent coffeescript integration for Rails and Rack applications.
|