Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move helper stuff out of bundle

  • Loading branch information...
commit 719e20148393070bbcba2bd0d0eb899d9b850eb2 1 parent 61da444
@jnicklas authored
Showing with 30 additions and 24 deletions.
  1. +6 −23 lib/bistro_car/bundle.rb
  2. +24 −1 lib/bistro_car/helpers.rb
View
29 lib/bistro_car/bundle.rb
@@ -1,9 +1,8 @@
module BistroCar
class Bundle
- attr_reader :name, :view
+ attr_reader :name
- def initialize(view, name)
- @view = view
+ def initialize(name)
@name = name.to_sym
end
@@ -11,36 +10,20 @@ def file_paths
Dir.glob(path.join('*.coffee')).to_a
end
- def render(mode)
- __send__("render_#{mode}")
- end
-
def to_javascript
minify(file_paths.map { |path| BistroCar.compile(File.read(path)) }.join)
end
+ def javascript_url
+ "/javascripts/bundle/#{name}.js"
+ end
+
private
def minify(javascript)
if BistroCar.minify then JSMin.minify(javascript) else javascript end
end
- def javascript_url
- "/javascripts/bundle/#{name}.js"
- end
-
- def render_bundled
- view.content_tag(:script, '', :src => javascript_url, :type => 'text/javascript', :charset => 'utf-8')
- end
-
- def render_inline
- view.content_tag(:script, <<-JAVASCRIPT, :type => 'text/javascript', :charset => 'utf-8')
- //<![CDATA[
- #{to_javascript}
- //]]>
- JAVASCRIPT
- end
-
def path
if name == :default
Rails.root.join('app/scripts')
View
25 lib/bistro_car/helpers.rb
@@ -1,9 +1,14 @@
module BistroCar
module Helpers
+
def coffee_script_bundle(*bundles)
options = bundles.extract_options!
options[:mode] ||= BistroCar.mode
- [:default, *bundles].map { |name| Bundle.new(self, name).render(options[:mode]) }.join.try(:html_safe)
+
+ [:default, *bundles].map do |name|
+ bundle = Bundle.new(name)
+ render_cs_bundle(bundle, options[:mode])
+ end.join.try(:html_safe)
end
def coffee_script(&block)
@@ -16,6 +21,24 @@ def coffee_script(&block)
JAVASCRIPT
end
+ private
+
+ def render_cs_bundle(bundle, mode)
+ __send__("render_cs_bundle_#{mode}", bundle)
+ end
+
+ def render_cs_bundle_bundled(bundle)
+ content_tag(:script, '', :src => bundle.javascript_url, :type => 'text/javascript', :charset => 'utf-8')
+ end
+
+ def render_cs_bundle_inline(bundle)
+ content_tag(:script, <<-JAVASCRIPT, :type => 'text/javascript', :charset => 'utf-8')
+ //<![CDATA[
+ #{bundle.to_javascript}
+ //]]>
+ JAVASCRIPT
+ end
+
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.