Class: TabBuilder::Tab
- Inherits:
-
Object
- Object
- TabBuilder::Tab
- Defined in:
- lib/tab_builder/tab.rb
Instance Attribute Summary collapse
-
#controller(name = nil) ⇒ Object
Getter/setter for controller.
-
#options ⇒ Object
Returns the value of attribute options.
-
#paths ⇒ Object
Returns the value of attribute paths.
Instance Method Summary collapse
-
#current(&block) ⇒ Object
Override how to specify a current tab.
-
#initialize(name, options, context, &block) ⇒ Tab
constructor
A new instance of Tab.
- #method_missing(name, *args, &block) ⇒ Object
- #name ⇒ Object
-
#path(url, options = {}) ⇒ Object
Define the path(s) for this tab (ie. what paths correspond to this tab).
-
#root ⇒ Object
Get the root path (ie. what path the tab links to.
- #tooltip ⇒ Object
Constructor Details
#initialize(name, options, context, &block) ⇒ Tab
Returns a new instance of Tab.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/tab_builder/tab.rb', line 5 def initialize(name, , context, &block) @name = name @options = @context = context @current = nil @paths = [] @controller = nil # Copy over context instance variables @context.instance_variables.each do |iv| instance_variable_set(iv, @context.instance_variable_get(iv)) unless instance_variable_defined? iv end instance_eval &block if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/tab_builder/tab.rb', line 53 def method_missing(name, *args, &block) # Pass methods along to the context, if it responds to them (allows for helpers, etc. to be used): if @context.respond_to? name @context.send(name, *args, &block) else super(name, *args, &block) end end |
Instance Attribute Details
#controller(name = nil) ⇒ Object
Getter/setter for controller
38 39 40 |
# File 'lib/tab_builder/tab.rb', line 38 def controller @controller end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/tab_builder/tab.rb', line 3 def @options end |
#paths ⇒ Object
Returns the value of attribute paths.
3 4 5 |
# File 'lib/tab_builder/tab.rb', line 3 def paths @paths end |
Instance Method Details
#current(&block) ⇒ Object
Override how to specify a current tab
44 45 46 47 |
# File 'lib/tab_builder/tab.rb', line 44 def current(&block) @current = block if block_given? @current end |
#name ⇒ Object
22 23 24 |
# File 'lib/tab_builder/tab.rb', line 22 def name I18n.t("#{.string_prefix}#{@name}") end |
#path(url, options = {}) ⇒ Object
Define the path(s) for this tab (ie. what paths correspond to this tab)
27 28 29 30 |
# File 'lib/tab_builder/tab.rb', line 27 def path(url, = {}) url = url_for(url.merge(:only_path => false)) if url.is_a? Hash @paths << OpenHash.new({ :url => url, :method => .delete(:method) || :get }) end |
#root ⇒ Object
Get the root path (ie. what path the tab links to
33 34 35 |
# File 'lib/tab_builder/tab.rb', line 33 def root @paths.first end |
#tooltip ⇒ Object
49 50 51 |
# File 'lib/tab_builder/tab.rb', line 49 def tooltip @options[:tooltip] end |