headjs-rails 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/headjs-rails.gemspec +2 -2
- data/lib/generators/headjs/install/install_generator.rb +15 -4
- data/lib/headjs-rails/tag_helper.rb +2 -2
- data/test/test_tag_helper.rb +12 -8
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/headjs-rails.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{headjs-rails}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["David Bittencourt"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-01-17}
|
13
13
|
s.description = %q{This gem adds a helper and generator to facilitate the use of Head JS in your Rails 3 projects the same way you would normally add javascript tags using Rails default helpers.}
|
14
14
|
s.email = %q{muitocomplicado@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -4,6 +4,7 @@ module Headjs
|
|
4
4
|
desc "This generator downloads and installs Head JS"
|
5
5
|
class_option :version, :type => :string, :default => "master", :desc => "Which version of Head JS to fetch"
|
6
6
|
@@default_version = "master"
|
7
|
+
@@dist_url = "https://github.com/headjs/headjs/raw/{version}/dist/{file}"
|
7
8
|
|
8
9
|
def remove_headjs
|
9
10
|
%w(head.js head.min.js).each do |js|
|
@@ -16,15 +17,25 @@ module Headjs
|
|
16
17
|
get_headjs(options.version)
|
17
18
|
rescue OpenURI::HTTPError
|
18
19
|
say_status("warning", "could not find Head JS (#{options.version})", :yellow)
|
19
|
-
say_status("
|
20
|
-
|
20
|
+
say_status("warning", headjs_url(options.version, 'head.js'), :yellow)
|
21
|
+
say_status("warning", headjs_url(options.version, 'head.min.js'), :yellow)
|
22
|
+
|
23
|
+
if @@default_version != options.version
|
24
|
+
say_status("fetching", "Head JS (#{@@default_version})", :green)
|
25
|
+
get_headjs(@@default_version)
|
26
|
+
end
|
21
27
|
end
|
22
28
|
|
23
29
|
private
|
24
30
|
|
25
31
|
def get_headjs(version)
|
26
|
-
|
27
|
-
|
32
|
+
%w(head.js head.min.js).each do |js|
|
33
|
+
get headjs_url(version, js), "public/javascripts/#{js}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def headjs_url(version, file)
|
38
|
+
@@dist_url.gsub("{version}", version).gsub("{file}", file)
|
28
39
|
end
|
29
40
|
|
30
41
|
end
|
@@ -4,14 +4,14 @@ module Headjs
|
|
4
4
|
|
5
5
|
def headjs_include_tag(*sources)
|
6
6
|
keys = []
|
7
|
-
content_tag :script, :type => Mime::JS do
|
7
|
+
content_tag :script, { :type => Mime::JS }, false do
|
8
8
|
"head.js( #{javascript_include_tag(*sources).scan(/src="([^"]+)"/).flatten.map { |src|
|
9
9
|
key = URI.parse(src).path[%r{[^/]+\z}].gsub(/\.js$/,'').gsub(/\.min$/,'')
|
10
10
|
while keys.include?(key) do
|
11
11
|
key += '_' + key
|
12
12
|
end
|
13
13
|
keys << key
|
14
|
-
"{ '#{key}': '#{src}' }"
|
14
|
+
"{ '#{key}': '#{src}' }"
|
15
15
|
}.join(', ')} );"
|
16
16
|
end
|
17
17
|
end
|
data/test/test_tag_helper.rb
CHANGED
@@ -31,38 +31,42 @@ module Headjs
|
|
31
31
|
context "The Head JS helper include tag" do
|
32
32
|
|
33
33
|
should "return a valid script tag" do
|
34
|
-
assert_equal "<script type=\"text/javascript\">head.js( { 'jquery': '#{jquery}' } );</script>"
|
34
|
+
assert_equal @helpers.headjs_include_tag(jquery), "<script type=\"text/javascript\">head.js( { 'jquery': '#{jquery}' } );</script>"
|
35
35
|
end
|
36
36
|
|
37
37
|
should "concatenate labels to avoid overwriting" do
|
38
|
-
assert_equal "<script type=\"text/javascript\">head.js( { 'jquery': '#{jquery}' }, { 'jquery_jquery': '#{jquery}' } );</script>"
|
38
|
+
assert_equal @helpers.headjs_include_tag(jquery, jquery), "<script type=\"text/javascript\">head.js( { 'jquery': '#{jquery}' }, { 'jquery_jquery': '#{jquery}' } );</script>"
|
39
39
|
end
|
40
40
|
|
41
41
|
should "accept strings for local paths" do
|
42
|
-
assert_equal "<script type=\"text/javascript\">head.js( { 'jquery': '/javascripts/jquery.js' }, { 'rails': '/javascripts/other/rails.js' } );</script>"
|
42
|
+
assert_equal @helpers.headjs_include_tag('jquery', 'other/rails'), "<script type=\"text/javascript\">head.js( { 'jquery': '/javascripts/jquery.js' }, { 'rails': '/javascripts/other/rails.js' } );</script>"
|
43
43
|
end
|
44
44
|
|
45
45
|
should "accept :defaults registered expansions" do
|
46
|
-
assert_equal "<script type=\"text/javascript\">head.js( { 'jquery': '/javascripts/jquery.js' }, { 'rails': '/javascripts/rails.js' } );</script>"
|
46
|
+
assert_equal @helpers.headjs_include_tag(:defaults), "<script type=\"text/javascript\">head.js( { 'jquery': '/javascripts/jquery.js' }, { 'rails': '/javascripts/rails.js' } );</script>"
|
47
|
+
end
|
48
|
+
|
49
|
+
should "accept :defaults mixed with other strings" do
|
50
|
+
assert_equal @helpers.headjs_include_tag(:defaults, 'modernizr'), "<script type=\"text/javascript\">head.js( { 'jquery': '/javascripts/jquery.js' }, { 'rails': '/javascripts/rails.js' }, { 'modernizr': '/javascripts/modernizr.js' } );</script>"
|
47
51
|
end
|
48
52
|
|
49
53
|
should "accept :all expansion" do
|
50
|
-
assert_equal "<script type=\"text/javascript\">head.js( { 'jquery': '/javascripts/jquery.js' }, { 'rails': '/javascripts/rails.js' }, { 'application': '/javascripts/application.js' } );</script>"
|
54
|
+
assert_equal @helpers.headjs_include_tag(:all), "<script type=\"text/javascript\">head.js( { 'jquery': '/javascripts/jquery.js' }, { 'rails': '/javascripts/rails.js' }, { 'application': '/javascripts/application.js' } );</script>"
|
51
55
|
end
|
52
56
|
|
53
57
|
should "accept a :cache => true parameter" do
|
54
58
|
@helpers.config.perform_caching = true
|
55
|
-
assert_equal "<script type=\"text/javascript\">head.js( { 'all': '/javascripts/all.js' } );</script>"
|
59
|
+
assert_equal @helpers.headjs_include_tag(:defaults, :cache => true), "<script type=\"text/javascript\">head.js( { 'all': '/javascripts/all.js' } );</script>"
|
56
60
|
end
|
57
61
|
|
58
62
|
should "accept a :cache => bundle parameter" do
|
59
63
|
@helpers.config.perform_caching = true
|
60
|
-
assert_equal "<script type=\"text/javascript\">head.js( { 'bundle': '/javascripts/bundle.js' } );</script>"
|
64
|
+
assert_equal @helpers.headjs_include_tag(:defaults, :cache => 'bundle'), "<script type=\"text/javascript\">head.js( { 'bundle': '/javascripts/bundle.js' } );</script>"
|
61
65
|
end
|
62
66
|
|
63
67
|
should "work with random rails asset ids" do
|
64
68
|
ENV["RAILS_ASSET_ID"] = '123456789'
|
65
|
-
assert_equal "<script type=\"text/javascript\">head.js( { 'jquery': '/javascripts/jquery.js?#{ENV["RAILS_ASSET_ID"]}' }, { 'rails': '/javascripts/rails.js?#{ENV["RAILS_ASSET_ID"]}' } );</script>"
|
69
|
+
assert_equal @helpers.headjs_include_tag(:defaults), "<script type=\"text/javascript\">head.js( { 'jquery': '/javascripts/jquery.js?#{ENV["RAILS_ASSET_ID"]}' }, { 'rails': '/javascripts/rails.js?#{ENV["RAILS_ASSET_ID"]}' } );</script>"
|
66
70
|
end
|
67
71
|
|
68
72
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: headjs-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- David Bittencourt
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-01-17 00:00:00 -02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|