-
Notifications
You must be signed in to change notification settings - Fork 0
/
SNIPPETS
116 lines (87 loc) · 3.44 KB
/
SNIPPETS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
* Using Repertoire Assets as a Build Tool *
If you want to build your assets for use outside of ruby applications, you can
use the repertoire assets' rake tasks to generate a set of bundled standalone
files. First, import the rake tasks into your gem's Rakefile:
... [ ./Rakefile ]
begin
require 'repertoire-assets'
Repertoire::Assets::Tasks.new(:gem_excludes => ["jquery", ...]) # list any libraries to distribute separately here
rescue LoadError
puts "Repertoire assets not available. Install it with: sudo gem install repertoire-assets"
end
...
Then you can build a bundled and compressed directory of assets for your
component with:
# rake assets:build
This gives you the flexibility of developing and deploying components that use
javascript dependencies and version management for use within ruby frameworks,
but also distributing your code for a wider audience.
The gem_excludes option allow you to list of required javascript libraries NOT to
bundle into your distribution directory for legal reasons. You may also supply
any of the other the other standard repertoire-assets options.
[ since the Rake tasks now require Rails, this use case is less useful ]
/* Repertoire gem assets manifest file */
(function() {
function require_js(src, callback) {
var script = document.createElement("script"),
head = document.getElementsByTagName("head")[0],
done = false;
script.type = "text/javascript";
script.language = "javascript";
script.src = src;
if (callback) {
script.onload = script.onreadystatechange = function() {
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
done = true;
callback();
head.removeChild(script);
}
}
}
head.appendChild(script);
}
function require_css(href) {
var link = document.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.href = href;
document.getElementsByTagName("head")[0].appendChild(link);
}
function depend_js(list) {
if (list.length > 0) {
var src = list.shift();
require_js(src, function() {
depend_js(list);
});
}
return list;
};
<% manifest.grep(/\.css$/) do |uri| -%>
require_css('<%= uri %>');
<% end -%>
var list = depend_js(<%= manifest.grep(/\.js$/).to_json %>);
while (list.length > 0) { /* block until loads finish */ }
})();
Possible regexp for matching HTML documents
/(\s*<\s*!DOCTYPE[^>]*>)?\s*<\s*HTML[^>]*>\s*<\s*HEAD[^>]*>/i
path = case pathspec
when %r{^"(.*?)?(\.js|\.css)?"$} then path.dirname + $1 + ($3 || '.js')
when %r{^<([^/>]*)(.*?)?(\.js|\.css)?>$} then libraries[$1] + $2 + ($3 || '.js')
else raise PreprocessingError, "Unkown path format: #{pathspec}"
# //= require <foo>
if [lib, subpath] = line[/^\s*\/\/=\s+require\s+<([^/>]*)(/[^>]*)?>\s*$/, 1]
path_lint(libraries[lib] + subpath, "<#{lib}>", path, line_num) do |p|
requires(p, indent)
end
# //= require "foo" or //= require "foo.css"
elsif subpath = line[/^\s*\/\/=\s+require\s+\"(.*?)\"\s*$/, 1]
subpath += '.js' unless subpath[/\.(js|css)$/]
path_lint(path.dirname + subpath, "\"#{subpath}\"", path, line_num) do |p|
requires(p, indent)
end
# //= provide "../assets"
elsif subpath = line[/^\s*\/\/=\s+provide\s+\"(.*?)\"\s*$/, 1]
path_lint(path.dirname + subpath, "\"#{subpath}\"", path, line_num) do |p|
provides(p, indent)
end
end