Class: Interview::Link

Inherits:
Control show all
Includes:
HasHtmlOptions, NestedBuildable
Defined in:
lib/interview/controls/link.rb

Direct Known Subclasses

NavigationItem

Instance Attribute Summary collapse

Attributes included from HasHtmlOptions

#html_class, #html_options

Attributes inherited from Control

#parent

Instance Method Summary collapse

Methods included from NestedBuildable

#create_nested_builder, #render_nested_builder

Methods inherited from Control

#ancestors, #build_child, #build_with_params, #find_attribute, #find_attribute!, #set_attributes, #set_defaults

Constructor Details

#initialize(params = {}) ⇒ Link

Returns a new instance of Link.



11
12
13
14
# File 'lib/interview/controls/link.rb', line 11

def initialize(params={})
  @options = {}
  super
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



6
7
8
# File 'lib/interview/controls/link.rb', line 6

def action
  @action
end

#activeObject

Returns the value of attribute active.



6
7
8
# File 'lib/interview/controls/link.rb', line 6

def active
  @active
end

#assoc_objectObject

Returns the value of attribute assoc_object.



6
7
8
# File 'lib/interview/controls/link.rb', line 6

def assoc_object
  @assoc_object
end

#captionObject

Returns the value of attribute caption.



6
7
8
# File 'lib/interview/controls/link.rb', line 6

def caption
  @caption
end

#hintObject

Returns the value of attribute hint.



6
7
8
# File 'lib/interview/controls/link.rb', line 6

def hint
  @hint
end

#http_methodObject

Returns the value of attribute http_method.



6
7
8
# File 'lib/interview/controls/link.rb', line 6

def http_method
  @http_method
end

#imageObject

Returns the value of attribute image.



6
7
8
# File 'lib/interview/controls/link.rb', line 6

def image
  @image
end

#nested_resourceObject

Returns the value of attribute nested_resource.



6
7
8
# File 'lib/interview/controls/link.rb', line 6

def nested_resource
  @nested_resource
end

#new_siteObject

Returns the value of attribute new_site.



6
7
8
# File 'lib/interview/controls/link.rb', line 6

def new_site
  @new_site
end

#objectObject

Returns the value of attribute object.



6
7
8
# File 'lib/interview/controls/link.rb', line 6

def object
  @object
end

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/interview/controls/link.rb', line 6

def options
  @options
end

#styleObject

Returns the value of attribute style.



6
7
8
# File 'lib/interview/controls/link.rb', line 6

def style
  @style
end

#urlObject

Returns the value of attribute url.



6
7
8
# File 'lib/interview/controls/link.rb', line 6

def url
  @url
end

#url_paramsObject (readonly)

Returns the value of attribute url_params.



9
10
11
# File 'lib/interview/controls/link.rb', line 9

def url_params
  @url_params
end

Instance Method Details

#build(b) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/interview/controls/link.rb', line 16

def build(b)
  html_options = @html_options.dup
  html_class = @html_class.dup
  
  url = get_url
  
  if @action == 'destroy'
    html_options[:method] = :delete
    html_options[:data] = {} unless html_options[:data]
    html_options[:data][:confim] = 'Are you sure?' # todo
  end
  
  if @http_method
    html_options[:method] = @http_method.to_sym
  end
  
  if @hint
    html_options[:title] = @hint
  end
  
  if @style == 'button'
    html_class += %w(btn btn-default)
  elsif @style == 'primary_button'
    html_class += %w(btn btn-primary)
  end
  
  if @new_site
    html_options[:target] = 'blank'
  end
  
  add_list_item(b) do
    b << h.link_to(url, options_to_html(html_options, html_class)) do
      create_nested_builder(b)
      b.glyphicon image: @image if @image
      b.space if @image and @caption
      b.text text: @caption if @caption
      yield if block_given?
      render_nested_builder(b)
    end
  end
end