Class: SimpleNavigation::Adapters::Rails
- Defined in:
- lib/simple_navigation/adapters/rails.rb
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
- #content_tag(type, content, options = {}) ⇒ Object
- #context_for_eval ⇒ Object
- #current_page?(url) ⇒ Boolean
-
#initialize(context) ⇒ Rails
constructor
A new instance of Rails.
- #link_to(name, url, options = {}) ⇒ Object
- #request_path ⇒ Object
- #request_uri ⇒ Object
Constructor Details
#initialize(context) ⇒ Rails
Returns a new instance of Rails.
29 30 31 32 33 |
# File 'lib/simple_navigation/adapters/rails.rb', line 29 def initialize(context) @controller = extract_controller_from context @template = template_from @controller @request = @template.request if @template end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
4 5 6 |
# File 'lib/simple_navigation/adapters/rails.rb', line 4 def controller @controller end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
4 5 6 |
# File 'lib/simple_navigation/adapters/rails.rb', line 4 def template @template end |
Class Method Details
.register ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/simple_navigation/adapters/rails.rb', line 6 def self.register SimpleNavigation.set_env(::Rails.root, ::Rails.env) # Autoloading in initializers is deprecated on rails 6.0 # This delays the hook initialization using the on_load # hooks, but does not change behaviour for existing # rails versions. if ::Rails::VERSION::MAJOR >= 6 ActiveSupport.on_load(:action_controller_base) do SimpleNavigation::Adapters::Rails.register_controller_helpers end else register_controller_helpers end end |
.register_controller_helpers ⇒ Object
22 23 24 25 26 27 |
# File 'lib/simple_navigation/adapters/rails.rb', line 22 def self.register_controller_helpers 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
63 64 65 |
# File 'lib/simple_navigation/adapters/rails.rb', line 63 def content_tag(type, content, = {}) template && template.content_tag(type, html_safe(content), ) end |
#context_for_eval ⇒ Object
49 50 51 52 53 |
# File 'lib/simple_navigation/adapters/rails.rb', line 49 def context_for_eval template || controller || fail('no context set for evaluation the config file') end |
#current_page?(url) ⇒ Boolean
55 56 57 |
# File 'lib/simple_navigation/adapters/rails.rb', line 55 def current_page?(url) template && template.current_page?(url) end |
#link_to(name, url, options = {}) ⇒ Object
59 60 61 |
# File 'lib/simple_navigation/adapters/rails.rb', line 59 def link_to(name, url, = {}) template && template.link_to(link_title(name), url, ) end |
#request_path ⇒ Object
45 46 47 |
# File 'lib/simple_navigation/adapters/rails.rb', line 45 def request_path request ? request.path : '' end |
#request_uri ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/simple_navigation/adapters/rails.rb', line 35 def request_uri return '' unless request if request.respond_to?(:fullpath) request.fullpath else request.request_uri end end |