lib/ajaxlibs/library.rb in ajaxlibs-0.1.9 vs lib/ajaxlibs/library.rb in ajaxlibs-0.1.10
- old
+ new
@@ -67,11 +67,13 @@
def latest_version
self.class::Versions.max {|a, b| Ajaxlibs::VersionsTools.compare a, b}
end
# Local path for a particular version, or the latest if given version is nil.
+ # Search for the file in rails public path and copy it if needed.
def local_path
+ check_and_copy_local_file_to_rails_public
File.join('ajaxlibs', library_name, version, file_name)
end
# Include path using google CDN
def google_cdn_include_path
@@ -98,7 +100,23 @@
# Passing a nil value will returns the latest available version
def check_version_or_latest_version(version = nil)
version ||= latest_version
raise Ajaxlibs::Exception::VersionNotFound unless self.class::Versions.include?(version)
version
+ end
+
+ def check_and_copy_local_file_to_rails_public
+ if Object.const_defined?(:Rails) and File.directory?(File.join(Rails.root, 'public'))
+
+ ajaxlibs_js_path = File.join(Rails.root, 'public', 'javascripts', 'ajaxlibs')
+ source_path = File.join(File.dirname(__FILE__), '../../public', library_name, version)
+ source = File.join(source_path, '*.*')
+ destination = File.join(ajaxlibs_js_path, library_name, version)
+
+ if not File.exists?(destination) or Dir.entries(source_path) != Dir.entries(destination)
+ FileUtils.mkdir_p(destination)
+ FileUtils.cp(Dir.glob(source), destination)
+ end
+
+ end
end
end
\ No newline at end of file