Class SimpleNavigation::Adapters::Rails
In: lib/simple_navigation/adapters/rails.rb
Parent: Base

Methods

Attributes

controller  [R] 
template  [R] 

Public Class methods

[Source]

# File lib/simple_navigation/adapters/rails.rb, line 13
      def initialize(context)
        @controller = extract_controller_from context
        @template = template_from @controller
        @request = @template.request if @template
      end

[Source]

# 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)
        ActionController::Base.send(:helper_method, :render_navigation)
      end

Protected Class methods

[Source]

# File lib/simple_navigation/adapters/rails.rb, line 57
      def self.rails3?
        ::Rails::VERSION::MAJOR == 3
      end

[Source]

# File lib/simple_navigation/adapters/rails.rb, line 53
      def self.rails_env
        rails3? ? ::Rails.env : ::RAILS_ENV
      end

[Source]

# File lib/simple_navigation/adapters/rails.rb, line 49
      def self.rails_root
        rails3? ? ::Rails.root : ::RAILS_ROOT
      end

Public Instance methods

[Source]

# File lib/simple_navigation/adapters/rails.rb, line 43
      def content_tag(type, content, options={})
        template.content_tag(type, html_safe(content), options) if template
      end

[Source]

# File lib/simple_navigation/adapters/rails.rb, line 30
      def context_for_eval
        raise 'no context set for evaluation the config file' unless template || controller
        template || controller
      end

[Source]

# File lib/simple_navigation/adapters/rails.rb, line 35
      def current_page?(url)
        template.current_page?(url) if template
      end

[Source]

# File lib/simple_navigation/adapters/rails.rb, line 39
      def link_to(name, url, options={})
        template.link_to(html_safe(name), url, options) if template
      end

[Source]

# File lib/simple_navigation/adapters/rails.rb, line 25
      def request_path
        return '' unless request
        request.path
      end

[Source]

# File lib/simple_navigation/adapters/rails.rb, line 19
      def request_uri
        return '' unless request
        return request.fullpath if request.respond_to?(:fullpath)
        request.request_uri
      end

Protected Instance methods

Extracts a controller from the context.

[Source]

# File lib/simple_navigation/adapters/rails.rb, line 72
      def extract_controller_from(context)
        if context.respond_to? :controller
          context.controller
        else
          context
        end
      end

Marks the specified input as html_safe (for Rails3). Does nothing if html_safe is not defined on input.

[Source]

# File lib/simple_navigation/adapters/rails.rb, line 67
      def html_safe(input)
        input.respond_to?(:html_safe) ? input.html_safe : input
      end

[Source]

# File lib/simple_navigation/adapters/rails.rb, line 61
      def template_from(controller)
        controller.instance_variable_get(:@template) || (controller.respond_to?(:view_context) ? controller.view_context : nil)
      end

[Validate]