barista 0.6.1 → 0.7.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,61 @@
1
+ module Barista
2
+ module Helpers
3
+
4
+ def coffeescript_interpreter_js
5
+ return if defined?(@coffeescript_embedded) && @coffeescript_embedded
6
+ check_for_helper_method! :javascript_include_tag
7
+ @coffeescript_embedded = true
8
+ if Barista.embedded_interpreter?
9
+ javascript_include_tag 'coffeescript'
10
+ end
11
+ end
12
+
13
+ def coffeescript_include_tag(*names)
14
+ check_for_helper_method! :javascript_include_tag
15
+ if Barista.embedded_interpreter?
16
+ output = defined?(ActiveSupport::SafeBuffer) ? ActiveSupport::SafeBuffer.new : ""
17
+ output << coffeescript_interpreter_js
18
+ check_for_helper_method! :content_tag
19
+ Array(names).each do |name|
20
+ output << "\n"
21
+ output << content_tag(:script, '', :type => 'text/coffeescript', :src => normalise_coffeescript_path(name.to_s))
22
+ end
23
+ output
24
+ else
25
+ javascript_include_tag(*names)
26
+ end
27
+ end
28
+
29
+ def coffeescript_tag(code, html_options = {})
30
+ check_for_helper_method! :javascript_tag
31
+ if Barista.embedded_interpreter?
32
+ check_for_helper_method! :content_tag
33
+ output = defined?(ActiveSupport::SafeBuffer) ? ActiveSupport::SafeBuffer.new : ""
34
+ output << coffeescript_interpreter_js
35
+ embed = "\n#<![CDATA[\n#{code}\n#]]>\n"
36
+ embed = embed.html_safe if embed.respond_to?(:html_safe)
37
+ output << content_tag(:script, embed, html_options.merge(:type => 'text/coffeescript'))
38
+ output
39
+ else
40
+ javascript_tag Barista::Compiler.compile(code), html_options
41
+ end
42
+ end
43
+
44
+ protected
45
+
46
+ def normalise_coffeescript_path(path)
47
+ if respond_to?(:compute_public_path)
48
+ compute_public_path path, 'coffeescript', 'coffee'
49
+ else
50
+ path = path.gsub(/\.(js|coffee)$/, '') + '.coffee'
51
+ path = "/coffeescripts/#{path}" unless path =~ /^\//
52
+ path
53
+ end
54
+ end
55
+
56
+ def check_for_helper_method!(name)
57
+ raise "Please make sure #{name} is available." unless respond_to?(name)
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,28 @@
1
+ module Barista
2
+ module Integration
3
+
4
+ autoload :Rails2, 'barista/integration/rails2'
5
+ autoload :Rails3, 'barista/integration/rails3'
6
+ autoload :Sinatra, 'barista/integration/sinatra'
7
+
8
+ def self.setup
9
+ setup_rails if defined?(Rails)
10
+ setup_sinatra if defined?(::Sinatra)
11
+ end
12
+
13
+ def self.setup_rails
14
+ case Rails::VERSION::MAJOR
15
+ when 3
16
+ Rails3
17
+ when 2
18
+ # We need to manually call the initialiser stuff in Rails 2.
19
+ Rails2.setup
20
+ end
21
+ end
22
+
23
+ def self.setup_sinatra
24
+ ::Sinatra::Base.register(Sinatra)
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,16 @@
1
+ module Barista
2
+ module Integration
3
+ module Rails2
4
+
5
+ def self.setup
6
+ ActionController::Dispatcher.middleware.tap do |middleware|
7
+ middleware.use Barista::Filter if Barista.add_filter?
8
+ middleware.use Barista::Server::Proxy
9
+ end
10
+ Barista.setup_defaults
11
+ ActionController::Base.helper Barista::Helpers
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,26 @@
1
+ module Barista
2
+ module Integration
3
+ module Rails3
4
+ class Railtie < Rails::Railtie
5
+
6
+ rake_tasks do
7
+ load Barista.library_root.join('barista/tasks/barista.rake').to_s
8
+ end
9
+
10
+ initializer 'barista.wrap_filter' do
11
+ config.app_middleware.use Barista::Filter if Barista.add_filter?
12
+ config.app_middleware.use Barista::Server::Proxy
13
+ end
14
+
15
+ initializer 'barista.defaults' do
16
+ Barista.setup_defaults
17
+ end
18
+
19
+ initializer 'barista.helpers' do
20
+ ActionController::Base.helper Barista::Helpers
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ module Barista
2
+ module Integration
3
+ module Sinatra
4
+
5
+ def self.registered(app)
6
+ app.configure do |inner_app|
7
+ setup_defaults inner_app
8
+ inner_app.use Barista::Filter if Barista.add_filter?
9
+ inner_app.use Barista::Server::Proxy
10
+ Barista.setup_defaults
11
+ end
12
+
13
+ end
14
+
15
+ def self.setup_defaults(app)
16
+ Barista.configure do |c|
17
+ c.env = app.environment.to_s
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,110 @@
1
+ require 'rack/utils'
2
+
3
+ module Barista
4
+ class Server
5
+
6
+ CACHE_FOR_SECONDS = 300
7
+ JS_CONTENT_TYPE = 'text/javascript'
8
+ COFFEE_CONTENT_TYPE = 'text/coffeescript'
9
+ PATH_REGEXP = /^\/(coffee|java)scripts\//
10
+
11
+ # Extensions to the type.
12
+ EXTENSION_MAPPING = {
13
+ '.coffee' => :coffeescript,
14
+ '.js' => :javascript
15
+ }
16
+
17
+ # Content types for responses.
18
+ CONTENT_TYPE_MAPPING = {
19
+ :coffeescript => COFFEE_CONTENT_TYPE,
20
+ :javascript => JS_CONTENT_TYPE
21
+ }
22
+
23
+ class Proxy
24
+
25
+ def initialize(app)
26
+ @app = app
27
+ @server = Server.new
28
+ end
29
+
30
+ def call(env)
31
+ result = @server.call(env)
32
+ if result[0] == 404
33
+ @app.call(env)
34
+ else
35
+ result
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ def initialize
42
+ # Cache the responses for common errors.
43
+ forbidden
44
+ not_found
45
+ end
46
+
47
+ def call(env)
48
+ dup._call(env)
49
+ end
50
+
51
+ def _call(env)
52
+ @path_info = Rack::Utils.unescape(env['PATH_INFO'].to_s)
53
+ return not_found unless @path_info =~ PATH_REGEXP
54
+ # Strip the prefix.
55
+ @path_info.gsub! PATH_REGEXP, ''
56
+ # Check it's a valid path.
57
+ return forbidden if @path_info.include?('..')
58
+
59
+ # If coffeescript.js is the request, render the coffeescript compiler code.
60
+ if @path_info == 'coffeescript.js'
61
+ return response_for_text(CoffeeScript::Source.contents)
62
+ end
63
+ # Look up the type of the file based off of the extension.
64
+ @result_type = EXTENSION_MAPPING[File.extname(@path_info)]
65
+ return not_found if @result_type.nil? || (@result_type == :coffeescript && !Barista.embedded_interpreter?)
66
+ # Process the difference in content type.
67
+ content, last_modified = Barista::Compiler.compile_as(@path_info, @result_type)
68
+ if content.nil?
69
+ not_found
70
+ else
71
+ response_for_text content, CONTENT_TYPE_MAPPING[@result_type], last_modified
72
+ end
73
+ end
74
+
75
+ protected
76
+
77
+ def forbidden
78
+ @_forbidden_response ||= begin
79
+ body = "Forbidden\n"
80
+ [403, {
81
+ 'Content-Type' => 'text/plain',
82
+ 'Content-Length' => Rack::Utils.bytesize(body).to_s,
83
+ 'X-Cascade' => 'pass'
84
+ }, [body]]
85
+ end
86
+ end
87
+
88
+ def not_found
89
+ @_not_found_response ||= begin
90
+ body = "Not Found\n"
91
+ [404, {
92
+ 'Content-Type' => 'text/plain',
93
+ 'Content-Length' => Rack::Utils.bytesize(body).to_s,
94
+ 'X-Cascade' => 'pass'
95
+ }, [body]]
96
+ end
97
+ end
98
+
99
+ def response_for_text(content, content_type = 'text/javascript', modified_at = nil)
100
+ headers = {
101
+ 'Content-Type' => content_type,
102
+ 'Content-Length' => Rack::Utils.bytesize(content).to_s,
103
+ 'Cache-Control' => "public, max-age=#{CACHE_FOR_SECONDS}"
104
+ }
105
+ headers.merge!('Last-Modified' => modified_at.httpdate) unless modified_at.nil?
106
+ [200, headers, [content]]
107
+ end
108
+
109
+ end
110
+ end
@@ -1,8 +1,8 @@
1
1
  module Barista
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 6
5
- PATCH = 1
6
- STRING = [MAJOR, MINOR, PATCH].join(".")
4
+ MINOR = 7
5
+ PATCH = 0
6
+ STRING = [MAJOR, MINOR, PATCH, 'pre2'].join(".")
7
7
  end
8
8
  end
@@ -42,19 +42,6 @@ Barista.configure do |c|
42
42
  # Or, make sure it is always on
43
43
  # c.verbose!
44
44
 
45
- # Changing the compiler
46
-
47
- # To use a customer compiler class:
48
- # c.compiler_klass = MyAwesomeCompilerClass
49
- # c.compiler = :null # Barista::Compilers::Null
50
-
51
- # To switch between the built in compilers:
52
- # c.compiler = :native
53
- # or...
54
- # c.compiler = :node
55
-
56
- # The default compiler is auto detected.
57
-
58
45
  # If you want to use a custom JS file, you can as well
59
46
  # e.g. vendoring CoffeeScript in your application:
60
47
  # c.js_path = Rails.root.join('public', 'javascripts', 'coffee-script.js')
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barista
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
5
- prerelease: false
4
+ hash: -1876988199
5
+ prerelease: true
6
6
  segments:
7
7
  - 0
8
- - 6
9
- - 1
10
- version: 0.6.1
8
+ - 7
9
+ - 0
10
+ - pre2
11
+ version: 0.7.0.pre2
11
12
  platform: ruby
12
13
  authors:
13
14
  - Darcy Laycock
@@ -15,60 +16,60 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-11-22 00:00:00 +08:00
19
+ date: 2010-11-26 00:00:00 +08:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
22
- name: open4
23
23
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ type: :runtime
25
+ name: coffee-script
26
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
27
  none: false
