rack-coffee_filter 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .DS_Store
7
+ vendor/bundle
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rack-coffee_filter.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Chris Kalafarski
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # Rack::CoffeeFilter
2
+
3
+ Watches for .coffee requests and tries to compile down to javascript. It will only try to compile HTTP 2xx responses; everything else just gets passed along. It doesn't check to see if the file is actually coffeescript because it's not your mom. It doesn't do caching. Produces bare (unwrapped) javascript by default. Do `use Rack::CoffeeFilter::Filter, false` to wrap.
4
+
5
+ You might think you want to use this gem. You could be wrong.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'rack-coffee_filter'
12
+
13
+ ## Usage
14
+
15
+
16
+ In your config.ru
17
+
18
+ use Rack::CoffeeFilter::Filter
19
+ # if you want to wrap the output in a function
20
+ # use Rack::CoffeeFilter::Filter, true
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,7 @@
1
+ require 'rack-coffee_filter/version'
2
+ require 'rack-coffee_filter/filter'
3
+
4
+ module Rack
5
+ module CoffeeFilter
6
+ end
7
+ end
@@ -0,0 +1,34 @@
1
+ require "coffee-script"
2
+
3
+ module Rack
4
+ module CoffeeFilter
5
+ class Filter
6
+ def initialize(app, wrap_js = false)
7
+ @wrap_js = wrap_js
8
+ @app = app
9
+ end
10
+
11
+ def filtered_response(env)
12
+ status, headers, response = @app.call(env)
13
+
14
+ return @app.call(env) if !(200..299).cover?(status)
15
+
16
+ response_body = ''
17
+ response.each { |part| response_body += part }
18
+
19
+ js = ::CoffeeScript.compile(response_body, { bare: !@wrap_js })
20
+
21
+ headers['Content-Length'] = js.length.to_s
22
+ headers['Content-Type'] = 'application/javascript;charset=utf-8'
23
+ headers['Cache-Control'] = 'private, max-age=0, must-revalidate'
24
+ headers['Last-Modified'] = Time.now.to_s
25
+
26
+ [200, headers, [js]]
27
+ end
28
+
29
+ def call(env)
30
+ env['PATH_INFO'].match(/\.coffee$/) ? filtered_response(env) : @app.call(env)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ module CoffeeFilter
3
+ VERSION = '0.9.0'
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rack-coffee_filter/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "rack-coffee_filter"
8
+ gem.version = Rack::CoffeeFilter::VERSION
9
+ gem.authors = ["Chris Kalafarski"]
10
+ gem.email = ["chris@farski.com"]
11
+ gem.description = %q{Makes coffeescript javascript}
12
+ gem.summary = %q{Cut down on your coffee cold turkey.}
13
+ gem.homepage = "https://github.com/farski/rack-coffee_filter"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "coffee-script"
21
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-coffee_filter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chris Kalafarski
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: coffee-script
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Makes coffeescript javascript
31
+ email:
32
+ - chris@farski.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - lib/rack-coffee_filter.rb
43
+ - lib/rack-coffee_filter/filter.rb
44
+ - lib/rack-coffee_filter/version.rb
45
+ - rack-coffee_filter.gemspec
46
+ homepage: https://github.com/farski/rack-coffee_filter
47
+ licenses: []
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 1.8.23
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Cut down on your coffee cold turkey.
70
+ test_files: []