Module: RedCloth::Formatters::Docbook

Defined in:
lib/redcloth-formatters-docbook/formatters/docbook.rb

Constant Summary collapse

@@stack =
[]
@@footnotes =
{}
@@table_headers =
nil

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, opts) ⇒ Object (private)



368
369
370
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 368

def method_missing(method, opts)
  opts[:text] || ""
end

Class Method Details

.close_all_levels(text = "") ⇒ Object



284
285
286
287
288
289
290
291
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 284

def self.close_all_levels text = ""
  return "" if @@stack.empty?
  begin
    entry = @@stack.pop
    text += "\n#{entry[:tag]}"
  end while !@@stack.empty?
  text
end

.close_bookObject



299
300
301
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 299

def self.close_book
  self.close_all_levels + "\n</book>"
end

.open_bookObject



293
294
295
296
297
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 293

def self.open_book
  out = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  out += "<book xmlns=\"http://docbook.org/ns/docbook\" xmlns:xi=\"http://www.w3.org/2001/XInclude\" xmlns:xl=\"http://www.w3.org/1999/xlink\" version=\"5.0\">\n"
  out
end

Instance Method Details

#author(opts) ⇒ Object



28
29
30
31
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 28

def author(opts)
  first, last = opts[:text].split(" ")
  "#{"\t" * @@stack.size}<author><firstname>#{first}</firstname><surname>#{last}</surname></author>\n"
end

#b(opts) ⇒ Object Also known as: strong



212
213
214
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 212

def b(opts)
  "<emphasis role=\"bold\">#{opts[:text]}</emphasis>"
end

#bc(opts) ⇒ Object



273
274
275
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 273

def bc(opts)
  puts "middle"
end

#bc_close(opts) ⇒ Object



277
278
279
280
281
282
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 277

def bc_close(opts)
  out = "]]></programlisting>\n"
  out += "\t</example>\n"
  out += "</para>\n"
  out
end

#bc_open(opts) ⇒ Object

source



263
264
265
266
267
268
269
270
271
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 263

def bc_open(opts)
  opts[:block] = true
  options = parse_css(opts[:style])
  out = "<para>\n"
  out += "\t<example xml:id=\"#{parse_id(options[:name])}\">\n"
  out += "\t<title>#{options[:name]}</title>\n"
  out += "\t<programlisting width=\"100%\" linenumbering=\"numbered\"><![CDATA[\n"
  out
end

#bq_close(opts) ⇒ Object



258
259
260
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 258

def bq_close(opts)
  "</blockquote>\n"
end

#bq_open(opts) ⇒ Object



250
251
252
253
254
255
256
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 250

def bq_open(opts)
  opts[:block] = true
  options = parse_css(opts[:style])
  out = "<blockquote>\n"
  out += "\t<attribution>#{options[:by]}</attribution>\n" if options[:by]
  out
end

#br(opts) ⇒ Object



217
218
219
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 217

def br(opts)
  " "
end

#cite(opts) ⇒ Object



221
222
223
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 221

def cite(opts)
  "<citation xl:href=\"##{opts[:text]}\">#{opts[:text]}</citation>"
end

#code(opts) ⇒ Object



225
226
227
228
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 225

def code(opts)
  return opts[:text] if opts[:block]
  "<code>#{opts[:text]}</code>"
end


33
34
35
36
37
38
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 33

def copyright(opts)
  split = opts[:text].split(",")
  year = split.first
  holder = split.slice(1, split.length - 1).join(",").strip
  "#{"\t" * @@stack.size}<copyright><year>#{year}</year><holder>#{holder}</holder></copyright>\n"
end

#fn(opts) ⇒ Object



201
202
203
204
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 201

def fn(opts)
  @@footnotes[opts[:id]] = opts[:text]
  ""
end

#footno(opts) ⇒ Object

footnotes



196
197
198
199
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 196

def footno(opts)
  opts[:id] ||= opts[:text]
  "<footnote><para>#{@@footnotes[opts[:id]]}</para></footnote>"
end

#h0(opts) ⇒ Object

preface



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 41

