Class: Breadcrumbs::Render::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/breadcrumbs/render/base.rb

Overview

:nodoc: all

Direct Known Subclasses

Inline, List

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(breadcrumbs, options = {}) ⇒ Base

Returns a new instance of Base.



7
8
9
10
# File 'lib/breadcrumbs/render/base.rb', line 7

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

Instance Attribute Details

Returns the value of attribute breadcrumbs.



5
6
7
# File 'lib/breadcrumbs/render/base.rb', line 5

def breadcrumbs
  @breadcrumbs
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/breadcrumbs/render/base.rb', line 5

def options
  @options
end

Instance Method Details

#default_optionsHash

This method is abstract.

Returns default options.

Returns:

  • (Hash)

    default options



14
15
16
# File 'lib/breadcrumbs/render/base.rb', line 14

def default_options
  { :class => "breadcrumbs" }
end

#renderString

This method is abstract.

Returns the rendered HTML.

Returns:

  • (String)

    the rendered HTML



20
21
22
# File 'lib/breadcrumbs/render/base.rb', line 20

def render
  ""
end

#tag(name, *args, &block) ⇒ Object

Build a HTML tag.

tag(:p, "Hello!")
tag(:p, "Hello!", :class => "hello")
tag(:p, :class => "phrase") { "Hello" }


30
31
32
33
34
35
36
37
38
39
40
# File 'lib/breadcrumbs/render/base.rb', line 30

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