closure 1.1.692 → 1.2.701

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/README.md +0 -13
  2. data/closure-library/alltests.js +1 -1
  3. data/closure-library/closure/goog/debug/reflect.js +5 -1
  4. data/closure-library/closure/goog/deps.js +7 -0
  5. data/closure-library/closure/goog/i18n/messageformat.js +4 -1
  6. data/closure-library/closure/goog/i18n/messageformat_test.html +11 -0
  7. data/closure-library/closure/goog/math/vec3.js +0 -19
  8. data/closure-library/closure/goog/messaging/portcaller.js +150 -0
  9. data/closure-library/closure/goog/messaging/portcaller_test.html +66 -0
  10. data/closure-library/closure/goog/messaging/portnetwork.js +78 -0
  11. data/closure-library/closure/goog/messaging/portnetwork_test.html +64 -0
  12. data/closure-library/closure/goog/messaging/portoperator.js +196 -0
  13. data/closure-library/closure/goog/messaging/portoperator_test.html +112 -0
  14. data/closure-library/closure/goog/messaging/testdata/portchannel_inner.html +28 -0
  15. data/closure-library/closure/goog/messaging/testdata/portnetwork_inner.html +35 -0
  16. data/closure-library/closure/goog/messaging/testdata/portnetwork_worker1.js +33 -0
  17. data/closure-library/closure/goog/messaging/testdata/portnetwork_worker2.js +33 -0
  18. data/closure-library/closure/goog/testing/functionmock.js +1 -1
  19. data/closure-library/closure/goog/testing/messaging/mockmessageport.js +85 -0
  20. data/closure-library/closure/goog/testing/messaging/mockportnetwork.js +64 -0
  21. data/closure-library/closure/goog/tweak/tweak.js +1 -1
  22. data/closure-library/closure/goog/ui/advancedtooltip.js +1 -2
  23. data/closure-library/closure/goog/ui/filteredmenu.js +2 -2
  24. data/closure-library/closure/goog/ui/menubutton.js +6 -0
  25. data/closure-library/third_party/closure/goog/dojo/dom/query.js +9 -4
  26. data/closure.gemspec +1 -2
  27. data/config.ru +4 -4
  28. data/lib/closure.rb +3 -1
  29. data/lib/closure/compiler.rb +11 -24
  30. data/lib/closure/goog.rb +37 -16
  31. data/lib/closure/middleware.rb +2 -2
  32. data/lib/closure/script.rb +12 -4
  33. data/lib/closure/server.rb +3 -1
  34. data/lib/closure/show_exceptions.rb +63 -0
  35. data/lib/closure/sources.rb +22 -6
  36. data/lib/closure/templates.rb +2 -2
  37. data/lib/closure/version.rb +1 -1
  38. data/scripts/demos/compiler.build +1 -0
  39. data/scripts/demos/compiler.debug +24 -0
  40. data/scripts/demos/compiler.js.erb +22 -0
  41. data/scripts/demos/compiler.map +114 -0
  42. data/scripts/demos/googly.erb +19 -0
  43. data/scripts/demos/googly.js +24 -0
  44. data/scripts/demos/helloworld.erb +24 -0
  45. data/scripts/demos/index.erb +29 -0
  46. data/scripts/demos/{externs_jquery.js → jquery.js} +0 -0
  47. data/scripts/demos/rails_ujs.erb +38 -0
  48. data/scripts/{examples/rails/ujs.js → demos/rails_ujs.js} +0 -0
  49. data/scripts/externs/jquery-ui.externs +10 -0
  50. data/scripts/externs/jquery.externs +4 -0
  51. data/scripts/{demos/externs_jquery.externs → externs/jquery_1_4_2.externs} +1 -1
  52. data/scripts/index.erb +19 -0
  53. metadata +36 -24
  54. data/scripts/demos/compile.js.erb +0 -8
  55. data/scripts/demos/compile.out +0 -1
  56. data/scripts/demos/compiler.haml +0 -17
  57. data/scripts/demos/compiler.js +0 -12
  58. data/scripts/demos/externs.haml +0 -16
  59. data/scripts/demos/externs.js.erb +0 -8
  60. data/scripts/demos/externs.out +0 -1
  61. data/scripts/demos/externs_jquerytest.js +0 -11
  62. data/scripts/demos/helloworld.haml +0 -15
  63. data/scripts/demos/index.haml +0 -21
  64. data/scripts/demos/rails_ujs.haml +0 -24
  65. data/scripts/favicon.ico +0 -0
  66. data/scripts/index.haml +0 -14
