Class: Lustr::Generator
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from EvalContext
#current_gadget, #for_gadget, #init_gadget, #is_runtime?
Constructor Details
#initialize(options) ⇒ Generator
Returns a new instance of Generator.
20
21
22
23
|
# File 'lib/lustr/generator.rb', line 20
def initialize(options)
super()
@options=options
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
18
19
20
|
# File 'lib/lustr/generator.rb', line 18
def options
@options
end
|
#parse_context ⇒ Object
Returns the value of attribute parse_context.
18
19
20
|
# File 'lib/lustr/generator.rb', line 18
def parse_context
@parse_context
end
|
Instance Method Details
#create_context(name) ⇒ Object
67
68
69
70
|
# File 'lib/lustr/generator.rb', line 67
def create_context(name)
raise Exception('Lustr::Generator#create_context must be overridden!')
end
|
#create_gadget_context(name) ⇒ Object
72
73
74
|
# File 'lib/lustr/generator.rb', line 72
def create_gadget_context(name)
return create_context(name) end
|
#generate(parse_context) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/lustr/generator.rb', line 25
def generate(parse_context)
@parse_context=parse_context
parse_context.gadget_builders.each_pair do |name, builder|
if name
base=name
dir=options[:gadget_dir] || options[:dir]
ext=options[:gadget_ext] || options[:extension]
ctxt=create_gadget_context(base)
else
base=options[:default_name] || 'application'
dir=options[:dir]
ext=options[:extension]
ctxt=create_context(base)
end
builder.build_all(self).generate(ctxt)
generate_builder(builder, dir, base, ext, options, ctxt)
end
(options[:dir])
end
|
#generate_builder(builder, dir, base, ext, options, ctxt) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/lustr/generator.rb', line 48
def generate_builder(builder, dir, base, ext, options, ctxt)
FileUtils.mkdir_p(dir)
path=File::join(dir, base+ext)
File.open(path, "w") do |aFile|
aFile.puts ctxt.to_s
end
if options[:script_extension]
path=File::join(dir, '_'+base+options[:script_extension])
if !File::exists?(path)
File.open(path, "w") do |aFile|
aFile.puts ""
end
end
end
end
|
76
77
78
|
# File 'lib/lustr/generator.rb', line 76
def (dir)
end
|