Class: Dyndoc::RenderProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/dyndoc/common/uv.rb

Constant Summary collapse

@@score_manager =
Textpow::ScoreManager.new

Instance Attribute Summary collapse

Class Method 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.



35
36
37
38
39
40
41
42
# File 'lib/dyndoc/common/uv.rb', line 35

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.



23
24
25
# File 'lib/dyndoc/common/uv.rb', line 23

def escapeHTML
  @escapeHTML
end

#stringObject (readonly)

Returns the value of attribute string.



22
23
24
# File 'lib/dyndoc/common/uv.rb', line 22

def string
  @string
end

Class Method Details

.load(output, style = nil, line_numbers = false, headers = false) {|processor| ... } ⇒ Object

Yields:

  • (processor)

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
32
33
# File 'lib/dyndoc/common/uv.rb', line 25

def self.load(output, style = nil, line_numbers = false, headers = false)
  style  ||= Uv.default_style
  renderer = File.join( Uv.render_path, output,"#{style}.render")
  raise( ArgumentError, "Output for #{output} in #{style} style is not yet implemented" ) unless File.exist?(renderer)
  options   = YAML.load_file(renderer)
  processor = RenderProcessor.new(options, line_numbers, headers)
  yield processor if block_given?
  processor
end

Instance Method Details

#close_lineObject



87
88
89
90
91
92
93
94
# File 'lib/dyndoc/common/uv.rb', line 87

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



79
80
81
82
83
84
85
# File 'lib/dyndoc/common/uv.rb', line 79

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



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/dyndoc/common/uv.rb', line 126

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



61
62
63
64
65
66
67
68
69
# File 'lib/dyndoc/common/uv.rb', line 61

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



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/dyndoc/common/uv.rb', line 106

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



96
97
98
99
100
101
102
103
104
# File 'lib/dyndoc/common/uv.rb', line 96

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



71
72
73
74
75
76
77
# File 'lib/dyndoc/common/uv.rb', line 71

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



144
145
146
147
148
149
150
151
152
153
# File 'lib/dyndoc/common/uv.rb', line 144

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


57
58
59
# File 'lib/dyndoc/common/uv.rb', line 57

def print string
  @string << string
end

#start_parsing(name) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/dyndoc/common/uv.rb', line 44

def start_parsing name
  @stack       = [name]
  @string      = ""
  @line        = nil
  @line_number = 0
  ## Dyndoc.warn "render_options",@render_options["listing"]
  print @render_options["document"]["begin"] if @headers
  ## FIX (01/09/2014): "begin-line-numbers" undefined for xhtml and has to replaced by "begin" 
  print (@line_numbers ? @render_options["listing"]["begin"] : @render_options["listing"]["begin-line-numbers"] || @render_options["listing"]["begin"])
  #         opt = options @stack
  #         print opt["begin"] if opt
end