Class: Uv::RenderProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/ultra_pow_list/vendor/ruby1.8/uv/uv/render_processor.rb,
lib/ultra_pow_list/vendor/ruby1.9/uv/uv/render_processor.rb

Constant Summary collapse

@@score_manager =
Textpow::ScoreManager.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(render_options, line_numbers = false, headers = true, score_manager = nil) ⇒ RenderProcessor

Returns a new instance of RenderProcessor.



12
13
14
15
16
17
18
19
# File 'lib/ultra_pow_list/vendor/ruby1.8/uv/uv/render_processor.rb', line 12

def initialize render_options, line_numbers = false, headers = true, score_manager = nil
   @score_manager = score_manager || @@score_manager
   @render_options = render_options
   @options = {}
   @headers = headers
   @line_numbers = line_numbers
   @escapeHTML = true
end

Instance Attribute Details

#escapeHTMLObject

Returns the value of attribute escapeHTML.



10
11
12
# File 'lib/ultra_pow_list/vendor/ruby1.8/uv/uv/render_processor.rb', line 10

def escapeHTML
  @escapeHTML
end

#stringObject (readonly)

Returns the value of attribute string.



9
10
11
# File 'lib/ultra_pow_list/vendor/ruby1.8/uv/uv/render_processor.rb', line 9

def string
  @string
end

Instance Method Details

#close_lineObject



62
63
64
65
66
67
68
69
# File 'lib/ultra_pow_list/vendor/ruby1.8/uv/uv/render_processor.rb', line 62

def close_line
   stack = @stack[0..-1]
   while stack.size > 1
      opt = options stack
      print opt["end"] if opt
      stack.pop
   end
end

#close_tag(name, position) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/ultra_pow_list/vendor/ruby1.8/uv/uv/render_processor.rb', line 54

def close_tag name, position
   print escape(@line[@position...position].gsub(/\n|\r/, '')) if position > @position
   @position = position
   opt = options @stack
   print opt["end"] if opt
   @stack.pop
end

#end_parsing(name) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/ultra_pow_list/vendor/ruby1.8/uv/uv/render_processor.rb', line 101

def end_parsing name
   if @line
      print escape(@line[@position..-1].gsub(/\n|\r/, '')) 
      while @stack.size > 1
         opt = options @stack
         print opt["end"] if opt
         @stack.pop
      end
      print @render_options["line"]["end"]
      print "\n"
   end
#         opt = options @stack
#         print opt["end"] if opt
   @stack.pop
   print @render_options["listing"]["end"]
   print @render_options["document"]["end"] if @headers
end

#escape(string) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/ultra_pow_list/vendor/ruby1.8/uv/uv/render_processor.rb', line 36

def escape string
   if @render_options["filter"]
      @escaped = string
      @escaped = self.instance_eval( @render_options["filter"] )
      @escaped
   else
      string
   end
end

#new_line(line) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/ultra_pow_list/vendor/ruby1.8/uv/uv/render_processor.rb', line 81

def new_line line
   if @line
      print escape(@line[@position..-1].gsub(/\n|\r/, ''))
      close_line
      print @render_options["line"]["end"]
      print "\n" 
   end
   @position = 0
   @line_number += 1
   @line = line
   print @render_options["line"]["begin"]
   if @line_numbers
      print @render_options["line-numbers"]["begin"] 
      print @line_number.to_s.rjust(4).ljust(5)
      print @render_options["line-numbers"]["end"] 
      print " "
   end
   open_line
end

#open_lineObject



71
72
73
74
75
76
77
78
79
# File 'lib/ultra_pow_list/vendor/ruby1.8/uv/uv/render_processor.rb', line 71

def open_line
   stack = [@stack.first]
   clone = @stack[1..-1]
   while stack.size < @stack.size
      stack << clone.shift
      opt = options stack
      print opt["begin"] if opt
   end
end

#open_tag(name, position) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/ultra_pow_list/vendor/ruby1.8/uv/uv/render_processor.rb', line 46

def open_tag name, position
   @stack << name
   print escape(@line[@position...position].gsub(/\n|\r/, '')) if position > @position
   @position = position
   opt = options @stack
   print opt["begin"] if opt
end

#options(stack) ⇒ Object



119
120
121
122
123
124
125
126
127
128
# File 'lib/ultra_pow_list/vendor/ruby1.8/uv/uv/render_processor.rb', line 119

def options stack
   ref = stack.join ' '
   return @options[ref] if @options.has_key? ref
   
   result = @render_options['tags'].max do |a, b| 
      @score_manager.score( a['selector'], ref ) <=> @score_manager.score( b['selector'], ref )
   end
   result = nil if @score_manager.score( result['selector'], ref ) == 0
   @options[ref] = result
end


32
33
34
# File 'lib/ultra_pow_list/vendor/ruby1.8/uv/uv/render_processor.rb', line 32

def print string
   @string << string
end

#start_parsing(name) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/ultra_pow_list/vendor/ruby1.8/uv/uv/render_processor.rb', line 21

def start_parsing name
   @stack = [name]
   @string = ""
   @line = nil
   @line_number = 0
   print @render_options["document"]["begin"] if @headers
   print @render_options["listing"]["begin"]
#         opt = options @stack
#         print opt["begin"] if opt
end