Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use helpers so we're html safe in Rails 3

  • Loading branch information...
commit bb4dd2595ae8d709192208de0875257018590e44 1 parent c4dcf60
@jnicklas authored
Showing with 11 additions and 14 deletions.
  1. +7 −8 lib/bistro_car/bundle.rb
  2. +4 −6 lib/bistro_car/helpers.rb
View
15 lib/bistro_car/bundle.rb
@@ -1,8 +1,9 @@
module BistroCar
class Bundle
- attr_reader :name
+ attr_reader :name, :view
- def initialize(name)
+ def initialize(view, name)
+ @view = view
@name = name.to_sym
end
@@ -29,17 +30,15 @@ def javascript_url
end
def render_bundled
- %(<script src="#{javascript_url}" type="text/javascript" charset="utf-8"></script>)
+ view.content_tag(:script, '', :src => javascript_url, :type => 'text/javascript', :charset => 'utf-8')
end
def render_inline
- <<-HTML
- <script type="text/javascript" charset="utf-8">
+ view.content_tag(:script, <<-JAVASCRIPT, :type => 'text/javascript', :charset => 'utf-8')
//<![CDATA[
#{to_javascript}
//]]>
- </script>
- HTML
+ JAVASCRIPT
end
def path
@@ -50,4 +49,4 @@ def path
end
end
end
-end
+end
View
10 lib/bistro_car/helpers.rb
@@ -3,20 +3,18 @@ module Helpers
def coffee_script_bundle(*bundles)
options = bundles.extract_options!
options[:mode] ||= BistroCar.mode
- [:default, *bundles].map { |name| Bundle.new(name).render(options[:mode]) }.join
+ [:default, *bundles].map { |name| Bundle.new(self, name).render(options[:mode]) }.join.try(:html_safe)
end
def coffee_script(&block)
input = realign_indentation(capture(&block))
output = CoffeeScript.compile(input)
- concat <<-HTML
- <script type="text/javascript" charset="utf-8">
+ content_tag(:script, <<-JAVASCRIPT, :type => 'text/javascript', :charset => 'utf-8')
//<![CDATA[
#{output}
//]]>
- </script>
- HTML
+ JAVASCRIPT
end
private
@@ -30,4 +28,4 @@ def realign_indentation(string)
end
end
-ActionView::Base.send(:include, BistroCar::Helpers) if defined?(ActionView::Base)
+ActionView::Base.send(:include, BistroCar::Helpers) if defined?(ActionView::Base)
Please sign in to comment.
Something went wrong with that request. Please try again.