Class: Lux::Application::Nav

Inherits:
Object
  • Object
show all
Defined in:
lib/lux/application/lib/nav.rb

Overview

experiment for different nav in rooter

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#domainObject (readonly)

Returns the value of attribute domain.



5
6
7
# File 'lib/lux/application/lib/nav.rb', line 5

def domain
  @domain
end

#formatObject

Returns the value of attribute format.



4
5
6
# File 'lib/lux/application/lib/nav.rb', line 4

def format
  @format
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/lux/application/lib/nav.rb', line 4

def id
  @id
end

#originalObject (readonly)

Returns the value of attribute original.



5
6
7
# File 'lib/lux/application/lib/nav.rb', line 5

def original
  @original
end

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/lux/application/lib/nav.rb', line 4

def path
  @path
end

#subdomainObject (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

#activeObject



100
101
102
# File 'lib/lux/application/lib/nav.rb', line 100

def active
  @active
end

#active_shiftObject



34
35
36
# File 'lib/lux/application/lib/nav.rb', line 34

def active_shift
  @active = @path.shift
end

#firstObject



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_onceObject



30
31
32
# File 'lib/lux/application/lib/nav.rb', line 30

def get_format_once
  @format_once.tap { @format_once = nil }
end

#lastObject



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

#secondObject



96
97
98
# File 'lib/lux/application/lib/nav.rb', line 96

def second
  @path[2]
end

#set_formatObject



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

#shiftObject



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_sObject



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