Class: Overapp::TemplateFile
- Inherits:
-
Object
show all
- Includes:
- FromHash
- Defined in:
- lib/overapp/template_file.rb,
lib/overapp/template_file/params.rb,
lib/overapp/template_file/var_obj.rb,
lib/overapp/template_file/body_mod.rb
Defined Under Namespace
Classes: BodyMod, Params, VarObj
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#full_body ⇒ Object
Returns the value of attribute full_body.
4
5
6
|
# File 'lib/overapp/template_file.rb', line 4
def full_body
@full_body
end
|
Returns the value of attribute path.
4
5
6
|
# File 'lib/overapp/template_file.rb', line 4
def path
@path
end
|
Instance Method Details
#apply_body_to(base_body) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/overapp/template_file.rb', line 28
def apply_body_to(base_body)
params_obj.inject(base_body) do |new_base_body,params|
if params[:action].blank?
templated_body(params)
elsif params[:action]
body_after_action(new_base_body,params)
else
raise "bad"
end
end
end
|
40
41
42
|
# File 'lib/overapp/template_file.rb', line 40
def body
full_body
end
|
#body_after_action(base_body, params) ⇒ Object
23
24
25
26
|
# File 'lib/overapp/template_file.rb', line 23
def body_after_action(base_body,params)
body = templated_body(params)
BodyMod.transform(base_body,body,params)
end
|
#combined(base = nil) ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'lib/overapp/template_file.rb', line 44
def combined(base=nil)
b = apply_body_to(base ? base.full_body : "")
if b == :delete
nil
else
self.class.new(:path => path, :full_body => b)
end
end
|
#has_note? ⇒ Boolean
10
11
12
|
# File 'lib/overapp/template_file.rb', line 10
def has_note?
params_obj.has_note?
end
|
#templated_body(params) ⇒ Object
14
15
16
17
18
19
20
21
|
# File 'lib/overapp/template_file.rb', line 14
def templated_body(params)
body = params[:body]
if params[:template] == 'erb'
v = VarObj.new(:file => self)
body = v.render(body)
end
body
end
|
#write_to!(dir) ⇒ Object
53
54
55
56
57
58
|
# File 'lib/overapp/template_file.rb', line 53
def write_to!(dir)
raise "bad path" if path.blank?
d = File.dirname("#{dir}/#{path}")
Overapp.ec "mkdir -p #{d}", :silent => true
Overapp.file_create "#{dir}/#{path}",body
end
|