Class: RD::RD2MANVisitor

Inherits:
RDVisitor show all
Includes:
AutoLabel, MethodParse
Defined in:
lib/rd/rd2man-lib.rb

Constant Summary collapse

SYSTEM_NAME =
"RDtool -- RD2ManVisitor"
SYSTEM_VERSION =
"$Version: "+RD::VERSION+"$"
VERSION =
Version.new_from_version_string(SYSTEM_NAME, SYSTEM_VERSION)
OUTPUT_SUFFIX =

must-have constants

"1"
INCLUDE_SUFFIX =
["1"]

Constants included from MethodParse

MethodParse::KIND2NUM

Instance Attribute Summary

Attributes inherited from OutputFormatVisitor

#filename, #include_suffix, #input_filename

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MethodParse

analize_method, kind2num, kind2str, make_method_index, make_mindex_label, str2kind, tr_method

Methods inherited from RDVisitor

#apply_to_DescListItemTerm, #apply_to_MethodListItemTerm, #prepare_labels, #refer_external

Methods inherited from OutputFormatVisitor

#apply_to_Include

Methods included from SearchFile

#search_file

Methods inherited from Visitor

define_visit_Nonterminal, define_visit_Terminal, #visit_DescListItem, #visit_MethodListItem, #visit_Reference, #visit_children

Constructor Details

#initializeRD2MANVisitor

Returns a new instance of RD2MANVisitor.



31
32
33
34
35
# File 'lib/rd/rd2man-lib.rb', line 31

def initialize
  @enumcounter = 0
  @index = {}
  @filename = nil
end

Class Method Details

.versionObject



23
24
25
# File 'lib/rd/rd2man-lib.rb', line 23

def self.version
  VERSION
end

Instance Method Details

#apply_to_Code(element, content) ⇒ Object



162
163
164
# File 'lib/rd/rd2man-lib.rb', line 162

