dcolthorp-bistro_car 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,3 @@
1
+ === 0.1 2010-01-03
2
+
3
+ First release
data/Manifest.txt ADDED
@@ -0,0 +1,12 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ app/controllers/bistro_car/bundle_controller.rb
6
+ config/routes.rb
7
+ lib/bistro_car.rb
8
+ lib/bistro_car/bundle.rb
9
+ lib/bistro_car/helpers.rb
10
+ script/console
11
+ script/destroy
12
+ script/generate
data/README.rdoc ADDED
@@ -0,0 +1,88 @@
1
+ = BistroCar
2
+
3
+ * http://github.com/jnicklas/bistro_car
4
+
5
+ == Description:
6
+
7
+ BistroCar serves up {CoffeeScript}[http://jashkenas.github.com/coffee-script/]
8
+ from within your Rails application.
9
+
10
+ == Install:
11
+
12
+ You'll need to install {node.js}[http://nodejs.org/#download] and
13
+ {CoffeeScript}[http://jashkenas.github.com/coffee-script/#installation].
14
+
15
+ Add it as a gem dependency to you Rails application:
16
+
17
+ config.gem "bistro_car"
18
+
19
+ == Usage:
20
+
21
+ Add your CoffeeScript files to <tt>app/scripts</tt>. Then in your layout or wherever else suits you, add:
22
+
23
+ <%= coffee_script_bundle %>
24
+
25
+ This will insert automatically link to your JavaScriptified CoffeeScript files. You might find it useful, for debugging purposes, to render your CoffeeScript inline, instead of linking to external scripts, you can do that with:
26
+
27
+ <%= coffee_script_bundle :mode => :inline %>
28
+
29
+ You can set this for the entire application:
30
+
31
+ BistroCar.mode = :inline
32
+
33
+ == Secondary bundles:
34
+
35
+ You're encouraged to create only a single bundle, but sometimes you might find it useful/necessary to create multiple bundles for different parts of your application. In that case you can create a directory structure like this:
36
+
37
+ + app
38
+ + scripts
39
+ + admin
40
+ - admin.coffee
41
+ - other_admin.coffee
42
+ - application.coffee
43
+
44
+ Now you can require both bundles like this:
45
+
46
+ <%= coffee_script_bundle :admin %>
47
+
48
+ == Minification:
49
+
50
+ You can make BistroCar minify your JavaScript bundles using JSMin by setting:
51
+
52
+ BistroCar.minify = true
53
+
54
+ This is done automatically for the production environment.
55
+
56
+ == Inline CoffeeScript
57
+
58
+ You can also render CoffeeScript inline from within your erb templates like this:
59
+
60
+ <% coffee_script do %>
61
+ x: x => x * 2
62
+ y: y => y + 2
63
+ <% end %>
64
+
65
+ == License:
66
+
67
+ (The MIT License)
68
+
69
+ Copyright (c) 2010 Jonas Nicklas
70
+
71
+ Permission is hereby granted, free of charge, to any person obtaining
72
+ a copy of this software and associated documentation files (the
73
+ 'Software'), to deal in the Software without restriction, including
74
+ without limitation the rights to use, copy, modify, merge, publish,
75
+ distribute, sublicense, and/or sell copies of the Software, and to
76
+ permit persons to whom the Software is furnished to do so, subject to
77
+ the following conditions:
78
+
79
+ The above copyright notice and this permission notice shall be
80
+ included in all copies or substantial portions of the Software.
81
+
82
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
83
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
84
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
85
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
86
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
87
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
88
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ $:.unshift(File.expand_path('./lib', File.dirname(__FILE__)))
6
+ require 'bistro_car'
7
+
8
+ Hoe.plugin :newgem
9
+
10
+ Hoe.spec 'bistro_car' do
11
+ self.developer 'Jonas Nicklas', 'jonas.nicklas@gmail.com'
12
+ self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
13
+ self.rubyforge_name = self.name # TODO this is default value
14
+ self.extra_deps = [
15
+ ['jsmin','>= 1.0.1']
16
+ ]
17
+ self.version = BistroCar::VERSION
18
+ end
@@ -0,0 +1,8 @@
1
+ class BistroCar::BundleController < ActionController::Base
2
+ caches_page :show
3
+
4
+ def show
5
+ headers['Content-Type'] = "application/javascript"
6
+ render :text => BistroCar::Bundle.new(params[:bundle]).to_javascript
7
+ end
8
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,9 @@
1
+ if Rails.respond_to?(:application) # Rails 3
2
+ Rails.application.routes.draw do
3
+ match 'javascripts/bundle/:bundle.js', :to => 'bistro_car/bundle#show'
4
+ end
5
+ else # Rails 2.3
6
+ ActionController::Routing::Routes.draw do |map|
7
+ map.connect 'javascripts/bundle/:bundle.js', :controller => 'bistro_car/bundle', :action => 'show'
8
+ end
9
+ end
data/lib/bistro_car.rb ADDED
@@ -0,0 +1,28 @@
1
+ require 'jsmin'
2
+ require 'tempfile'
3
+ require 'bistro_car/bundle'
4
+ require 'bistro_car/helpers'
5
+
6
+ module BistroCar
7
+ VERSION = "0.2.0"
8
+
9
+ if defined?(Rails::Engine)
10
+ class Engine < Rails::Engine
11
+ engine_name :bistro_car
12
+ end
13
+ end
14
+
15
+ class << self
16
+ def compile(source)
17
+ file = Tempfile.new('script.coffee')
18
+ file.write(source)
19
+ file.close
20
+ %x(coffee -p #{file.path})
21
+ end
22
+
23
+ attr_accessor :mode, :minify
24
+ end
25
+ end
26
+
27
+ BistroCar.mode = :bundled
28
+ BistroCar.minify = true if defined?(Rails) and Rails.env.production?
@@ -0,0 +1,35 @@
1
+ module BistroCar
2
+ class Bundle
3
+ attr_reader :name
4
+
5
+ def initialize(name)
6
+ @name = name.to_sym
7
+ end
8
+
9
+ def file_paths
10
+ Dir.glob(path.join('*.coffee')).to_a
11
+ end
12
+
13
+ def to_javascript
14
+ minify(file_paths.map { |path| BistroCar.compile(File.read(path)) }.join)
15
+ end
16
+
17
+ def javascript_url
18
+ "/javascripts/bundle/#{name}.js"
19
+ end
20
+
21
+ private
22
+
23
+ def minify(javascript)
24
+ if BistroCar.minify then JSMin.minify(javascript) else javascript end
25
+ end
26
+
27
+ def path
28
+ if name == :default
29
+ Rails.root.join('app/scripts')
30
+ else
31
+ Rails.root.join('app/scripts', name.to_s)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,47 @@
1
+ module BistroCar
2
+ module Helpers
3
+
4
+ def coffee_script_bundle(*bundles)
5
+ options = bundles.extract_options!
6
+ options[:mode] ||= BistroCar.mode
7
+
8
+ bundles = [:default, *bundles].map do |name|
9
+ bundle = Bundle.new(name)
10
+ render_cs_bundle(bundle, options[:mode])
11
+ end.join
12
+ bundles = bundles.html_safe if bundles.respond_to?(:html_safe)
13
+ bundles
14
+ end
15
+
16
+ def coffee_script(&block)
17
+ output = BistroCar.compile(capture(&block))
18
+
19
+ concat content_tag(:script, <<-JAVASCRIPT, :type => 'text/javascript', :charset => 'utf-8')
20
+ //<![CDATA[
21
+ #{output}
22
+ //]]>
23
+ JAVASCRIPT
24
+ end
25
+
26
+ private
27
+
28
+ def render_cs_bundle(bundle, mode)
29
+ __send__("render_cs_bundle_#{mode}", bundle)
30
+ end
31
+
32
+ def render_cs_bundle_bundled(bundle)
33
+ content_tag(:script, '', :src => bundle.javascript_url, :type => 'text/javascript', :charset => 'utf-8')
34
+ end
35
+
36
+ def render_cs_bundle_inline(bundle)
37
+ content_tag(:script, <<-JAVASCRIPT.html_safe, :type => 'text/javascript', :charset => 'utf-8')
38
+ //<![CDATA[
39
+ #{bundle.to_javascript}
40
+ //]]>
41
+ JAVASCRIPT
42
+ end
43
+
44
+ end
45
+ end
46
+
47
+ ActionView::Base.send(:include, BistroCar::Helpers) if defined?(ActionView::Base)
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/bistro_car.rb'}"
9
+ puts "Loading bistro_car gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dcolthorp-bistro_car
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ version: "0.2"
9
+ platform: ruby
10
+ authors:
11
+ - Jonas Nicklas, Drew Colthorp
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2010-03-09 00:00:00 -05:00
17
+ default_executable:
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: jsmin
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ segments:
27
+ - 1
28
+ - 0
29
+ - 1
30
+ version: 1.0.1
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: rubyforge
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 2
42
+ - 0
43
+ - 3
44
+ version: 2.0.3
45
+ type: :development
46
+ version_requirements: *id002
47
+ - !ruby/object:Gem::Dependency
48
+ name: gemcutter
49
+ prerelease: false
50
+ requirement: &id003 !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ - 3
57
+ - 0
58
+ version: 0.3.0
59
+ type: :development
60
+ version_requirements: *id003
61
+ - !ruby/object:Gem::Dependency
62
+ name: hoe
63
+ prerelease: false
64
+ requirement: &id004 !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ segments:
69
+ - 2
70
+ - 5
71
+ - 0
72
+ version: 2.5.0
73
+ type: :development
74
+ version_requirements: *id004
75
+ description: |-
76
+ BistroCar serves up {CoffeeScript}[http://jashkenas.github.com/coffee-script/]
77
+ from within your Rails application.
78
+ email:
79
+ - jonas.nicklas@gmail.com
80
+ executables: []
81
+
82
+ extensions: []
83
+
84
+ extra_rdoc_files:
85
+ - History.txt
86
+ - Manifest.txt
87
+ files:
88
+ - History.txt
89
+ - Manifest.txt
90
+ - README.rdoc
91
+ - Rakefile
92
+ - app/controllers/bistro_car/bundle_controller.rb
93
+ - config/routes.rb
94
+ - lib/bistro_car.rb
95
+ - lib/bistro_car/bundle.rb
96
+ - lib/bistro_car/helpers.rb
97
+ - script/console
98
+ - script/destroy
99
+ - script/generate
100
+ has_rdoc: true
101
+ homepage: http://github.com/jnicklas/bistro_car
102
+ licenses: []
103
+
104
+ post_install_message: PostInstall.txt
105
+ rdoc_options:
106
+ - --main
107
+ - README.rdoc
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ segments:
115
+ - 0
116
+ version: "0"
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ segments:
122
+ - 0
123
+ version: "0"
124
+ requirements: []
125
+
126
+ rubyforge_project: bistro_car
127
+ rubygems_version: 1.3.6
128
+ signing_key:
129
+ specification_version: 3
130
+ summary: BistroCar serves up {CoffeeScript}[http://jashkenas.github.com/coffee-script/] from within your Rails application.
131
+ test_files: []
132
+