Sha256: 563cbc403cc75fe81405774e51c1c74f3e29e5683e53dd8cf86f11c5f9ab0925

Contents?: true

Size: 1.97 KB

Versions: 16

Compression:

Stored size: 1.97 KB

Contents

# A Rails view helper module, which over-rides #url_for and some other
# rails url-generating methods, so that they can be forced to generate
# absolute URLs if a controller iVar is set to say so. 
#
# This is used by our partial HTML api responses, so make sure html snippets
# have absolute URLs in them. 

module Umlaut::UrlGeneration
  
  # Over-ride to allow default forcing of urls with hostnames.
  # This is neccesary for our partial_html_sections service
  # to work properly. Just set @generate_url_with_host = true
  # in your controller, and urls will be generated with hostnames
  # for the remainder of that action.
  def url_for(*arguments)
    url = super
    if @generate_urls_with_host && url.starts_with?("/")
      #regex take root url and get just scheme/port part, no path. 
      # the path we want is in our own url we will add on. 
      url = root_url.gsub(/\A(.*\/\/[^\/]+)\/.*\Z/, '\1') + url
    end
    return url
  end

  # over-ride path_to_image to generate complete urls with hostname and everything
  # if @generate_url_with_host is set. This makes image_tag generate
  # src with full url with host. See #url_for
  def path_to_image(source)
    path = super(source)
    if @generate_urls_with_host
      protocol =  request.protocol()
      path = protocol + request.host_with_port() + path
    end
    return path
  end
  # Rails2 uses 'path_to_image' instead, that's what we have to override,
  # we used to use image_path, so let's alias that too. 
  alias :image_path :path_to_image

  
  # We want stylesheets and javascripts to do the exact same thing,
  # magic of polymorphous super() makes it work:
  def path_to_stylesheet(*args)
    path = super
    if @generate_urls_with_host    
      path = request.protocol() + request.host_with_port() + path
    end
    return path
  end

  def path_to_javascript(*args)
    path = super
    if @generate_urls_with_host    
      path = request.protocol() + request.host_with_port() + path
    end
    return path
  end  

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
umlaut-4.1.7 app/helpers/umlaut/url_generation.rb
umlaut-4.1.6 app/helpers/umlaut/url_generation.rb
umlaut-4.1.5 app/helpers/umlaut/url_generation.rb
umlaut-4.1.4 app/helpers/umlaut/url_generation.rb
umlaut-4.1.3 app/helpers/umlaut/url_generation.rb
umlaut-4.1.2 app/helpers/umlaut/url_generation.rb
umlaut-4.1.1 app/helpers/umlaut/url_generation.rb
umlaut-4.1.0 app/helpers/umlaut/url_generation.rb
umlaut-4.1.0.pre3 app/helpers/umlaut/url_generation.rb
umlaut-4.1.0.pre.2 app/helpers/umlaut/url_generation.rb
umlaut-4.1.0.pre.alpha.1 app/helpers/umlaut/url_generation.rb
umlaut-4.0.3 app/helpers/umlaut/url_generation.rb
umlaut-4.0.2 app/helpers/umlaut/url_generation.rb
umlaut-4.0.1 app/helpers/umlaut/url_generation.rb
umlaut-4.0.0 app/helpers/umlaut/url_generation.rb
umlaut-4.0.0.beta5 app/helpers/umlaut/url_generation.rb