Class: Tr8nTextExtractor

Inherits:
BaseTextExtractor show all
Defined in:
lib/core/tr8n_text_extractor.rb

Instance Method Summary collapse

Methods inherited from BaseTextExtractor

#html_text

Constructor Details

#initializeTr8nTextExtractor

Returns a new instance of Tr8nTextExtractor.



3
4
5
6
7
8
9
10
# File 'lib/core/tr8n_text_extractor.rb', line 3

def initialize
  @current_node = nil
  @node_queue = []
  @key_store = []
  @debug = false
  @html_tag_count = 0
  @lambda_call = nil
end

Instance Method Details

#add_html_text(text_node) ⇒ Object



16
17
18
19
# File 'lib/core/tr8n_text_extractor.rb', line 16

def add_html_text( text_node )
  puts "Adding html text: #{text_node.text_value}" if @debug
  @current_node.add_text( text_node.text_value )
end

#add_non_text(non_text_node) ⇒ Object



74
75
76
77
78
79
80
81
82
83
# File 'lib/core/tr8n_text_extractor.rb', line 74

def add_non_text( non_text_node )
  puts "Adding non text" if @debug
  if( non_text_node.node_name == 'html_start_tag' )
    start_html_tag( non_text_node )
  elsif( non_text_node.node_name == 'html_end_tag' )
    end_html_tag( non_text_node )
  elsif( non_text_node.node_name == 'html_self_contained' )
    self_contained_html_node( non_text_node )
  end
end

#add_variable(variable_name, variable_value) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/core/tr8n_text_extractor.rb', line 21

def add_variable( variable_name, variable_value )
  puts "Adding variable: #{variable_name} = #{variable_value}" if @debug
  if( @lambda_call.nil? )
    @current_node.add_variable( variable_name, variable_value )
  else
    @current_node.add_lambda( variable_name, variable_value, @lambda_call )
    @lambda_call = nil
  end      
end

#completed_text_extractionObject



66
67
# File 'lib/core/tr8n_text_extractor.rb', line 66

def completed_text_extraction
end

#end_html_tag(html_end_node) ⇒ Object



94
95
96
97
98
99
100
101
# File 'lib/core/tr8n_text_extractor.rb', line 94

def end_html_tag( html_end_node )
  puts "End html tag: #{html_end_node.text_value}" if @debug
  if( !@node_queue.empty? && @current_node.closing_tag_for_this_node?( html_end_node ) )
    @current_node.end_html_tag( html_end_node )
    @current_node = @node_queue.pop
  end
  
end

#end_html_textObject



45
46
47
48
49
50
51
52
# File 'lib/core/tr8n_text_extractor.rb', line 45

def end_html_text
  puts "End HTML Text" if @debug
  to_return = @current_node
  @current_node = nil
  @html_tag_count = 0
  @key_store = []    
  [to_return]
end

#pluralize(pluralize_node, variable_name) ⇒ Object



54
55
56
57
58
59
# File 'lib/core/tr8n_text_extractor.rb', line 54

def pluralize( pluralize_node, variable_name )
   variable = pluralize_node.repetition.text_value
   singluar = pluralize_node.string_to_pluralize.text_value
   variable_name
   @current_node.add_pluralization( variable_name, singluar, variable ) 
end

#self_contained_html_node(html_self_contained_node) ⇒ Object



103
104
105
106
# File 'lib/core/tr8n_text_extractor.rb', line 103

def self_contained_html_node( html_self_contained_node )
  puts "Self contained html node" if @debug
  @current_node.self_contained_html_node( html_self_contained_node.tag_name.text_value )
end

#start_html_tag(html_start_node) ⇒ Object



85
86
87
88
89
90
91
92
# File 'lib/core/tr8n_text_extractor.rb', line 85

def start_html_tag( html_start_node )
  puts "Start html tag: #{html_start_node.text_value}" if @debug
  @node_queue.push(  @current_node )
  new_node = HerbTr8nTextCallNode.new( html_start_node, get_and_increment_tag_count, I18nKey.new( html_start_node.tag_name.text_value, @key_store ).to_s )
  new_node.start_html_tag( html_start_node )
  @current_node.add_child( new_node )
  @current_node = new_node
end

#start_html_textObject



61
62
63
64
# File 'lib/core/tr8n_text_extractor.rb', line 61

def start_html_text
  puts "Starting html text" if @debug
  @current_node = HerbErbTr8nTextCallNode.new
end

#starting_text_extractionObject

This is called when text extraction has begun



13
14
# File 'lib/core/tr8n_text_extractor.rb', line 13

def starting_text_extraction
end

#translate_method_call_text(method_to_translate) ⇒ Object



31
32
33
34
# File 'lib/core/tr8n_text_extractor.rb', line 31

def translate_method_call_text( method_to_translate )
  @lambda_call = HerbTr8nLambdaCallNode.new( method_to_translate )
  @lambda_call
end

#translate_text(text_node_to_translate) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/core/tr8n_text_extractor.rb', line 36

def translate_text( text_node_to_translate )
  puts "Translating text: #{text_node_to_translate}" if @debug
  # This should just return a node that responds to text_value
  to_return = HerbTr8nTextCallNode.new
  to_return.add_text( text_node_to_translate )
  to_return
  
end

#white_space(node) ⇒ Object



69
70
71
72
# File 'lib/core/tr8n_text_extractor.rb', line 69

def white_space( node )
  puts "Whitespace" if @debug
  @current_node.white_space( node.text_value )
end