Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 100 lines (66 sloc) 4.388 kB
55afa0c @Sutto Add framework docs
authored
1 # Barista #
02b7a2d @Sutto Add more barista stuff
authored
2
3 Barista is very, very similar to [bistro\_car](http://github.com/jnicklas/bistro_car) (infact, credit where credit is due - it shares similar
4 code / is almost a fork).
5
6 The main difference being, it lets you use coffee as you would javascript. Simply put, Write coffee
6497165 @Sutto Add Barista.configure, misc doc changes
authored
7 and place it in `app/coffeescripts` and Barista will automatically serve it as if it was placed in `public/javascripts`
02b7a2d @Sutto Add more barista stuff
authored
8
6497165 @Sutto Add Barista.configure, misc doc changes
authored
9 That is, `app/coffeescripts/demo.coffee` will work for `/javascripts/demo.js`. Even better (and more importantly
02b7a2d @Sutto Add more barista stuff
authored
10 for me), it provides `Barista.compile_all!` which takes all coffee files and compiles them into `public/javascripts`.
11
12 If you're using Jammit, this means you can simple run a rake task (`rake barista:brew` before running jammit) and
13 your coffeescripts will be automatically provided, ready for bundling.
14
762266f @Sutto More docs
authored
15 To add to your project, simply add:
16
8410919 @Sutto Misc fixes
authored
17 gem 'barista', '>= 0.2.1'
762266f @Sutto More docs
authored
18
19 To your Gemfile and run bundle install.
20
21 As you place .coffee files in app/scripts, it will automatically handle them for you.
22
f6d9273 @Sutto More docs
authored
23 Please note that for Jammit compatibility etc, by default in test and dev mode it will
24 automatically compile all coffeescripts that have changed before rendering the page.
25
6497165 @Sutto Add Barista.configure, misc doc changes
authored
26 Barista require rails 3+ (but patches for Rails 2 will be accepted.)
27
55afa0c @Sutto Add framework docs
authored
28 ## Frameworks ##
29
30 One of the other main features Barista adds (over bistro\_car) is frameworks similar
31 to Compass. The idea being, you add coffeescripts at runtime from gems etc. To do this,
32 in your gem just have a coffeescript directory and then in you gem add the following code:
33
34 Barista::Framework.register 'name', 'full-path-to-directory' if defined?(Barista::Framework)
35
36 For an example of this in practice, check out [bhm-google-maps](http://github.com/YouthTree/bhm-google-maps)
83f23b6 @Sutto Readme info
authored
37 or, the currently-in-development, [shuriken](http://github.com/Sutto/shuriken). The biggest advantage of this
38 is you can then manage js dependencies using existing tools like bundler.
55afa0c @Sutto Add framework docs
authored
39
85060b1 @Sutto Bump version, allow you to change prefixes for frameworks
authored
40 In your `Barista.configure` block, you can also configure on a per-application basis the output directory
41 for individual frameworks (e.g. put shuriken into vendor/shuriken, bhm-google-maps into vendor/bhm-google-maps):
42
91a269d @Sutto WIP implementation of hooks
authored
43 Barista.configure do |c|
44 c.change_output_prefix! 'shuriken', 'vendor/shuriken'
45 c.change_output_prefix! 'bhm-google-maps', 'vendor/bhm-google-maps'
85060b1 @Sutto Bump version, allow you to change prefixes for frameworks
authored
46 end
47
48 Alternatively, to prefix all, you can use `Barista.each_framework` (if you pass true, it includes the 'default' framework
49 which is your application root).
50
91a269d @Sutto WIP implementation of hooks
authored
51 Barista.configure do |c|
52 c.each_framework do |framework|
53 c.change_output_prefix! framework.name, "vendor/#{framework.name}"
85060b1 @Sutto Bump version, allow you to change prefixes for frameworks
authored
54 end
55 end
91a269d @Sutto WIP implementation of hooks
authored
56
57 ## Hooks ##
58
59 Barista lets you hook into the compilation at several stages. Namely:
60
61 * before compilation
62 * after compilation
63 * after compilation fails
64
65 To hook into these hooks, you can use like so:
66
67 * `Barista.before_compilation { |path| puts "Barista: Compiling #{path}" }`
68 * `Barista.on_compilation { |path| puts "Barista: Successfully compiled #{path}" }`
69 * `Barista.on_compilation_error { |path, output| puts "Barista: Compilation of #{path} failed with:\n#{output}" }`
70
71 These allow you to do things such as notify on compilation, automatically
72 perform compression post compilation and a variety of other cool things.
85060b1 @Sutto Bump version, allow you to change prefixes for frameworks
authored
73
6497165 @Sutto Add Barista.configure, misc doc changes
authored
74 ## Configuration ##
75
76 Please note that barista lets you configure several options. To do this,
77 it's as simple as setting up an initializer with:
78
3442ea5 @Sutto Add the generator
authored
79 rails generate barista_install
6497165 @Sutto Add Barista.configure, misc doc changes
authored
80
81 Then editing `config/initializers/barista_config.rb`.
82
83 Currently available options are:
84
85 * root - the folder path to read coffeescripts from, defaults to app/coffeescripts
86 * output\_root - the folder to write them into, defautls to public/javascripts.
87 * no\_wrap - stop coffee from automatically wrapping JS in a closure.
83f23b6 @Sutto Readme info
authored
88 * change\_output\_prefix! - method to change the output prefix for a framework.
6497165 @Sutto Add Barista.configure, misc doc changes
authored
89
870add6 @Sutto Contributor details for Barista
authored
90 ## Note on Patches/Pull Requests ##
91
92 1. Fork the project.
93 2. Make your feature addition or bug fix.
94 3. Add tests for it. This is important so I don't break it in a future version unintentionally.
95 4. Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
96 5. Send me a pull request. Bonus points for topic branches.
97
98 ## Copyright ##
99
100 Copyright (c) 2010 Darcy Laycock. See LICENSE for details.
Something went wrong with that request. Please try again.