Class: MiddlemanMdocs::Navigation::Item
- Inherits:
-
Object
- Object
- MiddlemanMdocs::Navigation::Item
- Defined in:
- lib/middleman-mdocs/navigation.rb
Instance Attribute Summary collapse
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #group? ⇒ Boolean
- #groupped(sitemap) ⇒ Object
-
#initialize(label, value = nil) ⇒ Item
constructor
A new instance of Item.
- #link? ⇒ Boolean
- #recursive? ⇒ Boolean
- #separator? ⇒ Boolean
- #tr(group) ⇒ Object
Constructor Details
#initialize(label, value = nil) ⇒ Item
Returns a new instance of Item.
6 7 8 9 10 11 12 13 14 |
# File 'lib/middleman-mdocs/navigation.rb', line 6 def initialize(label, value = nil) @label = label @value = value if @value.is_a?(Hash) && @value.group? @group = @value.group elsif @value.is_a?(Array) @recursive = true end end |
Instance Attribute Details
#group ⇒ Object (readonly)
Returns the value of attribute group.
4 5 6 |
# File 'lib/middleman-mdocs/navigation.rb', line 4 def group @group end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
4 5 6 |
# File 'lib/middleman-mdocs/navigation.rb', line 4 def label @label end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
4 5 6 |
# File 'lib/middleman-mdocs/navigation.rb', line 4 def value @value end |
Instance Method Details
#group? ⇒ Boolean
24 25 26 |
# File 'lib/middleman-mdocs/navigation.rb', line 24 def group? !!@group end |
#groupped(sitemap) ⇒ Object
32 33 34 35 36 |
# File 'lib/middleman-mdocs/navigation.rb', line 32 def groupped(sitemap) sitemap.(@group.to_sym).group_by do |resource| resource.[@group.to_sym] end end |
#link? ⇒ Boolean
20 21 22 |
# File 'lib/middleman-mdocs/navigation.rb', line 20 def link? value.is_a?(String) end |
#recursive? ⇒ Boolean
28 29 30 |
# File 'lib/middleman-mdocs/navigation.rb', line 28 def recursive? !!@recursive end |
#separator? ⇒ Boolean
16 17 18 |
# File 'lib/middleman-mdocs/navigation.rb', line 16 def separator? value.nil? end |
#tr(group) ⇒ Object
38 39 40 |
# File 'lib/middleman-mdocs/navigation.rb', line 38 def tr(group) I18n.t(group, scope: [:mdocs, self.group], default: group) end |