Class: VivlioPack::Renderer
- Inherits:
-
Redcarpet::Render::HTML
- Object
- Redcarpet::Render::HTML
- VivlioPack::Renderer
- Includes:
- Rouge::Plugins::Redcarpet
- Defined in:
- lib/vivlio_pack/renderer.rb
Instance Method Summary collapse
- #footnote_def(content, number) ⇒ Object
- #footnotes(content) ⇒ Object
- #header(c, level) ⇒ Object
- #image(link, title, alt_text) ⇒ Object
-
#initialize ⇒ Renderer
constructor
A new instance of Renderer.
- #onepoint(text) ⇒ Object
- #paragraph(text) ⇒ Object
Constructor Details
#initialize ⇒ Renderer
Returns a new instance of Renderer.
9 10 11 12 13 14 |
# File 'lib/vivlio_pack/renderer.rb', line 9 def initialize super @sec = 0 @ch = 0 @para = 0 end |
Instance Method Details
#footnote_def(content, number) ⇒ Object
84 85 86 |
# File 'lib/vivlio_pack/renderer.rb', line 84 def footnote_def(content, number) "<span class='footnote'>#{content}</span>" end |
#footnotes(content) ⇒ Object
80 81 82 |
# File 'lib/vivlio_pack/renderer.rb', line 80 def footnotes(content) content end |
#header(c, level) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/vivlio_pack/renderer.rb', line 16 def header(c, level) case level when 1 @sec += 1 @ch = 0 @para = 0 "<h1 id='sec#{@sec}'>#{c}</h1>\n\n" when 2 @ch += 1 @para = 0 "<h2 id='ch#{@sec}-#{@ch}'>#{c}</h2>\n\n" when 3 @para += 1 "<h3 id='para#{@sec}-#{@ch}-#{@para}'>#{c}</h3>\n\n" when 4 "<h4>#{c}</h4>\n\n" end end |
#image(link, title, alt_text) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/vivlio_pack/renderer.rb', line 88 def image(link, title, alt_text) name = File.basename(link, ".*") " <figure>\n <img src=\"\#{link}\" alt=\"\#{alt_text}\" />\n <figcaption id=\"\#{name}\">\#{alt_text}</figcaption>\n </figure>\n HTML\nend\n" |
#onepoint(text) ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'lib/vivlio_pack/renderer.rb', line 98 def onepoint(text) case text.strip when "[begin one-point]" return "<img src='images/onepoint_before.png' class='onepoint'>\n" when "[end one-point]" return "<img src='images/onepoint_after.png' class='onepoint'>\n" end end |
#paragraph(text) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/vivlio_pack/renderer.rb', line 35 def paragraph(text) case text.strip when "[begin dialog]" @in_dialog = true return "<div class='dialog'>\n" when "[end dialog]" @in_dialog = false return "</div>\n" when "[page break]" return "<div class='page-break'></div>\n" when "[begin one-point]" return "<div><img src='images/onepoint_before.png' class='one-point'>\n" when "[end one-point]" return "<img src='images/onepoint_after.png' class='one-point'></div>\n" when /\A%([a-z][a-z0-9\-]*):(.*)/m return "<div class='#{$1}'>#{$2}</div>\n" end if @in_dialog case text when /^わかばちゃん「(.+)」$/ return " <div class=\"speech shinra\">\n <div class=\"icon\"></div>\n <div class=\"baloon\">\n <p>\#{$1}</p>\n </div>\n </div>\n HTML\n when /^\u9ED2\u732B\u5148\u751F\u300C(.+)\u300D$/\n return <<~HTML\n <div class=\"speech kuroneko\">\n <div class=\"icon\"></div>\n <div class=\"baloon\">\n <p>\#{$1}</p>\n </div>\n </div>\n HTML\n end\n end\n\n text = text.strip.gsub(/%([a-z][a-z0-9\\-]*){(.*)}/, \"<span class='\\\\1'>\\\\2</span>\")\n \"<p>\#{text.gsub(/ $/, \"<br>\\n\")}</p>\\n\"\nend\n" |