Class: Haml::More::CoffeeScript::NodeCompiler

Inherits:
Compiler
  • Object
show all
Defined in:
lib/haml/more/coffee_script.rb

Instance Attribute Summary collapse

Attributes inherited from Compiler

#coffee_directory, #coffee_url

Instance Method Summary collapse

Methods inherited from Compiler

#available?, available_compilers, #compile_statement, #dependencies, #files, inherited, #javascript, new, #not_available!, #urls

Constructor Details

#initialize(command = nil) ⇒ NodeCompiler

Returns a new instance of NodeCompiler.



92
93
94
95
96
# File 'lib/haml/more/coffee_script.rb', line 92

def initialize(command = nil)
  super
  @command = `which #{command || "node"}`.strip
  not_available! if @command.empty?
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



91
92
93
# File 'lib/haml/more/coffee_script.rb', line 91

def command
  @command
end

Instance Method Details

#render(text) ⇒ Object



98
99
100
101
# File 'lib/haml/more/coffee_script.rb', line 98

def render(text)
  sanitized = text.inspect.gsub("\\n", "\n").gsub("\\r", "\r")
  javascript `#{command} #{coffee_directory}/bin/coffee -p -e #{sanitized}`
end