ajaxlibs 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +13 -14
- data/VERSION +1 -1
- data/lib/ajaxlibs/includes_helper.rb +17 -36
- data/lib/ajaxlibs/libraries/dojo.rb +14 -0
- data/lib/ajaxlibs/libraries/jqueryui.rb +3 -5
- data/lib/ajaxlibs/libraries/mootools.rb +8 -0
- data/lib/ajaxlibs/libraries/scriptaculous.rb +2 -4
- data/lib/ajaxlibs/library.rb +30 -9
- data/lib/ajaxlibs.rb +2 -0
- data/public/dojo/1.1.1/dojo.xd.js.uncompressed.js +8986 -0
- data/public/dojo/1.2.0/dojo.xd.js.uncompressed.js +9350 -0
- data/public/dojo/1.2.3/dojo.xd.js.uncompressed.js +9337 -0
- data/public/dojo/1.3.0/dojo.xd.js.uncompressed.js +10322 -0
- data/public/dojo/1.3.1/dojo.xd.js.uncompressed.js +10329 -0
- data/public/dojo/1.3.2/dojo.xd.js.uncompressed.js +10331 -0
- data/public/dojo/1.4.0/dojo.xd.js.uncompressed.js +12129 -0
- data/public/dojo/1.4.1/dojo.xd.js.uncompressed.js +12129 -0
- data/spec/includes_helper_spec.rb +25 -40
- data/spec/library_spec.rb +92 -10
- metadata +13 -3
data/README.rdoc
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
= Ajaxlibs
|
2
2
|
|
3
|
+
== Synopsis
|
4
|
+
|
5
|
+
Simplify standard javascript library includes :
|
6
|
+
* specify your library name and if necessary version number
|
7
|
+
* provides most common javascript libraries, no need to download them
|
8
|
+
* easy CDN for javascript libraries : relies on Google CDN to distribute javascript files on production environment
|
9
|
+
|
10
|
+
All that using a simple helper ruby method.
|
11
|
+
|
3
12
|
== Description
|
4
13
|
|
5
14
|
Ajaxlibs provides helpers to load various javascript libraries, specifying version number, locally served or using google CDN.
|
@@ -20,12 +29,7 @@ will produce, under the development environment :
|
|
20
29
|
|
21
30
|
and in production :
|
22
31
|
|
23
|
-
<script
|
24
|
-
<script type="text/javascript">
|
25
|
-
//<![CDATA[
|
26
|
-
google.load('jquery', '1.4.2');
|
27
|
-
//]]>
|
28
|
-
</script>
|
32
|
+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js" type="text/javascript"></script>
|
29
33
|
|
30
34
|
=== multiple libraries load
|
31
35
|
|
@@ -34,17 +38,12 @@ and in production :
|
|
34
38
|
in development environment :
|
35
39
|
|
36
40
|
<script src="/javascripts/ajaxlibs/jquery/1.4.2/jquery.js?1267013480" type="text/javascript"></script>
|
37
|
-
<script src="/javascripts/ajaxlibs/jqueryui/1.7.2/jqueryui.js" type="text/javascript"></script>
|
41
|
+
<script src="/javascripts/ajaxlibs/jqueryui/1.7.2/jqueryui.js?1267013480" type="text/javascript"></script>
|
38
42
|
|
39
43
|
this time in production :
|
40
44
|
|
41
|
-
<script
|
42
|
-
<script type="text/javascript">
|
43
|
-
//<![CDATA[
|
44
|
-
google.load('jquery', '1.4.2');
|
45
|
-
google.load('jqueryui', '1.7.2');
|
46
|
-
//]]>
|
47
|
-
</script>
|
45
|
+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js" type="text/javascript"></script>
|
46
|
+
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js" type="text/javascript"></script>
|
48
47
|
|
49
48
|
=== forcing a version
|
50
49
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -19,20 +19,15 @@ module Ajaxlibs::IncludesHelper
|
|
19
19
|
#
|
20
20
|
# ajaxlibs_include :jquery, :jqueryui
|
21
21
|
# <script src="/javascripts/ajaxlibs/jquery/1.4.2/jquery.js?1267013480" type="text/javascript"></script>
|
22
|
-
# <script src="/javascripts/ajaxlibs/jqueryui/1.7.2/jqueryui.js" type="text/javascript"></script>
|
22
|
+
# <script src="/javascripts/ajaxlibs/jqueryui/1.7.2/jqueryui.js?1267013480" type="text/javascript"></script>
|
23
23
|
#
|
24
24
|
# * Same examples as above, this time in production
|
25
25
|
# ajaxlibs_include :jquery
|
26
|
-
# <script src="/
|
26
|
+
# <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js" type="text/javascript"></script>
|
27
27
|
#
|
28
28
|
# ajaxlibs_include :jquery, :jqueryui
|
29
|
-
# <script
|
30
|
-
# <script type="text/javascript">
|
31
|
-
# //<![CDATA[
|
32
|
-
# google.load('jquery', '1.4.2');
|
33
|
-
# google.load('jqueryui', '1.7.2');
|
34
|
-
# //]]>
|
35
|
-
# </script>
|
29
|
+
# <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js" type="text/javascript"></script>
|
30
|
+
# <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js" type="text/javascript"></script>
|
36
31
|
#
|
37
32
|
# * Specifying version
|
38
33
|
# ajaxlibs_include :prototype, :version => '1.6.0.3'
|
@@ -45,46 +40,32 @@ module Ajaxlibs::IncludesHelper
|
|
45
40
|
#
|
46
41
|
def ajaxlibs_include(*args)
|
47
42
|
options = (Hash === args.last) ? args.pop : {}
|
48
|
-
|
49
|
-
includes = args.collect {|library| javascript_include_library library, options}.compact.join("\n")
|
50
43
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
#{javascript_tag includes}
|
55
|
-
EOB
|
56
|
-
else
|
57
|
-
includes
|
58
|
-
end
|
44
|
+
includes = args.collect {|library| javascript_include_library library, options}.flatten.compact
|
45
|
+
|
46
|
+
includes.collect {|ajaxlib| javascript_include_tag ajaxlib.include_path}.join("\n")
|
59
47
|
end
|
60
48
|
|
61
49
|
private
|
62
50
|
def javascript_include_library(library, options)
|
63
51
|
library = library.to_sym
|
52
|
+
version = options.delete(:version)
|
53
|
+
source = (options[:local] === true or RAILS_ENV != 'production') ? :local : :remote
|
54
|
+
ajaxlib = Ajaxlibs::Library.by_name(library, :version => version, :source => source)
|
64
55
|
|
65
56
|
@included_javascript_libraries ||= []
|
66
57
|
|
67
|
-
return if @included_javascript_libraries.include?(
|
68
|
-
|
69
|
-
version = options.delete(:version)
|
70
|
-
ajaxlib = Ajaxlibs::Library.by_name(library)
|
58
|
+
return if @included_javascript_libraries.include?(ajaxlib)
|
59
|
+
@included_javascript_libraries << ajaxlib
|
71
60
|
|
72
61
|
result = []
|
73
62
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
@included_javascript_libraries << library
|
80
|
-
|
81
|
-
# Javascript load code
|
82
|
-
if options[:local] === true or RAILS_ENV != 'production'
|
83
|
-
result << javascript_include_tag(ajaxlib.local_path(version))
|
84
|
-
else
|
85
|
-
result << ajaxlib.google_cdn_load_code(version)
|
63
|
+
if ajaxlib.requires
|
64
|
+
ajaxlib.requires.each do |required_library, required_version|
|
65
|
+
result << javascript_include_library(required_library, :version => required_version)
|
66
|
+
end
|
86
67
|
end
|
87
68
|
|
88
|
-
result
|
69
|
+
result << ajaxlib
|
89
70
|
end
|
90
71
|
end
|
data/lib/ajaxlibs/library.rb
CHANGED
@@ -7,6 +7,9 @@ require 'ajaxlibs/versions_tools'
|
|
7
7
|
class Ajaxlibs::Library
|
8
8
|
# Available versions for this library.
|
9
9
|
Versions = []
|
10
|
+
Requirements = {}
|
11
|
+
|
12
|
+
attr_reader :version, :source
|
10
13
|
|
11
14
|
@@subclasses = {}
|
12
15
|
|
@@ -19,9 +22,9 @@ class Ajaxlibs::Library
|
|
19
22
|
@@subclasses.values
|
20
23
|
end
|
21
24
|
|
22
|
-
# Search a specific library by its name
|
23
|
-
def self.by_name(name)
|
24
|
-
@@subclasses[name.to_sym].new
|
25
|
+
# Search a specific library by its name (could be either a string or a symbol) and initialized it with given version and source.
|
26
|
+
def self.by_name(name, options = {})
|
27
|
+
@@subclasses[name.to_sym].new options
|
25
28
|
rescue NoMethodError
|
26
29
|
raise Ajaxlibs::Exception::LibraryNotFound
|
27
30
|
end
|
@@ -31,9 +34,14 @@ class Ajaxlibs::Library
|
|
31
34
|
name.match(/::(\w+)$/)[1].downcase
|
32
35
|
end
|
33
36
|
|
37
|
+
def initialize(options = {})
|
38
|
+
@version = check_version_or_latest_version(options[:version])
|
39
|
+
@source = options[:source] || :local
|
40
|
+
end
|
41
|
+
|
34
42
|
# Returns requirements for a library (for example, prototype for scriptaculous)
|
35
43
|
def requires
|
36
|
-
|
44
|
+
self.class::Requirements[@version] || self.class::Requirements[:all]
|
37
45
|
end
|
38
46
|
|
39
47
|
# Library name based on class name
|
@@ -52,13 +60,26 @@ class Ajaxlibs::Library
|
|
52
60
|
end
|
53
61
|
|
54
62
|
# Local path for a particular version, or the latest if given version is nil.
|
55
|
-
def local_path
|
56
|
-
File.join('ajaxlibs', library_name,
|
63
|
+
def local_path
|
64
|
+
File.join('ajaxlibs', library_name, version, file_name)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Include path using google CDN
|
68
|
+
def google_cdn_include_path
|
69
|
+
"http://ajax.googleapis.com/ajax/libs/#{library_name}/#{version}/#{file_name}.js"
|
70
|
+
end
|
71
|
+
|
72
|
+
# Javascript include path regarding source (call either local_path or google_cdn_include_path)
|
73
|
+
def include_path
|
74
|
+
source == :local ? local_path : google_cdn_include_path
|
75
|
+
end
|
76
|
+
|
77
|
+
def local_only?
|
78
|
+
false
|
57
79
|
end
|
58
80
|
|
59
|
-
|
60
|
-
|
61
|
-
"google.load('#{library_name}', '#{check_version_or_latest_version(version)}');"
|
81
|
+
def ==(other)
|
82
|
+
self.class == other.class and self.version == other.version and self.source == other.source
|
62
83
|
end
|
63
84
|
|
64
85
|
private
|
data/lib/ajaxlibs.rb
CHANGED
@@ -2,8 +2,10 @@ require 'ajaxlibs/constants'
|
|
2
2
|
require 'ajaxlibs/exceptions'
|
3
3
|
require 'ajaxlibs/versions_tools'
|
4
4
|
require 'ajaxlibs/library'
|
5
|
+
require 'ajaxlibs/libraries/dojo'
|
5
6
|
require 'ajaxlibs/libraries/jquery'
|
6
7
|
require 'ajaxlibs/libraries/jqueryui'
|
8
|
+
require 'ajaxlibs/libraries/mootools'
|
7
9
|
require 'ajaxlibs/libraries/prototype'
|
8
10
|
require 'ajaxlibs/libraries/scriptaculous'
|
9
11
|
require 'ajaxlibs/includes_helper'
|