Class: Ritsu::Template

Inherits:
Object
  • Object
show all
Includes:
BlockMixin
Defined in:
lib/ritsu/template.rb

Instance Attribute Summary

Attributes included from BlockMixin

#contents, #id, #indent_length, #indent_level, #local_indentation

Instance Method Summary collapse

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, options = {})
  initialize_block_mixin(id, options)
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.

Returns:

  • (Template)

    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.

Returns:

  • (Template)

    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_templatesObject



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(options={})
  options = {}.merge(options)
  options[:local_indentation] = local_indentation
  block = Block.new(id, options)
  contents.each do |content|
    if !content.kind_of?(Template)
      block.contents << content
    else
      block.contents << content.create_block(options)
    end
  end
  block
end

#update_block(block, options = {}) ⇒ Object

Raises:

  • (NotImplementedError)


53
54
55
# File 'lib/ritsu/template.rb', line 53

def update_block(block, options={})
  raise NotImplementedError.new
end