class Lux::Application::Nav

experiment for different nav in rooter

Attributes

domain[R]
format[RW]
id[RW]
original[R]
path[RW]
subdomain[R]

Public Class Methods

new(request) click to toggle source

acepts path as a string

# 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

Public Instance Methods

active() click to toggle source
# File lib/lux/application/lib/nav.rb, line 100
def active
  @active
end
active_shift() click to toggle source
# File lib/lux/application/lib/nav.rb, line 34
def active_shift
  @active = @path.shift
end
first() { |path| ... } click to toggle source
# 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() click to toggle source
# File lib/lux/application/lib/nav.rb, line 30
def get_format_once
  @format_once.tap { @format_once = nil }
end
last() { |last| ... } click to toggle source
# 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) { |path| ... } click to toggle source
# 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) click to toggle source
# File lib/lux/application/lib/nav.rb, line 68
def root= value
  @path[0] = value
end
second() click to toggle source
# File lib/lux/application/lib/nav.rb, line 96
def second
  @path[2]
end
set_format() click to toggle source
# 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() { |path| ... } click to toggle source
# 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() click to toggle source
# File lib/lux/application/lib/nav.rb, line 104
def to_s
  @path.join('/').sub(/\/$/, '')
end
unshift(name) click to toggle source

used to make admin.lvm.me/users to lvh.me/admin/users

# File lib/lux/application/lib/nav.rb, line 51
def unshift name
  @path.unshift name
end