doc/lib/doc_proxy.rb in ruby-vpi-11.1.1 vs doc/lib/doc_proxy.rb in ruby-vpi-12.0.0
- old
+ new
@@ -23,38 +23,43 @@
# Processes ERB templates to produce documentation. Templates may contain "<xref...>" tags where the ... represents the target anchor of the cross-reference.
class DocProxy < ErbProxy
Block = Struct.new :anchor, :title, :type
Heading = Struct.new :anchor, :title, :depth
+ CATEGORIES = {
+ :admonition => [:tip, :note, :important, :caution, :warning],
+
+ # formal blocks; see http://www.sagehill.net/docbookxsl/FormalTitles.html
+ :formal => [:figure, :table, :example, :equation, :procedure],
+ }
+
attr_reader :blocks, :headings, :references
def initialize
super
@blocks = Hash.new {|h,k| h[k] = []}
@headings = []
- # admonitions
- [:tip, :note, :important, :caution, :warning].each do |type|
- add_block_handler :admonition, type do |index, title, text|
- join_redcloth_elements [
- %{!<images/#{type}.png(#{type})!},
- %{p(title). #{type.to_s.capitalize}: #{title}},
- text,
- ]
- end
+ CATEGORIES[:admonition].each do |type|
+ add_block_handler :admonition, type do |index, title, text|
+ join_redcloth_elements [
+ %{!<images/#{type}.png(#{type})!},
+ %{p(title). #{type.to_s.capitalize}: #{title}},
+ text,
+ ]
end
+ end
- # formal blocks; see http://www.sagehill.net/docbookxsl/FormalTitles.html
- [:figure, :table, :example, :equation, :procedure].each do |type|
- add_block_handler :formal, type do |index, title, text|
- join_redcloth_elements [
- %{p(title). #{type.to_s.capitalize} #{index}. #{title}},
- text,
- ]
- end
+ CATEGORIES[:formal].each do |type|
+ add_block_handler :formal, type do |index, title, text|
+ join_redcloth_elements [
+ %{p(title). #{type.to_s.capitalize} #{index}. #{title}},
+ text,
+ ]
end
+ end
end
# Post-processes the given ERB template result by parsing the document structure and expanding cross-references, and returns the result.
def post_process! aResult
buffer = aResult
@@ -139,22 +144,7 @@
end
# Removes the # from a HTML anchor so that only its name is preserved.
def unanchor aAnchor
aAnchor.sub(/^#+/, '')
- end
-
- # update positions of xrefs so that they are later inserted in correct place
- def update_xrefs aSrcPos, aSrcLen, aDstLen
- # because it's a replacement, we delete the match and insert the replacement
- change = 0 - aSrcLen + aDstLen
-
- @references.select {|ref| ref.position >= aSrcPos}.each do |ref|
- ref.position += change
- end
- end
-
- def append_to_buffer aBuff, aText
- update_xrefs aBuff.length, 0, aText.length
- aBuff << aText
end
end