barista 0.6.1 → 0.7.0.pre2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/DESCRIPTION ADDED
@@ -0,0 +1,7 @@
1
+ Barista provides simple, integrated support for CoffeeScript in Rack and Rails applications.
2
+
3
+ Much like Compass does for Sass, It also provides Frameworks (bundleable code which can be shared via Gems).
4
+
5
+ Lastly, it also provides a Rack Application (which can be used to server compiled code), a around_filter-style precompiler (as Rack middleware) and simple helpers for rails and Haml.
6
+
7
+ For more details, please see the the README file bundled with it.
data/Gemfile CHANGED
@@ -1,7 +1,9 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- group :development do
4
- gem 'jeweler'
5
- end
3
+ gem 'coffee-script', '~> 2.1.1'
6
4
 
7
- gemspec
5
+ group :development, :test do
6
+ gem 'jeweler', '~> 1.0'
7
+ gem 'rspec', '~> 2.1'
8
+ gem 'rr', '~> 1.0'
9
+ end
data/Gemfile.lock CHANGED
@@ -1,27 +1,38 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- barista (0.5.1)
5
- open4
4
+ barista (0.7.0.pre)
5
+ coffee-script (~> 2.1.1)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- gemcutter (0.6.1)
10
+ coffee-script (2.1.1)
11
+ coffee-script-source
12
+ coffee-script-source (0.9.5)
13
+ diff-lcs (1.1.2)
11
14
  git (1.2.5)
12
- jeweler (1.4.0)
13
- gemcutter (>= 0.1.0)
15
+ jeweler (1.5.1)
16
+ bundler (~> 1.0.0)
14
17
  git (>= 1.2.5)
15
- rubyforge (>= 2.0.0)
16
- json_pure (1.4.6)
17
- open4 (1.0.1)
18
- rubyforge (2.0.4)
19
- json_pure (>= 1.1.7)
18
+ rake
19
+ rake (0.8.7)
20
+ rr (1.0.2)
21
+ rspec (2.1.0)
22
+ rspec-core (~> 2.1.0)
23
+ rspec-expectations (~> 2.1.0)
24
+ rspec-mocks (~> 2.1.0)
25
+ rspec-core (2.1.0)
26
+ rspec-expectations (2.1.0)
27
+ diff-lcs (~> 1.1.2)
28
+ rspec-mocks (2.1.0)
20
29
 
21
30
  PLATFORMS
22
31
  ruby
23
32
 
24
33
  DEPENDENCIES
25
34
  barista!
26
- jeweler
27
- open4
35
+ coffee-script (~> 2.1.1)
36
+ jeweler (~> 1.0)
37
+ rr (~> 1.0)
38
+ rspec (~> 2.1)
data/Rakefile CHANGED
@@ -7,19 +7,12 @@ begin
7
7
  require 'jeweler'
8
8
  Jeweler::Tasks.new do |gem|
9
9
  gem.name = "barista"
