Sha256: e96694b631606777ad3996f7d6d813f0ac4318629d7e9f6b198b070328046645

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

class Breadcrumbs
  module Render
    class Base # :nodoc: all
      attr_accessor :breadcrumbs
      attr_accessor :default_options

      def initialize(breadcrumbs, default_options = {})
        @breadcrumbs = breadcrumbs
        @default_options = default_options
      end

      # Build a HTML tag.
      #
      #   tag(:p, "Hello!")
      #   tag(:p, "Hello!", :class => "hello")
      #   tag(:p, :class => "phrase") { "Hello" }
      #
      def tag(name, *args, &block)
        options = args.pop if args.last.kind_of?(Hash)
        options ||= {}

        content = args.first
        content = self.instance_eval(&block) if block_given?

        attrs = " " + options.collect {|n, v| %[%s="%s"] % [n, v] }.join(" ") unless options.empty?

        %[<#{name}#{attrs}>#{content}</#{name}>]
      end

      protected
      def wrap_item(url, text, options)
        if url
          tag(:a, text, options.merge(:href => url))
        else
          tag(:span, text, options)
        end
      end

      def escape(text)
        text.respond_to?(:html_safe?) && text.html_safe? ? text : Rack::Utils.escape_html(text)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bsm-breadcrumbs-0.3.3 lib/breadcrumbs/render/base.rb