Class: AtechDocs::Page
- Inherits:
-
Object
- Object
- AtechDocs::Page
- Defined in:
- lib/atech_docs/page.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#body ⇒ Object
Return the processed HTML content for this page.
-
#initialize(path, raw) ⇒ Page
constructor
A new instance of Page.
Constructor Details
#initialize(path, raw) ⇒ Page
Returns a new instance of Page.
9 10 11 12 13 14 |
# File 'lib/atech_docs/page.rb', line 9 def initialize(path, raw) @path = path @content = raw @options = Hash.new end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/atech_docs/page.rb', line 7 def @options end |
Instance Method Details
#body ⇒ Object
Return the processed HTML content for this page.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/atech_docs/page.rb', line 17 def body content = @content.strip content.gsub!(/^\[([A-Z]+)\](.*)/) do "<p class='#{$1.downcase}'>#{$2.strip}</p>" end content.gsub!(/\]\(~\//) do "](/#{@path}/" end markdown = RDiscount.new(content) html = markdown.to_html html.gsub!(/<pre><code>\[([\w\s\|]+)\]\n(.*?)<\/code><\/pre>/m) do properties, code = $1, $2 syntax, title = properties.split('|', 2) output = CodeRay.scan(code, syntax.to_sym).div(:css => :class) output.gsub!('<div class="CodeRay">', "<div class='CodeRay'><p class='label'>#{title}</p>") output end html end |