Class: Slippery::Converter
- Inherits:
-
Object
- Object
- Slippery::Converter
- Defined in:
- lib/slippery/converter.rb
Instance Attribute Summary collapse
-
#attr ⇒ Object
Returns the value of attribute attr.
-
#children ⇒ Object
Returns the value of attribute children.
-
#options ⇒ Object
Returns the value of attribute options.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#codeblock ⇒ Hexp::Node
Process a Kramdown :codeblock type element.
- #codespan ⇒ Object
-
#convert(el) ⇒ Hexp::Node
Convert a Kramdown syntax tree into Hexp.
-
#convert_children ⇒ Array<Hexp::Node>
private
Convert the children of the Kramdown element to Hexps.
- #entity ⇒ Object
-
#header ⇒ Hexp::Node
Process a Kramdown :header type element.
- #html_element ⇒ Object
-
#root ⇒ Hexp::Node
Process a Kramdown :root type element.
- #smart_quote ⇒ Object
-
#tag!(tag) ⇒ Hexp::Node
Create a Hexp::Node from the current element.
- #typographic_sym ⇒ Object
- #xml_comment ⇒ Object
Instance Attribute Details
#attr ⇒ Object
Returns the value of attribute attr.
11 12 13 |
# File 'lib/slippery/converter.rb', line 11 def attr @attr end |
#children ⇒ Object
Returns the value of attribute children.
11 12 13 |
# File 'lib/slippery/converter.rb', line 11 def children @children end |
#options ⇒ Object
Returns the value of attribute options.
11 12 13 |
# File 'lib/slippery/converter.rb', line 11 def @options end |
#type ⇒ Object
Returns the value of attribute type.
11 12 13 |
# File 'lib/slippery/converter.rb', line 11 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
11 12 13 |
# File 'lib/slippery/converter.rb', line 11 def value @value end |
Instance Method Details
#codeblock ⇒ Hexp::Node
Process a Kramdown :codeblock type element
55 56 57 |
# File 'lib/slippery/converter.rb', line 55 def codeblock H[:pre, attr, H[:code, value]] end |
#codespan ⇒ Object
88 89 90 |
# File 'lib/slippery/converter.rb', line 88 def codespan H[:code, value] end |
#convert(el) ⇒ Hexp::Node
Convert a Kramdown syntax tree into Hexp.
25 26 27 28 29 30 |
# File 'lib/slippery/converter.rb', line 25 def convert(el) #Kernel.p el ; exit @type, @value, @attr, @children, @options = el.type, el.value, el.attr, el.children, el. send(type) end |
#convert_children ⇒ Array<Hexp::Node>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Convert the children of the Kramdown element to Hexps
In other words, recurse down the tree. This will pass each child element into the converter.
128 129 130 |
# File 'lib/slippery/converter.rb', line 128 def convert_children children.map {|ch| convert ch }.compact end |
#entity ⇒ Object
84 85 86 |
# File 'lib/slippery/converter.rb', line 84 def entity value.char end |
#header ⇒ Hexp::Node
Process a Kramdown :header type element
46 47 48 |
# File 'lib/slippery/converter.rb', line 46 def header tag! "h#{[:level]}".intern end |
#html_element ⇒ Object
80 81 82 |
# File 'lib/slippery/converter.rb', line 80 def html_element H[value.to_sym, attr, convert_children] end |
#root ⇒ Hexp::Node
Process a Kramdown :root type element
37 38 39 |
# File 'lib/slippery/converter.rb', line 37 def root H[:html, [H[:head], tag!(:body)]] end |
#smart_quote ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/slippery/converter.rb', line 59 def smart_quote { :lsquo => '‘', :rsquo => '’', :ldquo => '“', :rdquo => '”', }[value] end |
#tag!(tag) ⇒ Hexp::Node
Create a Hexp::Node from the current element
Helper for when you want to turn the Kramdown element straight into a Hexp::Node with the same attributes, and a one-to-one mapping of the child elements.
104 105 106 |
# File 'lib/slippery/converter.rb', line 104 def tag!(tag) H[tag, attr, convert_children] end |
#typographic_sym ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/slippery/converter.rb', line 68 def typographic_sym { :hellip => '…', :mdash => '—', :ndash => '–', :laquo => '«', :raquo => '»', :laquo_space => '« ', :raquo_space => ' »', }[value] end |
#xml_comment ⇒ Object
92 |
# File 'lib/slippery/converter.rb', line 92 def xml_comment; end |