Permalink
Browse files

Added option to allow for serving jQuery lib from a remote asset serv…

…er (ie. Google).
  • Loading branch information...
1 parent 978d61c commit 9eb569bb978cdfbd7d0f0197f4b0f7319a063268 @midas committed Jan 4, 2010
View
@@ -1,3 +1,13 @@
+= 1.0.10 2010-04-22
+
+* Added option to allow for serving jQuery lib from a remote asset server (ie. Google).
+
+
+= 1.0.9 2010-04-16
+
+* Updated the Rails Guilded initializer template to use Rails.root.
+
+
= 1.0.8 2010-04-16
* Updated the Rails Guilded initializer to get rid of deprecated RAILS_ROOT in favor of Rails.root.
@@ -206,13 +206,45 @@ def generate_asset_lists #:nodoc:
@g_elements.each_value do |defi|
#TODO get stylesheet (skin) stuff using rails caching
combine_css_sources( defi.kind, defi.options[:skin], defi.styles ) unless defi.exclude_css?
-
+
# Combine all JavaScript sources so that the caching option can be used on
# the javascript_incldue_tag helper.
combine_js_sources( defi.kind, defi.libs ) unless defi.exclude_js?
end
end
+ def jquery_js
+ @config[:jquery_js]
+ end
+
+ def jquery_remote_url
+ @config[:jquery_remote_url]
+ end
+
+ def use_remote_jquery
+ @config[:use_remote_jquery]
+ end
+
+ def app_root
+ @config[:app_root]
+ end
+
+ def environment
+ @config[:environment]
+ end
+
+ def development? #:nodoc:
+ environment.to_sym == :development
+ end
+
+ def production? #:nodoc:
+ environment.to_sym == :production
+ end
+
+ def test? #:nodoc:
+ environment.to_sym == :test
+ end
+
protected
def configure_guilded #:nodoc:
@@ -242,14 +274,15 @@ def configure_guilded #:nodoc:
@css_folder.freeze
@reset_css.freeze
@env.freeze
- end
+ end
# Adds the Guilded reset CSS file and the guilded.js and jQuery files to the respective sources
# collections.
#
def init_sources #:nodoc:
@css_temp_hold[:reset] << "#{@reset_css}" unless @reset_css.nil? || @reset_css.empty?
resolve_js_libs( "#{@jquery_js}", "#{@jquery_folder}#{@url_js}", "#{@js_folder}#{@guilded_js}" )
+ #TODO include the jQuery lib from Google server in production
end
# Helper method that takes the libs and component specific js files and puts them
@@ -281,7 +314,7 @@ def resolve_js_libs( *libs ) #:nodoc:
# Try to use an unpacked or unminimized version
libs.each do |lib|
debug_lib = lib.gsub( /.pack/, '' ).gsub( /.min/, '' ).gsub( /.compressed/, '' )
- path = "#{RAILS_ROOT}/public/javascripts/#{debug_lib}"
+ path = "#{app_root}/public/javascripts/#{debug_lib}"
if File.exist?( path )
@combined_js_srcs.push( debug_lib ) unless @combined_js_srcs.include?( debug_lib )
else
@@ -342,18 +375,5 @@ def add_guilded_css_path( source, skin ) #:nodoc:
path = "#{@css_path}#{part}"
File.exists?( path ) ? part : ''
end
-
- def development? #:nodoc:
- @env.to_sym == :development
- end
-
- def production? #:nodoc:
- @env.to_sym == :production
- end
-
- def test? #:nodoc:
- @env.to_sym == :test
- end
-
end
end
@@ -22,8 +22,19 @@ def g_apply_behavior
def g_apply_includes
g = Guilded::Guilder.instance
g.generate_asset_lists
+
+ # CSS
self.output_buffer.sub!( /<!-- guilded.styles -->/, stylesheet_link_tag( g.combined_css_srcs, :cache => "cache/#{g.css_cache_name}" ) )
- javascript_include_tag( g.combined_js_srcs, :cache => "cache/#{g.js_cache_name}" )
+
+ # JavaScript
+ if g.production? && g.use_remote_jquery
+ js_groups = g.combined_js_srcs.partition { |src| src == g.jquery_js }
+ output = javascript_include_tag( g.jquery_remote_url )
+ output << javascript_include_tag( js_groups[1], :cache => "cache/#{g.js_cache_name}" ) unless js_groups[1].nil?
+ else
+ output = javascript_include_tag( g.combined_js_srcs, :cache => "cache/#{g.js_cache_name}" )
+ end
+ output
end
def g_apply_style
@@ -2,9 +2,12 @@
# on this one in order to work in different environments.
#
GUILDED_CONFIG = {
+ :app_root => Rails.root.to_s,
:js_path => "#{Rails.root}/public/javascripts/",
:js_folder => "", # from the js_path
:jquery_js => "jquery/jquery-1.3.2.min.js", # from the js_path
+ :use_remote_jquery => true,
+ :jquery_remote_url => "http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js",
:mootools_js => "mootools/mootools-1.2.3.min.js", # from the js_path
:css_path => "#{Rails.root}/public/stylesheets/",
:css_folder => "guilded/", # from the css_path

0 comments on commit 9eb569b

Please sign in to comment.