Class: RD::RD2HTMLVisitor

### Home Classes Methods

### In Files

- lib/rd/rd2html-lib.rb

### Parent

RDVisitor

### Methods

- ::new
- ::version
- #add_foottext
- #apply_to_Code
- #apply_to_DescList
- #apply_to_DescListItem
- #apply_to_DocumentElement
- #apply_to_Emphasis
- #apply_to_EnumList
- #apply_to_EnumListItem
- #apply_to_Footnote
- #apply_to_Foottext
- #apply_to_Headline
- #apply_to_Index
- #apply_to_ItemList
- #apply_to_ItemListItem
- #apply_to_Keyboard
- #apply_to_MethodList
- #apply_to_MethodListItem
- #apply_to_RefToElement
- #apply_to_RefToOtherFile
- #apply_to_Reference_with_RDLabel
- #apply_to_Reference_with_URL
- #apply_to_String
- #apply_to_StringElement
- #apply_to_TextBlock
- #apply_to_Var
- #apply_to_Verb
- #apply_to_Verbatim
- #consist_of_one_textblock_and_sublists
- #get_footnote_num
- #hyphen_escape
- #is_this_textblock_only_one_block_of_parent_listitem?
- #is_this_textblock_only_one_block_other_than_sublists_in_parent_listitem?
- #visit

### Included Modules

- RD::MethodParse

### Files

- post-install

### Class/Module Index

Quicksearch

- RD
- RD::AutoLabel
- RD::BlockElement
- RD::Code
- RD::ComplexListItem
- RD::DescList
- RD::DescListItem
- RD::DescListItem::Term
- RD::DocumentElement
- RD::DocumentStructure
- RD::Element
- RD::ElementRelationship
- RD::Emphasis
- RD::EnumList
- RD::EnumListItem
- RD::Filter
- RD::Filter::FileInclude
- RD::Footnote
- RD::Headline
- RD::Include
- RD::Index
- RD::InlineElement
- RD::InlineIncludable
- RD::ItemList
- RD::ItemListItem
- RD::Keyboard
- RD::LabelComposable
- RD::LabeledElement
- RD::List
- RD::ListItem
- RD::ListItemComposable
- RD::MethodList
- RD::MethodListItem
- RD::MethodListItem::Term
- RD::MethodParse
- RD::NonterminalElement
- RD::NonterminalInline
- RD::OutputFormatVisitor
- RD::ParserUtility
- RD::Part
- RD::RBLFile
- RD::RBLSuite
- RD::RD2HTMLExtVisitor
- RD::RD2HTMLExtVisitor::EnableBr
- RD::RD2HTMLExtVisitor::HeadElement
- RD::RD2HTMLExtVisitor::HeadLineTitle
- RD::RD2HTMLExtVisitor::HeadlineSecno
- RD::RD2HTMLExtVisitor::NativeInline
- RD::RD2HTMLExtVisitor::RefExtension
- RD::RD2HTMLVisitor
- RD::RD2MANVisitor
- RD::RD2RDOVisitor
- RD::RD2RMIVisitor
- RD::RDElement
- RD::RDInlineParser
- RD::RDParser
- RD::RDTree
- RD::RDVisitor
- RD::Reference
- RD::Reference::Label
- RD::Reference::RDLabel
- RD::Reference::TemporaryLabel
- RD::Reference::URL
- RD::ReferenceResolver
- RD::SearchFile
- RD::StringElement
- RD::TerminalElement
- RD::TerminalInline
- RD::TextBlock
- RD::Tree
- RD::Var
- RD::Verb
- RD::Verbatim
- RD::Version
- RD::Visitor
- Array

No matching classes.

# RD::RD2HTMLVisitor

### Constants

INCLUDE_SUFFIX
METACHAR
OUTPUT_SUFFIX

  must-have constants

SYSTEM_NAME
SYSTEM_VERSION
VERSION

### Attributes

charcode[RW]
charcode=[RW]
charset[RW]
css[RW]
footnotes[R]
foottexts[R]
html_link_rel[R]
html_link_rev[R]
lang[RW]
output_rbl[RW]

output external Label file.

title[RW]
use_old_anchor[RW]

### Public Class Methods

new() click to toggle source

    # File lib/rd/rd2html-lib.rb, line 42
    def initialize
      @css = nil
      @charset = nil
      @lang = nil
      @title = nil
      @html_link_rel = {}
      @html_link_rev = {}

      @footnotes = []
      @index = {}

      #      @use_old_anchor = nil
      @use_old_anchor = true # MUST -> nil
      @output_rbl = nil
      super
    end

version() click to toggle source

    # File lib/rd/rd2html-lib.rb, line 17
    def self.version
      VERSION
    end

### Public Instance Methods