def h0(opts)
  options = parse_css(opts[:style])
  reference_id = ""
  reference_id = " xml:id=\"#{options[:id]}\"" if options[:id]
  out = ""
  out += close_level("section4")
  out += close_level("section3")
  out += close_level("section2")
  out += close_level("chapter")
  out += close_level("preface")
  out += close_level("title")
  out += "#{"\t" * @@stack.size}<preface#{reference_id}>\n\n"
  out += "#{"\t" * @@stack.size}\t<title>#{opts[:text]}</title>\n"
  open_level("preface", "#{"\t" * @@stack.size}</preface>\n\n")
  out
end

#h1(opts) ⇒ Object

chapter



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 59

def h1(opts)
  options = parse_css(opts[:style])
  reference_id = ""
  reference_id = " xml:id=\"#{options[:id]}\"" if options[:id]
  out = ""
  out += close_level("section4")
  out += close_level("section3")
  out += close_level("section2")
  out += close_level("chapter")
  out += close_level("preface")
  out += close_level("title")
  out += "#{"\t" * @@stack.size}<chapter xmlns='http://docbook.org/ns/docbook' xmlns:xi='http://www.w3.org/2001/XInclude' version='5.0'#{reference_id}>\n\n"
  out += "#{"\t" * @@stack.size}\t<title>#{opts[:text]}</title>\n"
  open_level("chapter", "#{"\t" * @@stack.size}</chapter>\n\n")
  out
end

#h2(opts) ⇒ Object

section 1



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 77

def h2(opts)
  options = parse_css(opts[:style])
  reference_id = ""
  reference_id = " xml:id=\"#{options[:id]}\"" if options[:id]
  out = ""
  out += close_level("section4")
  out += close_level("section3")
  out += close_level("section2")
  out += "\n"
  out += "#{"\t" * @@stack.size}<section#{reference_id}>\n"
  out += "#{"\t" * @@stack.size}\t<title>#{opts[:text]}</title>\n"
  open_level("section2", "#{"\t" * @@stack.size}</section>\n")
  out
end

#h3(opts) ⇒ Object

section 2



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 93

def h3(opts)
  options = parse_css(opts[:style])
  reference_id = ""
  reference_id = " xml:id=\"#{options[:id]}\"" if options[:id]
  out = ""
  out += close_level("section4")
  out += close_level("section3")
  out += "\n"
  out += "#{"\t" * @@stack.size}<section#{reference_id}>\n"
  out += "#{"\t" * @@stack.size}\t<title>#{opts[:text]}</title>\n"
  open_level("section3", "#{"\t" * @@stack.size}</section>\n")
  out
end

#h4(opts) ⇒ Object

section 3



108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 108

def h4(opts)
  options = parse_css(opts[:style])
  reference_id = ""
  reference_id = " xml:id=\"#{options[:id]}\"" if options[:id]
  out = ""
  out += close_level("section4")
  out += "\n"
  out += "#{"\t" * @@stack.size}<section#{reference_id}>\n"
  out += "#{"\t" * @@stack.size}\t<title>#{opts[:text]}</title>\n"
  open_level("section4", "#{"\t" * @@stack.size}</section>\n")
  out
end

#i(opts) ⇒ Object Also known as: em

phrase



207
208
209
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 207

def i(opts)
  "<emphasis>#{opts[:text]}</emphasis>"
end

#image(opts) ⇒ Object



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 234

def image(opts)
  title = opts[:title]
  id = title.split(" ").join(".")
  options = parse_css(opts[:style])
  width = options[:width] || "100%"
  
  out = "\n"
  out += "<figure xml:id=\"#{id}\">\n"
  out += "<title>#{title}</title>\n"
  out += "<mediaobject>\n"
  out += "\t<imageobject><imagedata fileref=\"#{opts[:src]}\" format=\"PNG\" width=\"#{width}\"/></imageobject>\n"
  out += "</mediaobject>\n"
  out += "</figure>\n"
  out
end

#li_close(opts = nil) ⇒ Object



147
148
149
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 147

def li_close(opts=nil)
  "</para></listitem>#{opts[:text]}\n"
end