10
- gem.summary = %Q{Transparent coffeescript support for rails 3.}
11
- gem.description = %Q{Automatically compiles app/coffeescripts/*.coffee to javascript for rails awesomesauce.}
10
+ gem.summary = %Q{Simple, transparent coffeescript integration for Rails and Rack applications.}
11
+ gem.description = File.read(File.expand_path('DESCRIPTION', File.dirname(__FILE__)))
12
12
  gem.email = "sutto@sutto.net"
13
13
  gem.homepage = "http://github.com/Sutto/barista"
14
14
  gem.version = Barista::Version::STRING
15
15
  gem.authors = ["Darcy Laycock"]
16
- gem.add_dependency 'open4'
17
- gem.add_dependency 'railties', '~> 3.0'
18
-
19
- gem.add_development_dependency 'rspec', '~> 2.0.0.beta.22'
20
- gem.add_development_dependency 'rr', '~> 1.0'
21
- gem.add_development_dependency 'therubyracer'
22
-
23
16
  end
24
17
  Jeweler::GemcutterTasks.new
25
18
  rescue LoadError
@@ -28,8 +21,7 @@ end
28
21
 
29
22
  require 'rake/rdoctask'
30
23
  Rake::RDocTask.new do |rdoc|
31
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
32
-
24
+ version = Barista::Version::STRING
33
25
  rdoc.rdoc_dir = 'rdoc'
34
26
  rdoc.title = "barista #{version}"
35
27
  rdoc.rdoc_files.include('README*')
data/barista.gemspec CHANGED
@@ -1,61 +1,67 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{barista}
8
- s.version = "0.6.1"
8
+ s.version = "0.7.0.pre2"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
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{2010-11-22}
13
- s.description = %q{Automatically compiles app/coffeescripts/*.coffee to javascript for rails awesomesauce.}
12
+ s.date = %q{2010-11-26}
13
+ s.description = %q{Barista provides simple, integrated support for CoffeeScript in Rack and Rails applications.
14
+
15
+ Much like Compass does for Sass, It also provides Frameworks (bundleable code which can be shared via Gems).
16
+
17
+ Lastly, it also provides a Rack Application (which can be used to server compiled code), a around_filter-style precompiler (as Rack middleware) and simple helpers for rails and Haml.
18
+
19
+ For more details, please see the the README file bundled with it.}
14
20
  s.email = %q{sutto@sutto.net}
15
21
  s.extra_rdoc_files = [
16
22
  "LICENSE",
17
- "README.md"
23
+ "README.md"
18
24
  ]
19
25
  s.files = [
20
26
  ".document",
21
- ".gitignore",
22
- ".rspec",
23
- ".rvmrc",
24
- "Gemfile",
25
- "Gemfile.lock",
26
- "LICENSE",
27
- "README.md",
28
- "Rakefile",
29
- "app/controllers/barista_controller.rb",
30
- "barista.gemspec",
31
- "config/routes.rb",
32
- "lib/barista.rb",
33
- "lib/barista/compiler.rb",
34
- "lib/barista/compilers.rb",
35
- "lib/barista/compilers/base.rb",
36
- "lib/barista/compilers/native.rb",
37
- "lib/barista/compilers/node.rb",
38
- "lib/barista/filter.rb",
39
- "lib/barista/framework.rb",
40
- "lib/barista/hooks.rb",
41
- "lib/barista/tasks/barista.rake",
42
- "lib/barista/version.rb",
43
- "lib/coffee-script/coffee-script-0.9.4.js",
44
- "lib/generators/barista/install/USAGE",
45
- "lib/generators/barista/install/install_generator.rb",
46
- "lib/generators/barista/install/templates/initializer.rb",
47
- "lib/generators/barista_install_generator.rb",
48
- "spec/barista_spec.rb",
49
- "spec/spec_helper.rb"
27
+ ".rspec",
28
+ ".rvmrc",
29
+ "DESCRIPTION",
30
+ "Gemfile",
31
+ "Gemfile.lock",
32
+ "LICENSE",
33
+ "README.md",
34
+ "Rakefile",
35
+ "barista.gemspec",
36
+ "lib/barista.rb",
37
+ "lib/barista/compiler.rb",
38
+ "lib/barista/extensions.rb",
39
+ "lib/barista/filter.rb",
40
+ "lib/barista/framework.rb",
41
+ "lib/barista/haml_filter.rb",
42
+ "lib/barista/helpers.rb",
43
+ "lib/barista/hooks.rb",
44
+ "lib/barista/integration.rb",
45
+ "lib/barista/integration/rails2.rb",
46
+ "lib/barista/integration/rails3.rb",
47
+ "lib/barista/integration/sinatra.rb",
48
+ "lib/barista/server.rb",
49
+ "lib/barista/tasks/barista.rake",
50
+ "lib/barista/version.rb",
51
+ "lib/generators/barista/install/USAGE",
52
+ "lib/generators/barista/install/install_generator.rb",
53
+ "lib/generators/barista/install/templates/initializer.rb",
54
+ "lib/generators/barista_install_generator.rb",
55
+ "spec/barista_spec.rb",
56
+ "spec/spec_helper.rb"
50
57
  ]
51
58
  s.homepage = %q{http://github.com/Sutto/barista}
52
- s.rdoc_options = ["--charset=UTF-8"]
53
59
  s.require_paths = ["lib"]
54
60
  s.rubygems_version = %q{1.3.7}
55
- s.summary = %q{Transparent coffeescript support for rails 3.}
61
+ s.summary = %q{Simple, transparent coffeescript integration for Rails and Rack applications.}
56
62
  s.test_files = [
57
63
  "spec/barista_spec.rb",
58
- "spec/spec_helper.rb"
64
+ "spec/spec_helper.rb"
59
65
  ]
60
66
 
61
67
  if s.respond_to? :specification_version then
@@ -63,24 +69,21 @@ Gem::Specification.new do |s|
63
69
  s.specification_version = 3
64
70
 
65
71
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
66
- s.add_runtime_dependency(%q<open4>, [">= 0"])
67
- s.add_runtime_dependency(%q<railties>, ["~> 3.0"])
68
- s.add_development_dependency(%q<rspec>, ["~> 2.0.0.beta.22"])
72
+ s.add_runtime_dependency(%q<coffee-script>, ["~> 2.1.1"])
73
+ s.add_development_dependency(%q<jeweler>, ["~> 1.0"])
74
+ s.add_development_dependency(%q<rspec>, ["~> 2.1"])
69
75
  s.add_development_dependency(%q<rr>, ["~> 1.0"])
70
- s.add_development_dependency(%q<therubyracer>, [">= 0"])
71
76
  else
72
- s.add_dependency(%q<open4>, [">= 0"])
73
- s.add_dependency(%q<railties>, ["~> 3.0"])
74
- s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.22"])
77
+ s.add_dependency(%q<coffee-script>, ["~> 2.1.1"])
78
+ s.add_dependency(%q<jeweler>, ["~> 1.0"])
79
+ s.add_dependency(%q<rspec>, ["~> 2.1"])
75
80
  s.add_dependency(%q<rr>, ["~> 1.0"])
76
- s.add_dependency(%q<therubyracer>, [">= 0"])
77
81
  end
78
82
  else
79
- s.add_dependency(%q<open4>, [">= 0"])
80
- s.add_dependency(%q<railties>, ["~> 3.0"])
81
- s.add_dependency(%q<rspec>, ["~> 2.0.0.beta.22"])
83
+ s.add_dependency(%q<coffee-script>, ["~> 2.1.1"])
84
+ s.add_dependency(%q<jeweler>, ["~> 1.0"])
85
+ s.add_dependency(%q<rspec>, ["~> 2.1"])
82
86
  s.add_dependency(%q<rr>, ["~> 1.0"])
83
- s.add_dependency(%q<therubyracer>, [">= 0"])
84
87
  end
85
88
  end
86
89
 
data/lib/barista.rb CHANGED
@@ -1,19 +1,34 @@
1
- require 'active_support'
2
1
  require 'pathname'
3
2
 
3
+ require 'coffee_script'
4
+
4
5
  module Barista
5
6
 
6
7
  Error = Class.new(StandardError)
7
8
  CompilationError = Class.new(Error)
8
9
  CompilerUnavailableError = Class.new(Error)
9
10
 
10
- autoload :Compiler, 'barista/compiler'
11
- autoload :Compilers, 'barista/compilers'
12
- autoload :Filter, 'barista/filter'
13
- autoload :Framework, 'barista/framework'
14
- autoload :Hooks, 'barista/hooks'
11
+ autoload :Compiler, 'barista/compiler'
12
+ autoload :Extensions, 'barista/extensions'
13
+ autoload :Filter, 'barista/filter'
14
+ autoload :Framework, 'barista/framework'
15
+ autoload :HamlFilter, 'barista/haml_filter'
16
+ autoload :Helpers, 'barista/helpers'
17
+ autoload :Hooks, 'barista/hooks'
18
+ autoload :Integration, 'barista/integration'
19
+ autoload :Server, 'barista/server'
15
20
 
16
21
  class << self
22
+ include Extensions
23
+
24
+ def library_root
25
+ @library_root ||= Pathname(__FILE__).dirname
26
+ end
27
+
28
+ # Hook methods
29
+ #
30
+ # Hooks are a generic way to define blocks that are executed at run time.
31
+ # For a full list of hooks, see the readme.
17
32
 
18
33
  def hooks
19
34
  @hooks ||= Hooks.new
@@ -27,105 +42,152 @@ module Barista
27
42
  hooks.invoke(name, *args)
28
43
  end
29
44
 
30
- def on_compilation_error(&blk)
31
- on_hook :compilation_failed, &blk
32
- end
45
+ has_hook_method :on_compilation_error => :compilation_failed,
46
+ :on_compilation => :compiled,
47
+ :on_compilation_complete => :all_compiled,
48
+ :on_compilation_with_warning => :compiled_with_warning,
49
+ :before_full_compilation => :before_full_compilation,
50
+ :before_compilation => :before_compilation
51
+
52
+
53
+ # Configuration - Tweak how you use Barista.
33
54
 
34
- def on_compilation(&blk)
35
- on_hook :compiled, &blk
36
- end
55
+ has_boolean_options :verbose, :bare, :add_filter, :add_preamble, :exception_on_error, :embedded_interpreter
56
+ has_delegate_methods Compiler, :bin_path, :bin_path=, :js_path, :js_path=
57
+ has_deprecated_methods :compiler, :compiler=, :compiler_klass, :compiler_klass=
37
58
 
38
- def on_compilation_complete(&blk)
39
- on_hook :all_compiled, &blk
59
+ def configure
60
+ yield self if block_given?
40
61
  end
41
-
42
- def on_compilation_with_warning(&blk)
43
- on_hook :compiled_with_warning, &blk
62
+
63
+ def env
64
+ @env ||= default_for_env
44
65
  end
45
66
 
46
- def before_full_compilation(&blk)
47
- on_hook :before_full_compilation, &blk
67
+ def env=(value)
68
+ @env = value.to_s.strip
69
+ @env = nil if @env == ''
48
70
  end
49
71
 
50
- def before_compilation(&blk)
51
- on_hook :before_compilation, &blk
72
+ def logger
73
+ @logger ||= default_for_logger
52
74
  end
53
75
 
54
- def configure
55
- yield self if block_given?
76
+ def logger=(value)
77
+ @logger = value
56
78
  end
57
79
 
58
- def exception_on_error?
59
- @exception_on_error = true if !defined?(@exception_on_error)
60
- !!@exception_on_error
80
+ def app_root
81
+ @app_root ||= default_for_app_root
61
82
  end
62
83
 
63
- def exception_on_error=(value)
64
- @exception_on_error = value
84
+ def app_root=(value)
85
+ @app_root = value.nil? ? nil : Pathname(value.to_s)
65
86
  end
66
87
 
67
88
  def root
68
- @root ||= Rails.root.join("app", "coffeescripts")
89
+ @root ||= app_root.join("app", "coffeescripts")
69
90
  end
70
91
 
71
92
  def root=(value)
72
- @root = Pathname(value.to_s)
93
+ @root = value.nil? ? nil : Pathname(value.to_s)
73
94
  Framework.default_framework = nil
74
95
  end
75
96
 
76
97
  def output_root
77
- @output_root ||= Rails.root.join("public", "javascripts")
98
+ @output_root ||= app_root.join("public", "javascripts")
78
99
  end
79
100
 
80
101
  def output_root=(value)
81
- @output_root = Pathname(value.to_s)
102
+ @output_root = value.nil? ? nil : Pathname(value.to_s)
82
103
  end
83
104
 
84
- def compile_file!(file, force = false, silence_error = false)
85
- # Ensure we have a coffeescript compiler available.
86
- if !Compiler.check_availability!(silence_error)
87
- debug "The coffeescript compiler at '#{Compiler.bin_path}' is currently unavailable."
88
- return ""
105
+ def no_wrap?
106
+ deprecate! self, :no_wrap?, 'Please use bare? instead.'
107
+ bare?
108
+ end
109
+
110
+ def no_wrap!
111
+ deprecate! self, :no_wrap!, 'Please use bare! instead.'
112
+ bare!
113
+ end
114
+
115
+ def no_wrap=(value)
116
+ deprecate! self, :no_wrap=, 'Please use bare= instead.'
117
+ self.bare = value
118
+ end
119
+
120
+ # Default configuration options
121
+
122
+ def local_env?
123
+ %w(test development).include? Barista.env
124
+ end
125
+
126
+ def default_for_env
127
+ return Rails.env.to_s if defined?(Rails.env)
128
+ ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
129
+ end
130
+
131
+ def default_for_app_root
132
+ if defined?(Rails.root)
133
+ Rails.root
134
+ else
135
+ Pathname(Dir.pwd)
89
136
  end
90
- # Expand the path from the framework.
91
- origin_path, framework = Framework.full_path_for(file)
92
- return if origin_path.blank?
93
- destination_path = self.output_path_for(file)
94
- return unless force || Compiler.dirty?(origin_path, destination_path)
95
- debug "Compiling #{file} from framework '#{framework.name}'"
96
- FileUtils.mkdir_p File.dirname(destination_path)
97
- content = Compiler.compile(origin_path, :silence_error => silence_error)
98
- # Write the rendered content to file.
99
- # nil is only when silence_error is true.
100
- if content.nil?
101
- debug "An error occured compiling '#{file}' - Leaving file as is."
137
+ end
138
+
139
+ def default_for_logger
140
+ if defined?(Rails.logger)
141
+ Rails.logger
102
142
  else
103
- File.open(destination_path, "w+") { |f| f.write content }
104
- content
143
+ require 'logger'
144
+ Logger.new(STDOUT)
105
145
  end
106
- rescue SystemCallError
107
- debug "An unknown error occured attempting to compile '#{file}'"
108
- ""
146
+ end
147
+
148
+ def default_for_verbose
149
+ local_env?
150
+ end
151
+
152
+ def default_for_add_filter
153
+ local_env?
154
+ end
155
+
156
+ def default_for_add_preamble
157
+ local_env?
158
+ end
159
+
160
+ def default_for_exception_on_error
161
+ true
162
+ end
163
+
164
+ def default_for_embedded_interpreter
165
+ local_env?
166
+ end
167
+
168
+ # Actual tasks on the barista module.
169
+
170
+ def compile_file!(file, force = false, silence_error = false)
171
+ Compiler.autocompile_file file, force, silence_error
109
172
  end
110
173
 
111
174
  def compile_all!(force = false, silence_error = true)
112
175
  debug "Compiling all coffeescripts"
113
176
  Barista.invoke_hook :before_full_compilation
114
177
  Framework.exposed_coffeescripts.each do |coffeescript|
115
- compile_file! coffeescript, force, silence_error
178
+ Compiler.autocompile_file coffeescript, force, silence_error
116
179
  end
117
180
  Barista.invoke_hook :all_compiled
118
181
  true
119
182
  end
120
183
 
121
184
  def change_output_prefix!(framework, prefix = nil)
122
- framework = framework.is_a?(Barista::Framework) ? framework : Barista::Framework[framework]
123
- return unless framework
124
- framework.output_prefix = prefix
185
+ framework = Barista::Framework[framework] unless framework.is_a?(Barista::Framework)
186
+ framework.output_prefix = prefix if framework.present?
125
187
  end
126
188
 
127
- def each_framework(include_default = false)
128
- Framework.all(include_default).each { |f| yield f if block_given? }
189
+ def each_framework(include_default = false, &blk)
190
+ Framework.all(include_default).each(&blk)
129
191
  end
130
192
 
131
193
  def output_path_for(file)
@@ -133,56 +195,17 @@ module Barista
133
195
  end
134
196
 
135
197
  def debug(message)
136
- Rails.logger.debug "[Barista] #{message}" if defined?(Rails.logger) && Rails.logger
137
- end
138
-
139
- def verbose?
140
- @verbose ||= (defined?(Rails) && (Rails.env.test? || Rails.env.development?))
198
+ logger.debug "[Barista] #{message}"
141
199
  end
142
200
 
143
- def verbose!
144
- self.verbose = true
145
- end
146
-
147
- def verbose=(value)
148
- @verbose = !!value
201
+ def setup_defaults
202
+ Barista::HamlFilter.setup
203
+ Barista::Compiler.setup_default_error_logger
149
204
  end
150
205
 
151
- alias add_filter? verbose?
152
- alias add_preamble? verbose?
153
-
154
- def no_wrap?
155
- defined?(@no_wrap) && @no_wrap
156
- end
157
- alias bare? no_wrap?
158
-
159
- def no_wrap!
160
- self.no_wrap = true
161
- end
162
- alias bare! no_wrap!
163
-
164
- def no_wrap=(value)
165
- @no_wrap = !!value
166
- end
167
- alias bare= no_wrap=
168
-
169
- delegate :bin_path, :bin_path=, :js_path, :js_path=, :compiler, :compiler=,
170
- :compiler_klass, :compiler_klass=, :to => Compiler
171
-
172
- end
173
-
174
- if defined?(Rails::Engine)
175
- class Engine < Rails::Engine
176
-
177
- rake_tasks do
178
- load File.expand_path('./barista/tasks/barista.rake', File.dirname(__FILE__))
179
- end
180
-
181
- initializer "barista.wrap_filter" do
182
- ActionController::Base.before_filter(Barista::Filter) if Barista.add_filter?
183
- end
184
-
185
- end
186
206
  end
207
+
208
+ # Setup integration by default.
209
+ Integration.setup
187
210
 
188
211
  end