Class: Documentation::MarkdownRenderer
- Inherits:
-
Redcarpet::Render::HTML
- Object
- Redcarpet::Render::HTML
- Documentation::MarkdownRenderer
- Includes:
- ActionView::Helpers::TagHelper
- Defined in:
- lib/documentation/markdown_renderer.rb
Instance Attribute Summary collapse
-
#page ⇒ Object
Returns the value of attribute page.
Instance Method Summary collapse
- #block_code(code, language) ⇒ Object
- #image(src, title, alt) ⇒ Object
- #link(link, title, content) ⇒ Object
- #paragraph(text) ⇒ Object
Instance Attribute Details
#page ⇒ Object
Returns the value of attribute page.
7 8 9 |
# File 'lib/documentation/markdown_renderer.rb', line 7 def page @page end |
Instance Method Details
#block_code(code, language) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/documentation/markdown_renderer.rb', line 11 def block_code(code, language) title = nil code.gsub!(/\A\:\:(.*)$/) { title = $1 ; nil } String.new.tap do |s| s << "<p class='codeTitle'>#{title}</p>" if title s << Pygments.highlight(code, :lexer => language) end rescue "<div class='highlight'><pre>#{code}</pre></div>" end |
#image(src, title, alt) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/documentation/markdown_renderer.rb', line 42 def image(src, title, alt) if alt.gsub!(/\*([\w\-\s]+)\z/, '') klass = "imgcontainer #{$1}" else klass = nil end content_tag :span, tag(:img, :src => src, :title => title, :alt => alt), :class => klass end |
#link(link, title, content) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/documentation/markdown_renderer.rb', line 22 def link(link, title, content) if link =~ /\A\^/ case link when /\A\^\.\/(.*)/ # ^./pagename # Links to pages on the same level as the current page link = "{{docRoot}}/#{page.parents.map(&:permalink).join('/')}/#{$1}" when /\A\^\/(.*)/ # ^/full/path # Links to a page frmo the root of the docs link = "{{docRoot}}/#{$1}" when /\A\^(.*)/ # ^child/item # Links to a child of the current page link = "{{docRoot}}/#{page.full_permalink}/#{$1}" end end "<a href='#{link}' title='#{title}'>#{content}</a>" end |
#paragraph(text) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/documentation/markdown_renderer.rb', line 51 def paragraph(text) klass = '' text.gsub!(/\A(\w+)\:/) do klass = $1 nil end text.sub!(/ ([^ ]+)$/, ' \1') "<p class='#{klass.downcase}'>#{text}</p>" end |