Sha256: feff9682c47e910fe0acdbc20a313df59f596086d26dce1f1d7ed5d927657980

Contents?: true

Size: 1.48 KB

Versions: 24

Compression:

Stored size: 1.48 KB

Contents

module Rad::ViewRoutingHelper
  inherit Rad::AbstractRoutingHelper
  
  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    
  
  protected
    def add_js_link_options! url, html_options
      remote = html_options.delete(:remote) || rad.html.remote_link_formats.include?(url.marks.format)
      method = html_options.delete(:method)
      
      if remote or method
        action = html_options.delete(:href).must_be.defined
        html_options[:href] = '#'
                  
        html_options['data-action'] = action
        html_options['data-remote'] = 'true' if remote
        html_options['data-method'] = method || 'post'
      end
      
      if confirm = html_options.delete(:confirm)
        html_options['data-confirm'] = confirm
      end
    end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
rad_core-0.2.6 lib/rad/web/_router/view_routing_helper.rb
rad_core-0.2.5 lib/rad/web/_router/view_routing_helper.rb
rad_core-0.2.4 lib/rad/web/_router/view_routing_helper.rb
rad_core-0.2.3 lib/rad/web/_router/view_routing_helper.rb
rad_core-0.2.2 lib/rad/web/_router/view_routing_helper.rb
rad_core-0.2.1 lib/rad/web/_router/view_routing_helper.rb
rad_core-0.2.0 lib/rad/web/_router/view_routing_helper.rb
rad_core-0.0.30 lib/rad/web/_router/view_routing_helper.rb
rad_core-0.0.29 lib/rad/web/_router/view_routing_helper.rb
rad_core-0.0.28 lib/rad/web/_router/view_routing_helper.rb
rad_core-0.0.27 lib/rad/web/_router/view_routing_helper.rb
rad_core-0.0.26 lib/rad/web/_router/view_routing_helper.rb
rad_core-0.0.25 lib/rad/core_web/_router/view_routing_helper.rb
rad_core-0.0.24 lib/rad/core_web/_router/view_routing_helper.rb
rad_core-0.0.23 lib/rad/core_web/_router/view_routing_helper.rb
rad_core-0.0.22 lib/rad/core_web/_router/view_routing_helper.rb
rad_core-0.0.21 lib/rad/core_web/_router/view_routing_helper.rb
rad_core-0.0.20 lib/rad/core_web/_router/view_routing_helper.rb
rad_core-0.0.19 lib/rad/core_web/_router/view_routing_helper.rb
rad_core-0.0.18 lib/rad/core_web/_router/view_routing_helper.rb