Module: Haml::Filters::Coffee

Includes:
Base
Defined in:
lib/haml/filters/coffee.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#coffee_pathObject

Returns the value of attribute coffee_path.



2
3
4
# File 'lib/haml/filters/coffee.rb', line 2

def coffee_path
  @coffee_path
end

Instance Method Details

#popen_argsObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/haml/filters/coffee.rb', line 11

def popen_args
  bin, args = coffee_path.split(' ')
  if args
    args << " -sc"
  else
    args = "-sc"
  end

  [bin, args]
end

#render_with_options(text, options) ⇒ Object

Raises:

  • (SyntaxError)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/haml/filters/coffee.rb', line 21

def render_with_options(text, options)
  bin, path = popen_args
  js, error = Open3.popen3(bin, path) do |i,o,e|
    i << text
    i.close
    [o.read, e.read]
  end
  raise SyntaxError, error unless error.blank?
  <<END
<script type=#{options[:attr_wrapper]}text/javascript#{options[:attr_wrapper]}>
//<![CDATA[
  #{js}
//]]>
</script>
END
end