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).
# File lib/review/rstbuilder.rb, line 192 def base_block(_type, lines, caption = nil) blank puts compile_inline(caption) unless caption.nil? puts lines.join("\n") blank end
# File lib/review/rstbuilder.rb, line 199 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
# File lib/review/rstbuilder.rb, line 577 def best(lines, caption = nil) base_parablock 'best', lines, caption end
# File lib/review/rstbuilder.rb, line 725 def bibpaper_bibpaper(id, caption, lines) puts ".. [#{id}] #{compile_inline(caption)} #{split_paragraph(lines).join}" end
# File lib/review/rstbuilder.rb, line 722 def bibpaper_header(id, caption) end
# File lib/review/rstbuilder.rb, line 656 def bpo(lines) base_block 'bpo', lines, nil end
# File lib/review/rstbuilder.rb, line 589 def caution(lines, caption = nil) base_parablock 'caution', lines, caption end
# File lib/review/rstbuilder.rb, line 553 def centering(lines) base_parablock 'centering', lines, nil end
# File lib/review/rstbuilder.rb, line 706 def circle_begin(_level, _label, caption) puts "・\t#{caption}" end
# File lib/review/rstbuilder.rb, line 710 def circle_end(level) end
# File lib/review/rstbuilder.rb, line 239 def cmd(lines, _caption = nil) puts '.. code-block:: bash' lines.each { |line| puts ' ' + detab(line) } end
# File lib/review/rstbuilder.rb, line 485 def column_begin(_level, _label, caption) common_column_begin('column', caption) end
# File lib/review/rstbuilder.rb, line 489 def column_end(_level) common_column_end('column') end
# File lib/review/rstbuilder.rb, line 331 def comment(lines, _comment = nil) puts lines.map { |line| " .. #{line}" }.join end
# File lib/review/rstbuilder.rb, line 473 def common_column_begin(_type, caption) blank puts ".. column:: #{compile_inline(caption)}" blank @in_role = true end
# File lib/review/rstbuilder.rb, line 480 def common_column_end(_type) @in_role = false blank end
# File lib/review/rstbuilder.rb, line 355 def compile_href(url, label) label = url if label.blank? " `#{label} <#{url}>`_ " end
# File lib/review/rstbuilder.rb, line 348 def compile_kw(word, alt) if alt then " **#{word}(#{alt.strip})** " else " **#{word}** " end end
# File lib/review/rstbuilder.rb, line 344 def compile_ruby(base, ruby) " :ruby:`#{base}`<#{ruby}>`_ " end
# File lib/review/rstbuilder.rb, line 154 def dd(lines) split_paragraph(lines).each { |paragraph| puts " #{paragraph.gsub(/\n/, '')}" } end
# File lib/review/rstbuilder.rb, line 147 def dl_begin end
# File lib/review/rstbuilder.rb, line 158 def dl_end end
# File lib/review/rstbuilder.rb, line 150 def dt(line) puts line end
# File lib/review/rstbuilder.rb, line 652 def dtp(str) # FIXME end
# File lib/review/rstbuilder.rb, line 517 def edition_begin(_level, _label, caption) common_column_begin('edition', caption) end
# File lib/review/rstbuilder.rb, line 521 def edition_end(_level) common_column_end('edition') end
# File lib/review/rstbuilder.rb, line 207 def emlist(lines, caption = nil, lang = nil) blank if caption puts caption print "\n" end lang ||= 'none' puts ".. code-block:: #{lang}" blank lines.each { |line| puts ' ' + detab(line) } blank end
# File lib/review/rstbuilder.rb, line 220 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 { |line| puts ' ' + detab(line) } blank end
# File lib/review/rstbuilder.rb, line 327 def emtable(lines, caption = nil) table(lines, nil, caption) end
# File lib/review/rstbuilder.rb, line 621 def expert(lines) base_parablock 'expert', lines, nil end
# File lib/review/rstbuilder.rb, line 50 def extname '.rst' end
# File lib/review/rstbuilder.rb, line 549 def flushright(lines) base_parablock 'flushright', lines, nil end
# File lib/review/rstbuilder.rb, line 335 def footnote(id, str) puts ".. [##{id.sub(' ', '_')}] #{compile_inline(str)}" blank end
# File lib/review/rstbuilder.rb, line 90 def headline(level, label, caption) blank if label puts ".. _#{label}:" blank end p = '=' case level when 1 then unless label puts ".. _#{@chapter.name}:" blank end puts '=' * caption.size * 2 when 2 then p = '=' when 3 then p = '-' when 4 then p = '`' when 5 then p = '~' end puts caption puts p * caption.size * 2 blank end
# File lib/review/rstbuilder.rb, line 509 def hood_begin(_level, _label, caption) common_column_begin('hood', caption) end
# File lib/review/rstbuilder.rb, line 513 def hood_end(_level) common_column_end('hood') end
# File lib/review/rstbuilder.rb, line 175 def hr puts '----' end
# File lib/review/rstbuilder.rb, line 271 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
# File lib/review/rstbuilder.rb, line 46 def image_ext 'png' end
# File lib/review/rstbuilder.rb, line 258 def image_image(id, caption, metric) chapter, id = extract_chapter_id(id) scale = metric.split('=')[1].to_f * 100 if metric puts ".. _#{id}:" blank puts ".. figure:: images/#{chapter.name}/#{id}.#{image_ext}" puts " :scale:#{scale}%" if scale blank puts " #{caption}" blank end
# File lib/review/rstbuilder.rb, line 581 def important(lines, caption = nil) base_parablock 'important', lines, caption end
# File lib/review/rstbuilder.rb, line 635 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
# File lib/review/rstbuilder.rb, line 569 def info(lines, caption = nil) base_parablock 'info', lines, caption end
# File lib/review/rstbuilder.rb, line 395 def inline_ami(str) # TODO: ami is not default role " :ami:`#{str}` " end
# File lib/review/rstbuilder.rb, line 404 def inline_b(str) " **#{str.gsub('*', '\*')}** " end
# File lib/review/rstbuilder.rb, line 437 def inline_balloon(str) %Q(\t←#{str.gsub(/@maru\[(\d+)\]/, inline_maru('\1'))}) end
# File lib/review/rstbuilder.rb, line 733 def inline_bib(id) " [#{id}]_ " end
# File lib/review/rstbuilder.rb, line 427 def inline_bou(str) # TODO: bou is not default role " :bou:`#{str}` " end
# File lib/review/rstbuilder.rb, line 672 def inline_br(_str) "\n" end
# File lib/review/rstbuilder.rb, line 680 def inline_chap(id) super end
# File lib/review/rstbuilder.rb, line 684 def inline_chapref(id) " :numref:`#{id}` " end
# File lib/review/rstbuilder.rb, line 668 def inline_code(str) " :code:`#{str}` " end
# File lib/review/rstbuilder.rb, line 445 def inline_comment(str) if @book.config['draft'] str else '' end end
# File lib/review/rstbuilder.rb, line 664 def inline_del(str) " :del:`#{str}` " end
# File lib/review/rstbuilder.rb, line 660 def inline_dtp(_str) '' end
# File lib/review/rstbuilder.rb, line 340 def inline_fn(id) " [##{id.sub(' ', '_')}]_ " end
# File lib/review/rstbuilder.rb, line 457 def inline_hd_chap(_chap, id) " :ref:`#{id}` " end
# File lib/review/rstbuilder.rb, line 391 def inline_hidx(str) " :index:`#{str}` " end
# File lib/review/rstbuilder.rb, line 377 def inline_hint(str) # TODO: hint is not default role " :hint:`#{str}` " end
# File lib/review/rstbuilder.rb, line 400 def inline_i(str) " *#{str.gsub('*', '\*')}* " end
# File lib/review/rstbuilder.rb, line 423 def inline_icon(id) " :ref:`#{id}` " end
# File lib/review/rstbuilder.rb, line 387 def inline_idx(str) " :index:`#{str}` " end
# File lib/review/rstbuilder.rb, line 254 def inline_img(id) " :numref:`#{id}` " end
# File lib/review/rstbuilder.rb, line 432 def inline_keytop(str) # TODO: keytop is not default role " :keytop:`#{str}` " end
# File lib/review/rstbuilder.rb, line 697 def inline_labelref(idref) end
# File lib/review/rstbuilder.rb, line 179 def inline_list(id) " :numref:`#{id}` " end
# File lib/review/rstbuilder.rb, line 453 def inline_m(str) " :math:`#{str}` " end
# File lib/review/rstbuilder.rb, line 382 def inline_maru(str) # TODO: maru is not default role " :maru:`#{str}` " end
# File lib/review/rstbuilder.rb, line 702 def inline_pageref(idref) " :ref:`#{idref}` " end
# File lib/review/rstbuilder.rb, line 368 def inline_raw(str) matched = str.match(/\|(.*?)\|(.*)/) if matched matched[2].gsub('\n', "\n") else str.gsub('\n', "\n") end end
# File lib/review/rstbuilder.rb, line 364 def inline_sub(str) " :subscript:`#{str}` " end
# File lib/review/rstbuilder.rb, line 360 def inline_sup(str) " :superscript:`#{str}` " end
# File lib/review/rstbuilder.rb, line 250 def inline_table(id) "表 :numref:`#{id}` " end
# File lib/review/rstbuilder.rb, line 410 def inline_tt(str) " ``#{str}`` " end
# File lib/review/rstbuilder.rb, line 692 def inline_ttibold(str) # TODO " **#{str}** " end
# File lib/review/rstbuilder.rb, line 419 def inline_u(str) " :subscript:`#{str}` " end
# File lib/review/rstbuilder.rb, line 441 def inline_uchar(str) [str.to_i(16)].pack('U') end
# File lib/review/rstbuilder.rb, line 729 def inline_warn(str) " :warn:`#{str}` " end
# File lib/review/rstbuilder.rb, line 525 def insideout_begin(_level, _label, caption) common_column_begin('insideout', caption) end
# File lib/review/rstbuilder.rb, line 529 def insideout_end(_level) common_column_end('insideout') end
# File lib/review/rstbuilder.rb, line 625 def insn(lines, caption = nil) base_block 'insn', lines, caption end
# File lib/review/rstbuilder.rb, line 647 def label(id) puts ".. _#{id}:" blank end
# File lib/review/rstbuilder.rb, line 597 def link(lines, caption = nil) base_parablock 'link', lines, caption end
# File lib/review/rstbuilder.rb, line 188 def list_body(_id, lines, _lang) lines.each { |line| puts '-' + detab(line) } end
# File lib/review/rstbuilder.rb, line 183 def list_header(id, _caption, _lang) puts ".. _#{id}:" blank end
# File lib/review/rstbuilder.rb, line 234 def listnum_body(lines, _lang) lines.each_with_index { |line, i| puts(i + 1).to_s.rjust(2) + ": #{line}" } blank end
# File lib/review/rstbuilder.rb, line 561 def memo(lines, caption = nil) base_parablock 'memo', lines, caption end
# File lib/review/rstbuilder.rb, line 713 def nofunc_text(str) str end
# File lib/review/rstbuilder.rb, line 461 def noindent # TODO end
# File lib/review/rstbuilder.rb, line 465 def nonum_begin(_level, _label, caption) puts ".. rubric: #{compile_inline(caption)}" blank end
# File lib/review/rstbuilder.rb, line 470 def nonum_end(level) end
# File lib/review/rstbuilder.rb, line 557 def note(lines, caption = nil) base_parablock 'note', lines, caption end
# File lib/review/rstbuilder.rb, line 601 def notice(lines, caption = nil) base_parablock 'notice', lines, caption end
# File lib/review/rstbuilder.rb, line 133 def ol_begin blank @ol_indent += 1 end
# File lib/review/rstbuilder.rb, line 142 def ol_end @ol_indent -= 1 blank end
# File lib/review/rstbuilder.rb, line 138 def ol_item(lines, _num) puts ' ' * (@ol_indent - 1) + "#. #{lines.join}" end
# File lib/review/rstbuilder.rb, line 161 def paragraph(lines) pre = '' pre = ' ' if @in_role == true puts pre + lines.join puts "\n" end
# File lib/review/rstbuilder.rb, line 573 def planning(lines, caption = nil) base_parablock 'planning', lines, caption end
# File lib/review/rstbuilder.rb, line 605 def point(lines, caption = nil) base_parablock 'point', lines, caption end
# File lib/review/rstbuilder.rb, line 42 def post_paragraph '' end
# File lib/review/rstbuilder.rb, line 617 def practice(lines) base_parablock 'practice', lines, nil end
# File lib/review/rstbuilder.rb, line 38 def pre_paragraph '' end
# File lib/review/rstbuilder.rb, line 244 def quote(lines) blank puts lines.map { |line| " #{line}" }.join blank end
# File lib/review/rstbuilder.rb, line 168 def read(lines) puts split_paragraph(lines).map { |line| " #{line}" }.join blank end
# File lib/review/rstbuilder.rb, line 533 def ref_begin(_level, _label, caption) common_column_begin('ref', caption) end
# File lib/review/rstbuilder.rb, line 537 def ref_end(_level) common_column_end('ref') end
# File lib/review/rstbuilder.rb, line 613 def reference(lines) base_parablock 'reference', lines, nil end
# File lib/review/rstbuilder.rb, line 86 def result @output.string end
# File lib/review/rstbuilder.rb, line 585 def security(lines, caption = nil) base_parablock 'security', lines, caption end
# File lib/review/rstbuilder.rb, line 609 def shoot(lines, caption = nil) base_parablock 'shoot', lines, caption end
# File lib/review/rstbuilder.rb, line 688 def source(lines, caption = nil, _lang = nil) base_block 'source', lines, caption end
# File lib/review/rstbuilder.rb, line 541 def sup_begin(_level, _label, caption) common_column_begin('sup', caption) end
# File lib/review/rstbuilder.rb, line 545 def sup_end(_level) common_column_end('sup') end
# File lib/review/rstbuilder.rb, line 300 def table_begin(ncols) end
# File lib/review/rstbuilder.rb, line 323 def table_end blank end
# File lib/review/rstbuilder.rb, line 289 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
# File lib/review/rstbuilder.rb, line 319 def td(str) str end
# File lib/review/rstbuilder.rb, line 593 def term(lines) base_parablock 'term', lines, nil end
# File lib/review/rstbuilder.rb, line 282 def texequation(lines) puts '.. math::' blank puts lines.map { |line| " #{line}" }.join blank end
# File lib/review/rstbuilder.rb, line 676 def text(str) str end
# File lib/review/rstbuilder.rb, line 315 def th(str) str end
# File lib/review/rstbuilder.rb, line 565 def tip(lines, caption = nil) base_parablock 'tip', lines, caption end
# File lib/review/rstbuilder.rb, line 303 def tr(rows) first = true rows.each do |row| if first puts " * - #{row}" first = false else puts " - #{row}" end end end
# File lib/review/rstbuilder.rb, line 119 def ul_begin blank @ul_indent += 1 end
# File lib/review/rstbuilder.rb, line 128 def ul_end @ul_indent -= 1 blank end
# File lib/review/rstbuilder.rb, line 124 def ul_item(lines) puts ' ' * (@ul_indent - 1) + "* #{lines.join}" end
# File lib/review/rstbuilder.rb, line 629 def warning(lines, caption = nil) base_parablock 'warning', lines, caption end
# File lib/review/rstbuilder.rb, line 501 def world_begin(_level, _label, caption) common_column_begin('world', caption) end
# File lib/review/rstbuilder.rb, line 505 def world_end(_level) common_column_end('world') end
# File lib/review/rstbuilder.rb, line 493 def xcolumn_begin(_level, _label, caption) common_column_begin('xcolumn', caption) end
# File lib/review/rstbuilder.rb, line 497 def xcolumn_end(_level) common_column_end('xcolumn') end
# File lib/review/rstbuilder.rb, line 717 def bib_label(id) " [#{id}]_ " end
# File lib/review/rstbuilder.rb, line 80 def blank @output.puts unless @blank_seen @blank_seen = true end
# File lib/review/rstbuilder.rb, line 54 def builder_init_file @section = 0 @subsection = 0 @subsubsection = 0 @subsubsubsection = 0 @blank_seen = true @sec_counter = SecCounter.new(5, @chapter) @ul_indent = 0 @ol_indent = 0 @in_role = false @in_table = false end
# File lib/review/rstbuilder.rb, line 68 def print(s) @blank_seen = false super end
# File lib/review/rstbuilder.rb, line 74 def puts(s) @blank_seen = false super end