add_foottext(num, foottext) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 393
    def add_foottext(num, foottext)
      raise ArgumentError, "[BUG] footnote ##{num} isn't here." unless
        footnotes[num - 1]
      @foottexts[num - 1] = foottext
    end

apply_to_Code(element, content) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 287
    def apply_to_Code(element, content)
      %[<code>#{content.join("")}</code>]
    end

apply_to_DescList(element, items) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 230
    def apply_to_DescList(element, items)
      %[<dl>\n#{items.join("\n").chomp}\n</dl>]
    end

apply_to_DescListItem(element, term, description) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 251
    def apply_to_DescListItem(element, term, description)
      anchor = get_anchor(element.term)
      label = hyphen_escape(element.label)
      term = term.join("")
      if description.empty?
        %[<dt><a name="#{anchor}" id="#{anchor}">#{term}</a></dt>] +
        %[<!-- RDLabel: "#{label}" -->]
      else
        %[<dt><a name="#{anchor}" id="#{anchor}">#{term}</a></dt>] +
        %[<!-- RDLabel: "#{label}" -->\n] +
        %[<dd>\n#{description.join("\n").chomp}\n</dd>]
      end
    end

apply_to_DocumentElement(element, content) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 67
    def apply_to_DocumentElement(element, content)
      ret = ""
      ret << xml_decl + "\n"
      ret << doctype_decl + "\n"
      ret << html_open_tag + "\n"
      ret << html_head + "\n"
      ret << html_body(content) + "\n"
      ret << "</html>\n"
      ret
    end

apply_to_Emphasis(element, content) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 283
    def apply_to_Emphasis(element, content)
      %[<em>#{content.join("")}</em>]
    end

apply_to_EnumList(element, items) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 226
    def apply_to_EnumList(element, items)
      %[<ol>\n#{items.join("\n").chomp}\n</ol>]
    end

apply_to_EnumListItem(element, content) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 242
    def apply_to_EnumListItem(element, content)
      %[<li>#{content.join("\n").chomp}</li>]
    end

apply_to_Footnote(element, content) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 354
    def apply_to_Footnote(element, content)
      num = get_footnote_num(element)
      raise ArgumentError, "[BUG?] #{element} is not registered." unless num

      add_foottext(num, content)
      anchor = a_name("footmark", num)
      href = a_name("foottext", num)
      %<a name="#{anchor}" id="#{anchor}" | +
        %href="##{href}"><sup><small>| +
      %*#{num}</small></sup></a>|
    end

apply_to_Foottext(element, content) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 382
    def apply_to_Foottext(element, content)
      num = get_footnote_num(element)
      raise ArgumentError, "[BUG] #{element} isn't registered." unless num
      anchor = a_name("foottext", num)
      href = a_name("footmark", num)
      content = content.join("")
      %<a name="#{anchor}" id="#{anchor}" href="##{href}">|+
        %<sup><small>*#{num}</small></sup></a>| +
        %<small>#{content}</small><br />|
    end

apply_to_Headline(element, title) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 163
    def apply_to_Headline(element, title)
      anchor = get_anchor(element)
      label = hyphen_escape(element.label)
      title = title.join("")
      %[<h#{element.level}><a name="#{anchor}" id="#{anchor}">#{title}</a>] +
      %[</h#{element.level}><!-- RDLabel: "#{label}" -->]
    end

apply_to_Index(element, content) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 299
    def apply_to_Index(element, content)
      tmp = []
      element.each do |i|
        tmp.push(i) if i.is_a?(String)
      end
      key = meta_char_escape(tmp.join(""))
      if @index.has_key?(key)
        # warning?
        %[<!-- Index, but conflict -->#{content.join("")}<!-- Index end -->]
      else
        num = @index[key] = @index.size
        anchor = a_name("index", num)
        %[<a name="#{anchor}" id="#{anchor}">#{content.join("")}</a>]
      end
    end

apply_to_ItemList(element, items) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 222
    def apply_to_ItemList(element, items)
      %[<ul>\n#{items.join("\n").chomp}\n</ul>]
    end

apply_to_ItemListItem(element, content) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 238
    def apply_to_ItemListItem(element, content)
      %[<li>#{content.join("\n").chomp}</li>]
    end

apply_to_Keyboard(element, content) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 295
    def apply_to_Keyboard(element, content)
      %[<kbd>#{content.join("")}</kbd>]
    end

apply_to_MethodList(element, items) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 234
    def apply_to_MethodList(element, items)
      %[<dl>\n#{items.join("\n").chomp}\n</dl>]
    end

apply_to_MethodListItem(element, term, description) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 265
    def apply_to_MethodListItem(element, term, description)
      term = parse_method(term)  # maybe: term -> element.term
      anchor = get_anchor(element.term)
      label = hyphen_escape(element.label)
      if description.empty?
        %[<dt><a name="#{anchor}" id="#{anchor}"><code>#{term}] +
        %[</code></a></dt><!-- RDLabel: "#{label}" -->]
      else
        %[<dt><a name="#{anchor}" id="#{anchor}"><code>#{term}] +
        %[</code></a></dt><!-- RDLabel: "#{label}" -->\n] +
        %[<dd>\n#{description.join("\n")}</dd>]
      end
    end

apply_to_RefToElement(element, content) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 328
    def apply_to_RefToElement(element, content)
      content = content.join("")
      if anchor = refer(element)
        content = content.sub(/^function#/, "")
        %[<a href="\##{anchor}">#{content}</a>]
      else
        # warning?
        label = hyphen_escape(element.to_label)
        %[<!-- Reference, RDLabel "#{label}" doesn't exist -->] +
          %[<em class="label-not-found">#{content}</em><!-- Reference end -->]
        #'
      end
    end

apply_to_RefToOtherFile(element, content) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 342
    def apply_to_RefToOtherFile(element, content)
      content = content.join("")
      filename = element.label.filename.sub(/\.(rd|rb)(\.\w+)?$/, "." +
                                            OUTPUT_SUFFIX)
      anchor = refer_external(element)
      if anchor
        %[<a href="#{filename}\##{anchor}">#{content}</a>]
      else
        %[<a href="#{filename}">#{content}</a>]
      end
    end

apply_to_Reference_with_RDLabel(element, content) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 315
    def apply_to_Reference_with_RDLabel(element, content)
      if element.label.filename
        apply_to_RefToOtherFile(element, content)
      else
        apply_to_RefToElement(element, content)
      end
    end

apply_to_Reference_with_URL(element, content) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 323
    def apply_to_Reference_with_URL(element, content)
      %[<a href="#{meta_char_escape(element.label.url)}">] +
        %[#{content.join("")}</a>]
    end

apply_to_String(element) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 409
    def apply_to_String(element)
      meta_char_escape(element)
    end

apply_to_StringElement(element) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 279
    def apply_to_StringElement(element)
      apply_to_String(element.content)
    end

apply_to_TextBlock(element, content) click to toggle source

RDVisitor#apply_to_Include

    # File lib/rd/rd2html-lib.rb, line 173
    def apply_to_TextBlock(element, content)
      content = content.join("")
      if (is_this_textblock_only_one_block_of_parent_listitem?(element) or
          is_this_textblock_only_one_block_other_than_sublists_in_parent_listitem?(element))
        content.chomp
      else
        %[<p>#{content.chomp}</p>]
      end
    end

apply_to_Var(element, content) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 291
    def apply_to_Var(element, content)
      %[<var>#{content.join("")}</var>]
    end

apply_to_Verb(element) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 399
    def apply_to_Verb(element)
      content = apply_to_String(element.content)
      %[#{content}]
    end

apply_to_Verbatim(element) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 214
    def apply_to_Verbatim(element)
      content = []
      element.each_line do |i|
        content.push(apply_to_String(i))
      end
      %[<pre>#{content.join("").chomp}</pre>]
    end

consist_of_one_textblock_and_sublists(element) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 201
    def consist_of_one_textblock_and_sublists(element)
      i = 0
      element.each_child do |child|
        if i == 0
          return false unless child.is_a?(TextBlock)
        else
          return false unless child.is_a?(List)
        end
        i += 1
      end
      return true
    end

get_footnote_num(fn) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 366
    def get_footnote_num(fn)
      raise ArgumentError, "#{fn} must be Footnote." unless fn.is_a? Footnote
      i = @footnotes.index(fn)
      if i
        i + 1
      else
        nil
      end
    end

hyphen_escape(str) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 461
    def hyphen_escape(str)
      str.gsub(/--/, "&shy;&shy;")
    end

is_this_textblock_only_one_block_of_parent_listitem?(element) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 183
    def is_this_textblock_only_one_block_of_parent_listitem?(element)
      parent = element.parent
      (parent.is_a?(ItemListItem) or
       parent.is_a?(EnumListItem) or
       parent.is_a?(DescListItem) or
       parent.is_a?(MethodListItem)) and
        consist_of_one_textblock?(parent)
    end

is_this_textblock_only_one_block_other_than_sublists_in_parent_listitem?(element) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 192
    def is_this_textblock_only_one_block_other_than_sublists_in_parent_listitem?(element)
      parent = element.parent
      (parent.is_a?(ItemListItem) or
       parent.is_a?(EnumListItem) or
       parent.is_a?(DescListItem) or
       parent.is_a?(MethodListItem)) and
        consist_of_one_textblock_and_sublists(element.parent)
    end

visit(tree) click to toggle source

    # File lib/rd/rd2html-lib.rb, line 59
    def visit(tree)
      prepare_labels(tree, "label-")
      prepare_footnotes(tree)
      tmp = super(tree)
      make_rbl_file(@filename) if @output_rbl and @filename
      tmp
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.