Class Mack::Rendering::Type::Url
In: lib/mack/rendering/type/url.rb
Parent: Mack::Rendering::Type::Base

This class will render the contents of a url.

Examples: This is considered a ‘remote’ request and will be made using GET.

  <%= render(:url, "http://www.mackframework.com") %>

This is considered a ‘remote’ request and will be made using POST.

  <%= render(:url, "http://www.mackframework.com", :method => :post) %>

This is considered a ‘remote’ request and will be made using GET, and will have query string parameters.

  <%= render(:url, "http://www.mackframework.com", :parameters => {:name => "mark"}) %> # http://www.mackframework.com?name=mark

This is considered a ‘remote’ request and will be made using POST, and will have form parameters.

  <%= render(:url, "http://www.mackframework.com", :method => :post, :parameters => {:name => "mark"}) %>

‘Local’ requests can also be made: This is considered a ‘local’ request and will be made using GET.

  <%= render(:url, "/users") %>

This is considered a ‘local’ request and will be made using POST.

  <%= render(:url, "/users", :method => :post) %>

This is considered a ‘local’ request and will be made using GET, and will have query string parameters.

  <%= render(:url, "/users", :parameters => {:name => "mark"}) %> # /users?name=mark

This is considered a ‘local’ request and will be made using POST, and will have form parameters.

  <%= render(:url, "/users", :method => :post, :parameters => {:name => "mark"}) %>

Methods

Public Instance methods

No layouts should be used with this Mack::Rendering::Type

[Source]

    # File lib/mack/rendering/type/url.rb, line 29
29:         def allow_layout?
30:           false
31:         end

Retrieves the contents of the url using either GET or POST, passing along any specified parameters.

[Source]

    # File lib/mack/rendering/type/url.rb, line 34
34:         def render
35:           options = {:method => :get, :raise_exception => false}.merge(self._options)
36:           url = self._render_value
37:           remote = url.match(/^[a-zA-Z]+:\/\//)
38:           case options[:method]
39:           when :get
40:             if remote
41:               do_render_remote_url(url_with_query(url, options[:parameters]), options) do |uri, options|
42:                 Net::HTTP.get_response(uri)
43:               end
44:             else
45:               do_render_local_url(url, options) do |url, options|
46:                 Rack::MockRequest.new(self._app_for_rendering).get(url, options)
47:               end
48:             end
49:           when :post
50:             if remote
51:               do_render_remote_url(url, options) do |uri, options|
52:                 Net::HTTP.post_form(uri, options[:parameters] || {})
53:               end
54:             else
55:               do_render_local_url(url, options) do |url, options|
56:                 Rack::MockRequest.new(self._app_for_rendering).post(url, options)
57:               end
58:             end
59:           else
60:             raise Mack::Errors::UnsupportRenderUrlMethodType.new(options[:method])
61:           end
62:         end

[Validate]