Class: InlineForms::Tabs::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/inline_forms/tabs.rb

Overview

Renders a tab group: open tag, one tab_for per named tab, close tag. tab.anything(...) is dispatched to the builder's tab_for via method_missing, exactly like upstream.

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Renderer.



85
86
87
88
89
# File 'lib/inline_forms/tabs.rb', line 85

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object



99
100
101
# File 'lib/inline_forms/tabs.rb', line 99

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

Instance Method Details

#close_tabs(*args) ⇒ Object



95
96
97
# File 'lib/inline_forms/tabs.rb', line 95

def close_tabs(*args)
  call_builder(:close_tabs, *args)
end

#open_tabs(*args) ⇒ Object



91
92
93
# File 'lib/inline_forms/tabs.rb', line 91

def open_tabs(*args)
  call_builder(:open_tabs, *args)
end

#render(&block) ⇒ Object

Raises:

  • (LocalJumpError)


107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/inline_forms/tabs.rb', line 107

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) || {}

  "".dup.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

#respond_to_missing?(_name, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/inline_forms/tabs.rb', line 103

def respond_to_missing?(_name, _include_private = false)
  true
end