Method: Interview::Link#build

Defined in:
lib/interview/controls/link.rb

#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