class ReVIEW::RSTBuilder
RSTBuilder
is a builder for reStructuredText (docutils.sourceforge.net/rst.html). reStructuredText is used in Sphinx (www.sphinx-doc.org/).
If you want to use `ruby`, `del` and `column`, you sould use sphinxcontrib-textstyle package (pypi.python.org/pypi/sphinxcontrib-textstyle).
Public Instance Methods
base_block(_type, lines, caption = nil)
click to toggle source
# File lib/review/rstbuilder.rb, line 201 def base_block(_type, lines, caption = nil) blank puts compile_inline(caption) unless caption.nil? puts lines.join("\n") blank end
base_parablock(type, lines, caption = nil)
click to toggle source
# File lib/review/rstbuilder.rb, line 208 def base_parablock(type, lines, caption = nil) puts ".. #{type}::" blank puts " #{compile_inline(caption)}" unless caption.nil? puts ' ' + split_paragraph(lines).join("\n") blank end
best(lines, caption = nil)
click to toggle source
# File lib/review/rstbuilder.rb, line 633 def best(lines, caption = nil) base_parablock('best', lines, caption) end
bibpaper_bibpaper(id, caption, lines)
click to toggle source
# File lib/review/rstbuilder.rb, line 781 def bibpaper_bibpaper(id, caption, lines) puts ".. [#{id}] #{compile_inline(caption)} #{split_paragraph(lines).join}" end
bibpaper_header(id, caption)
click to toggle source
# File lib/review/rstbuilder.rb, line 778 def bibpaper_header(id, caption) end
bpo(lines)
click to toggle source
# File lib/review/rstbuilder.rb, line 712 def bpo(lines) base_block('bpo', lines, nil) end
caution(lines, caption = nil)
click to toggle source
# File lib/review/rstbuilder.rb, line 645 def caution(lines, caption = nil) base_parablock('caution', lines, caption) end
centering(lines)
click to toggle source
# File lib/review/rstbuilder.rb, line 591 def centering(lines) base_parablock('centering', lines, nil) end
circle_begin(_level, _label, caption)
click to toggle source
# File lib/review/rstbuilder.rb, line 762 def circle_begin(_level, _label, caption) puts "・\t#{caption}" end
circle_end(level)
click to toggle source
# File lib/review/rstbuilder.rb, line 766 def circle_end(level) end
cmd(lines, _caption = nil)
click to toggle source
# File lib/review/rstbuilder.rb, line 254 def cmd(lines, _caption = nil) puts '.. code-block:: bash' lines.each do |line| puts ' ' + detab(line) end end
column_begin(_level, _label, caption)
click to toggle source
# File lib/review/rstbuilder.rb, line 523 def column_begin(_level, _label, caption) common_column_begin('column', caption) end
column_end(_level)
click to toggle source
# File lib/review/rstbuilder.rb, line 527 def column_end(_level) common_column_end('column') end
comment(lines, _comment = nil)
click to toggle source
# File lib/review/rstbuilder.rb, line 358 def comment(lines, _comment = nil) puts lines.map { |line| " .. #{line}" }.join end
common_column_begin(_type, caption)
click to toggle source
# File lib/review/rstbuilder.rb, line 511 def common_column_begin(_type, caption) blank puts ".. column:: #{compile_inline(caption)}" blank @in_role = true end
common_column_end(_type)
click to toggle source
# File lib/review/rstbuilder.rb, line 518 def common_column_end(_type) @in_role = false blank end
compile_href(url, label)
click to toggle source
# File lib/review/rstbuilder.rb, line 391 def compile_href(url, label) if label.blank? label = url end " `#{label} <#{url}>`_ " end
compile_kw(word, alt)
click to toggle source
# File lib/review/rstbuilder.rb, line 383 def compile_kw(word, alt) if alt " **#{word}(#{alt.strip})** " else " **#{word}** " end end
compile_ruby(base, ruby)
click to toggle source
# File lib/review/rstbuilder.rb, line 379 def compile_ruby(base, ruby) " :ruby:`#{base}`<#{ruby}>`_ " end
dd(lines)
click to toggle source
# File lib/review/rstbuilder.rb, line 157 def dd(lines) split_paragraph(lines).each do |paragraph| puts " #{paragraph.delete("\n")}" end end
dl_begin()
click to toggle source
# File lib/review/rstbuilder.rb, line 150 def dl_begin end
dl_end()
click to toggle source
# File lib/review/rstbuilder.rb, line 163 def dl_end end
dt(line)
click to toggle source
# File lib/review/rstbuilder.rb, line 153 def dt(line) puts line end
dtp(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 708 def dtp(str) # FIXME end
edition_begin(_level, _label, caption)
click to toggle source
# File lib/review/rstbuilder.rb, line 555 def edition_begin(_level, _label, caption) common_column_begin('edition', caption) end
edition_end(_level)
click to toggle source
# File lib/review/rstbuilder.rb, line 559 def edition_end(_level) common_column_end('edition') end
emlist(lines, caption = nil, lang = nil)
click to toggle source
# File lib/review/rstbuilder.rb, line 216 def emlist(lines, caption = nil, lang = nil) blank if caption puts caption print "\n" end lang ||= 'none' puts ".. code-block:: #{lang}" blank lines.each do |line| puts ' ' + detab(line) end blank end
emlistnum(lines, caption = nil, lang = nil)
click to toggle source
# File lib/review/rstbuilder.rb, line 231 def emlistnum(lines, caption = nil, lang = nil) blank if caption puts caption print "\n" end lang ||= 'none' puts ".. code-block:: #{lang}" puts ' :linenos:' blank lines.each do |line| puts ' ' + detab(line) end blank end
emtable(lines, caption = nil)
click to toggle source
# File lib/review/rstbuilder.rb, line 354 def emtable(lines, caption = nil) table(lines, nil, caption) end
endnote_item(id)
click to toggle source
# File lib/review/rstbuilder.rb, line 375 def endnote_item(id) puts ".. [(#{@chapter.endnote(id).number})] #{compile_inline(@chapter.endnote(id).content)}" end
expert(lines)
click to toggle source
# File lib/review/rstbuilder.rb, line 677 def expert(lines) base_parablock('expert', lines, nil) end
extname()
click to toggle source
# File lib/review/rstbuilder.rb, line 52 def extname '.rst' end
flushright(lines)
click to toggle source
# File lib/review/rstbuilder.rb, line 587 def flushright(lines) base_parablock('flushright', lines, nil) end
footnote(id, str)
click to toggle source
# File lib/review/rstbuilder.rb, line 362 def footnote(id, str) puts ".. [##{id.sub(' ', '_')}] #{compile_inline(str)}" blank end
headline(level, label, caption)
click to toggle source
# File lib/review/rstbuilder.rb, line 93 def headline(level, label, caption) blank if label puts ".. _#{label}:" blank end p = '=' case level when 1 unless label puts ".. _#{@chapter.name}:" blank end puts '=' * caption.size * 2 when 2 p = '=' when 3 p = '-' when 4 p = '`' when 5 p = '~' end puts caption puts p * caption.size * 2 blank end
hood_begin(_level, _label, caption)
click to toggle source
# File lib/review/rstbuilder.rb, line 547 def hood_begin(_level, _label, caption) common_column_begin('hood', caption) end
hood_end(_level)
click to toggle source
# File lib/review/rstbuilder.rb, line 551 def hood_end(_level) common_column_end('hood') end
hr()
click to toggle source
# File lib/review/rstbuilder.rb, line 182 def hr puts '----' end
image_dummy(id, caption, lines)
click to toggle source
# File lib/review/rstbuilder.rb, line 290 def image_dummy(id, caption, lines) chapter, id = extract_chapter_id(id) puts ".. _#{id}:" blank puts ".. figure:: images/#{chapter.name}/#{id}.#{image_ext}" blank puts " #{caption}" puts " #{lines.join}" blank end
image_ext()
click to toggle source
# File lib/review/rstbuilder.rb, line 48 def image_ext 'png' end
image_image(id, caption, metric)
click to toggle source
# File lib/review/rstbuilder.rb, line 275 def image_image(id, caption, metric) chapter, id = extract_chapter_id(id) if metric scale = metric.split('=')[1].to_f * 100 end puts ".. _#{id}:" blank puts ".. figure:: images/#{chapter.name}/#{id}.#{image_ext}" puts " :scale:#{scale}%" if scale blank puts " #{caption}" blank end
important(lines, caption = nil)
click to toggle source
# File lib/review/rstbuilder.rb, line 637 def important(lines, caption = nil) base_parablock('important', lines, caption) end
indepimage(_lines, id, caption = '', _metric = nil)
click to toggle source
# File lib/review/rstbuilder.rb, line 691 def indepimage(_lines, id, caption = '', _metric = nil) chapter, id = extract_chapter_id(id) puts ".. _#{id}:" blank puts ".. figure:: images/#{chapter.name}/#{id}.#{image_ext}" blank puts " #{compile_inline(caption)}" blank end
Also aliased as: numberlessimage
info(lines, caption = nil)
click to toggle source
# File lib/review/rstbuilder.rb, line 625 def info(lines, caption = nil) base_parablock('info', lines, caption) end
inline_ami(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 433 def inline_ami(str) # TODO: ami is not default role " :ami:`#{str}` " end
inline_b(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 442 def inline_b(str) " **#{str.gsub('*', '\*')}** " end
Also aliased as: inline_strong
inline_balloon(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 475 def inline_balloon(str) %Q(\t←#{str.gsub(/@maru\[(\d+)\]/, inline_maru('\1'))}) end
inline_bib(id)
click to toggle source
# File lib/review/rstbuilder.rb, line 789 def inline_bib(id) " [#{id}]_ " end
inline_bou(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 465 def inline_bou(str) # TODO: bou is not default role " :bou:`#{str}` " end
inline_br(_str)
click to toggle source
# File lib/review/rstbuilder.rb, line 728 def inline_br(_str) "\n" end
inline_chap(id)
click to toggle source
Calls superclass method
ReVIEW::Builder#inline_chap
# File lib/review/rstbuilder.rb, line 736 def inline_chap(id) # rubocop:disable Lint/UselessMethodDefinition super end
inline_chapref(id)
click to toggle source
# File lib/review/rstbuilder.rb, line 740 def inline_chapref(id) " :numref:`#{id}` " end
inline_code(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 724 def inline_code(str) " :code:`#{str}` " end
inline_comment(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 483 def inline_comment(str) if @book.config['draft'] str else '' end end
inline_del(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 720 def inline_del(str) " :del:`#{str}` " end
inline_dtp(_str)
click to toggle source
# File lib/review/rstbuilder.rb, line 716 def inline_dtp(_str) '' end
inline_endnote(id)
click to toggle source
# File lib/review/rstbuilder.rb, line 371 def inline_endnote(id) " [(#{@chapter.endnote(id).number})]_ " end
inline_fn(id)
click to toggle source
# File lib/review/rstbuilder.rb, line 367 def inline_fn(id) " [##{id.sub(' ', '_')}]_ " end
inline_hd_chap(_chap, id)
click to toggle source
# File lib/review/rstbuilder.rb, line 495 def inline_hd_chap(_chap, id) " :ref:`#{id}` " end
inline_hidx(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 429 def inline_hidx(str) " :index:`#{str}` " end
inline_hint(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 415 def inline_hint(str) # TODO: hint is not default role " :hint:`#{str}` " end
inline_i(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 438 def inline_i(str) " *#{str.gsub('*', '\*')}* " end
inline_icon(id)
click to toggle source
# File lib/review/rstbuilder.rb, line 461 def inline_icon(id) " :ref:`#{id}` " end
inline_idx(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 425 def inline_idx(str) " :index:`#{str}` " end
inline_img(id)
click to toggle source
# File lib/review/rstbuilder.rb, line 271 def inline_img(id) " :numref:`#{id}` " end
inline_keytop(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 470 def inline_keytop(str) # TODO: keytop is not default role " :keytop:`#{str}` " end
inline_labelref(idref)
click to toggle source
# File lib/review/rstbuilder.rb, line 753 def inline_labelref(idref) end
Also aliased as: inline_ref
inline_list(id)
click to toggle source
# File lib/review/rstbuilder.rb, line 186 def inline_list(id) " :numref:`#{id}` " end
inline_m(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 491 def inline_m(str) " :math:`#{str}` " end
inline_maru(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 420 def inline_maru(str) # TODO: maru is not default role " :maru:`#{str}` " end
inline_pageref(idref)
click to toggle source
# File lib/review/rstbuilder.rb, line 758 def inline_pageref(idref) " :ref:`#{idref}` " end
inline_raw(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 406 def inline_raw(str) matched = str.match(/\|(.*?)\|(.*)/) if matched matched[2].gsub('\\n', "\n") else str.gsub('\\n', "\n") end end
inline_sub(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 402 def inline_sub(str) " :subscript:`#{str}` " end
inline_sup(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 398 def inline_sup(str) " :superscript:`#{str}` " end
inline_table(id)
click to toggle source
# File lib/review/rstbuilder.rb, line 267 def inline_table(id) "表 :numref:`#{id}` " end
inline_tt(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 448 def inline_tt(str) " ``#{str}`` " end
Also aliased as: inline_ttb, inline_tti
inline_ttibold(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 748 def inline_ttibold(str) # TODO " **#{str}** " end
inline_u(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 457 def inline_u(str) " :subscript:`#{str}` " end
inline_uchar(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 479 def inline_uchar(str) [str.to_i(16)].pack('U') end
inline_warn(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 785 def inline_warn(str) " :warn:`#{str}` " end
insideout_begin(_level, _label, caption)
click to toggle source
# File lib/review/rstbuilder.rb, line 563 def insideout_begin(_level, _label, caption) common_column_begin('insideout', caption) end
insideout_end(_level)
click to toggle source
# File lib/review/rstbuilder.rb, line 567 def insideout_end(_level) common_column_end('insideout') end
insn(lines, caption = nil)
click to toggle source
# File lib/review/rstbuilder.rb, line 681 def insn(lines, caption = nil) base_block('insn', lines, caption) end
Also aliased as: box
label(id)
click to toggle source
# File lib/review/rstbuilder.rb, line 703 def label(id) puts ".. _#{id}:" blank end
link(lines, caption = nil)
click to toggle source
# File lib/review/rstbuilder.rb, line 653 def link(lines, caption = nil) base_parablock('link', lines, caption) end
list_body(_id, lines, _lang)
click to toggle source
# File lib/review/rstbuilder.rb, line 195 def list_body(_id, lines, _lang) lines.each do |line| puts '-' + detab(line) end end
list_header(id, _caption, _lang)
click to toggle source
# File lib/review/rstbuilder.rb, line 190 def list_header(id, _caption, _lang) puts ".. _#{id}:" blank end
listnum_body(lines, _lang)
click to toggle source
# File lib/review/rstbuilder.rb, line 247 def listnum_body(lines, _lang) lines.each_with_index do |line, i| puts(i + 1).to_s.rjust(2) + ": #{line}" end blank end
memo(lines, caption = nil)
click to toggle source
# File lib/review/rstbuilder.rb, line 617 def memo(lines, caption = nil) base_parablock('memo', lines, caption) end
nofunc_text(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 769 def nofunc_text(str) str end
noindent()
click to toggle source
# File lib/review/rstbuilder.rb, line 499 def noindent # TODO end
nonum_begin(_level, _label, caption)
click to toggle source
# File lib/review/rstbuilder.rb, line 503 def nonum_begin(_level, _label, caption) puts ".. rubric: #{compile_inline(caption)}" blank end
nonum_end(level)
click to toggle source
# File lib/review/rstbuilder.rb, line 508 def nonum_end(level) end
note(lines, caption = nil)
click to toggle source
# File lib/review/rstbuilder.rb, line 613 def note(lines, caption = nil) base_parablock('note', lines, caption) end
notice(lines, caption = nil)
click to toggle source
# File lib/review/rstbuilder.rb, line 657 def notice(lines, caption = nil) base_parablock('notice', lines, caption) end
ol_begin()
click to toggle source
# File lib/review/rstbuilder.rb, line 136 def ol_begin blank @ol_indent += 1 end
ol_end()
click to toggle source
# File lib/review/rstbuilder.rb, line 145 def ol_end @ol_indent -= 1 blank end
ol_item(lines, _num)
click to toggle source
# File lib/review/rstbuilder.rb, line 141 def ol_item(lines, _num) puts (' ' * (@ol_indent - 1)) + "#. #{join_lines_to_paragraph(lines)}" end
paragraph(lines)
click to toggle source
# File lib/review/rstbuilder.rb, line 166 def paragraph(lines) pre = '' if @in_role pre = ' ' end puts pre + join_lines_to_paragraph(lines) puts "\n" end
planning(lines, caption = nil)
click to toggle source
# File lib/review/rstbuilder.rb, line 629 def planning(lines, caption = nil) base_parablock('planning', lines, caption) end
point(lines, caption = nil)
click to toggle source
# File lib/review/rstbuilder.rb, line 661 def point(lines, caption = nil) base_parablock('point', lines, caption) end
post_paragraph()
click to toggle source
# File lib/review/rstbuilder.rb, line 44 def post_paragraph '' end
practice(lines)
click to toggle source
# File lib/review/rstbuilder.rb, line 673 def practice(lines) base_parablock('practice', lines, nil) end
pre_paragraph()
click to toggle source
# File lib/review/rstbuilder.rb, line 40 def pre_paragraph '' end
quote(lines)
click to toggle source
# File lib/review/rstbuilder.rb, line 261 def quote(lines) blank puts lines.map { |line| " #{line}" }.join blank end
read(lines)
click to toggle source
# File lib/review/rstbuilder.rb, line 175 def read(lines) puts split_paragraph(lines).map { |line| " #{line}" }.join blank end
Also aliased as: lead
ref_begin(_level, _label, caption)
click to toggle source
# File lib/review/rstbuilder.rb, line 571 def ref_begin(_level, _label, caption) common_column_begin('ref', caption) end
ref_end(_level)
click to toggle source
# File lib/review/rstbuilder.rb, line 575 def ref_end(_level) common_column_end('ref') end
reference(lines)
click to toggle source
# File lib/review/rstbuilder.rb, line 669 def reference(lines) base_parablock('reference', lines, nil) end
result()
click to toggle source
# File lib/review/rstbuilder.rb, line 88 def result check_printendnotes solve_nest(@output.string) end
security(lines, caption = nil)
click to toggle source
# File lib/review/rstbuilder.rb, line 641 def security(lines, caption = nil) base_parablock('security', lines, caption) end
shoot(lines, caption = nil)
click to toggle source
# File lib/review/rstbuilder.rb, line 665 def shoot(lines, caption = nil) base_parablock('shoot', lines, caption) end
source(lines, caption = nil, _lang = nil)
click to toggle source
# File lib/review/rstbuilder.rb, line 744 def source(lines, caption = nil, _lang = nil) base_block('source', lines, caption) end
sup_begin(_level, _label, caption)
click to toggle source
# File lib/review/rstbuilder.rb, line 579 def sup_begin(_level, _label, caption) common_column_begin('sup', caption) end
sup_end(_level)
click to toggle source
# File lib/review/rstbuilder.rb, line 583 def sup_end(_level) common_column_end('sup') end
table_begin(ncols)
click to toggle source
# File lib/review/rstbuilder.rb, line 327 def table_begin(ncols) end
table_end()
click to toggle source
# File lib/review/rstbuilder.rb, line 350 def table_end blank end
table_header(id, caption)
click to toggle source
# File lib/review/rstbuilder.rb, line 316 def table_header(id, caption) unless id.nil? blank puts ".. _#{id}:" end blank puts ".. list-table:: #{compile_inline(caption)}" puts ' :header-rows: 1' blank end
td(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 346 def td(str) str end
term(lines)
click to toggle source
# File lib/review/rstbuilder.rb, line 649 def term(lines) base_parablock('term', lines, nil) end
texequation(lines, id = nil, caption = '')
click to toggle source
# File lib/review/rstbuilder.rb, line 301 def texequation(lines, id = nil, caption = '') if id puts ".. _#{id}:" end puts '.. math::' blank puts lines.map { |line| " #{line}" }.join blank if caption.present? puts " #{caption}" blank end end
text(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 732 def text(str) str end
th(str)
click to toggle source
# File lib/review/rstbuilder.rb, line 342 def th(str) str end
tip(lines, caption = nil)
click to toggle source
# File lib/review/rstbuilder.rb, line 621 def tip(lines, caption = nil) base_parablock('tip', lines, caption) end
tr(rows)
click to toggle source
# File lib/review/rstbuilder.rb, line 330 def tr(rows) first = true rows.each do |row| if first puts " * - #{row}" first = false else puts " - #{row}" end end end
ul_begin()
click to toggle source
# File lib/review/rstbuilder.rb, line 122 def ul_begin blank @ul_indent += 1 end
ul_end()
click to toggle source
# File lib/review/rstbuilder.rb, line 131 def ul_end @ul_indent -= 1 blank end
ul_item(lines)
click to toggle source
# File lib/review/rstbuilder.rb, line 127 def ul_item(lines) puts (' ' * (@ul_indent - 1)) + "* #{join_lines_to_paragraph(lines)}" end
warning(lines, caption = nil)
click to toggle source
# File lib/review/rstbuilder.rb, line 685 def warning(lines, caption = nil) base_parablock('warning', lines, caption) end
world_begin(_level, _label, caption)
click to toggle source
# File lib/review/rstbuilder.rb, line 539 def world_begin(_level, _label, caption) common_column_begin('world', caption) end
world_end(_level)
click to toggle source
# File lib/review/rstbuilder.rb, line 543 def world_end(_level) common_column_end('world') end
xcolumn_begin(_level, _label, caption)
click to toggle source
# File lib/review/rstbuilder.rb, line 531 def xcolumn_begin(_level, _label, caption) common_column_begin('xcolumn', caption) end
xcolumn_end(_level)
click to toggle source
# File lib/review/rstbuilder.rb, line 535 def xcolumn_end(_level) common_column_end('xcolumn') end
Private Instance Methods
bib_label(id)
click to toggle source
# File lib/review/rstbuilder.rb, line 773 def bib_label(id) " [#{id}]_ " end
blank()
click to toggle source
# File lib/review/rstbuilder.rb, line 82 def blank @output.puts unless @blank_seen @blank_seen = true end
builder_init_file()
click to toggle source
Calls superclass method
ReVIEW::Builder#builder_init_file
# File lib/review/rstbuilder.rb, line 56 def builder_init_file super @section = 0 @subsection = 0 @subsubsection = 0 @subsubsubsection = 0 @blank_seen = true @ul_indent = 0 @ol_indent = 0 @in_role = false @in_table = false end
print(*s)
click to toggle source
Calls superclass method
ReVIEW::Builder#print
# File lib/review/rstbuilder.rb, line 70 def print(*s) @blank_seen = false super end
puts(*s)
click to toggle source
Calls superclass method
ReVIEW::Builder#puts
# File lib/review/rstbuilder.rb, line 76 def puts(*s) @blank_seen = false super end