Class: Mccloud::Template
- Inherits:
-
Object
- Object
- Mccloud::Template
- Defined in:
- lib/mccloud/template.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#bootstrap ⇒ Object
Returns the value of attribute bootstrap.
-
#env ⇒ Object
Returns the value of attribute env.
-
#erb ⇒ Object
Returns the value of attribute erb.
-
#file ⇒ Object
Returns the value of attribute file.
-
#name ⇒ Object
Returns the value of attribute name.
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
-
#comment(flag) ⇒ Object
Bindings in ERB www.stuartellis.eu/articles/erb/ Links: * Trimming whitespace in ERB blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/242656 * Appending to ERB output blog.jayfields.com/2007/01/appending-to-erb-output-from-block.html.
- #exists? ⇒ Boolean
-
#initialize(name, env) ⇒ Template
constructor
A new instance of Template.
- #path ⇒ Object
- #to_s ⇒ Object
- #to_template(vm_name = "noname") ⇒ Object
Constructor Details
#initialize(name, env) ⇒ Template
Returns a new instance of Template.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/mccloud/template.rb', line 12 def initialize(name,env) @name=name @env=env @erb=true @file=nil @params=Hash.new @author="No author specified" @bootstrap=nil end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
6 7 8 |
# File 'lib/mccloud/template.rb', line 6 def @author end |
#bootstrap ⇒ Object
Returns the value of attribute bootstrap.
7 8 9 |
# File 'lib/mccloud/template.rb', line 7 def bootstrap @bootstrap end |
#env ⇒ Object
Returns the value of attribute env.
10 11 12 |
# File 'lib/mccloud/template.rb', line 10 def env @env end |
#erb ⇒ Object
Returns the value of attribute erb.
4 5 6 |
# File 'lib/mccloud/template.rb', line 4 def erb @erb end |
#file ⇒ Object
Returns the value of attribute file.
3 4 5 |
# File 'lib/mccloud/template.rb', line 3 def file @file end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/mccloud/template.rb', line 9 def name @name end |
#params ⇒ Object
Returns the value of attribute params.
5 6 7 |
# File 'lib/mccloud/template.rb', line 5 def params @params end |
Instance Method Details
#comment(flag) ⇒ Object
Bindings in ERB www.stuartellis.eu/articles/erb/ Links:
-
Trimming whitespace in ERB
blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/242656
-
Appending to ERB output
blog.jayfields.com/2007/01/appending-to-erb-output-from-block.html
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/mccloud/template.rb', line 37 def comment(flag) cur_pos=@output.length yield new_pos=@output.length if flag # Extraxt the block block_text=@output[cur_pos..new_pos] # Remove the block @output[cur_pos..new_pos]='' # Comment the block, with leading spaces into account block_text.gsub!(/^(\s)*/,'\1# ') # Re-insert the block @output=@output.insert cur_pos, block_text end end |
#exists? ⇒ Boolean
27 28 29 |
# File 'lib/mccloud/template.rb', line 27 def exists? File.directory?(self.path) end |
#path ⇒ Object
23 24 25 |
# File 'lib/mccloud/template.rb', line 23 def path File.join(@env.config.templates.path,@name) end |
#to_s ⇒ Object
58 59 60 |
# File 'lib/mccloud/template.rb', line 58 def to_s "Template #{name}" end |
#to_template(vm_name = "noname") ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/mccloud/template.rb', line 62 def to_template(vm_name="noname") result="" filename=@file env.logger.info "Opening template file #{@file}" if File.exists?(filename) template=File.new(filename).read result=ERB.new(template,nil,"-","@output").result(binding) end return result end |