#li_open(opts) ⇒ Object



143
144
145
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 143

def li_open(opts)
  "#{"\t" * @@stack.size}\t<listitem><para>#{opts[:text]}"
end


230
231
232
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 230

def link(opts)
  "<link xl:href=\"#{opts[:href]}\">#{opts[:name]}</link>"
end

#ol_close(opt) ⇒ Object



139
140
141
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 139

def ol_close(opt)
  "#{"\t" * @@stack.size}</orderedlist>\n"
end

#ol_open(opt) ⇒ Object



135
136
137
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 135

def ol_open(opt)
  "\n#{"\t" * @@stack.size}<orderedlist>\n"
end

#p(opts) ⇒ Object

para



122
123
124
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 122

def p(opts)
  "#{"\t" * @@stack.size}<para>#{clean_text(opts[:text])}</para>\n"
end

#subtitle(opts) ⇒ Object



24
25
26
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 24

def subtitle(opts)
  "#{"\t" * @@stack.size}<subtitle>#{opts[:text]}</subtitle>\n"
end

#table_close(opts) ⇒ Object



166
167
168
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 166

def table_close(opts)
  "#{"\t" * @@stack.size}\t\t</tbody>\n#{"\t" * @@stack.size}\t</tgroup>\n</table>\n"
end

#table_open(opts) ⇒ Object

tables



154
155
156
157
158
159
160
161
162
163
164
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 154

def table_open(opts)
  options = parse_css(opts[:style])
  options[:align] ||= 'left'
  @@table_headers = options[:cols].to_i
  out = "\n"
  out += "#{"\t" * @@stack.size}<table frame='all'>\n"
  out += "#{"\t" * @@stack.size}\t<title>#{options[:name]}</title>\n\n"
  out += "#{"\t" * @@stack.size}\t<tgroup cols='#{options[:cols]}' align='#{options[:align]}' colsep='1' rowsep='1'>\n"
  out += "#{"\t" * @@stack.size}\t\t<thead>\n"
  out
end

#td(opts) ⇒ Object



189
190
191
192
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 189

def td(opts)
  @@table_headers -= 1 if opts[:th]
  "#{"\t" * @@stack.size}\t\t\t\t<entry>#{opts[:text].strip}</entry>\n"
end

#th(opts) ⇒ Object



170
171
172
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 170

def th(opts)
  "\t<tr#{pba(opts)}>\n"
end

#title(opts) ⇒ Object

cover



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 7

def title(opts)
  options = parse_css(opts[:style])
  reference_id = ""
  reference_id = " xml:id=\"#{options[:id]}\"" if options[:id]
  out = ""
  out += close_level("section4")
  out += close_level("section3")
  out += close_level("section2")
  out += close_level("chapter")
  out += close_level("preface")
  out += close_level("title")
  out += "\n#{"\t" * @@stack.size}<info#{reference_id}>\n"
  out += "#{"\t" * @@stack.size}\t<title>#{opts[:text]}</title>\n"
  open_level("title", "#{"\t" * @@stack.size}</info>\n\n")
  out
end

#tr_close(opts) ⇒ Object



178
179
180
181
182
183
184
185
186
187
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 178

def tr_close(opts)
  out = "#{"\t" * @@stack.size}\t\t\t</row>\n"
  
  if @@table_headers == 0
    out += "#{"\t" * @@stack.size}\t\t</thead>\n#{"\t" * @@stack.size}\t\t<tbody>\n"
    @@table_headers = nil
  end
  
  out
end

#tr_open(opts) ⇒ Object



174
175
176
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 174

def tr_open(opts)
  "#{"\t" * @@stack.size}\t\t\t<row>\n"
end

#ul_close(opt) ⇒ Object



131
132
133
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 131

def ul_close(opt)
  "#{"\t" * @@stack.size}</itemizedlist>\n"
end

#ul_open(opt) ⇒ Object

lists



127
128
129
# File 'lib/redcloth-formatters-docbook/formatters/docbook.rb', line 127

def ul_open(opt)
  "\n#{"\t" * @@stack.size}<itemizedlist>\n"
end