Module: NavigatorRails::Decorators::Generic
- Defined in:
- lib/navigator_rails/decorators/generic.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #child_count ⇒ Object
- #children(params = {}) ⇒ Object
- #children_except(params = {}) ⇒ Object
- #children_of(resource) ⇒ Object
- #draw(resource) ⇒ Object
- #draw_children(elements = nil) ⇒ Object
- #has_visible_children ⇒ Object
- #resource ⇒ Object
Instance Attribute Details
#type ⇒ Object
Returns the value of attribute type.
14 15 16 |
# File 'lib/navigator_rails/decorators/generic.rb', line 14 def type @type end |
Class Method Details
.included(base) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/navigator_rails/decorators/generic.rb', line 5 def included base type = base.to_s.demodulize.downcase.to_sym decorator = base base.send(:extend,NavigatorRails::Decorators::Generic) decorator.type = type base.send(:include,Singleton) NavigatorRails::Decorator.register type, decorator.instance end |
Instance Method Details
#child_count ⇒ Object
18 19 20 |
# File 'lib/navigator_rails/decorators/generic.rb', line 18 def child_count resource.children.count end |
#children(params = {}) ⇒ Object
33 34 35 |
# File 'lib/navigator_rails/decorators/generic.rb', line 33 def children params={} resource.children(params) end |
#children_except(params = {}) ⇒ Object
30 31 32 |
# File 'lib/navigator_rails/decorators/generic.rb', line 30 def children_except params={} resource.children_except(params) end |
#children_of(resource) ⇒ Object
43 44 |
# File 'lib/navigator_rails/decorators/generic.rb', line 43 def children_of resource end |
#draw(resource) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/navigator_rails/decorators/generic.rb', line 45 def draw resource old_resource = @resource @resource = resource output = ERB.new(template).result(binding).html_safe @resource = old_resource output end |
#draw_children(elements = nil) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/navigator_rails/decorators/generic.rb', line 36 def draw_children elements=nil elements ||= resource.children elements.collect do |child| next unless child.constraint child.decorator.draw(child).html_safe end.join end |
#has_visible_children ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/navigator_rails/decorators/generic.rb', line 21 def has_visible_children begin children.collect do |child| child.constraint end.reduce(:|) rescue NoMethodError false end end |
#resource ⇒ Object
15 16 17 |
# File 'lib/navigator_rails/decorators/generic.rb', line 15 def resource @resource end |