Class: Vitreous::Share::Element
- Inherits:
-
Mustache
- Object
- Mustache
- Vitreous::Share::Element
- Defined in:
- lib/vitreous/share/element.rb
Instance Method Summary collapse
- #collection? ⇒ Boolean
- #collections ⇒ Object
- #elements ⇒ Object
- #home? ⇒ Boolean
-
#initialize(hash) ⇒ Element
constructor
A new instance of Element.
- #item? ⇒ Boolean
- #items ⇒ Object
- #meta_methods ⇒ Object
- #not_found? ⇒ Boolean
- #to_md(text) ⇒ Object
Constructor Details
#initialize(hash) ⇒ Element
Returns a new instance of Element.
4 5 6 7 |
# File 'lib/vitreous/share/element.rb', line 4 def initialize( hash ) @hash = hash end |
Instance Method Details
#collection? ⇒ Boolean
26 27 28 |
# File 'lib/vitreous/share/element.rb', line 26 def collection? @hash['type'] == 'collection' end |
#collections ⇒ Object
38 39 40 |
# File 'lib/vitreous/share/element.rb', line 38 def collections @hash['elements'].select { |e| e['type'] == 'collection' }.map { |e| Element.new( e ) } end |
#elements ⇒ Object
34 35 36 |
# File 'lib/vitreous/share/element.rb', line 34 def elements @hash['elements'].map { |e| Element.new( e ) } end |
#home? ⇒ Boolean
22 23 24 |
# File 'lib/vitreous/share/element.rb', line 22 def home? @hash['type'] == 'home' end |
#item? ⇒ Boolean
30 31 32 |
# File 'lib/vitreous/share/element.rb', line 30 def item? @hash['type'] == 'item' end |
#items ⇒ Object
42 43 44 |
# File 'lib/vitreous/share/element.rb', line 42 def items @hash['elements'].select { |e| e['type'] == 'item' }.map { |e| Element.new( e ) } end |
#meta_methods ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/vitreous/share/element.rb', line 9 def @hash.each do |k,v| (class << self; self; end).class_eval do define_method( k.to_sym ) { v } if !method_defined?( k.to_sym ) end end end |
#not_found? ⇒ Boolean
18 19 20 |
# File 'lib/vitreous/share/element.rb', line 18 def not_found? @hash['type'] == 'not_found' end |
#to_md(text) ⇒ Object
46 47 48 |
# File 'lib/vitreous/share/element.rb', line 46 def to_md( text ) RDiscount.new( render( text ) ).to_html end |