require_assets 0.1.0
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/.document +6 -0
- data/.gitignore +23 -0
- data/LICENSE +21 -0
- data/README.rdoc +54 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/lib/require_assets.rb +98 -0
- data/rails/init.rb +5 -0
- data/spec/require_assets_spec.rb +4 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +86 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2008 Ezra Zygmuntowicz
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
= require_assets
|
2
|
+
|
3
|
+
Ruby on Rails helpers to add asset links to views. Extracted from merb-assets Merb plugin.
|
4
|
+
|
5
|
+
== Quick overview of the API
|
6
|
+
|
7
|
+
* {RequireAssets::Helpers#require_js require_js} is smart(-er) way to do includes just once per page no matter how many times partial use it.
|
8
|
+
* {RequireAssets::Helpers#require_css require_css} is like require_js but for CSS.
|
9
|
+
* {RequireAssets::Helpers#include_required_js include_required_js} generates script tags for previously included files.
|
10
|
+
* {RequireAssets::Helpers#include_required_css include_required_css} generates link tags for previously included files.
|
11
|
+
|
12
|
+
== Examples
|
13
|
+
|
14
|
+
{RequireAssets::Helpers#require_js require_js} and {RequireAssets::Helpers#require_css require_css}, {RequireAssets::Helpers#include_required_js include_required_js} and {RequireAssets::Helpers#include_required_css include_required_css} require assets just once:
|
15
|
+
|
16
|
+
In your application layout:
|
17
|
+
|
18
|
+
include_required_js
|
19
|
+
|
20
|
+
In your controller layout:
|
21
|
+
|
22
|
+
require_js 'posts'
|
23
|
+
|
24
|
+
The require_js method can be used to require any JavaScript file anywhere in your templates. Regardless of how many times a single script is included with require_js, it will only be included once in the header.
|
25
|
+
|
26
|
+
# File: app/views/layouts/application.html.erb
|
27
|
+
|
28
|
+
<html>
|
29
|
+
<head>
|
30
|
+
<%= include_required_js %>
|
31
|
+
<%= include_required_css %>
|
32
|
+
</head>
|
33
|
+
<body>
|
34
|
+
<%= yield %>
|
35
|
+
</body>
|
36
|
+
</html>
|
37
|
+
|
38
|
+
# File: app/views/whatever/index.html.erb
|
39
|
+
|
40
|
+
<% require_js 'this' -%>
|
41
|
+
<% require_css 'that', 'another_one' -%>
|
42
|
+
|
43
|
+
# Will generate the following in the final page...
|
44
|
+
<html>
|
45
|
+
<head>
|
46
|
+
<script src="/javascripts/this.js" type="text/javascript"></script>
|
47
|
+
<link href="/stylesheets/that.css" media="screen" rel="stylesheet" type="text/css"/>
|
48
|
+
<link href="/stylesheets/another_one.css" media="screen" rel="stylesheet" type="text/css"/>
|
49
|
+
</head>
|
50
|
+
.
|
51
|
+
.
|
52
|
+
.
|
53
|
+
</html>
|
54
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "require_assets"
|
8
|
+
gem.summary = 'Ruby on Rails helpers to add asset links to views.'
|
9
|
+
gem.description = 'Ruby on Rails helpers to add asset links to views. Extracted from merb-assets Merb plugin.'
|
10
|
+
gem.email = "jeremy.burks@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/jrun/require_assets"
|
12
|
+
gem.authors = ["Jeremy Burks"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
gem.add_development_dependency "yard", ">= 0"
|
15
|
+
gem.files += FileList['rails/*']
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'spec/rake/spectask'
|
24
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
25
|
+
spec.libs << 'lib' << 'spec'
|
26
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
27
|
+
end
|
28
|
+
|
29
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
30
|
+
spec.libs << 'lib' << 'spec'
|
31
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
32
|
+
spec.rcov = true
|
33
|
+
end
|
34
|
+
|
35
|
+
task :spec => :check_dependencies
|
36
|
+
|
37
|
+
task :default => :spec
|
38
|
+
|
39
|
+
begin
|
40
|
+
require 'yard'
|
41
|
+
YARD::Rake::YardocTask.new
|
42
|
+
rescue LoadError
|
43
|
+
task :yardoc do
|
44
|
+
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
45
|
+
end
|
46
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module RequireAssets
|
2
|
+
module Helpers
|
3
|
+
# The require_js method can be used to require any JavaScript file anywhere in
|
4
|
+
# your templates. Regardless of how many times a single script is included
|
5
|
+
# with require_js, Rails will only include it once in the header.
|
6
|
+
#
|
7
|
+
# @param [#to_s] JavaScript files to include
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# <% require_js('jquery') %>
|
11
|
+
# # A subsequent call to include_required_js will render...
|
12
|
+
# # => <script src="/javascripts/jquery.js" type="text/javascript"></script>
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# <% require_js('jquery', 'effects', 'validation') %>
|
16
|
+
#
|
17
|
+
# # A subsequent call to include_required_js will render...
|
18
|
+
# # => <script src="/javascripts/jquery.js" type="text/javascript"></script>
|
19
|
+
# # <script src="/javascripts/effects.js" type="text/javascript"></script>
|
20
|
+
# # <script src="/javascripts/validation.js" type="text/javascript"></script>
|
21
|
+
#
|
22
|
+
def require_js(*js)
|
23
|
+
@required_js ||= []
|
24
|
+
@required_js |= js
|
25
|
+
end
|
26
|
+
|
27
|
+
# The require_css method can be used to require any CSS file anywhere in
|
28
|
+
# your templates. Regardless of how many times a single stylesheet is
|
29
|
+
# included with require_css, Rails will only include it once in the header.
|
30
|
+
#
|
31
|
+
# @param [#to_s] CSS files to include
|
32
|
+
#
|
33
|
+
# @example
|
34
|
+
# <% require_css('style') %>
|
35
|
+
# # A subsequent call to include_required_css will render...
|
36
|
+
# # => <link href="/stylesheets/style.css" media="screen" rel="Stylesheet" type="text/css"/>
|
37
|
+
#
|
38
|
+
# @example
|
39
|
+
# <% require_css('style', 'ie-specific') %>
|
40
|
+
# # A subsequent call to include_required_css will render...
|
41
|
+
# # => <link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css"/>
|
42
|
+
# # <link href="/stylesheets/ie-specific.css" media="screen" rel="stylesheet" type="text/css"/>
|
43
|
+
#
|
44
|
+
def require_css(*css)
|
45
|
+
@required_css ||= []
|
46
|
+
@required_css |= css
|
47
|
+
end
|
48
|
+
|
49
|
+
# A method used in the layout of an application to create +<script>+ tags
|
50
|
+
# to include JavaScripts required in in templates and subtemplates using
|
51
|
+
# require_js.
|
52
|
+
#
|
53
|
+
# @return [String] The JavaScript tag
|
54
|
+
#
|
55
|
+
# @example
|
56
|
+
# # my_action.html.erb has a call to require_js 'jquery'
|
57
|
+
# # File: layout/application.html.erb
|
58
|
+
# include_required_js
|
59
|
+
# # => <script src="/javascripts/jquery.js" type="text/javascript"></script>
|
60
|
+
#
|
61
|
+
# @example
|
62
|
+
# # my_action.html.erb has a call to require_js 'jquery', 'effects', 'validation'
|
63
|
+
# # File: layout/application.html.erb
|
64
|
+
# include_required_js
|
65
|
+
# # => <script src="/javascripts/jquery.js" type="text/javascript"></script>
|
66
|
+
# # <script src="/javascripts/effects.js" type="text/javascript"></script>
|
67
|
+
# # <script src="/javascripts/validation.js" type="text/javascript"></script>
|
68
|
+
#
|
69
|
+
def include_required_js
|
70
|
+
return '' if @required_js.nil?
|
71
|
+
javascript_include_tag(*@required_js)
|
72
|
+
end
|
73
|
+
|
74
|
+
# A method used in the layout of an application to create +<link>+ tags for
|
75
|
+
# CSS stylesheets required in in templates and subtemplates using
|
76
|
+
# require_css.
|
77
|
+
#
|
78
|
+
# @return [String] The CSS tag
|
79
|
+
#
|
80
|
+
# @example
|
81
|
+
# # my_action.html.erb has a call to require_css 'style'
|
82
|
+
# # File: layout/application.html.erb
|
83
|
+
# include_required_css
|
84
|
+
# # => <link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css"/>
|
85
|
+
#
|
86
|
+
# @example
|
87
|
+
# # my_action.html.erb has a call to require_js 'style', 'ie-specific'
|
88
|
+
# # File: layout/application.html.erb
|
89
|
+
# include_required_css
|
90
|
+
# # => <link href="/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css"/>
|
91
|
+
# <link href="/stylesheets/ie-specific.css" media="screen" rel="stylesheet" type="text/css"/>
|
92
|
+
#
|
93
|
+
def include_required_css
|
94
|
+
return '' if @required_css.nil?
|
95
|
+
stylesheet_link_tag(*@required_css)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/rails/init.rb
ADDED
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: require_assets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeremy Burks
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-22 00:00:00 -06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.9
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: yard
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
description: Ruby on Rails helpers to add asset links to views. Extracted from merb-assets Merb plugin.
|
36
|
+
email: jeremy.burks@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .document
|
46
|
+
- .gitignore
|
47
|
+
- LICENSE
|
48
|
+
- README.rdoc
|
49
|
+
- Rakefile
|
50
|
+
- VERSION
|
51
|
+
- lib/require_assets.rb
|
52
|
+
- rails/init.rb
|
53
|
+
- spec/require_assets_spec.rb
|
54
|
+
- spec/spec.opts
|
55
|
+
- spec/spec_helper.rb
|
56
|
+
has_rdoc: true
|
57
|
+
homepage: http://github.com/jrun/require_assets
|
58
|
+
licenses: []
|
59
|
+
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options:
|
62
|
+
- --charset=UTF-8
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: "0"
|
70
|
+
version:
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: "0"
|
76
|
+
version:
|
77
|
+
requirements: []
|
78
|
+
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 1.3.5
|
81
|
+
signing_key:
|
82
|
+
specification_version: 3
|
83
|
+
summary: Ruby on Rails helpers to add asset links to views.
|
84
|
+
test_files:
|
85
|
+
- spec/require_assets_spec.rb
|
86
|
+
- spec/spec_helper.rb
|