Sha256: 5734308734cf54a47c0aa6190650a7f3e57f1b0760786172245942cdc3fe590d

Contents?: true

Size: 1009 Bytes

Versions: 1

Compression:

Stored size: 1009 Bytes

Contents

# encoding: utf-8

require 'loaf/crumb_formatter'
require 'loaf/options_validator'

module Loaf
  module ViewExtensions
    include Loaf::CrumbFormatter
    include Loaf::OptionsValidator

    # Adds breadcrumbs inside view.
    #
    def breadcrumb(name, url)
      _breadcrumbs.push Loaf::Crumb.new(name, url)
    end
    alias :add_breadcrumb :breadcrumb

    # Renders breadcrumbs inside view.
    #
    def breadcrumbs(options={}, &block)
      #builder = Loaf::Builder.new(options)
      valid? options
      options = Loaf.config.merge(options)
      _breadcrumbs.each do |crumb|
        name = format_name crumb, options

        url = url_for _process_url_for(crumb.url)

        styles = current_page?(url) ? "#{options[:style_classes]}" : ''

        block.call(name, url, styles)
      end
    end

    private

    def _process_url_for(url)
      if url.is_a?(String) || url.is_a?(Symbol)
        return send url
      else
        return url
      end
    end

  end # ViewExtensions
end # Loaf

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
loaf-0.3.0 lib/loaf/view_extensions.rb