Class: Rwiki::Utils::TextileHelper
- Inherits:
-
Object
- Object
- Rwiki::Utils::TextileHelper
- Defined in:
- lib/rwiki/utils/textile_helper.rb
Constant Summary collapse
- HEADER_REGEXP =
Regexp for extracting an article headers
/^\s*h(?<number>[1-6]?)\.\s+(?<name>.*)/.freeze
- CODE_REGEXP =
RedCloth for extracting code blocks
/\<code( lang="(?<lang>.+?)")?\>(?<code>.+?)\<\/code\>/m.freeze
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#processed_content ⇒ Object
readonly
Returns the value of attribute processed_content.
Instance Method Summary collapse
-
#initialize(content) ⇒ TextileHelper
constructor
A new instance of TextileHelper.
- #parsed_content ⇒ Object
- #parsed_toc ⇒ Object
- #textile_toc ⇒ Object
Constructor Details
#initialize(content) ⇒ TextileHelper
Returns a new instance of TextileHelper.
14 15 16 17 |
# File 'lib/rwiki/utils/textile_helper.rb', line 14 def initialize(content) @content = content.clone @processed_content = content.clone end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
11 12 13 |
# File 'lib/rwiki/utils/textile_helper.rb', line 11 def content @content end |
#processed_content ⇒ Object (readonly)
Returns the value of attribute processed_content.
12 13 14 |
# File 'lib/rwiki/utils/textile_helper.rb', line 12 def processed_content @processed_content end |
Instance Method Details
#parsed_content ⇒ Object
19 20 21 22 23 24 |
# File 'lib/rwiki/utils/textile_helper.rb', line 19 def parsed_content process_coderay! process_toc! RedCloth.new(processed_content).to_html end |
#parsed_toc ⇒ Object
26 27 28 |
# File 'lib/rwiki/utils/textile_helper.rb', line 26 def parsed_toc RedCloth.new(textile_toc).to_html end |
#textile_toc ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rwiki/utils/textile_helper.rb', line 30 def textile_toc toc_items = [] content.gsub(HEADER_REGEXP) do number = $~[:number].to_i name = $~[:name].strip anchor = sanitize_anchor_name(name) toc_items << ('#' * number) + %Q{ "#{name}":##{anchor}} end toc_items.join("\n") end |