Module: Barista::Helpers

Defined in:
lib/barista/helpers.rb

Instance Method Summary collapse

Instance Method Details

#coffeescript_include_tag(*names) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/barista/helpers.rb', line 13

def coffeescript_include_tag(*names)
  check_for_helper_method! :javascript_include_tag
  if Barista.embedded_interpreter?
    output = defined?(ActiveSupport::SafeBuffer) ? ActiveSupport::SafeBuffer.new : ""
    output << coffeescript_interpreter_js
    check_for_helper_method! :content_tag
    Array(names).each do |name|
      output << "\n"
      output << (:script, '', :type => 'text/coffeescript', :src => normalise_coffeescript_path(name.to_s))
    end
    output
  else
    javascript_include_tag(*names)
  end
end

#coffeescript_interpreter_jsObject



4
5
6
7
8
9
10
11
# File 'lib/barista/helpers.rb', line 4

def coffeescript_interpreter_js
  return if defined?(@coffeescript_embedded) && @coffeescript_embedded
  check_for_helper_method! :javascript_include_tag
  @coffeescript_embedded = true
  if Barista.embedded_interpreter?
    javascript_include_tag 'coffeescript'
  end
end

#coffeescript_tag(code, html_options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/barista/helpers.rb', line 29

def coffeescript_tag(code, html_options = {})
  check_for_helper_method! :javascript_tag
  if Barista.embedded_interpreter?
    check_for_helper_method! :content_tag
    output = defined?(ActiveSupport::SafeBuffer) ? ActiveSupport::SafeBuffer.new : ""
    output << coffeescript_interpreter_js 
    embed = "\n#<![CDATA[\n#{code}\n#]]>\n"
    embed = embed.html_safe if embed.respond_to?(:html_safe)  
    output << (:script, embed, html_options.merge(:type => 'text/coffeescript'))
    output
  else
    javascript_tag Barista::Compiler.compile(code), html_options
  end
end