Class: Bunch::JadeNode
Instance Attribute Summary
Attributes inherited from AbstractNode
#options
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from FileNode
#inspect
#write_to_dir, #write_to_file
Constructor Details
#initialize(fn) ⇒ JadeNode
Returns a new instance of JadeNode.
3
4
5
6
|
# File 'lib/bunch/jade_node.rb', line 3
def initialize(fn)
JadeNode.require_jade
@filename = fn
end
|
Class Method Details
.require_jade ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'lib/bunch/jade_node.rb', line 41
def require_jade
unless @required
require 'ruby-jade'
@required = true
end
rescue LoadError
raise "'gem install ruby-jade' to compile .jade files."
end
|
Instance Method Details
#content ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/bunch/jade_node.rb', line 8
def content
@content ||= fetch(@filename) {
<<-JAVASCRIPT
(function() {
this.JST || (this.JST = {});
this.JST['#{template_name}'] = #{Jade.compile(File.read(@filename))};
})();
JAVASCRIPT
}
rescue => e
raise CompileError.new(e, @filename)
end
|
#name ⇒ Object
21
22
23
|
# File 'lib/bunch/jade_node.rb', line 21
def name
File.basename(@filename, '.jade')
end
|
#target_extension ⇒ Object
35
36
37
|
# File 'lib/bunch/jade_node.rb', line 35
def target_extension
'.js'
end
|
#template_name ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'lib/bunch/jade_node.rb', line 25
def template_name
name = @filename.sub(/\.jst\.jade/, '')
if @options[:root]
name.sub(/^#{Regexp.escape(@options[:root].to_s)}\//, '')
else
name
end
end
|