Class: Bunch::CoffeeNode

Inherits:
FileNode show all
Defined in:
lib/bunch/coffee_node.rb

Class Attribute Summary collapse

Attributes inherited from AbstractNode

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FileNode

#inspect

Methods inherited from AbstractNode

#write_to_dir, #write_to_file

Constructor Details

#initialize(fn) ⇒ CoffeeNode

Returns a new instance of CoffeeNode.



3
4
5
6
# File 'lib/bunch/coffee_node.rb', line 3

def initialize(fn)
  CoffeeNode.require_coffee
  @filename = fn
end

Class Attribute Details

.bareObject



35
36
37
# File 'lib/bunch/coffee_node.rb', line 35

def bare
  defined?(@bare) ? @bare : (@bare = false)
end

Class Method Details

.require_coffeeObject



26
27
28
29
30
31
32
33
# File 'lib/bunch/coffee_node.rb', line 26

def require_coffee
  unless @required
    require 'coffee-script'
    @required = true
  end
rescue LoadError
  raise "'gem install coffee-script' to compile .coffee files."
end

Instance Method Details

#contentObject



8
9
10
11
12
# File 'lib/bunch/coffee_node.rb', line 8

def content
  @content ||= fetch(@filename) { CoffeeScript.compile(File.read(@filename), :bare => CoffeeNode.bare) }
rescue => e
  raise CompileError.new(e, @filename)
end

#nameObject



14
15
16
# File 'lib/bunch/coffee_node.rb', line 14

def name
  File.basename(@filename, '.coffee')
end

#target_extensionObject



18
19
20
# File 'lib/bunch/coffee_node.rb', line 18

def target_extension
  '.js'
end