Class: Ritsu::Template
- Inherits:
-
Object
- Object
- Ritsu::Template
- Includes:
- BlockMixin
- Defined in:
- lib/ritsu/template.rb
Direct Known Subclasses
SrcFiles::ExecutableCmakeLists::ExecutableTemplate, SrcFiles::ProjectCmakeLists::ConfigureFileTemplate, SrcFiles::ProjectCmakeLists::CustomScriptTemplate, SrcFiles::ProjectCmakeLists::DirectoriesTemplate, SrcFiles::ProjectCmakeLists::ExternalLibrariesTemplate, SrcFiles::ProjectCmakeLists::FakeInstallTemplate, SrcFiles::ProjectCmakeLists::HeaderTemplate, SrcFiles::ProjectCmakeLists::Template, SrcFiles::ProjectConfigHeaderTemplateFile::Template, SrcFiles::SharedLibraryCmakeLists::SharedLibraryTemplate, SrcFiles::StaticLibraryCmakeLists::StaticLibraryTemplate, SrcFiles::TargetCmakeLists::CudaCompileTemplate, SrcFiles::TargetCmakeLists::CudaIncludeDirectoriesTemplate, SrcFiles::TargetCmakeLists::CustomCommandsTemplate, SrcFiles::TargetCmakeLists::DependenciesTemplate, SrcFiles::TargetCmakeLists::InstallTemplate, SrcFiles::TargetCmakeLists::LibrariesTemplate, SrcFiles::TargetCmakeLists::QtMocTemplate, SrcFiles::TargetCmakeLists::QtUiTemplate, SrcFiles::TargetCmakeLists::SourceFilesTemplate, SrcFiles::TargetCmakeLists::Template
Instance Attribute Summary
Attributes included from BlockMixin
#contents, #id, #indent_length, #indent_level, #local_indentation
Instance Method Summary collapse
- #add_content(content) ⇒ Object
- #add_template(template) ⇒ Object
-
#child_template_with_id(id) ⇒ Template
The first child template with the given ID.
-
#child_template_with_id_position(id) ⇒ Template
The position of the child template with the given ID in the contents array.
- #child_templates ⇒ Object
- #create_block(options = {}) ⇒ Object
-
#initialize(id = nil, options = {}) ⇒ Template
constructor
A new instance of Template.
- #update_block(block, options = {}) ⇒ Object
Methods included from BlockMixin
#add_line, #add_new_line, #block_structure?, #clear_contents, #indent, #initialize_block_mixin, #outdent
Constructor Details
#initialize(id = nil, options = {}) ⇒ Template
Returns a new instance of Template.
7 8 9 |
# File 'lib/ritsu/template.rb', line 7 def initialize(id = nil, = {}) initialize_block_mixin(id, ) end |
Instance Method Details
#add_content(content) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/ritsu/template.rb', line 61 def add_content(content) if content.kind_of?(Template) add_template(content) else add_line_or_other_content(content) end end |
#add_template(template) ⇒ Object
57 58 59 |
# File 'lib/ritsu/template.rb', line 57 def add_template(template) add_block_structure(template) end |
#child_template_with_id(id) ⇒ Template
Returns the first child template with the given ID. nil if there is no such child template.
14 15 16 17 18 19 20 21 |
# File 'lib/ritsu/template.rb', line 14 def child_template_with_id(id) contents.each do |content| if content.kind_of?(Template) and content.id == id return content end end return nil end |
#child_template_with_id_position(id) ⇒ Template
Returns the position of the child template with the given ID in the contents array. nil if there is no such child template.
26 27 28 29 30 31 32 33 |
# File 'lib/ritsu/template.rb', line 26 def child_template_with_id_position(id) contents.length.times do |i| if contents[i].kind_of?(Template) and contents[i].id == id return i end end return nil end |
#child_templates ⇒ Object
35 36 37 |
# File 'lib/ritsu/template.rb', line 35 def child_templates contents.select {|x| x.kind_of?(Template)} end |
#create_block(options = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ritsu/template.rb', line 39 def create_block(={}) = {}.merge() [:local_indentation] = local_indentation block = Block.new(id, ) contents.each do |content| if !content.kind_of?(Template) block.contents << content else block.contents << content.create_block() end end block end |
#update_block(block, options = {}) ⇒ Object
53 54 55 |
# File 'lib/ritsu/template.rb', line 53 def update_block(block, ={}) raise NotImplementedError.new end |