barista 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Barista
1
+ # Barista #
2
2
 
3
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
4
  code / is almost a fork).
@@ -14,7 +14,7 @@ your coffeescripts will be automatically provided, ready for bundling.
14
14
 
15
15
  To add to your project, simply add:
16
16
 
17
- gem 'barista', '>= 0.1.2'
17
+ gem 'barista', '>= 0.2.1'
18
18
 
19
19
  To your Gemfile and run bundle install.
20
20
 
@@ -25,6 +25,35 @@ automatically compile all coffeescripts that have changed before rendering the p
25
25
 
26
26
  Barista require rails 3+ (but patches for Rails 2 will be accepted.)
27
27
 
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)
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.
39
+
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
+
43
+ Barista.configure do |config|
44
+ config.change_output_prefix! 'shuriken', 'vendor/shuriken'
45
+ config.change_output_prefix! 'bhm-google-maps', 'vendor/bhm-google-maps'
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
+
51
+ Barista.configure do |config|
52
+ config.each_framework do |framework|
53
+ config.change_output_prefix! framework.name, "vendor/#{framework.name}"
54
+ end
55
+ end
56
+
28
57
  ## Configuration ##
29
58
 
30
59
  Please note that barista lets you configure several options. To do this,
@@ -39,4 +68,5 @@ Currently available options are:
39
68
  * root - the folder path to read coffeescripts from, defaults to app/coffeescripts
40
69
  * output\_root - the folder to write them into, defautls to public/javascripts.
41
70
  * no\_wrap - stop coffee from automatically wrapping JS in a closure.
