Class: Rpub::Document
- Inherits:
-
Object
- Object
- Rpub::Document
- Defined in:
- lib/rpub/document.rb
Defined Under Namespace
Classes: OutlineElement
Constant Summary collapse
- KRAMDOWN_OPTIONS =
{ :coderay_line_numbers => nil }
Instance Method Summary collapse
-
#images ⇒ Array<String>
List of all image references.
-
#initialize(content, layout) ⇒ Document
constructor
A new instance of Document.
-
#outline ⇒ Array<#text,#level,#html_id>
Ordered headers for this chapter, each header as an object responding to #level and #text.
-
#title ⇒ String
Text of the first heading in this chapter.
-
#to_html ⇒ String
Content parsed to HTML by the markdown engine.
-
#toc ⇒ Kramdown::Element
Toc elements hierarchy.
Constructor Details
#initialize(content, layout) ⇒ Document
Returns a new instance of Document.
9 10 11 |
# File 'lib/rpub/document.rb', line 9 def initialize(content, layout) @document = Kramdown::Document.new(content, KRAMDOWN_OPTIONS.merge(:template => layout)) end |
Instance Method Details
#images ⇒ Array<String>
Returns list of all image references.
45 46 47 |
# File 'lib/rpub/document.rb', line 45 def images @images ||= elements(:img).map { |e| e.attr['src'] } end |
#outline ⇒ Array<#text,#level,#html_id>
Ordered headers for this chapter, each header as an object responding to #level and #text.
22 23 24 25 26 27 28 29 30 |
# File 'lib/rpub/document.rb', line 22 def outline @outline ||= elements(:header).map do |element| OutlineElement.new( element.[:level], element_text(element), Kramdown::Converter::Html.send(:new, document, { :auto_id_prefix => '' }).generate_id(element.[:raw_text]) ) end end |
#title ⇒ String
Returns Text of the first heading in this chapter.
38 39 40 41 42 |
# File 'lib/rpub/document.rb', line 38 def title @title ||= begin (heading = outline.first) ? heading.text : 'untitled' end end |
#to_html ⇒ String
Returns content parsed to HTML by the markdown engine.
33 34 35 |
# File 'lib/rpub/document.rb', line 33 def to_html @to_html ||= Typogruby.improve(@document.to_html) end |
#toc ⇒ Kramdown::Element
Returns Toc elements hierarchy.
14 15 16 |
# File 'lib/rpub/document.rb', line 14 def toc Kramdown::Converter::Toc.convert(document.root).first end |