Module: Rad::ViewRoutingHelper

Defined in:
lib/rad/integration/router/view_routing_helper.rb

Instance Method Summary collapse

Instance Method Details

links

def link_to *args, &block

# parse args
content = if block
  capture(&block)
else
  args.shift
end

special = nil
html_options = if args.last.is_a?(Hash)
  if args[-2].is_a?(Hash)
    args.pop
  else
    {}
  end          
else        
  args << {}
  {}
end            

# build url
url = special_url(*args) || url_for(*args)

# add javascript
add_js_link_options! url, html_options

tag :a, content, html_options.merge(href: url)

end



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rad/integration/router/view_routing_helper.rb', line 37

def link_to *args, &block      
  # content
  content = if block
    capture(&block)
  else
    args.shift
  end
        
  # url, html_options
  if args.first.is_a? String
    args.size.must_be.in 1..2
    url, html_options = args
    html_options ||= {}
  else
    if url = special_url(args.first)
      args.size.must_be <= 2
      html_options = args[1] || {}
    else
      html_options = if args[-1].is_a?(Hash) and args[-1].is_a?(Hash)
        args.pop
      else
        {}
      end
      
      args << {} unless args[-1].is_a?(Hash)
      url = url_for(*args)
    end
  end
  
  # add javascript
  add_js_link_options! url, html_options
  
  tag :a, content, html_options.merge(href: url)
end