Sha256: fd93864553babcdc51446241a8c3da26f747a67f95235057b0f051d9bc6d35a0

Contents?: true

Size: 1.26 KB

Versions: 9

Compression:

Stored size: 1.26 KB

Contents

module SimpleNavigation
  module Adapters
    class Nanoc < Base
      class << self
        def register(root)
          SimpleNavigation.set_env(root, 'development')
          Nanoc3::Context.send(:include, SimpleNavigation::Helpers)
        end
      end

      def initialize(ctx)
        @context = ctx
      end

      # Returns the context in which the config files will be evaluated
      def context_for_eval
        context
      end
      
      # Returns true if the current request's url matches the specified url. 
      # Used to determine if an item should be autohighlighted.
      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.
      def link_to(name, url, options={})
        "<a href='#{url}' #{to_attributes(options)}>#{name}</a>"
      end

      # Returns a tag of the specified type, content and options.
      # Used for rendering.
      def content_tag(type, content, options={})
        "<#{type} #{to_attributes(options)}>#{content}</#{type}>"
      end

      private
      def to_attributes(options)
        options.map {|k, v| v.nil? ? nil : "#{k}='#{v}'"}.compact.join(' ')
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
simple-navigation-3.12.0 lib/simple_navigation/adapters/nanoc.rb
jordanyeo-simple-navigation-3.11.1 lib/simple_navigation/adapters/nanoc.rb
jordanyeo-simple-navigation-3.11.0 lib/simple_navigation/adapters/nanoc.rb
simple-navigation-3.11.0 lib/simple_navigation/adapters/nanoc.rb
simple-navigation-3.10.1 lib/simple_navigation/adapters/nanoc.rb
simple-navigation-3.10.0 lib/simple_navigation/adapters/nanoc.rb
simple-navigation-3.9.0 lib/simple_navigation/adapters/nanoc.rb
simple-navigation-3.8.0 lib/simple_navigation/adapters/nanoc.rb
simple-navigation-3.7.0 lib/simple_navigation/adapters/nanoc.rb