Class: ErbPP
- Inherits:
-
Object
show all
- Defined in:
- ext/numo/narray/gen/erbln.rb,
ext/numo/narray/gen/erbpp2.rb
Direct Known Subclasses
DefAlias, DefConst, DefError, DefInclueModule, DefLib, DefMethod, DefModule, DefStruct, UndefAllocFunc, UndefMethod, UndefSingletonMethod
Defined Under Namespace
Classes: CountLnString, ERBLN
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(parent = nil, erb_base = nil, **opts, &block) ⇒ ErbPP
Returns a new instance of ErbPP.
6
7
8
9
10
11
12
13
|
# File 'ext/numo/narray/gen/erbpp2.rb', line 6
def initialize(parent=nil, erb_base=nil, **opts, &block)
@parent = parent
@children = []
@opts = opts
set erb_base: erb_base if erb_base
@parent.add_child(self) if @parent
instance_eval(&block) if block
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(_meth_id, *args, &block) ⇒ Object
49
50
51
52
53
54
55
56
|
# File 'ext/numo/narray/gen/erbpp2.rb', line 49
def method_missing(_meth_id, *args, &block)
if args.empty?
v = get(_meth_id, *args, &block)
return v if !v.nil?
end
method_missing_alias(_meth_id, *args, &block)
end
|
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
15
16
17
|
# File 'ext/numo/narray/gen/erbpp2.rb', line 15
def children
@children
end
|
#parent ⇒ Object
Returns the value of attribute parent.
16
17
18
|
# File 'ext/numo/narray/gen/erbpp2.rb', line 16
def parent
@parent
end
|
Instance Method Details
#add_child(child) ⇒ Object
18
19
20
|
# File 'ext/numo/narray/gen/erbpp2.rb', line 18
def add_child(child)
@children.push(child)
end
|
#description ⇒ Object
Also known as:
desc
39
40
41
42
43
|
# File 'ext/numo/narray/gen/erbpp2.rb', line 39
def description
if s = @opts[:description] || @opts[:desc]
s.gsub(/\@\{/,"[").gsub(/\@\}/,"]")
end
end
|
#find(name) ⇒ Object
108
109
110
|
# File 'ext/numo/narray/gen/erbpp2.rb', line 108
def find(name)
children.find{|x| x.name == name }
end
|
#find_tmpl(name) ⇒ Object
104
105
106
|
# File 'ext/numo/narray/gen/erbpp2.rb', line 104
def find_tmpl(name)
@parent.children.find{|x| x.name == name }
end
|
#get(key, *args, &block) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'ext/numo/narray/gen/erbpp2.rb', line 26
def get(key, *args, &block)
if respond_to?(key)
return send(key, *args, &block)
end
if args.empty? && block.nil? && @opts.has_key?(key)
return @opts[key]
end
if @parent
return @parent.get(key, *args, &block)
end
nil
end
|
#init_def ⇒ Object
101
102
|
# File 'ext/numo/narray/gen/erbpp2.rb', line 101
def init_def
end
|
#load_erb(base_name) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'ext/numo/narray/gen/erbpp2.rb', line 60
def load_erb(base_name)
safe_level = nil
trim_mode = '%<>'
file = base_name + get(:erb_suffix)
dirs = get(:erb_dir)
dirs = [dirs] if !dirs.kind_of?(Array)
dirs.each do |x|
Dir.glob(x).each do |dir|
path = File.join(dir,file)
if File.exist?(path)
if get(:line_number)
erb = ERBLN.new(File.read(path), path, trim_mode)
else
erb = ERB.new(File.read(path), safe_level, trim_mode)
erb.filename = path
end
return erb
end
end
end
raise "file not found: #{file.inspect} in #{dirs.inspect}"
end
|
#method_missing_alias ⇒ Object
47
|
# File 'ext/numo/narray/gen/erbpp2.rb', line 47
alias method_missing_alias method_missing
|
#result ⇒ Object
89
90
91
92
93
|
# File 'ext/numo/narray/gen/erbpp2.rb', line 89
def result
if base = @opts[:erb_base]
load_erb(base).result(binding)
end
end
|
#run ⇒ Object
83
84
85
86
87
|
# File 'ext/numo/narray/gen/erbpp2.rb', line 83
def run
if base = @opts[:erb_base]
load_erb(base).run(binding)
end
end
|
#set(**opts) ⇒ Object
22
23
24
|
# File 'ext/numo/narray/gen/erbpp2.rb', line 22
def set(**opts)
@opts.merge!(opts)
end
|
#write(output) ⇒ Object
95
96
97
98
99
|
# File 'ext/numo/narray/gen/erbpp2.rb', line 95
def write(output)
File.open(output,"wt") do |f|
f.print(result)
end
end
|