Module: Rad::ViewRoutingHelper

Defined in:
lib/rad/web/_router/view_routing_helper.rb

Instance Method Summary collapse

Instance Method Details



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rad/web/_router/view_routing_helper.rb', line 4

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[-2].is_a?(Hash)
        args.pop
      else
        {}
      end

      args << {} unless args[-1].is_a?(Hash)
      url = url_for(*args)
    end
  end

  # add javascript
  html_options[:href] = url
  add_js_link_options! url, html_options
  tag :a, content, html_options
end