@@ -0,0 +1,85 @@
1
+ // Copyright 2011 The Closure Library Authors. All Rights Reserved.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS-IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ /**
16
+ * @fileoverview A simple dummy class for representing message ports in tests.
17
+ *
18
+ */
19
+
20
+ goog.provide('goog.testing.messaging.MockMessagePort');
21
+
22
+ goog.require('goog.events.EventTarget');
23
+
24
+
25
+
26
+ /**
27
+ * Class for unit-testing code that uses MessagePorts.
28
+ * @param {*} id An opaque identifier, used because message ports otherwise have
29
+ * no distinguishing characteristics.
30
+ * @param {goog.testing.MockControl} mockControl The mock control used to create
31
+ * the method mock for #postMessage.
32
+ * @constructor
33
+ * @extends {goog.events.EventTarget}
34
+ */
35
+ goog.testing.messaging.MockMessagePort = function(id, mockControl) {
36
+ goog.base(this);
37
+
38
+ /**
39
+ * An opaque identifier, used because message ports otherwise have no
40
+ * distinguishing characteristics.
41
+ * @type {*}
42
+ */
43
+ this.id = id;
44
+
45
+ /**
46
+ * Whether or not the port has been started.
47
+ * @type {boolean}
48
+ */
49
+ this.started = false;
50
+
51
+ /**
52
+ * Whether or not the port has been closed.
53
+ * @type {boolean}
54
+ */
55
+ this.closed = false;
56
+
57
+ mockControl.createMethodMock(this, 'postMessage');
58
+ };
59
+ goog.inherits(goog.testing.messaging.MockMessagePort, goog.events.EventTarget);
60
+
61
+
62
+ /**
63
+ * A mock postMessage funciton. Actually an instance of
64
+ * {@link goog.testing.FunctionMock}.
65
+ * @param {*} message The message to send.
66
+ * @param {Array.<MessagePort>=} opt_ports Ports to send with the message.
67
+ */
68
+ goog.testing.messaging.MockMessagePort.prototype.postMessage = function(
69
+ message, opt_ports) {};
70
+
71
+
72
+ /**
73
+ * Starts the port.
74
+ */
75
+ goog.testing.messaging.MockMessagePort.prototype.start = function() {
76
+ this.started = true;
77
+ };
78
+
79
+
80
+ /**
81
+ * Closes the port.
82
+ */
83
+ goog.testing.messaging.MockMessagePort.prototype.close = function() {
84
+ this.closed = true;
85
+ };
@@ -0,0 +1,64 @@
1
+ // Copyright 2011 The Closure Library Authors. All Rights Reserved.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS-IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ /**
16
+ * @fileoverview A fake PortNetwork implementation that simply produces
17
+ * MockMessageChannels for all ports.
18
+ *
19
+ */
20
+
21
+ goog.provide('goog.testing.messaging.MockPortNetwork');
22
+
23
+ goog.require('goog.messaging.PortNetwork'); // interface
24
+ goog.require('goog.testing.messaging.MockMessageChannel');
25
+
26
+
27
+
28
+ /**
29
+ * The fake PortNetwork.
30
+ *
31
+ * @param {!goog.testing.MockControl} mockControl The mock control for creating
32
+ * the mock message channels.
33
+ * @constructor
34
+ * @implements {goog.messaging.PortNetwork}
35
+ */
36
+ goog.testing.messaging.MockPortNetwork = function(mockControl) {
37
+ /**
38
+ * The mock control for creating mock message channels.
39
+ * @type {!goog.testing.MockControl}
40
+ * @private
41
+ */
42
+ this.mockControl_ = mockControl;
43
+
44
+ /**
45
+ * The mock ports that have been created.
46
+ * @type {!Object.<!goog.testing.messaging.MockMessageChannel>}
47
+ * @private
48
+ */
49
+ this.ports_ = {};
50
+ };
51
+
52
+
53
+ /**
54
+ * Get the mock port with the given name.
55
+ * @param {string} name The name of the port to get.
56
+ * @return {!goog.testing.messaging.MockMessageChannel} The mock port.
57
+ */
58
+ goog.testing.messaging.MockPortNetwork.prototype.dial = function(name) {
59
+ if (!(name in this.ports_)) {
60
+ this.ports_[name] =
61
+ new goog.testing.messaging.MockMessageChannel(this.mockControl_);
62
+ }
63
+ return this.ports_[name];
64
+ };
@@ -14,7 +14,7 @@
14
14
 
