Class: SimpleNavigation::Adapters::Nanoc

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

Instance Attribute Summary

Attributes inherited from Base

#context, #request

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#request_path, #request_uri

Constructor Details

#initialize(ctx) ⇒ Nanoc

Returns a new instance of Nanoc.



11
12
13
# File 'lib/simple_navigation/adapters/nanoc.rb', line 11

def initialize(ctx)
  @context = ctx
end

Class Method Details

.register(root) ⇒ Object



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

def register(root)
  SimpleNavigation.set_env(root, 'development')
  Nanoc3::Context.send(:include, SimpleNavigation::Helpers)
end

Instance Method Details

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

Returns a tag of the specified type, content and options. Used for rendering.



35
36
37
# File 'lib/simple_navigation/adapters/nanoc.rb', line 35

def (type, content, options = {})
  "<#{type} #{to_attributes(options)}>#{content}</#{type}>"
end

#context_for_evalObject

Returns the context in which the config files will be evaluated



16
17
18
# File 'lib/simple_navigation/adapters/nanoc.rb', line 16

def context_for_eval
  context
end

#current_page?(url) ⇒ Boolean

Returns true if the current request’s url matches the specified url. Used to determine if an item should be autohighlighted.

Returns:

  • (Boolean)


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

def current_page?(url)
  path = context.item.path
  path && path.chop == url
end

Returns a link with the specified name, url and options. Used for rendering.



29
30
31
# File 'lib/simple_navigation/adapters/nanoc.rb', line 29

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