26
28
  requirements:
27
- - - ">="
29
+ - - ~>
28
30
  - !ruby/object:Gem::Version
29
- hash: 3
31
+ hash: 9
30
32
  segments:
31
- - 0
32
- version: "0"
33
- type: :runtime
34
- version_requirements: *id001
33
+ - 2
34
+ - 1
35
+ - 1
36
+ version: 2.1.1
37
+ requirement: *id001
35
38
  - !ruby/object:Gem::Dependency
36
- name: railties
37
39
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
40
+ type: :development
41
+ name: jeweler
42
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
43
  none: false
40
44
  requirements:
41
45
  - - ~>
42
46
  - !ruby/object:Gem::Version
43
- hash: 7
47
+ hash: 15
44
48
  segments:
45
- - 3
49
+ - 1
46
50
  - 0
47
- version: "3.0"
48
- type: :runtime
49
- version_requirements: *id002
51
+ version: "1.0"
52
+ requirement: *id002
50
53
  - !ruby/object:Gem::Dependency
51
- name: rspec
52
54
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
55
+ type: :development
56
+ name: rspec
57
+ version_requirements: &id003 !ruby/object:Gem::Requirement
54
58
  none: false
55
59
  requirements:
56
60
  - - ~>
57
61
  - !ruby/object:Gem::Version
58
- hash: 62196431
62
+ hash: 1
59
63
  segments:
60
64
  - 2
61
- - 0
62
- - 0
63
- - beta
64
- - 22
65
- version: 2.0.0.beta.22
66
- type: :development
67
- version_requirements: *id003
65
+ - 1
66
+ version: "2.1"
67
+ requirement: *id003
68
68
  - !ruby/object:Gem::Dependency
69
- name: rr
70
69
  prerelease: false
