Class: TabsOnRails::Tabs

Inherits:
Object
  • Object
show all
Defined in:
lib/tabs_on_rails/tabs.rb,
lib/tabs_on_rails/tabs/builder.rb,
lib/tabs_on_rails/tabs/tabs_builder.rb

Defined Under Namespace

Classes: Builder, TabsBuilder

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, options = {}) ⇒ Tabs

Returns a new instance of Tabs.



25
26
27
28
29
# File 'lib/tabs_on_rails/tabs.rb', line 25

def initialize(context, options = {})
  @context = context
  @builder = (options.delete(:builder) || self.class.default_builder).new(@context, options)
  @options = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object



42
43
44
# File 'lib/tabs_on_rails/tabs.rb', line 42

def method_missing(*args, &block)
  @builder.tab_for(*args, &block)
end

Class Attribute Details

.default_builderObject



20
21
22
# File 'lib/tabs_on_rails/tabs.rb', line 20

def default_builder
  @default_builder ||= TabsBuilder
end

Instance Method Details

#render(&block) ⇒ Object

Renders the tab stack using the current builder.

Returns the String HTML content.

Raises:

  • (LocalJumpError)


50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/tabs_on_rails/tabs.rb', line 50

def render(&block)
  raise LocalJumpError, "no block given" unless block_given?

  options = @options.dup
  open_tabs_options  = options.delete(:open_tabs)  || {}
  close_tabs_options = options.delete(:close_tabs) || {}

  "".tap do |html|
    html << open_tabs(open_tabs_options).to_s
    html << @context.capture(self, &block)
    html << close_tabs(close_tabs_options).to_s
  end.html_safe
end