15
15
  /**
16
16
  * @fileoverview Provides facilities for creating and querying tweaks.
17
- * @see http://go/jstweaks
17
+ * @see http://code.google.com/p/closure-library/wiki/UsingTweaks
18
18
  *
19
19
  * @author agrieve@google.com (Andrew Grieve)
20
20
  */
@@ -253,8 +253,7 @@ goog.ui.AdvancedTooltip.prototype.isCoordinateInTooltip = function(coord) {
253
253
  * tooltip whose anchor is a child of this tooltip.
254
254
  * @private
255
255
  */
256
- goog.ui.AdvancedTooltip.prototype.isCoordinateActive_ = function(
257
- coord) {
256
+ goog.ui.AdvancedTooltip.prototype.isCoordinateActive_ = function(coord) {
258
257
  if ((this.anchorBox_ && this.anchorBox_.contains(coord)) ||
259
258
  this.isCoordinateInTooltip(coord)) {
260
259
  return true;
@@ -218,9 +218,9 @@ goog.ui.FilteredMenu.prototype.tearDownFilterListeners_ = function() {
218
218
 
219
219
 
220
220
  /** @inheritDoc */
221
- goog.ui.FilteredMenu.prototype.setVisible = function(show, opt_force) {
221
+ goog.ui.FilteredMenu.prototype.setVisible = function(show, opt_force, opt_e) {
222
222
  var visibilityChanged = goog.ui.FilteredMenu.superClass_.setVisible.call(this,
223
- show, opt_force);
223
+ show, opt_force, opt_e);
224
224
  if (visibilityChanged && show && this.isInDocument()) {
225
225
  this.setFilter('');
226
226
  this.setUpFilterListeners_();
@@ -653,6 +653,12 @@ goog.ui.MenuButton.prototype.setOpen = function(open, opt_e) {
653
653
  this.setActive(false);
654
654
  this.menu_.setMouseButtonPressed(false);
655
655
 
656
+ // Clear any remaining a11y state.
657
+ if (this.getElement()) {
658
+ goog.dom.a11y.setState(this.getElement(),
659
+ goog.dom.a11y.State.ACTIVEDESCENDANT, '');
660
+ }
661
+
656
662
  // Clear any sizes that might have been stored.
657
663
  if (goog.isDefAndNotNull(this.originalSize_)) {
658
664
  this.originalSize_ = undefined;
@@ -185,8 +185,8 @@ goog.require('goog.userAgent');
185
185
  * affecting any nested tables:
186
186
  * | dojo.query("#tabular_data > tbody > tr:nth-child(odd)");
187
187
  *
188
- * @param {string} query The CSS3 expression to match against. For details
189
- * on the syntax of CSS3 selectors, see
188
+ * @param {string|Array} query The CSS3 expression to match against.
189
+ * For details on the syntax of CSS3 selectors, see
190
190
  * http://www.w3.org/TR/css3-selectors/#selectors.
191
191
  * @param {(string|Node)=} opt_root A Node (or node id) to scope the search
192
192
  * from (optional).
@@ -1465,7 +1465,12 @@ goog.dom.query = (function() {
1465
1465
  return ret;
1466
1466
  };
1467
1467
 
1468
- // the main executor
1468
+ /**
1469
+ * The main executor. Type specification from above.
1470
+ * @param {string|Array} query The query.
1471
+ * @param {(string|Node)=} root The root.
1472
+ * @return { {length: number} } The elements that matched the query.
1473
+ */
1469
1474
  var query = function(query, root) {
1470
1475
  // NOTE: elementsById is not currently supported
1471
1476
  // NOTE: ignores xpath-ish queries for now
@@ -1478,7 +1483,7 @@ goog.dom.query = (function() {
1478
1483
  }
1479
1484
 
1480
1485
  if (query.constructor == Array) {
1481
- return query;
1486
+ return /** @type {!Array} */ (query);
1482
1487
  }
1483
1488
 
1484
1489
  if (!goog.isString(query)) {
@@ -5,11 +5,10 @@ Gem::Specification.new do |s|
5
5
  s.name = "closure"
6
6
  s.version = Closure::VERSION
7
7
  s.platform = Gem::Platform::RUBY
8
- s.homepage = "https://github.com/dturnbull/closure-script"
8
+ s.homepage = "http://www.closure-script.com/"
9
9
  s.summary = "Closure Script for Google Closure Compiler, Library, and Templates."
10
10
 
11
11
  s.required_rubygems_version = ">= 1.3"
12
- # s.rubyforge_project = "closure-script"
13
12
 
14
13
  s.add_dependency 'rack', '>= 1.0.0'
15
14
 
data/config.ru CHANGED
@@ -1,5 +1,5 @@
1
1
  #\ -p 9009 -E none
2
- # This is the rackup for developers working on (not with) Closure Script.
2
+ # This is for developers working on (not with) Closure Script.
3
3
 
4
4
  closure_lib_path = File.expand_path(File.dirname(__FILE__), 'lib')
5
5
  $LOAD_PATH.unshift(closure_lib_path) if !$LOAD_PATH.include?(closure_lib_path)
@@ -7,14 +7,14 @@ require 'closure'
7
7
 
8
8
  Closure.add_source :goog, '/goog'
9
9
  Closure.add_source :goog_vendor, '/goog_vendor'
10
- Closure.add_source :soy, '/soy_js'
11
- Closure.add_source File.join(Closure.base_path, 'scripts'), '/'
10
+ Closure.add_source :soy, '/soy'
11
+ Closure.add_source :demos, '/demos'
12
+ Closure.add_source :externs
12
13
  Closure.config.haml[:format] = :html5
13
14
 
14
15
  use Rack::CommonLogger # slow
15
16
  use Rack::Reloader, 1
16
17
  use Rack::Lint # slow
17
- use Rack::ShowExceptions
18
18
  use Closure::Templates, %w{
19
19
  --shouldProvideRequireSoyNamespaces
20
20
  --cssHandlingScheme goog
@@ -40,6 +40,7 @@ class Closure
40
40
  autoload(:Server, 'closure/server')
41
41
  autoload(:Goog, 'closure/goog')
42
42
  autoload(:Templates, 'closure/templates')
43
+ autoload(:ShowExceptions, 'closure/show_exceptions')
43
44
 
44
45
 
45
46
  # Filesystem location of the Closure Script install.
@@ -58,7 +59,8 @@ class Closure
58
59
  :goog => File.join(base_path, 'closure-library', 'closure', 'goog'),
59
60
  :goog_vendor => File.join(base_path, 'closure-library', 'third_party', 'closure', 'goog'),
60
61
  :soy => File.join(base_path, 'closure-templates'),
61
- :examples => File.join(base_path, 'scripts', 'examples')
62
+ :externs => File.join(base_path, 'scripts', 'externs'),
63
+ :demos => File.join(base_path, 'scripts', 'demos')
62
64
  }
63
65
 
64
66
 
@@ -47,12 +47,9 @@ class Closure
47
47
  # @param (String) base All filenames will be expanded to this location.
48
48
  # @param (Hash) env Rack environment. Supply if you want a response that is cacheable
49
49
  # and for {Templates} errors to be processed.
50
- # @param (Exception) exception Ruby Exception that prevents compilation. Ruby exceptions
51
- # generated by tools like {Sources} can be displayed in console.log. This unusual parameter
52
- # is the smallest wrinkle I could get when smoothing together compiler.jar and Ruby errors.
53
- def initialize(args, dependencies = [], base = nil, env = {}, exception = nil)
50
+ def initialize(args, dependencies = [], base = nil, env = {})
54
51
  @env = env
55
- return if @exception = exception # =
52
+ return if args.empty? # otherwise java locks up
56
53
  args = Array.new args
57
54
  files = []
58
55
  # Scan to expand paths and extend self with output options
@@ -111,13 +108,6 @@ class Closure
111
108
  # <% @response = goog.compile(args).to_response_with_console %>
112
109
  def to_response_with_console
113
110
  response = Rack::Response.new
114
- # Ruby exceptions
115
- if @exception
116
- response.write 'try{console.error('
117
- response.write '"Closure Script: Ruby Exception\n\n", '
118
- response.write @exception.to_s.dump
119
- response.write ")}catch(err){};\n"
120
- end
121
111
  # Closure Template Errors
122
112
  templates_errors_js = Templates.errors_js @env
123
113
  response.write templates_errors_js if templates_errors_js
@@ -136,7 +126,11 @@ class Closure
136
126
  error_log += (error_message + "\n\n" + split_log.join("\n")).dump
137
127
  end
138
128
  if error_message =~ /^0 err/i
139
- response.write "try{console.log(#{error_log})}catch(err){};\n"
129
+ if error_message =~ / 0 warn/i
130
+ response.write "try{console.log(#{error_log})}catch(err){};\n"
131
+ else
132
+ response.write "try{console.warn(#{error_log})}catch(err){};\n"
133
+ end
140
134
  else
141
135
  response.write "try{console.error(#{error_log})}catch(err){};\n"
142
136
  end
@@ -164,21 +158,14 @@ class Closure
164
158
  # Results from compiler.jar. If you didn't specify a --js_output_file
165
159
  # then this will be the compiled script. Otherwise, it's usually empty
166
160
  # but may contain output depending on the arguments.
167
- # If nil, compilation was skipped because js_output_file was up to date
168
- # or an exception was passed on initialization.
169
- attr_reader :stdout
161
+ # If nil, compilation was skipped because js_output_file was up to date.
162
+ attr_accessor :stdout
170
163
 
171
164
  # Results from compiler.jar. The log, when there is one, is found here.
172
165
  # Use `--summary_detail_level 3` to see log when no errors or warnings.
173
- # If nil, compilation was skipped because js_output_file was up to date
174
- # or an exception was passed on initialization.
175
- attr_reader :stderr
166
+ # If nil, compilation was skipped because js_output_file was up to date.
167
+ attr_accessor :stderr
176
168
 
177
- # Ruby exception; typically from {Sources}. The compiler will not
178
- # generate these exceptions. This is only a mechanism to get Ruby
179
- # exceptions about dependencies on to the Javascript console.log.
180
- attr_reader :exception
181
-
182
169
  end
183
170
 
184
171
  end
@@ -56,10 +56,11 @@ class Closure
56
56
  files_index = 0
57
57
  args_index = 0
58
58
  temp_deps_js = nil
59
- exception = nil
59
+ compilation_level = nil
60
60
  begin
61
61
  while args_index < args.length
62
62
  option, value = args[args_index, 2]
63
+ compilation_level = value if option == '--compilation_level'
63
64
  if option == '--ns'
64
65
  files_for(value, files)
65
66
  replacement = []
@@ -79,23 +80,36 @@ class Closure
79
80
  args_index = args_index + 2
80
81
  end
81
82
  end
82
- if temp_deps_js
83
- # EXPERIMENTAL: support for goog.provide and require in externs.
84
- # This is ugly but I hope it will no longer be necessary
85
- # once compiler.jar is made aware of goog.provide in externs.
86
- temp_deps_js.open
87
- @sources.deps_response(File.dirname(base_js), @env).each do |s|
88
- temp_deps_js.write s
83
+ if compilation_level
84
+ if temp_deps_js
85
+ # EXPERIMENTAL: support for goog.provide and require in externs.
86
+ # This is ugly but I hope it will no longer be necessary
87
+ # once compiler.jar is made aware of goog.provide in externs.
88
+ temp_deps_js.open
89
+ @sources.deps_response(File.dirname(base_js), @env).each do |s|
90
+ temp_deps_js.write s
91
+ end
92
+ temp_deps_js.close
93
+ # File mtime is rolled back to not trigger compilation.
94
+ File.utime(Time.now, Time.at(0), temp_deps_js.path)
95
+ args.unshift temp_deps_js.path
96
+ args.unshift '--js'
97
+ end
98
+ Compiler.new args, @dependencies, File.dirname(@render_stack.last), @env
99
+ else
100
+ comp = Compiler.new []
101
+ comp.stdout = ''
102
+ args_index = 0
103
+ while args_index < args.length
104
+ option, value = args[args_index, 2]
105
+ if option == '--js'
106
+ script_tag = "<script src=#{path_for(value).dump}></script>"
107
+ comp.stdout += "document.write(#{script_tag.dump});\n"
108
+ end
109
+ args_index = args_index + 2
89
110
  end
90
- temp_deps_js.close
91
- # File mtime is rolled back to not trigger compilation.
92
- File.utime(Time.now, Time.at(0), temp_deps_js.path)
93
- args.unshift temp_deps_js.path
94
- args.unshift '--js'
111
+ comp
95
112
  end
96
- Compiler.new args, @dependencies, File.dirname(@render_stack.last), @env, exception
97
- rescue Exception => e
98
- exception = e
99
113
  ensure
100
114
  temp_deps_js.unlink if temp_deps_js
101
115
  end
@@ -113,6 +127,13 @@ class Closure
113
127
  @sources.files_for(namespace, filenames, @env)
114
128
  end
115
129
 
130
+ # Calculate the file server path for a filename.
131
+ # @param (String) filename
132
+ # @return (String)
133
+ def path_for(filename)
134
+ @sources.path_for(filename, @env)
135
+ end
136
+
116
137
  # The Google Closure base.js script.
117
138
  # If you use this instead of a static link, you are free to relocate relative
118
139
  # to the Google Closure library without updating every html fixture page.
@@ -25,11 +25,11 @@ class Closure
25
25
  class Middleware
26
26
 
27
27
  # @param (String) home_page File to serve at the root. Handy for stand-alone projects.
28
- # You can use a closure-script, even in non-source folders, by using the url extension
28
+ # You can use a Closure Script, even in non-source folders, by using the url extension
29
29
  # e.g. 'index.html' instead of the actual filename 'index.haml'.
30
30
  def initialize(app, home_page=nil)
31
31
  @app = app
32
- @server = Server.new(Closure.sources, home_page)
32
+ @server = ShowExceptions.new(Server.new(Closure.sources, home_page))
33
33
  end
34
34
 
35
35
  def call(env)