webfontloader 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/Gemfile +9 -0
  2. data/LICENSE +201 -0
  3. data/README.md +148 -0
  4. data/Rakefile +243 -0
  5. data/bin/webfontloader-demos +28 -0
  6. data/docs/EVENTS.md +115 -0
  7. data/docs/MODULES.md +49 -0
  8. data/docs/TRANSITIONS.md +107 -0
  9. data/lib/webfontloader.rb +10 -0
  10. data/lib/webfontloader/demo/public/ascender.html +99 -0
  11. data/lib/webfontloader/demo/public/basic.css +9 -0
  12. data/lib/webfontloader/demo/public/custom.html +88 -0
  13. data/lib/webfontloader/demo/public/event-css-active-multiple.html +44 -0
  14. data/lib/webfontloader/demo/public/event-css-active.html +38 -0
  15. data/lib/webfontloader/demo/public/event-css-inactive.html +38 -0
  16. data/lib/webfontloader/demo/public/event-css-loading.html +55 -0
  17. data/lib/webfontloader/demo/public/event-js-active.html +39 -0
  18. data/lib/webfontloader/demo/public/event-js-font-active.html +40 -0
  19. data/lib/webfontloader/demo/public/event-js-loading.html +60 -0
  20. data/lib/webfontloader/demo/public/events-variations.html +130 -0
  21. data/lib/webfontloader/demo/public/events.html +103 -0
  22. data/lib/webfontloader/demo/public/google-css.html +27 -0
  23. data/lib/webfontloader/demo/public/google.html +33 -0
  24. data/lib/webfontloader/demo/public/ie-fast-js.html +47 -0
  25. data/lib/webfontloader/demo/public/ie-slow-js.html +48 -0
  26. data/lib/webfontloader/demo/public/ie-slow-link.html +38 -0
  27. data/lib/webfontloader/demo/public/index.html +70 -0
  28. data/lib/webfontloader/demo/public/typekit-variations.html +50 -0
  29. data/lib/webfontloader/demo/public/typekit.html +41 -0
  30. data/lib/webfontloader/demo/server.rb +92 -0
  31. data/lib/webfontloader/modules.rb +44 -0
  32. data/src-test/ascender/ascender_script_test.js +48 -0
  33. data/src-test/core/cssclassnametest.js +42 -0
  34. data/src-test/core/cssfontfamilynametest.js +54 -0
  35. data/src-test/core/domhelpertest.js +81 -0
  36. data/src-test/core/eventdispatchertest.js +99 -0
  37. data/src-test/core/fontmoduleloadertest.js +30 -0
  38. data/src-test/core/fonttest.js +92 -0
  39. data/src-test/core/fontvariationdescriptiontest.js +76 -0
  40. data/src-test/core/fontwatchertest.js +510 -0
  41. data/src-test/core/useragenttest.js +395 -0
  42. data/src-test/custom/customcsstest.js +30 -0
  43. data/src-test/google/fontapiparsertest.js +92 -0
  44. data/src-test/google/fontapiurlbuildertest.js +28 -0
  45. data/src-test/google/googlefontapitest.js +173 -0
  46. data/src-test/typekit/typekit_script_test.js +171 -0
  47. data/src/ascender/ascender_script.js +84 -0
  48. data/src/async_load.js +3 -0
  49. data/src/closure.js +3 -0
  50. data/src/core/cssclassname.js +21 -0
  51. data/src/core/cssfontfamilyname.js +20 -0
  52. data/src/core/domhelper.js +103 -0
  53. data/src/core/eventdispatcher.js +78 -0
  54. data/src/core/font.js +84 -0
  55. data/src/core/fontmoduleloader.js +25 -0
  56. data/src/core/fontvariationdescription.js +112 -0
  57. data/src/core/fontwatcher.js +121 -0
  58. data/src/core/initialize.js +26 -0
  59. data/src/core/namespace.js +11 -0
  60. data/src/core/useragent.js +41 -0
  61. data/src/core/useragentparser.js +234 -0
  62. data/src/custom/customcss.js +37 -0
  63. data/src/google/fontapiparser.js +94 -0
  64. data/src/google/fontapiurlbuilder.js +39 -0
  65. data/src/google/googlefontapi.js +49 -0
  66. data/src/modules.yml +27 -0
  67. data/src/typekit/typekit_script.js +58 -0
  68. data/tools/compiler/compiler.jar +0 -0
  69. data/tools/jstestdriver/JsTestDriver-1.2.1.jar +0 -0
  70. data/webfontloader.gemspec +144 -0
  71. metadata +191 -0
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source :gemcutter
2
+
3
+ gem "rake"
4
+
5
+ group :demos do
6
+ gem "rack"
7
+ gem "sinatra"
8
+ gem "vegas"
9
+ end
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [2010] [Small Batch Inc]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,148 @@
1
+ # WebFont Loader
2
+
3
+ WebFont Loader gives you added control when using linked fonts via
4
+ `@font-face`. It provides a common interface to loading fonts regardless of
5
+ the source, then adds a standard set of events you may use to control the
6
+ loading experience.
7
+
8
+
9
+ ## Get Started
10
+
11
+ (These samples use WebFont Loader hosted on [Google's AJAX Libraries][gajax].)
12
+
13
+ Link to the WebFont Loader library, then tell it which fonts to load. Here we'll
14
+ load fonts from [Google's Font API][gfontapi].
15
+
16
+ <script src="http://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js"></script>
17
+ <script>
18
+ WebFont.load({
19
+ google: {
20
+ families: ['Droid Sans', 'Droid Serif']
21
+ }
22
+ });
23
+ </script>
24
+
25
+ Alternatively, load fonts from Typekit. Just specify your Kit ID.
26
+
27
+ <script src="http://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js"></script>
28
+ <script>
29
+ WebFont.load({
30
+ typekit: {
31
+ id: 'xxxxxx'
32
+ }
33
+ });
34
+ </script>
35
+
36
+ Learn more about the
37
+ [modules][mod].
38
+
39
+
40
+ ## Do More
41
+
42
+ WebFont Loader gives you control over how fonts are loaded. If you're
43
+ frustrated by the "flash of unstyled text" typically seen in FireFox, try
44
+ this.
45
+
46
+ <script src="http://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js"></script>
47
+ <script>
48
+ WebFont.load({
49
+ google: {
50
+ families: ['Droid Sans']
51
+ }
52
+ });
53
+ </script>
54
+ <style>
55
+ h1 {
56
+ font-family: 'Droid Sans';
57
+ visibility: hidden;
58
+ }
59
+ .wf-active h1 {
60
+ visibility: visible;
61
+ }
62
+ </style>
63
+
64
+ <body>
65
+ <h1>This headline will be hidden until Droid Sans is completely loaded.</h1>
66
+ </body>
67
+
68
+ Learn more about [events][evt].
69
+
70
+
71
+ ## A common ground
72
+
73
+ WebFont Loader aims to provide a common interface for font loading. Today it
74
+ works with Google, Typekit, and your own CSS. Learn more in
75
+ [transitions][trn].
76
+
77
+
78
+ ## More to see
79
+
80
+ A full suite of demo pages is included in this source. Here you can find some
81
+ live examples using the JS and CSS events.
82
+
83
+ To view the demos, just boot up our demo server and start browsing.
84
+
85
+ $ rake demo
86
+
87
+ You may need a few rubygems to run the server. Get them with [Bundler](http://gembundler.com/).
88
+
89
+ $ gem install bundler
90
+ $ bundle install
91
+
92
+ Browse the demos [source code][demos].
93
+
94
+
95
+ ## Problems?
96
+
97
+ Please open [an issue][issues]. Sample pages are greatly appreciated.
98
+
99
+
100
+ ## Developing
101
+
102
+ Is there something else WebFont Loader should do? Did you find a bug and want
103
+ to fix it?
104
+
105
+ ### Testing
106
+
107
+ WebFont Loader has an extensive test suite that runs via
108
+ [jsTestDriver][jstestdriver]. Please add tests for any changes.
109
+
110
+ To run tests, first boot the test server. This open a browser
111
+ and start listing for test executions. You can register multiple browsers.
112
+
113
+ rake test:boot
114
+
115
+ Then, run the tests.
116
+
117
+ rake test
118
+
119
+ ## Contributing
120
+
121
+ * Fork webfontloader
122
+ * Create a topic branch - `git checkout -b my_branch`
123
+ * Push to your branch - `git push origin my_branch`
124
+ * Create an [issue][issues] with a link to your branch
125
+ * That's it!
126
+
127
+
128
+
129
+ ## Authors
130
+
131
+ * Ryan Carver / ryan@typekit.com
132
+ * Jeremie Lenfant-engelmann / jeremiele@google.com
133
+
134
+
135
+ ## License
136
+
137
+ WebFont Loader is released under the [Apache 2.0][lic] license.
138
+
139
+
140
+ [mod]: http://github.com/typekit/webfontloader/blob/master/docs/MODULES.md
141
+ [trn]: http://github.com/typekit/webfontloader/blob/master/docs/TRANSITIONS.md
142
+ [evt]: http://github.com/typekit/webfontloader/blob/master/docs/EVENTS.md
143
+ [lic]: http://github.com/typekit/webfontloader/blob/master/LICENSE
144
+ [demos]: http://github.com/typekit/webfontloader/blob/master/lib/webfontloader/demo/public
145
+ [gfontapi]: https://code.google.com/apis/webfonts/
146
+ [gajax]: http://code.google.com/apis/ajaxlibs/
147
+ [jstestdriver]: http://code.google.com/p/js-test-driver/
148
+ [issues]: https://github.com/typekit/webfontloader/issues
data/Rakefile ADDED
@@ -0,0 +1,243 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'date'
4
+
5
+ #############################################################################
6
+ #
7
+ # Helper functions
8
+ #
9
+ #############################################################################
10
+
11
+ def name
12
+ @name ||= Dir['*.gemspec'].first.split('.').first
13
+ end
14
+
15
+ def version
16
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
17
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
18
+ end
19
+
20
+ def date
21
+ Date.today.to_s
22
+ end
23
+
24
+ def gemspec_file
25
+ "#{name}.gemspec"
26
+ end
27
+
28
+ def gem_file
29
+ "#{name}-#{version}.gem"
30
+ end
31
+
32
+ def replace_header(head, header_name)
33
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
34
+ end
35
+
36
+ #############################################################################
37
+ #
38
+ # Standard tasks
39
+ #
40
+ #############################################################################
41
+
42
+ desc "Open an irb session preloaded with this library"
43
+ task :console do
44
+ sh "irb -rubygems -r ./lib/#{name}.rb"
45
+ end
46
+
47
+ #############################################################################
48
+ #
49
+ # Custom tasks (add your own tasks here)
50
+ #
51
+ #############################################################################
52
+
53
+ require 'rake/clean'
54
+
55
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/lib"
56
+ require 'webfontloader'
57
+
58
+ #
59
+ # Setup
60
+ #
61
+
62
+ # Build targets (remove with `rake clean`)
63
+ CLEAN.include("target")
64
+ CLEAN.include("tmp")
65
+
66
+ # JsTestDriver
67
+ JsTestPort = "9876"
68
+ JsTestServer = "http://localhost:#{JsTestPort}"
69
+ JsTestJar = "tools/jstestdriver/JsTestDriver-1.2.1.jar"
70
+
71
+ # JsCompiler
72
+ JsCompilerJar = "tools/compiler/compiler.jar"
73
+
74
+ # JS Source dependencies
75
+ AllJs = FileList["{src,src-test}/**/*"]
76
+ SourceJs = FileList["src/**/*"]
77
+
78
+ # JS Source loader
79
+ @modules = WebFontLoader::Modules.new
80
+
81
+ #
82
+ # Build
83
+ #
84
+
85
+ directory "target"
86
+ directory "tmp"
87
+
88
+ file "tmp/jsTestDriver.conf" => AllJs + ["tmp"] do |t|
89
+ require 'yaml'
90
+ config = {
91
+ "server" => JsTestServer,
92
+ "load" => (@modules.all_source_files + @modules.all_test_globs).map { |f| "../#{f}" }
93
+ }
94
+ File.open(t.name, "w") { |f| YAML.dump(config, f) }
95
+ end
96
+
97
+ desc "Compile the JavaScript into target/webfont.js"
98
+ task :compile => "target/webfont.js"
99
+
100
+ file "target/webfont.js" => SourceJs + ["target"] do |t|
101
+
102
+ output_marker = "%output%"
103
+ output_wrapper = @modules.js_output_wrapper(output_marker)
104
+
105
+ args = [
106
+ ["-jar", JsCompilerJar],
107
+ ["--compilation_level", "ADVANCED_OPTIMIZATIONS"],
108
+ ["--js_output_file", t.name],
109
+ ["--output_wrapper_marker", %("#{output_marker}")],
110
+ ["--output_wrapper", %("#{output_wrapper}")]
111
+ ]
112
+
113
+ source = @modules.all_source_files
114
+ args.concat source.map { |f| ["--js", f] }
115
+
116
+ system "java #{args.flatten.join(' ')}"
117
+ end
118
+
119
+ desc "Creates debug version into target/webfont.js"
120
+ task :debug => "target/webfont_debug.js"
121
+
122
+ file "target/webfont_debug.js" => SourceJs + ["target"] do |t|
123
+ File.open(t.name, "w") { |f|
124
+ @modules.all_source_files.each { |src|
125
+ f.puts File.read(src)
126
+ f.puts ""
127
+ }
128
+ }
129
+ end
130
+
131
+ #
132
+ # Run
133
+ #
134
+
135
+ namespace :test do
136
+ task :server do
137
+ system "java -jar #{JsTestJar} --port #{JsTestPort}"
138
+ end
139
+ task :capture do
140
+ system "open #{JsTestServer}/capture?strict"
141
+ end
142
+ desc "Execute tests against a running server"
143
+ task :run => ["tmp/jsTestDriver.conf"] do |t|
144
+ config = t.prerequisites.first
145
+ system "java -jar #{JsTestJar} --config #{config} --server #{JsTestServer} --tests all --captureConsole --verbose"
146
+ end
147
+ desc "Boot the test server and capture a browser"
148
+ multitask :boot => ['test:server', 'test:capture']
149
+ end
150
+
151
+ desc "Run all tests"
152
+ task :test => ["tmp/jsTestDriver.conf"] do |t|
153
+ config = t.prerequisites.first
154
+ system "java -jar #{JsTestJar} --port #{JsTestPort} --config #{config} --server #{JsTestServer} --browser open --tests all --captureConsole --verbose"
155
+ end
156
+
157
+ desc "Start the demo server"
158
+ task :demo => "target/webfont.js" do |t|
159
+ js = t.prerequisites.first
160
+ exec "bin/webfontloader-demos -F --compiled_js #{js}"
161
+ end
162
+
163
+ desc "Start the demo server for development"
164
+ task :demodev do
165
+ exec "bin/webfontloader-demos -F -L --modules"
166
+ end
167
+
168
+ desc "Find out how many bytes the source is"
169
+ task :bytes => "target/webfont.js" do |t|
170
+ js = t.prerequisites.first
171
+ bytes = File.read(js).size
172
+ puts "#{bytes} bytes uncompressed"
173
+ end
174
+
175
+ desc "Find out how many bytes the source is when gzipped"
176
+ task :gzipbytes => "target/webfont.js" do |t|
177
+ require 'zlib'
178
+ js = t.prerequisites.first
179
+ bytes = Zlib::Deflate.deflate(File.read(js)).size
180
+ puts "#{bytes} bytes gzipped"
181
+ end
182
+
183
+
184
+ #############################################################################
185
+ #
186
+ # Packaging tasks
187
+ #
188
+ #############################################################################
189
+
190
+ task :release => :build do
191
+ unless `git branch` =~ /^\* master$/
192
+ puts "You must be on the master branch to release!"
193
+ exit!
194
+ end
195
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
196
+ sh "git tag -a v#{version}"
197
+ sh "git push --tags origin master"
198
+ sh "gem push pkg/#{name}-#{version}.gem"
199
+ end
200
+
201
+ task :build => :gemspec do
202
+ sh "mkdir -p pkg"
203
+ sh "gem build #{gemspec_file}"
204
+ sh "mv #{gem_file} pkg"
205
+ end
206
+
207
+ task :gemspec => :validate do
208
+ # read spec file and split out manifest section
209
+ spec = File.read(gemspec_file)
210
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
211
+
212
+ # replace name version and date
213
+ replace_header(head, :name)
214
+ replace_header(head, :version)
215
+ replace_header(head, :date)
216
+
217
+ # determine file list from git ls-files
218
+ files = `git ls-files`.
219
+ split("\n").
220
+ sort.
221
+ reject { |file| file =~ /^\./ }.
222
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
223
+ map { |file| " #{file.gsub(/\s/, '\ ')}" }.
224
+ join("\n")
225
+
226
+ # piece file back together and write
227
+ manifest = " s.files = %w[\n#{files}\n ]\n"
228
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
229
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
230
+ puts "Updated #{gemspec_file}"
231
+ end
232
+
233
+ task :validate do
234
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
235
+ unless libfiles.empty?
236
+ puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
237
+ exit!
238
+ end
239
+ unless Dir['VERSION*'].empty?
240
+ puts "A `VERSION` file at root level violates Gem best practices."
241
+ exit!
242
+ end
243
+ end