def apply_to_Code(element, content)
  %{\\&\\fB#{content.join.sub(/\./, '\\.')}\\fP}
end

#apply_to_DescList(element, items) ⇒ Object



90
91
92
# File 'lib/rd/rd2man-lib.rb', line 90

def apply_to_DescList(element, items)
  items.map{ |i| i =~ /\n$/ ? i : i + "\n" }.join("")
end

#apply_to_DescListItem(element, term, description) ⇒ Object



107
108
109
110
111
112
113
114
# File 'lib/rd/rd2man-lib.rb', line 107

def apply_to_DescListItem(element, term, description)
  anchor = refer(element)
  if description.empty?
    ".TP\n.fi\n.B\n#{term.join(" ")}"
  else
    %[.TP\n.fi\n.B\n#{term.join(" ")}\n#{description.join("\n")}].chomp
  end
end

#apply_to_DocumentElement(element, content) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/rd/rd2man-lib.rb', line 42

def apply_to_DocumentElement(element, content)
  content = content.join
  title = guess_title
  title = title.sub(/\.rd$/i, '').upcase
  <<"EOT"
.\\" DO NOT MODIFY THIS FILE! it was generated by rd2
.TH #{title} 1 "#{Time.now.strftime '%B %Y'}"
#{content}
EOT
end

#apply_to_Emphasis(element, content) ⇒ Object



158
159
160
# File 'lib/rd/rd2man-lib.rb', line 158

def apply_to_Emphasis(element, content)
  %Q[\\fI#{content.join}\\fP]
end

#apply_to_EnumList(element, items) ⇒ Object



85
86
87
88
# File 'lib/rd/rd2man-lib.rb', line 85

def apply_to_EnumList(element, items)
  @enumcounter = 0
  items.join
end

#apply_to_EnumListItem(element, content) ⇒ Object



102
103
104
105
# File 'lib/rd/rd2man-lib.rb', line 102

def apply_to_EnumListItem(element, content)
  @enumcounter += 1
  %Q[.TP\n#{@enumcounter}.\n#{content.join("\n")}]
end

#apply_to_Footnote(element, content) ⇒ Object



215
216
217
# File 'lib/rd/rd2man-lib.rb', line 215

def apply_to_Footnote(element, content)
  ""
end

#apply_to_Headline(element, title) ⇒ Object



53
54
55
56
# File 'lib/rd/rd2man-lib.rb', line 53

def apply_to_Headline(element, title)
  title = title.join(" ")
  element.level <= 1 ? ".SH #{title}\n" : ".SS #{title}\n"
end

#apply_to_Index(element, content) ⇒ Object



174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/rd/rd2man-lib.rb', line 174

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?
    ""
  else
    num = @index[key] = @index.size
    %{\\&\\fB#{content.join.sub(/\./, '\\.')}\\fP}
  end
end

#apply_to_ItemList(element, items) ⇒ Object



79
80
81
82
83
# File 'lib/rd/rd2man-lib.rb', line 79

def apply_to_ItemList(element, items)
  items.collect! do |x| x.sub(/\n\n/, "\n") end
  items = items.join(".IP\n.B\n\\(bu\n")  # "\\(bu" -> "" ?
  ".IP\n.B\n\\(bu\n" + items
end

#apply_to_ItemListItem(element, content) ⇒ Object



98
99
100
# File 'lib/rd/rd2man-lib.rb', line 98

def apply_to_ItemListItem(element, content)
  content.map{ |c| c =~ /\n$/ ? c : c + "\n" }.join("")
end

#apply_to_Keyboard(element, content) ⇒ Object



170
171
172
# File 'lib/rd/rd2man-lib.rb', line 170

def apply_to_Keyboard(element, content)
  content.join
end

#apply_to_MethodList(element, items) ⇒ Object



94
95
96
# File 'lib/rd/rd2man-lib.rb', line 94

def apply_to_MethodList(element, items)
  items.map{ |i| i =~ /\n$/ ? i : i + "\n" }.join("")
end

#apply_to_MethodListItem(element, term, description) ⇒ Object



116
117
118
119
120
121
122
123
124
# File 'lib/rd/rd2man-lib.rb', line 116

def apply_to_MethodListItem(element, term, description)
  term = parse_method(term)  # maybe: term -> element.term
  anchor = refer(element)
  if description.empty?
    ".TP\n.fi\n.B\n#{term.join(" ")}"
  else
    %[.TP\n.fi\n.B\n#{term.join(" ")}\n#{description.join("\n")}]
  end
end

#apply_to_Reference(element, content) ⇒ Object



189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/rd/rd2man-lib.rb', line 189

def apply_to_Reference(element, content)
  case element.label
  when Reference::URL
    apply_to_RefToURL(element, content)
  when Reference::RDLabel
    if element.label.filename
      apply_to_RefToOtherFile(element, content)
    else
      apply_to_RefToElement(element, content)
    end
  end
end

#apply_to_RefToElement(element, content) ⇒ Object



202
203
204
205
# File 'lib/rd/rd2man-lib.rb', line 202

def apply_to_RefToElement(element, content)
  content = content.join
  content.sub(/^function#/, "")
end

#apply_to_RefToOtherFile(element, content) ⇒ Object



207
208
209
# File 'lib/rd/rd2man-lib.rb', line 207

def apply_to_RefToOtherFile(element, content)
  content.join
end

#apply_to_RefToURL(element, content) ⇒ Object



211
212
213
# File 'lib/rd/rd2man-lib.rb', line 211

def apply_to_RefToURL(element, content)
  content.join
end

#apply_to_String(element) ⇒ Object



223
224
225
# File 'lib/rd/rd2man-lib.rb', line 223

def apply_to_String(element)
  meta_char_escape(element)
end

#apply_to_StringElement(element) ⇒ Object



154
155
156
# File 'lib/rd/rd2man-lib.rb', line 154

def apply_to_StringElement(element)
  apply_to_String(element.content)
end

#apply_to_TextBlock(element, content) ⇒ Object

RDVisitor#apply_to_Include



60
61
62
63
64
65
66
67
68
# File 'lib/rd/rd2man-lib.rb', line 60

def apply_to_TextBlock(element, content)
  if RD::DescListItem === element.parent ||
      RD::ItemListItem === element.parent ||
      RD::EnumListItem === element.parent
    return content.join
  else
    return ".PP\n" + content.join
  end
end

#apply_to_Var(element, content) ⇒ Object



166
167
168
# File 'lib/rd/rd2man-lib.rb', line 166

def apply_to_Var(element, content)
  content.join
end

#apply_to_Verb(element) ⇒ Object



219
220
221
# File 'lib/rd/rd2man-lib.rb', line 219

def apply_to_Verb(element)
  apply_to_String(element.content)
end

#apply_to_Verbatim(element) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/rd/rd2man-lib.rb', line 70

def apply_to_Verbatim(element)
  content = []
  element.each_line do |i|
    content.push(apply_to_String(i))
  end
  # Can we use BLOCKQUOTE such like?
  %Q[.nf\n\\&    #{content.join("\\&    ")}.fi\n]
end

#visit(tree) ⇒ Object



37
38
39
40
# File 'lib/rd/rd2man-lib.rb', line 37

def visit(tree)
  prepare_labels(tree, "")
  super(tree)
end