Class: SimpleNavigation::Adapters::Rails

Inherits:
Base
  • Object
show all
Defined in:
lib/simple_navigation/adapters/rails.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#context, #request

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Rails



15
16
17
18
19
# File 'lib/simple_navigation/adapters/rails.rb', line 15

def initialize(context)
  @controller = extract_controller_from context
  @template = template_from @controller
  @request = @template.request if @template
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller



5
6
7
# File 'lib/simple_navigation/adapters/rails.rb', line 5

def controller
  @controller
end

#templateObject (readonly)

Returns the value of attribute template



5
6
7
# File 'lib/simple_navigation/adapters/rails.rb', line 5

def template
  @template
end

Class Method Details

.registerObject



7
8
9
10
11
12
13
# File 'lib/simple_navigation/adapters/rails.rb', line 7

def self.register
  SimpleNavigation.set_env(rails_root, rails_env)        
  ActionController::Base.send(:include, SimpleNavigation::Helpers)
  SimpleNavigation::Helpers.instance_methods.each do |m|
    ActionController::Base.send(:helper_method, m.to_sym)
  end
end

Instance Method Details

#content_tag(type, content, options = {}) ⇒ Object



45
46
47
# File 'lib/simple_navigation/adapters/rails.rb', line 45

def (type, content, options={})
  template.(type, html_safe(content), options) if template
end

#context_for_evalObject



32
33
34
35
# File 'lib/simple_navigation/adapters/rails.rb', line 32

def context_for_eval
  raise 'no context set for evaluation the config file' unless template || controller
  template || controller
end

#current_page?(url) ⇒ Boolean



37
38
39
# File 'lib/simple_navigation/adapters/rails.rb', line 37

def current_page?(url)
  template.current_page?(url) if template
end


41
42
43
# File 'lib/simple_navigation/adapters/rails.rb', line 41

def link_to(name, url, options={})
  template.link_to(html_safe(name), url, options) if template
end

#request_pathObject



27
28
29
30
# File 'lib/simple_navigation/adapters/rails.rb', line 27

def request_path
  return '' unless request
  request.path
end

#request_uriObject



21
22
23
24
25
# File 'lib/simple_navigation/adapters/rails.rb', line 21

def request_uri
  return '' unless request
  return request.fullpath if request.respond_to?(:fullpath)
  request.request_uri
end