Skip to content

Instantly share code, notes, and snippets.

@matthuhiggins
Created November 9, 2010 05:13
Show Gist options
  • Save matthuhiggins/668732 to your computer and use it in GitHub Desktop.
Save matthuhiggins/668732 to your computer and use it in GitHub Desktop.
google ajax
google_paths = {
'prototype' => 'http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/',
'controls' => 'http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.1/',
'dragdrop' => 'http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.1/',
'effects' => 'http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.1/'
}
config.action_controller.asset_host = Proc.new do |source, request|
google_asset = google_paths.keys.detect { |asset| source.starts_with?("/javascripts/#{asset}") }
google_asset ? google_paths[google_asset] : "#{request.protocol}#{request.host_with_port}"
end
module ActionView
module Helpers
module GoogleAssetTagHelper
GOOGLE_PATHS = {
'prototype' => 'http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype',
'controls' => 'http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.1/controls',
'dragdrop' => 'http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.1/dragdrop',
'effects' => 'http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.1/effects'
}
def self.included(base)
base.send :alias_method_chain, :expand_javascript_sources, :google unless ActionController::Base.consider_all_requests_local
end
def expand_javascript_sources_with_google(sources)
google_sources, normal_sources = sources.partition { |source| GOOGLE_PATHS.include? source }
GOOGLE_PATHS.values_at(*google_sources) + expand_javascript_sources_without_google(normal_sources)
end
end
end
end
ActionView::Base.class_eval do
include ActionView::Helpers::GoogleAssetTagHelper
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment