Class: HerbTr8nTextCallNode

Inherits:
Object
  • Object
show all
Defined in:
lib/nodes/herb_tr8n_text_call_node.rb

Direct Known Subclasses

HerbErbTr8nTextCallNode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(html_start_tag = nil, tag_count = 0, tag_variable_name = nil) ⇒ HerbTr8nTextCallNode

Returns a new instance of HerbTr8nTextCallNode.



5
6
7
8
9
10
11
12
# File 'lib/nodes/herb_tr8n_text_call_node.rb', line 5

def initialize( html_start_tag = nil, tag_count = 0, tag_variable_name = nil )
  @text_values = []
  @variable_names_and_values = []
  @html_start_tag = html_start_tag
  @variable_name_being_assigned_to = tag_variable_name
  @number_of_html_nodes = tag_count
  @child_nodes = []
end

Instance Attribute Details

#variable_name_being_assigned_toObject (readonly)

Returns the value of attribute variable_name_being_assigned_to.



3
4
5
# File 'lib/nodes/herb_tr8n_text_call_node.rb', line 3

def variable_name_being_assigned_to
  @variable_name_being_assigned_to
end

Instance Method Details

#add_child(child_node) ⇒ Object



18
19
20
21
# File 'lib/nodes/herb_tr8n_text_call_node.rb', line 18

def add_child( child_node )
  @child_nodes << child_node
  @text_values << child_node
end

#add_lambda(variable_name, variable_value, lambda_call_node) ⇒ Object



23
24
25
26
27
# File 'lib/nodes/herb_tr8n_text_call_node.rb', line 23

def add_lambda( variable_name, variable_value, lambda_call_node )
  @variable_names_and_values << [variable_name, lambda_call_node.generate_lambda( variable_value )]
  @text_values << generate_block_variable( variable_name, lambda_call_node.original_text )

end

#add_pluralization(variable_name, singular, variable) ⇒ Object



34
35
36
37
# File 'lib/nodes/herb_tr8n_text_call_node.rb', line 34

def add_pluralization( variable_name, singular, variable )
  @text_values << "[#{variable_name} || #{singular}]"
  @variable_names_and_values << [variable_name, variable ]
end

#add_text(text_value_as_string) ⇒ Object



14
15
16
# File 'lib/nodes/herb_tr8n_text_call_node.rb', line 14

def add_text( text_value_as_string )
  @text_values << HerbTr8nStringNode.new( text_value_as_string )
end

#add_variable(name, value) ⇒ Object



29
30
31
32
# File 'lib/nodes/herb_tr8n_text_call_node.rb', line 29

def add_variable( name, value )
  @variable_names_and_values << [name, value]
  @text_values << "{#{name}}"
end

#being_assigned_to_variable?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/nodes/herb_tr8n_text_call_node.rb', line 40

def being_assigned_to_variable?
  !@variable_name_being_assigned_to.nil?
end

#block_variableObject



48
49
50
# File 'lib/nodes/herb_tr8n_text_call_node.rb', line 48

def block_variable
  generate_block_variable( variable_name_being_assigned_to, text_values_as_concated_string )
end

#closing_tag_for_this_node?(closing_tag) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/nodes/herb_tr8n_text_call_node.rb', line 44

def closing_tag_for_this_node?( closing_tag )
  ( !@html_start_tag.nil? && @html_start_tag.tag_name.text_value == closing_tag.tag_name.text_value )
end

#empty?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/nodes/herb_tr8n_text_call_node.rb', line 59

def empty?
  @text_values.empty? && @variable_names_and_values.empty?
end

#end_html_tag(html_end_tag) ⇒ Object



63
64
65
# File 'lib/nodes/herb_tr8n_text_call_node.rb', line 63

def end_html_tag( html_end_tag )
  @variable_names_and_values << [self.variable_name_being_assigned_to, self.variable_string( html_end_tag, @number_of_html_nodes) ]
end

#generate_block_variable(variable, text) ⇒ Object



52
53
54
55
56
57
# File 'lib/nodes/herb_tr8n_text_call_node.rb', line 52

def generate_block_variable( variable, text )
  to_return = "[#{variable}: "
  to_return += text
  to_return += "]"
  to_return    
end

#self_contained_html_node(node_name) ⇒ Object



68
69
70
# File 'lib/nodes/herb_tr8n_text_call_node.rb', line 68

def self_contained_html_node( node_name )
    @text_values << "{#{node_name}}"
end

#start_html_tag(html_start_tag) ⇒ Object



72
73
# File 'lib/nodes/herb_tr8n_text_call_node.rb', line 72

def start_html_tag( html_start_tag )
end

#text_valueObject



76
77
78
79
80
81
82
# File 'lib/nodes/herb_tr8n_text_call_node.rb', line 76

def text_value
  if( being_assigned_to_variable? )
    block_variable
  else
    tr_call
  end
end

#text_values_as_concated_stringObject



84
85
86
87
88
89
90
# File 'lib/nodes/herb_tr8n_text_call_node.rb', line 84

def text_values_as_concated_string
  to_return = ""
  @text_values.each do |text_value|
    to_return += text_value.to_s
  end
  to_return
end

#to_sObject



100
101
102
# File 'lib/nodes/herb_tr8n_text_call_node.rb', line 100

def to_s
  text_value
end

#tr_call(html_end_tag = nil, count = 0) ⇒ Object



141
142
143
144
145
146
147
148
149
# File 'lib/nodes/herb_tr8n_text_call_node.rb', line 141

def tr_call( html_end_tag = nil, count = 0 )
  to_return = ""
  unless( empty? )
    to_return += 'tr( '
    to_return += tr_text( html_end_tag, count )
    to_return += ' )'
  end
  to_return
end

#tr_text(html_end_tag = nil, count = 0) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/nodes/herb_tr8n_text_call_node.rb', line 113

def tr_text( html_end_tag = nil, count = 0 )
  to_return = "\""
  unless( empty? )
    to_return += @html_start_tag.text_value if being_assigned_to_variable?

    if( being_assigned_to_variable? )
      to_return += "{$#{count}}"
    else
      to_return += text_values_as_concated_string      
    end

    to_return += html_end_tag.text_value if being_assigned_to_variable?
    
    to_return +='"'
    
    unless( self.variables.empty? )
      to_return += ", nil, { "
      self.variables.each do |variable_name_value|
        to_return += ":#{variable_name_value.first} => (#{variable_name_value.last})"
        to_return += ", " unless variable_name_value == variables.last
      end
      to_return += " }"
    end
  end

  to_return
end

#variable_string(html_end_tag, count) ⇒ Object



104
105
106
107
108
109
110
111
# File 'lib/nodes/herb_tr8n_text_call_node.rb', line 104

def variable_string( html_end_tag, count )
  to_return = "\""
  to_return += escape_double_quotes( @html_start_tag.text_value )
  to_return += "{$#{count}}"
  to_return += html_end_tag.text_value
  to_return += "\""
  to_return
end

#variablesObject



92
93
94
95
96
97
98
# File 'lib/nodes/herb_tr8n_text_call_node.rb', line 92

def variables
  to_return = @variable_names_and_values.dup
  @child_nodes.each do |child_node|
    to_return += child_node.variables
  end
  to_return
end

#white_space(white_space_text) ⇒ Object



151
152
153
# File 'lib/nodes/herb_tr8n_text_call_node.rb', line 151

def white_space( white_space_text )
  @text_values << ( HerbTr8nStringNode.new( white_space_text ) ).to_s
end