Class: Lux::Application::Nav
Overview
experiment for different nav in rooter
Instance Attribute Summary collapse
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#format ⇒ Object
Returns the value of attribute format.
-
#id ⇒ Object
Returns the value of attribute id.
-
#original ⇒ Object
readonly
Returns the value of attribute original.
-
#path ⇒ Object
Returns the value of attribute path.
-
#subdomain ⇒ Object
readonly
Returns the value of attribute subdomain.
Instance Method Summary collapse
- #active ⇒ Object
- #active_shift ⇒ Object
- #first ⇒ Object
- #get_format_once ⇒ Object
-
#initialize(request) ⇒ Nav
constructor
acepts path as a string.
- #last ⇒ Object
- #root(sub_nav = nil) ⇒ Object
- #root=(value) ⇒ Object
- #second ⇒ Object
- #set_format ⇒ Object
- #shift ⇒ Object
- #to_s ⇒ Object
-
#unshift(name) ⇒ Object
used to make admin.lvm.me/users to lvh.me/admin/users.
Constructor Details
#initialize(request) ⇒ Nav
acepts path as a string
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/lux/application/lib/nav.rb', line 8 def initialize request @path = request.path.split('/').slice(1, 100) || [] @original = @path.dup @subdomain = request.host.split('.') @domain = @subdomain.pop(2).join('.') @subdomain = @subdomain.join('.') @domain += ".#{@subdomain.pop}" if @domain.length < 6 set_format end |
Instance Attribute Details
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
5 6 7 |
# File 'lib/lux/application/lib/nav.rb', line 5 def domain @domain end |
#format ⇒ Object
Returns the value of attribute format.
4 5 6 |
# File 'lib/lux/application/lib/nav.rb', line 4 def format @format end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/lux/application/lib/nav.rb', line 4 def id @id end |
#original ⇒ Object (readonly)
Returns the value of attribute original.
5 6 7 |
# File 'lib/lux/application/lib/nav.rb', line 5 def original @original end |
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/lux/application/lib/nav.rb', line 4 def path @path end |
#subdomain ⇒ Object (readonly)
Returns the value of attribute subdomain.
5 6 7 |
# File 'lib/lux/application/lib/nav.rb', line 5 def subdomain @subdomain end |
Instance Method Details
#active ⇒ Object
100 101 102 |
# File 'lib/lux/application/lib/nav.rb', line 100 def active @active end |
#active_shift ⇒ Object
34 35 36 |
# File 'lib/lux/application/lib/nav.rb', line 34 def active_shift @active = @path.shift end |
#first ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/lux/application/lib/nav.rb', line 72 def first if block_given? # shift first in place if yields not nil return unless @path[1].present? result = yield(@path[1]) || return @path.slice!(1,1) result else @path[1] end end |
#get_format_once ⇒ Object
30 31 32 |
# File 'lib/lux/application/lib/nav.rb', line 30 def get_format_once @format_once.tap { @format_once = nil } end |
#last ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/lux/application/lib/nav.rb', line 84 def last if block_given? # replace root in place if yields not nil return unless @path.last.present? result = yield(@path.last) || return @path.pop result else @path.last end end |
#root(sub_nav = nil) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/lux/application/lib/nav.rb', line 55 def root sub_nav=nil if block_given? return unless @path[0] # shift root in place if yields not nil result = yield(@path[0]) || return active_shift result else sub_nav ? ('%s/%s' % [@path.first, sub_nav]) : @path.first end end |
#root=(value) ⇒ Object
68 69 70 |
# File 'lib/lux/application/lib/nav.rb', line 68 def root= value @path[0] = value end |
#second ⇒ Object
96 97 98 |
# File 'lib/lux/application/lib/nav.rb', line 96 def second @path[2] end |
#set_format ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/lux/application/lib/nav.rb', line 20 def set_format return unless @path.last parts = @path.last.split('.') if parts[1] @format = @format_once = parts.pop.to_s.downcase.to_sym @path.last = parts.join('.') end end |
#shift ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/lux/application/lib/nav.rb', line 38 def shift return unless @path[0].present? if block_given? result = yield(@path[0]) || return result else active_shift end end |
#to_s ⇒ Object
104 105 106 |
# File 'lib/lux/application/lib/nav.rb', line 104 def to_s @path.join('/').sub(/\/$/, '') end |
#unshift(name) ⇒ Object
used to make admin.lvm.me/users to lvh.me/admin/users
51 52 53 |
# File 'lib/lux/application/lib/nav.rb', line 51 def unshift name @path.unshift name end |