71
- requirement: &id004 !ruby/object:Gem::Requirement
70
+ type: :development
71
+ name: rr
72
+ version_requirements: &id004 !ruby/object:Gem::Requirement
72
73
  none: false
73
74
  requirements:
74
75
  - - ~>
@@ -78,23 +79,15 @@ dependencies:
78
79
  - 1
79
80
  - 0
80
81
  version: "1.0"
81
- type: :development
82
- version_requirements: *id004
83
- - !ruby/object:Gem::Dependency
84
- name: therubyracer
85
- prerelease: false
86
- requirement: &id005 !ruby/object:Gem::Requirement
87
- none: false
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- hash: 3
92
- segments:
93
- - 0
94
- version: "0"
95
- type: :development
96
- version_requirements: *id005
97
- description: Automatically compiles app/coffeescripts/*.coffee to javascript for rails awesomesauce.
82
+ requirement: *id004
83
+ description: |-
84
+ Barista provides simple, integrated support for CoffeeScript in Rack and Rails applications.
85
+
86
+ Much like Compass does for Sass, It also provides Frameworks (bundleable code which can be shared via Gems).
87
+
88
+ 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.
89
+
90
+ For more details, please see the the README file bundled with it.
98
91
  email: sutto@sutto.net
99
92
  executables: []
100
93
 
@@ -105,29 +98,30 @@ extra_rdoc_files:
105
98
  - README.md
106
99
  files:
107
100
  - .document
108
- - .gitignore
109
101
  - .rspec
110
102
  - .rvmrc
103
+ - DESCRIPTION
111
104
  - Gemfile
112
105
  - Gemfile.lock
113
106
  - LICENSE
114
107
  - README.md
115
108
  - Rakefile
116
- - app/controllers/barista_controller.rb
117
109
  - barista.gemspec
118
- - config/routes.rb
119
110
  - lib/barista.rb
120
111
  - lib/barista/compiler.rb
121
- - lib/barista/compilers.rb
122
- - lib/barista/compilers/base.rb
123
- - lib/barista/compilers/native.rb
124
- - lib/barista/compilers/node.rb
112
+ - lib/barista/extensions.rb
125
113
  - lib/barista/filter.rb
126
114
  - lib/barista/framework.rb
115
+ - lib/barista/haml_filter.rb
116
+ - lib/barista/helpers.rb
127
117
  - lib/barista/hooks.rb
118
+ - lib/barista/integration.rb
119
+ - lib/barista/integration/rails2.rb
120
+ - lib/barista/integration/rails3.rb
121
+ - lib/barista/integration/sinatra.rb
122
+ - lib/barista/server.rb
128
123
  - lib/barista/tasks/barista.rake
129
124
  - lib/barista/version.rb
130
- - lib/coffee-script/coffee-script-0.9.4.js
131
125
  - lib/generators/barista/install/USAGE
132
126
  - lib/generators/barista/install/install_generator.rb
133
127
  - lib/generators/barista/install/templates/initializer.rb
@@ -139,8 +133,8 @@ homepage: http://github.com/Sutto/barista
139
133
  licenses: []
140
134
 
141
135
  post_install_message:
142
- rdoc_options:
143
- - --charset=UTF-8
136
+ rdoc_options: []
137
+
144
138
  require_paths:
145
139
  - lib
146
140
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -155,19 +149,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
149
  required_rubygems_version: !ruby/object:Gem::Requirement
156
150
  none: false
157
151
  requirements:
158
- - - ">="
152
+ - - ">"
159
153
  - !ruby/object:Gem::Version
160
- hash: 3
154
+ hash: 25
161
155
  segments:
162
- - 0
163
- version: "0"
156
+ - 1
157
+ - 3
158
+ - 1
159
+ version: 1.3.1
164
160
  requirements: []
165
161
 
166
162
  rubyforge_project:
167
163
  rubygems_version: 1.3.7
168
164
  signing_key:
169
165
  specification_version: 3
170
- summary: Transparent coffeescript support for rails 3.
166
+ summary: Simple, transparent coffeescript integration for Rails and Rack applications.
171
167
  test_files:
172
168
  - spec/barista_spec.rb
173
169
  - spec/spec_helper.rb