Class: Trestle::Navigation::Item
- Inherits:
-
Object
- Object
- Trestle::Navigation::Item
- Defined in:
- lib/trestle/navigation/item.rb
Defined Under Namespace
Classes: Badge
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #admin ⇒ Object
- #badge ⇒ Object
- #badge? ⇒ Boolean
- #group ⇒ Object
- #hash ⇒ Object
- #html_options ⇒ Object
- #icon ⇒ Object
-
#initialize(name, path = nil, **options) ⇒ Item
constructor
A new instance of Item.
- #label ⇒ Object
- #path ⇒ Object
- #priority ⇒ Object
- #visible?(context) ⇒ Boolean
Constructor Details
#initialize(name, path = nil, **options) ⇒ Item
Returns a new instance of Item.
6 7 8 |
# File 'lib/trestle/navigation/item.rb', line 6 def initialize(name, path=nil, **) @name, @path, = name.to_s, path, end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/trestle/navigation/item.rb', line 4 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/trestle/navigation/item.rb', line 4 def end |
Instance Method Details
#<=>(other) ⇒ Object
19 20 21 |
# File 'lib/trestle/navigation/item.rb', line 19 def <=>(other) [priority, name] <=> [other.priority, other.name] end |
#==(other) ⇒ Object Also known as: eql?
10 11 12 |
# File 'lib/trestle/navigation/item.rb', line 10 def ==(other) other.is_a?(self.class) && name == other.name && path == other.path end |
#admin ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/trestle/navigation/item.rb', line 48 def admin case [:admin] when nil, false return when Symbol, String Trestle.lookup([:admin]) or raise ActionController::UrlGenerationError, "No admin found named #{options[:admin].inspect}" else [:admin] end end |
#badge ⇒ Object
71 72 73 |
# File 'lib/trestle/navigation/item.rb', line 71 def badge Badge.new([:badge]) if badge? end |
#badge? ⇒ Boolean
67 68 69 |
# File 'lib/trestle/navigation/item.rb', line 67 def badge? !![:badge] end |
#group ⇒ Object
34 35 36 |
# File 'lib/trestle/navigation/item.rb', line 34 def group [:group] || NullGroup.new end |
#hash ⇒ Object
15 16 17 |
# File 'lib/trestle/navigation/item.rb', line 15 def hash [name, path].hash end |
#html_options ⇒ Object
75 76 77 |
# File 'lib/trestle/navigation/item.rb', line 75 def .except(:action, :admin, :badge, :group, :icon, :if, :label, :priority, :unless) end |
#icon ⇒ Object
63 64 65 |
# File 'lib/trestle/navigation/item.rb', line 63 def icon [:icon] || Trestle.config. end |
#label ⇒ Object
59 60 61 |
# File 'lib/trestle/navigation/item.rb', line 59 def label [:label] || I18n.t("admin.navigation.items.#{name}", default: name.titlecase) end |
#path ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/trestle/navigation/item.rb', line 38 def path if @path @path elsif admin = self.admin admin.path([:action]) else "#" end end |
#priority ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/trestle/navigation/item.rb', line 23 def priority case [:priority] when :first -Float::INFINITY when :last Float::INFINITY else [:priority] || 0 end end |
#visible?(context) ⇒ Boolean
79 80 81 82 83 84 85 86 87 |
# File 'lib/trestle/navigation/item.rb', line 79 def visible?(context) if [:if] context.instance_exec(&[:if]) elsif [:unless] !context.instance_exec(&[:unless]) else true end end |