Class: SimpleNavigation::Adapters::Sinatra
- Defined in:
- lib/simple_navigation/adapters/sinatra.rb
Direct Known Subclasses
Instance Attribute Summary
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) ⇒ Sinatra
constructor
A new instance of Sinatra.
- #link_to(name, url, options = {}) ⇒ Object
- #request_path ⇒ Object
- #request_uri ⇒ Object
Constructor Details
#initialize(context) ⇒ Sinatra
Returns a new instance of Sinatra.
10 11 12 13 |
# File 'lib/simple_navigation/adapters/sinatra.rb', line 10 def initialize(context) @context = context @request = context.request end |
Class Method Details
.register(app) ⇒ Object
6 7 8 |
# File 'lib/simple_navigation/adapters/sinatra.rb', line 6 def self.register(app) SimpleNavigation.set_env(app.root, app.environment) end |
Instance Method Details
#content_tag(type, content, options = {}) ⇒ Object
46 47 48 |
# File 'lib/simple_navigation/adapters/sinatra.rb', line 46 def content_tag(type, content, = {}) "<#{type}#{to_attributes()}>#{content}</#{type}>" end |
#context_for_eval ⇒ Object
15 16 17 |
# File 'lib/simple_navigation/adapters/sinatra.rb', line 15 def context_for_eval context || fail('no context set for evaluation the config file') end |
#current_page?(url) ⇒ Boolean
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/simple_navigation/adapters/sinatra.rb', line 27 def current_page?(url) url_string = CGI.unescape(url) uri = if url_string.index('?') request_uri else request_uri.split('?').first end if url_string =~ %r(^\w+://) uri = "#{request.scheme}://#{request.host_with_port}#{uri}" end url_string == CGI.unescape(uri) end |
#link_to(name, url, options = {}) ⇒ Object
42 43 44 |
# File 'lib/simple_navigation/adapters/sinatra.rb', line 42 def link_to(name, url, = {}) "<a href='#{url}'#{to_attributes()}>#{name}</a>" end |
#request_path ⇒ Object
23 24 25 |
# File 'lib/simple_navigation/adapters/sinatra.rb', line 23 def request_path request.path end |
#request_uri ⇒ Object
19 20 21 |
# File 'lib/simple_navigation/adapters/sinatra.rb', line 19 def request_uri request.fullpath end |