71
+ * change\_output\_prefix! - method to change the output prefix for a framework.
42
72
 
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 = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Darcy Laycock"]
12
- s.date = %q{2010-05-02}
12
+ s.date = %q{2010-05-03}
13
13
  s.description = %q{Automatically compiles app/scripts/*.coffee to javascript for rails awesomesauce.}
14
14
  s.email = %q{sutto@sutto.net}
15
15
  s.extra_rdoc_files = [
@@ -38,7 +38,7 @@ Gem::Specification.new do |s|
38
38
  s.homepage = %q{http://github.com/Sutto/barista}
39
39
  s.rdoc_options = ["--charset=UTF-8"]
40
40
  s.require_paths = ["lib"]
41
- s.rubygems_version = %q{1.3.5}
41
+ s.rubygems_version = %q{1.3.6}
42
42
  s.summary = %q{Transparent coffeescript support for rails 3}
43
43
 
44
44
  if s.respond_to? :specification_version then
data/lib/barista.rb CHANGED
@@ -53,6 +53,16 @@ module Barista
53
53
  true
54
54
  end
55
55
 
56
+ def change_output_prefix!(framework, prefix = nil)
57
+ framework = framework.is_a?(Barista::Framework) ? framework : Barista::Framework[framework]
58
+ return unless framework
59
+ framework.output_prefix = prefix
60
+ end
61
+
62
+ def each_framework(include_default = false)
63
+ Framework.all(include_default).each { yield if block_given? }
64
+ end
65
+
56
66
  def output_path_for(file)
57
67
  output_root.join(file.to_s.gsub(/^\/+/, '')).to_s.gsub(/\.coffee$/, '.js')
58
68
  end
@@ -9,19 +9,21 @@ module Barista
9
9
  @default_framework = value
10
10
  end
11
11
 
12
- def self.all
13
- [default_framework] + (@all ||= [])
12
+ def self.all(include_default = false)
13
+ all = (@all ||= [])
14
+ all = [default_framework] + all if include_default
15
+ all
14
16
  end
15
17
 
16
18
  def self.exposed_coffeescripts
17
- all.inject([]) do |collection, fw|
19
+ all(true).inject([]) do |collection, fw|
18
20
  collection + fw.exposed_coffeescripts
19
- end.uniq
21
+ end.uniq.sort_by { |f| f.length }
20
22
  end
21
23
 
22
24
  def self.full_path_for(script)
23
25
  script = script.to_s.gsub(/\.js$/, '.coffee').gsub(/^\/+/, '')
24
- all.each do |fw|
26
+ all(true).each do |fw|
25
27
  full_path = fw.full_path_for(script)
26
28
  return full_path, fw if full_path
27
29
  end
@@ -32,10 +34,16 @@ module Barista
32
34
  (@all ||= []) << self.new(name, root)
33
35
  end
34
36
 
35
- attr_reader :name, :framework_root
37
+ def self.[](name)
38
+ name = name.to_s
39
+ (@all ||= []).detect { |fw| fw.name == name }
40
+ end
41
+
42
+ attr_reader :name, :framework_root, :output_prefix
36
43
 
37
- def initialize(name, root)
38
- @name = name
44
+ def initialize(name, root, output_prefix = nil)
45
+ @name = name.to_s
46
+ @output_prefix = nil
39
47
  @framework_root = File.expand_path(root)
40
48
  end
41
49
 
@@ -44,17 +52,29 @@ module Barista
44
52
  end
45
53
 
46
54
  def short_name(script)
47
- File.expand_path(script).gsub /^#{Regexp.escape(@framework_root)}\/?/, ''
55
+ short_name = remove_prefix script, @framework_root
56
+ File.join *[@output_prefix, short_name].compact
48
57
  end
49
58
 
50
59
  def exposed_coffeescripts
51
60
  coffeescripts.map { |script| short_name(script) }
52
61
  end
53
62
 
63
+ def output_prefix=(value)
64
+ value = value.to_s.gsub /(^\/|\/$)/, ''
65
+ @output_prefix = value.blank? ? nil : value
66
+ end
67
+
54
68
  def full_path_for(name)
55
- full_path = File.join(@framework_root, name)
69
+ full_path = File.join(@framework_root, remove_prefix(name, @output_prefix.to_s))
56
70
  File.exist?(full_path) ? full_path : nil
57
71
  end
58
72
 
73
+ protected
74
+
75
+ def remove_prefix(path, prefix)
76
+ path.to_s.gsub /^#{Regexp.escape(prefix.to_s)}\/?/, ''
77
+ end
78
+
59
79
  end
60
80
  end
@@ -2,7 +2,7 @@ module Barista
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- PATCH = 0
5
+ PATCH = 1
6
6
  STRING = [MAJOR, MINOR, PATCH].join(".")
7
7
  end
8
8
  end
@@ -12,4 +12,18 @@ Barista.configure do |c|
12
12
  # ... or ...
13
13
  # c.no_wrap!
14
14
 
15
+ # Change the output root for a framework:
16
+
17
+ # config.change_output_prefix! 'framework-name', 'output-prefix'
18
+
19
+ # or for all frameworks...
20
+
21
+ # config.each_framework do |framework|
22
+ # config.change_output_prefix! framework.name, "vendor/#{framework.name}"
23
+ # end
24
+
25
+ # or, prefix the path for the app files:
26
+
27
+ # config.change_output_prefix! :default, 'my-app-name'
28
+
15
29
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barista
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 1
9
+ version: 0.2.1
5
10
  platform: ruby
6
11
  authors:
7
12
  - Darcy Laycock
@@ -9,7 +14,7 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-05-02 00:00:00 +08:00
17
+ date: 2010-05-03 00:00:00 +08:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
@@ -53,18 +58,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
53
58
  requirements:
54
59
  - - ">="
55
60
  - !ruby/object:Gem::Version
61
+ segments:
62
+ - 0
56
63
  version: "0"
57
- version:
58
64
  required_rubygems_version: !ruby/object:Gem::Requirement
59
65
  requirements:
60
66
  - - ">="
61
67
  - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
62
70
  version: "0"
63
- version:
64
71
  requirements: []
65
72
 
66
73
  rubyforge_project:
67
- rubygems_version: 1.3.5
74
+ rubygems_version: 1.3.6
68
75
  signing_key:
69
76
  specification_version: 3
70
77
  summary: Transparent coffeescript support for rails 3