bistro_car 0.1.1 → 0.2.0
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/README.rdoc +4 -1
- data/Rakefile +1 -2
- data/config/routes.rb +8 -2
- data/lib/bistro_car/bundle.rb +7 -25
- data/lib/bistro_car/helpers.rb +26 -12
- data/lib/bistro_car.rb +16 -3
- metadata +54 -21
data/README.rdoc
CHANGED
@@ -9,6 +9,9 @@ from within your Rails application.
|
|
9
9
|
|
10
10
|
== Install:
|
11
11
|
|
12
|
+
You'll need to install {node.js}[http://nodejs.org/#download] and
|
13
|
+
{CoffeeScript}[http://jashkenas.github.com/coffee-script/#installation].
|
14
|
+
|
12
15
|
Add it as a gem dependency to you Rails application:
|
13
16
|
|
14
17
|
config.gem "bistro_car"
|
@@ -82,4 +85,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
82
85
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
83
86
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
84
87
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
85
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
88
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
CHANGED
@@ -12,8 +12,7 @@ Hoe.spec 'bistro_car' do
|
|
12
12
|
self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
13
13
|
self.rubyforge_name = self.name # TODO this is default value
|
14
14
|
self.extra_deps = [
|
15
|
-
['coffee-script','>= 0.1.6'],
|
16
15
|
['jsmin','>= 1.0.1']
|
17
16
|
]
|
18
17
|
self.version = BistroCar::VERSION
|
19
|
-
end
|
18
|
+
end
|
data/config/routes.rb
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
-
|
2
|
-
|
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
|
3
9
|
end
|
data/lib/bistro_car/bundle.rb
CHANGED
@@ -10,38 +10,20 @@ module BistroCar
|
|
10
10
|
Dir.glob(path.join('*.coffee')).to_a
|
11
11
|
end
|
12
12
|
|
13
|
-
def render(mode)
|
14
|
-
__send__("render_#{mode}")
|
15
|
-
end
|
16
|
-
|
17
13
|
def to_javascript
|
18
|
-
minify(file_paths.map { |path|
|
14
|
+
minify(file_paths.map { |path| BistroCar.compile(File.read(path)) }.join)
|
19
15
|
end
|
20
16
|
|
21
|
-
private
|
22
|
-
|
23
|
-
def minify(javascript)
|
24
|
-
if BistroCar.minify then JSMin.minify(javascript) else javascript end
|
25
|
-
end
|
26
|
-
|
27
17
|
def javascript_url
|
28
18
|
"/javascripts/bundle/#{name}.js"
|
29
19
|
end
|
30
|
-
|
31
|
-
def render_bundled
|
32
|
-
%(<script src="#{javascript_url}" type="text/javascript" charset="utf-8"></script>)
|
33
|
-
end
|
34
20
|
|
35
|
-
|
36
|
-
<<-HTML
|
37
|
-
<script type="text/javascript" charset="utf-8">
|
38
|
-
//<![CDATA[
|
39
|
-
#{to_javascript}
|
40
|
-
//]]>
|
41
|
-
</script>
|
42
|
-
HTML
|
43
|
-
end
|
21
|
+
private
|
44
22
|
|
23
|
+
def minify(javascript)
|
24
|
+
if BistroCar.minify then JSMin.minify(javascript) else javascript end
|
25
|
+
end
|
26
|
+
|
45
27
|
def path
|
46
28
|
if name == :default
|
47
29
|
Rails.root.join('app/scripts')
|
@@ -50,4 +32,4 @@ module BistroCar
|
|
50
32
|
end
|
51
33
|
end
|
52
34
|
end
|
53
|
-
end
|
35
|
+
end
|
data/lib/bistro_car/helpers.rb
CHANGED
@@ -1,33 +1,47 @@
|
|
1
1
|
module BistroCar
|
2
2
|
module Helpers
|
3
|
+
|
3
4
|
def coffee_script_bundle(*bundles)
|
4
5
|
options = bundles.extract_options!
|
5
6
|
options[:mode] ||= BistroCar.mode
|
6
|
-
|
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
|
7
14
|
end
|
8
15
|
|
9
16
|
def coffee_script(&block)
|
10
|
-
|
11
|
-
output = CoffeeScript.compile(input)
|
17
|
+
output = BistroCar.compile(capture(&block))
|
12
18
|
|
13
|
-
concat <<-
|
14
|
-
<script type="text/javascript" charset="utf-8">
|
19
|
+
concat content_tag(:script, <<-JAVASCRIPT, :type => 'text/javascript', :charset => 'utf-8')
|
15
20
|
//<![CDATA[
|
16
21
|
#{output}
|
17
22
|
//]]>
|
18
|
-
|
19
|
-
HTML
|
23
|
+
JAVASCRIPT
|
20
24
|
end
|
21
25
|
|
22
26
|
private
|
23
27
|
|
24
|
-
def
|
25
|
-
|
26
|
-
|
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, :type => 'text/javascript', :charset => 'utf-8')
|
38
|
+
//<![CDATA[
|
39
|
+
#{bundle.to_javascript}
|
40
|
+
//]]>
|
41
|
+
JAVASCRIPT
|
28
42
|
end
|
29
43
|
|
30
44
|
end
|
31
45
|
end
|
32
46
|
|
33
|
-
ActionView::Base.send(:include, BistroCar::Helpers) if defined?(ActionView::Base)
|
47
|
+
ActionView::Base.send(:include, BistroCar::Helpers) if defined?(ActionView::Base)
|
data/lib/bistro_car.rb
CHANGED
@@ -1,15 +1,28 @@
|
|
1
|
-
require 'coffee-script'
|
2
1
|
require 'jsmin'
|
2
|
+
require 'tempfile'
|
3
3
|
require 'bistro_car/bundle'
|
4
4
|
require 'bistro_car/helpers'
|
5
5
|
|
6
6
|
module BistroCar
|
7
|
-
VERSION = "0.
|
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
|
8
14
|
|
9
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
|
+
|
10
23
|
attr_accessor :mode, :minify
|
11
24
|
end
|
12
25
|
end
|
13
26
|
|
14
27
|
BistroCar.mode = :bundled
|
15
|
-
BistroCar.minify = true if defined?(Rails) and Rails.env.production?
|
28
|
+
BistroCar.minify = true if defined?(Rails) and Rails.env.production?
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bistro_car
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Jonas Nicklas
|
@@ -9,39 +14,65 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-03-23 00:00:00 +00:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
21
|
+
name: jsmin
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 0
|
30
|
+
- 1
|
31
|
+
version: 1.0.1
|
17
32
|
type: :runtime
|
18
|
-
|
19
|
-
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rubyforge
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
20
38
|
requirements:
|
21
39
|
- - ">="
|
22
40
|
- !ruby/object:Gem::Version
|
23
|
-
|
24
|
-
|
41
|
+
segments:
|
42
|
+
- 2
|
43
|
+
- 0
|
44
|
+
- 3
|
45
|
+
version: 2.0.3
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
25
48
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
name: gemcutter
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
30
52
|
requirements:
|
31
53
|
- - ">="
|
32
54
|
- !ruby/object:Gem::Version
|
33
|
-
|
34
|
-
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
- 3
|
58
|
+
- 0
|
59
|
+
version: 0.3.0
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
35
62
|
- !ruby/object:Gem::Dependency
|
36
63
|
name: hoe
|
37
|
-
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
40
66
|
requirements:
|
41
67
|
- - ">="
|
42
68
|
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
|
69
|
+
segments:
|
70
|
+
- 2
|
71
|
+
- 5
|
72
|
+
- 0
|
73
|
+
version: 2.5.0
|
74
|
+
type: :development
|
75
|
+
version_requirements: *id004
|
45
76
|
description: |-
|
46
77
|
BistroCar serves up {CoffeeScript}[http://jashkenas.github.com/coffee-script/]
|
47
78
|
from within your Rails application.
|
@@ -81,18 +112,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
112
|
requirements:
|
82
113
|
- - ">="
|
83
114
|
- !ruby/object:Gem::Version
|
115
|
+
segments:
|
116
|
+
- 0
|
84
117
|
version: "0"
|
85
|
-
version:
|
86
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
119
|
requirements:
|
88
120
|
- - ">="
|
89
121
|
- !ruby/object:Gem::Version
|
122
|
+
segments:
|
123
|
+
- 0
|
90
124
|
version: "0"
|
91
|
-
version:
|
92
125
|
requirements: []
|
93
126
|
|
94
127
|
rubyforge_project: bistro_car
|
95
|
-
rubygems_version: 1.3.
|
128
|
+
rubygems_version: 1.3.6
|
96
129
|
signing_key:
|
97
130
|
specification_version: 3
|
98
131
|
summary: BistroCar serves up {CoffeeScript}[http://jashkenas.github.com/coffee-script/] from within your Rails application.
|