Class: SimpleNavigation::Adapters::Sinatra

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

Direct Known Subclasses

Padrino

Instance Attribute Summary

Attributes inherited from Base

#context, #request

Class Method Summary collapse

Instance Method Summary collapse

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 (type, content, options = {})
  "<#{type}#{to_attributes(options)}>#{content}</#{type}>"
end

#context_for_evalObject



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

Returns:

  • (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


42
43
44
# File 'lib/simple_navigation/adapters/sinatra.rb', line 42

def link_to(name, url, options = {})
  "<a href='#{url}'#{to_attributes(options)}>#{name}</a>"
end

#request_pathObject



23
24
25
# File 'lib/simple_navigation/adapters/sinatra.rb', line 23

def request_path
  request.path
end

#request_uriObject



19
20
21
# File 'lib/simple_navigation/adapters/sinatra.rb', line 19

def request_uri
  request.fullpath
end