Class: Haml::More::CoffeeScript::Compiler

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

Direct Known Subclasses

ClientCompiler, JohnsonCompiler, NodeCompiler

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Compiler

Returns a new instance of Compiler.



29
30
31
32
33
# File 'lib/haml/more/coffee_script.rb', line 29

def initialize(*args)
  @available = true
  @coffee_directory = File.expand_path "../../../../vendor/coffee-script", __FILE__
  @coffee_url = "http://jashkenas.github.com/coffee-script"
end

Instance Attribute Details

#coffee_directoryObject

Returns the value of attribute coffee_directory.



11
12
13
# File 'lib/haml/more/coffee_script.rb', line 11

def coffee_directory
  @coffee_directory
end

#coffee_urlObject

Returns the value of attribute coffee_url.



11
12
13
# File 'lib/haml/more/coffee_script.rb', line 11

def coffee_url
  @coffee_url
end

Class Method Details

.available_compilersObject



13
14
15
# File 'lib/haml/more/coffee_script.rb', line 13

def self.available_compilers
  @available_compilers ||= []
end

.inherited(klass) ⇒ Object



17
18
19
# File 'lib/haml/more/coffee_script.rb', line 17

def self.inherited(klass)
  Compiler.available_compilers << klass
end

.new(*args) ⇒ Object

Raises:

  • (RuntimeError)


21
22
23
24
25
26
27
# File 'lib/haml/more/coffee_script.rb', line 21

def self.new(*args)
  return super unless self == Compiler
  available_compilers.each do |klass|
    klass.new(*args).tap { |c| return c if c.available? }
  end
  raise RuntimeError, "no compiler available (should not happen!)"
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/haml/more/coffee_script.rb', line 56

def available?
  !!@available
end

#compile_statement(text) ⇒ Object



52
53
54
# File 'lib/haml/more/coffee_script.rb', line 52

def compile_statement(text)
  "CoffeeScript.compile(#{text.inspect}, {no_wrap: true})"
end

#dependencies(prefix = nil) ⇒ Object



35
36
37
38
# File 'lib/haml/more/coffee_script.rb', line 35

def dependencies(prefix = nil)
  @dependencies ||= %w[rewriter lexer parser scope nodes coffee-script].map { |l| "lib/#{l}.js" }
  prefix ? @dependencies.map { |file| prefix / file } : @dependencies
end

#filesObject



40
41
42
# File 'lib/haml/more/coffee_script.rb', line 40

def files
  dependencies coffee_directory
end

#javascript(text) ⇒ Object



48
49
50
# File 'lib/haml/more/coffee_script.rb', line 48

def javascript(text)
  Haml::Filters::Javascript.render_with_options text, :attr_wrapper => "'"
end

#not_available!Object



60
61
62
# File 'lib/haml/more/coffee_script.rb', line 60

def not_available!
  @available = false
end

#urlsObject



44
45
46
# File 'lib/haml/more/coffee_script.rb', line 44

def urls
  dependencies coffee_url
end