middleman 2.0.9.pre.2-x86-mingw32 → 2.0.9.pre.3-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +9 -0
- data/features/builder.feature +6 -0
- data/features/data.feature +16 -1
- data/features/fonts.feature +11 -0
- data/features/relative_assets.feature +8 -2
- data/features/step_definitions/middleman_steps.rb +9 -2
- data/fixtures/data-app/config.rb +3 -0
- data/fixtures/data-app/data/pages.yml +6 -0
- data/fixtures/data-app/source/index.html.haml +1 -0
- data/fixtures/data-app/source/layout.haml +3 -0
- data/fixtures/fonts-app/config.rb +0 -0
- data/fixtures/fonts-app/source/fonts/StMarie-Thin.otf +0 -0
- data/fixtures/fonts-app/source/stylesheets/fonts.css.sass +3 -0
- data/fixtures/glob-app/config.rb +1 -0
- data/fixtures/glob-app/source/index.html.haml +6 -0
- data/fixtures/glob-app/source/stylesheets/site.css.sass +1 -0
- data/fixtures/test-app/config.rb +1 -0
- data/fixtures/test-app/data/test2.json +4 -0
- data/fixtures/test-app/source/data3.html.erb +1 -0
- data/lib/middleman/base.rb +8 -3
- data/lib/middleman/builder.rb +61 -22
- data/lib/middleman/cli.rb +2 -1
- data/lib/middleman/core_extensions/assets.rb +1 -1
- data/lib/middleman/core_extensions/compass.rb +6 -2
- data/lib/middleman/core_extensions/data.rb +20 -3
- data/lib/middleman/templates/html5.rb +1 -0
- data/lib/middleman/templates/mobile.rb +17 -0
- data/lib/middleman/templates/mobile/source/404.html +38 -0
- data/lib/middleman/templates/mobile/source/README.markdown +64 -0
- data/lib/middleman/templates/mobile/source/crossdomain.xml +25 -0
- data/lib/middleman/templates/mobile/source/css/style.css +236 -0
- data/lib/middleman/templates/mobile/source/default.appcache +17 -0
- data/lib/middleman/templates/mobile/source/humans.txt +43 -0
- data/lib/middleman/templates/mobile/source/img/h/apple-touch-icon.png +0 -0
- data/lib/middleman/templates/mobile/source/img/h/splash.png +0 -0
- data/lib/middleman/templates/mobile/source/img/l/apple-touch-icon-precomposed.png +0 -0
- data/lib/middleman/templates/mobile/source/img/l/apple-touch-icon.png +0 -0
- data/lib/middleman/templates/mobile/source/img/l/splash.png +0 -0
- data/lib/middleman/templates/mobile/source/img/m/apple-touch-icon.png +0 -0
- data/lib/middleman/templates/mobile/source/index.html +95 -0
- data/lib/middleman/templates/mobile/source/js/libs/jquery-1.5.1.js +8316 -0
- data/lib/middleman/templates/mobile/source/js/libs/jquery-1.5.1.min.js +16 -0
- data/lib/middleman/templates/mobile/source/js/libs/modernizr-custom.js +14 -0
- data/lib/middleman/templates/mobile/source/js/libs/respond.min.js +7 -0
- data/lib/middleman/templates/mobile/source/js/mylibs/helper.js +147 -0
- data/lib/middleman/templates/mobile/source/js/script.js +0 -0
- data/lib/middleman/templates/mobile/source/robots.txt +5 -0
- data/lib/middleman/templates/mobile/source/sitemap.xml +10 -0
- data/lib/middleman/templates/mobile/source/test/index.html +31 -0
- data/lib/middleman/templates/mobile/source/test/qunit/qunit.css +148 -0
- data/lib/middleman/templates/mobile/source/test/qunit/qunit.js +1265 -0
- data/lib/middleman/templates/mobile/source/test/tests.js +26 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/Readme.PDF +0 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/aspx/aspx1.snippet +31 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/aspx/aspx2.snippet +2 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/aspx/ga.aspx +195 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/aspx/sample.aspx +44 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/jsp/ga.jsp +225 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/jsp/jsp1.snippet +35 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/jsp/jsp2.snippet +2 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/jsp/sample.jsp +51 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/php/ga.php +176 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/php/php1.snippet +30 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/php/php2.snippet +4 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/php/sample.php +44 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/pl/ga.pl +195 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/pl/perl1.snippet +27 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/pl/perl2.snippet +1 -0
- data/lib/middleman/templates/mobile/source/tools/googleanalyticsformobile/pl/sample.pl +38 -0
- data/lib/middleman/templates/mobile/source/tools/mobile-bookmark-bubble/COPYING +202 -0
- data/lib/middleman/templates/mobile/source/tools/mobile-bookmark-bubble/bookmark_bubble.js +559 -0
- data/lib/middleman/templates/mobile/source/tools/mobile-bookmark-bubble/example/example.html +43 -0
- data/lib/middleman/templates/mobile/source/tools/mobile-bookmark-bubble/example/example.js +57 -0
- data/lib/middleman/templates/mobile/source/tools/mobile-bookmark-bubble/images/arrow.png +0 -0
- data/lib/middleman/templates/mobile/source/tools/mobile-bookmark-bubble/images/close.png +0 -0
- data/lib/middleman/templates/mobile/source/tools/mobile-bookmark-bubble/images/generate_base64_images +33 -0
- data/lib/middleman/templates/mobile/source/tools/mobile-bookmark-bubble/images/icon_calendar.png +0 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/README +27 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/databasefactory.js +45 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/dbworker.js +324 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/dbworker_test.html +393 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/dbworkerstarter.js +32 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/dbwrapper_gears.js +595 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/dbwrapper_gears_test.html +404 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/dbwrapper_html5.js +203 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/dbwrapper_html5_test.html +468 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/dbwrapperapi.js +202 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/dbwrapperapi_test.html +51 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/gears_resultset.js +71 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/gears_resultset_test.html +86 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/gears_transaction.js +196 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/gears_transaction_test.html +221 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/gearsutils.js +94 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/gearsutils_test.html +84 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/global_functions.js +72 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/simplenotes/index.html +347 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/simplenotes/simplenotes.js +503 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/simplenotes/styles.css +66 -0
- data/lib/middleman/templates/mobile/source/tools/wspl/simplenotes/template.js +75 -0
- data/lib/middleman/version.rb +1 -1
- data/middleman-x86-mingw32.gemspec +0 -1
- data/middleman.gemspec +3 -2
- metadata +103 -6
- data/lib/middleman/config.ru +0 -2
- data/lib/middleman/features/tiny_src.rb +0 -11
@@ -0,0 +1,221 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<!--
|
3
|
+
Copyright 2009 Google Inc.
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
16
|
+
-->
|
17
|
+
|
18
|
+
<html>
|
19
|
+
<head>
|
20
|
+
<title>Gears transaction tests</title>
|
21
|
+
<script type="text/javascript" src="../jsunit/app/jsUnitCore.js"></script>
|
22
|
+
<script type="text/javascript" src="jsmock.js"></script>
|
23
|
+
<script type="text/javascript" src="global_functions.js"></script>
|
24
|
+
<script type="text/javascript" src="dbwrapperapi.js"></script>
|
25
|
+
<script type="text/javascript" src="gears_resultset.js"></script>
|
26
|
+
<script type="text/javascript" src="gears_transaction.js"></script>
|
27
|
+
</head>
|
28
|
+
<body>
|
29
|
+
<script type='text/javascript'>
|
30
|
+
|
31
|
+
var mockControl;
|
32
|
+
var callbackMock;
|
33
|
+
var dbMock;
|
34
|
+
|
35
|
+
function setUp() {
|
36
|
+
mockControl = new MockControl();
|
37
|
+
callbackMock = mockControl.createMock({
|
38
|
+
onSuccess: function(){},
|
39
|
+
onFailure: function(){}
|
40
|
+
});
|
41
|
+
dbMock = mockControl.createMock({
|
42
|
+
doBegin: function(){},
|
43
|
+
doCommit: function(){},
|
44
|
+
doRollback: function(){},
|
45
|
+
doExecute: function(){}
|
46
|
+
});
|
47
|
+
}
|
48
|
+
|
49
|
+
function testConstructTransaction() {
|
50
|
+
var trans = new google.wspl.gears.Transaction(10, 'foo');
|
51
|
+
assertEquals('foo', trans.db_);
|
52
|
+
assertEquals(10, trans.id_);
|
53
|
+
}
|
54
|
+
|
55
|
+
function testExecuteAll_noStatements() {
|
56
|
+
var trans = new google.wspl.gears.Transaction(27, dbMock);
|
57
|
+
|
58
|
+
try {
|
59
|
+
trans.executeAll([], callbackMock);
|
60
|
+
fail('Should never get here');
|
61
|
+
} catch(e) {
|
62
|
+
if (e.isJsUnitException) {
|
63
|
+
throw e;
|
64
|
+
}
|
65
|
+
assertEquals('did not exception fault on empty statement list',
|
66
|
+
'Error: Possibly silly attempt to execute empty statement list.',
|
67
|
+
e.toString());
|
68
|
+
}
|
69
|
+
mockControl.verify();
|
70
|
+
}
|
71
|
+
|
72
|
+
function testExecuteAll_noCallback() {
|
73
|
+
var stat1 = new google.wspl.Statement('stat1');
|
74
|
+
var stat2 = new google.wspl.Statement('stat2', [1]);
|
75
|
+
var stat3 = new google.wspl.Statement('stat3', [2, 3]);
|
76
|
+
var transactionId = 27;
|
77
|
+
var callbackId = 1;
|
78
|
+
var trans = new google.wspl.gears.Transaction(transactionId, dbMock);
|
79
|
+
|
80
|
+
dbMock.expects().doBegin(transactionId);
|
81
|
+
dbMock.expects().doExecute([stat1, stat2, stat3], callbackId, transactionId);
|
82
|
+
dbMock.expects().doCommit(transactionId);
|
83
|
+
|
84
|
+
trans.executeAll([stat1, stat2, stat3]);
|
85
|
+
trans.success('resultset1', callbackId);
|
86
|
+
trans.success('resultset2', callbackId);
|
87
|
+
trans.success('resultset3', callbackId);
|
88
|
+
}
|
89
|
+
|
90
|
+
function testExecuteAll_success() {
|
91
|
+
var stat1 = new google.wspl.Statement('stat1');
|
92
|
+
var stat2 = new google.wspl.Statement('stat2', [1]);
|
93
|
+
var stat3 = new google.wspl.Statement('stat3', [2, 3]);
|
94
|
+
var transactionId = 27;
|
95
|
+
var callbackId = 1;
|
96
|
+
var trans = new google.wspl.gears.Transaction(transactionId, dbMock);
|
97
|
+
|
98
|
+
dbMock.expects().doBegin(transactionId);
|
99
|
+
dbMock.expects().doExecute([stat1, stat2, stat3], callbackId, transactionId);
|
100
|
+
callbackMock.expect().onSuccess(trans, 'resultset1');
|
101
|
+
callbackMock.expect().onSuccess(trans, 'resultset2');
|
102
|
+
callbackMock.expect().onSuccess(trans, 'resultset3');
|
103
|
+
dbMock.expects().doCommit(transactionId);
|
104
|
+
|
105
|
+
trans.executeAll([stat1, stat2, stat3], callbackMock);
|
106
|
+
trans.success('resultset1', callbackId);
|
107
|
+
trans.success('resultset2', callbackId);
|
108
|
+
trans.success('resultset3', callbackId);
|
109
|
+
|
110
|
+
mockControl.verify();
|
111
|
+
}
|
112
|
+
|
113
|
+
function testExecuteAll_failure() {
|
114
|
+
var stat1 = new google.wspl.Statement('stat1');
|
115
|
+
var stat2 = new google.wspl.Statement('stat2', [1]);
|
116
|
+
var stat3 = new google.wspl.Statement('stat3', [2, 3]);
|
117
|
+
var stat4 = new google.wspl.Statement('stat4', [4, 5]);
|
118
|
+
var transactionId = 27;
|
119
|
+
var callbackId = 1;
|
120
|
+
var trans = new google.wspl.gears.Transaction(transactionId, dbMock);
|
121
|
+
|
122
|
+
dbMock.expects().doBegin(transactionId);
|
123
|
+
dbMock.expects().doExecute([stat1, stat2, stat3, stat4], callbackId,
|
124
|
+
transactionId);
|
125
|
+
|
126
|
+
callbackMock.expect().onSuccess(trans, 'resultset1');
|
127
|
+
callbackMock.expect().onFailure('sql error');
|
128
|
+
dbMock.expects().doRollback(transactionId);
|
129
|
+
|
130
|
+
trans.executeAll([stat1, stat2, stat3, stat4], callbackMock);
|
131
|
+
trans.success('resultset1', callbackId);
|
132
|
+
trans.failure('sql error', callbackId);
|
133
|
+
|
134
|
+
// These should do nothing.
|
135
|
+
trans.success('resultset3', callbackId);
|
136
|
+
trans.failure('sql error', callbackId);
|
137
|
+
|
138
|
+
mockControl.verify();
|
139
|
+
}
|
140
|
+
|
141
|
+
function testExecuteAll_multipleCalls() {
|
142
|
+
var stat1 = new google.wspl.Statement('stat1');
|
143
|
+
var stat2 = new google.wspl.Statement('stat2', [1]);
|
144
|
+
var stat3 = new google.wspl.Statement('stat3', [2, 3]);
|
145
|
+
var stat4 = new google.wspl.Statement('stat4', [4, 5]);
|
146
|
+
var transactionId = 27;
|
147
|
+
var callbackId_1 = 1;
|
148
|
+
var callbackId_2 = 2;
|
149
|
+
var callbackId_3 = 3;
|
150
|
+
var trans = new google.wspl.gears.Transaction(transactionId, dbMock);
|
151
|
+
|
152
|
+
dbMock.expects().doBegin(transactionId);
|
153
|
+
dbMock.expects().doExecute([stat1, stat2], callbackId_1, transactionId);
|
154
|
+
dbMock.expects().doExecute([stat3], callbackId_2, transactionId);
|
155
|
+
callbackMock.expects().onSuccess(trans, 'resultset1').andStub(function() {
|
156
|
+
trans.executeAll([stat4], callbackMock);
|
157
|
+
});
|
158
|
+
dbMock.expects().doExecute([stat4], callbackId_3, transactionId);
|
159
|
+
callbackMock.expects().onSuccess(trans, 'resultset2').andStub(function() {});
|
160
|
+
callbackMock.expects().onSuccess(trans, 'resultset3');
|
161
|
+
callbackMock.expects().onSuccess(trans, 'resultset4');
|
162
|
+
dbMock.expects().doCommit(transactionId);
|
163
|
+
|
164
|
+
trans.executeAll([stat1, stat2], callbackMock);
|
165
|
+
trans.executeAll([stat3], callbackMock);
|
166
|
+
trans.success('resultset1', callbackId_1);
|
167
|
+
trans.success('resultset2', callbackId_1);
|
168
|
+
trans.success('resultset3', callbackId_2);
|
169
|
+
trans.success('resultset4', callbackId_3);
|
170
|
+
|
171
|
+
mockControl.verify();
|
172
|
+
}
|
173
|
+
|
174
|
+
function testOnSuccess() {
|
175
|
+
var transactionId = 27;
|
176
|
+
var callbackId = 3;
|
177
|
+
var trans = new google.wspl.gears.Transaction(transactionId, dbMock);
|
178
|
+
|
179
|
+
callbackMock.expects().onSuccess(trans, 'result2');
|
180
|
+
callbackMock.expects().onSuccess(trans, 'result3');
|
181
|
+
dbMock.expects().doCommit(transactionId);
|
182
|
+
|
183
|
+
trans.numActiveExecutes_ = 1;
|
184
|
+
trans.activeExecutes_[callbackId] = {
|
185
|
+
statements: ['s1', 's2', 's3'],
|
186
|
+
currentStatement: 1,
|
187
|
+
callback: callbackMock
|
188
|
+
};
|
189
|
+
trans.success('result2', callbackId);
|
190
|
+
trans.success('result3', callbackId);
|
191
|
+
assertUndefined('activeExecute not removed',
|
192
|
+
trans.activeExecutes_[callbackId]);
|
193
|
+
mockControl.verify();
|
194
|
+
}
|
195
|
+
|
196
|
+
function testOnFailure() {
|
197
|
+
var transactionId = 27;
|
198
|
+
var callbackId = 5;
|
199
|
+
callbackMock.expects().onFailure(TypeOf.isA(Error)).andStub(function() {
|
200
|
+
assertEquals('error not returned', 'error', arguments[0].message);
|
201
|
+
});
|
202
|
+
dbMock.expects().doRollback(transactionId);
|
203
|
+
var trans = new google.wspl.gears.Transaction(transactionId, dbMock);
|
204
|
+
|
205
|
+
trans.numActiveExecutes_ = 1;
|
206
|
+
trans.activeExecutes_[callbackId] = {
|
207
|
+
statements: ['s1', 's2', 's3'],
|
208
|
+
currentStatement: 1,
|
209
|
+
callback: callbackMock
|
210
|
+
};
|
211
|
+
|
212
|
+
trans.failure(Error('error'), callbackId);
|
213
|
+
trans.success('result3', callbackId);
|
214
|
+
assertUndefined('activeExecute not removed',
|
215
|
+
trans.activeExecutes_[callbackId]);
|
216
|
+
mockControl.verify();
|
217
|
+
}
|
218
|
+
|
219
|
+
</script>
|
220
|
+
</body>
|
221
|
+
</html>
|
@@ -0,0 +1,94 @@
|
|
1
|
+
/*
|
2
|
+
Copyright 2009 Google Inc.
|
3
|
+
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
you may not use this file except in compliance with the License.
|
6
|
+
You may obtain a copy of the License at
|
7
|
+
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
See the License for the specific language governing permissions and
|
14
|
+
limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
/**
|
18
|
+
* @fileoverview Some simple utilities for supporting Gears usage.
|
19
|
+
*/
|
20
|
+
google.wspl.GearsUtils = google.wspl.GearsUtils || {};
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Returns an array of hash objects, one per row in the result set,
|
24
|
+
* where the column names in the query are used as the members of
|
25
|
+
* the object.
|
26
|
+
*
|
27
|
+
* @param {GearsResultSet} rs the result set returned by execute.
|
28
|
+
* @return {Array.<Object>} An array containing hashes. Returns an empty
|
29
|
+
* array if there are no matching rows.
|
30
|
+
*/
|
31
|
+
google.wspl.GearsUtils.resultSetToObjectArray = function(rs) {
|
32
|
+
var rv = [];
|
33
|
+
if (rs) {
|
34
|
+
var cols = rs['fieldCount']();
|
35
|
+
var colNames = [];
|
36
|
+
for (var i = 0; i < cols; i++) {
|
37
|
+
colNames.push(rs['fieldName'](i));
|
38
|
+
}
|
39
|
+
|
40
|
+
while (rs['isValidRow']()) {
|
41
|
+
var h = {};
|
42
|
+
for (var i = 0; i < cols; i++) {
|
43
|
+
h[colNames[i]] = rs['field'](i);
|
44
|
+
}
|
45
|
+
rv.push(h);
|
46
|
+
rs['next']();
|
47
|
+
}
|
48
|
+
}
|
49
|
+
return rv;
|
50
|
+
};
|
51
|
+
|
52
|
+
/**
|
53
|
+
* Maximum file name length.
|
54
|
+
* @type {number}
|
55
|
+
* @private
|
56
|
+
*/
|
57
|
+
google.wspl.GearsUtils.MAX_FILE_NAME_LENGTH_ = 64;
|
58
|
+
|
59
|
+
/**
|
60
|
+
* Ensures that the given dbName is safe to use as a Gears database name.
|
61
|
+
* @type {!string} dbName
|
62
|
+
* @return {!string} The sanitized name.
|
63
|
+
* @private
|
64
|
+
*/
|
65
|
+
google.wspl.GearsUtils.makeSafeFileName_ = function(dbName) {
|
66
|
+
var sanitizedFileName = dbName.replace(/[^a-zA-Z0-9\.\-@_]/g, '');
|
67
|
+
if (sanitizedFileName.length <=
|
68
|
+
google.wspl.GearsUtils.MAX_FILE_NAME_LENGTH_) {
|
69
|
+
return sanitizedFileName;
|
70
|
+
} else {
|
71
|
+
return sanitizedFileName.substring(0,
|
72
|
+
google.wspl.GearsUtils.MAX_FILE_NAME_LENGTH_);
|
73
|
+
}
|
74
|
+
};
|
75
|
+
|
76
|
+
/**
|
77
|
+
* Opens a Gears Database using the provided userid and name.
|
78
|
+
* @param {string} userId The user to which the database belongs.
|
79
|
+
* @param {string} name The database's name.
|
80
|
+
* @param {GearsDatabase} db The Gears database to open.
|
81
|
+
* @param {function(string)} opt_logger A logger function for writing
|
82
|
+
* messages.
|
83
|
+
* @return {GearsDatabase} The open GearsDatabase object.
|
84
|
+
*/
|
85
|
+
google.wspl.GearsUtils.openDatabase = function(userId, name, db,
|
86
|
+
opt_logger) {
|
87
|
+
var dbId = userId + '-' + name;
|
88
|
+
var safeDbId = google.wspl.GearsUtils.makeSafeFileName_(dbId);
|
89
|
+
if (opt_logger && dbId != safeDbId) {
|
90
|
+
opt_logger('database name ' + dbId + '->' + safeDbId);
|
91
|
+
}
|
92
|
+
db.open(safeDbId);
|
93
|
+
return db;
|
94
|
+
};
|
@@ -0,0 +1,84 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<!--
|
3
|
+
Copyright 2009 Google Inc.
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
16
|
+
-->
|
17
|
+
|
18
|
+
<html>
|
19
|
+
<head>
|
20
|
+
<title>Gears Utilities Tests</title>
|
21
|
+
<script type="text/javascript" src="../jsunit/app/jsUnitCore.js"></script>
|
22
|
+
<script type="text/javascript" src="jsmock.js"></script>
|
23
|
+
<script type="text/javascript" src="global_functions.js"></script>
|
24
|
+
<script type="text/javascript" src="gearsutils.js"></script>
|
25
|
+
</head>
|
26
|
+
<body>
|
27
|
+
<script type='text/javascript'>
|
28
|
+
|
29
|
+
var mockControl;
|
30
|
+
var mockGearsDb;
|
31
|
+
var mockLogger;
|
32
|
+
|
33
|
+
function setUp() {
|
34
|
+
mockControl = new MockControl();
|
35
|
+
mockGearsDb = mockControl.createMock({
|
36
|
+
execute: function(){},
|
37
|
+
open: function(){},
|
38
|
+
close: function(){},
|
39
|
+
remove: function(){}
|
40
|
+
});
|
41
|
+
|
42
|
+
mockLogger = mockControl.createMock({
|
43
|
+
info: function(){}
|
44
|
+
});
|
45
|
+
|
46
|
+
}
|
47
|
+
|
48
|
+
function testMakeSafeFileName() {
|
49
|
+
assertEquals('simple name wrongly modified', 'ABCDEFGHIJKLMNOPQRSTUVXYZ',
|
50
|
+
google.wspl.GearsUtils.makeSafeFileName_('ABCDEFGHIJKLMNOPQRSTUVXYZ'));
|
51
|
+
assertEquals('simple name wrongly modified', 'abcdefghijklmnopqrstuvxyz',
|
52
|
+
google.wspl.GearsUtils.makeSafeFileName_('abcdefghijklmnopqrstuvxyz'));
|
53
|
+
assertEquals('simple name wrongly modified', '.-@_',
|
54
|
+
google.wspl.GearsUtils.makeSafeFileName_('.-@_'));
|
55
|
+
|
56
|
+
var longName = 'abcdefghijklmnopqrstuvxyz' + 'abcdefghijklmnopqrstuvxyz' +
|
57
|
+
'abcdefghijklmnopqrstuvxyz';
|
58
|
+
assertEquals('long name not truncated',
|
59
|
+
google.wspl.GearsUtils.MAX_FILE_NAME_LENGTH_,
|
60
|
+
google.wspl.GearsUtils.makeSafeFileName_(longName).length);
|
61
|
+
|
62
|
+
assertEquals('forbidden character not stripped', 'abc',
|
63
|
+
google.wspl.GearsUtils.makeSafeFileName_('a#b$()//c'));
|
64
|
+
}
|
65
|
+
|
66
|
+
function testCreateDatabase_success() {
|
67
|
+
mockGearsDb.expects().open('hello-there');
|
68
|
+
google.wspl.GearsUtils.openDatabase('hello', 'there', mockGearsDb,
|
69
|
+
mockLogger);
|
70
|
+
mockControl.verify();
|
71
|
+
}
|
72
|
+
|
73
|
+
function testCreateDatabase_invalidname() {
|
74
|
+
mockLogger.expects().info('database name foo/bar-ranch->foobar-ranch');
|
75
|
+
mockGearsDb.expects().open('foobar-ranch');
|
76
|
+
assertEquals('bad return value', mockGearsDb,
|
77
|
+
google.wspl.GearsUtils.openDatabase('foo/bar', 'ranch',
|
78
|
+
mockGearsDb, mockLogger.info));
|
79
|
+
mockControl.verify();
|
80
|
+
}
|
81
|
+
|
82
|
+
</script>
|
83
|
+
</body>
|
84
|
+
</html>
|
@@ -0,0 +1,72 @@
|
|
1
|
+
/*
|
2
|
+
Copyright 2009 Google Inc.
|
3
|
+
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
you may not use this file except in compliance with the License.
|
6
|
+
You may obtain a copy of the License at
|
7
|
+
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
See the License for the specific language governing permissions and
|
14
|
+
limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
/**
|
18
|
+
* @fileoverview Global function implementations used for running the
|
19
|
+
* web storage portability layer code outside of the Google internal
|
20
|
+
* development environment.
|
21
|
+
*
|
22
|
+
* Include this file only once.
|
23
|
+
*
|
24
|
+
*/
|
25
|
+
|
26
|
+
/**
|
27
|
+
* Namespace object.
|
28
|
+
* @type {Object}
|
29
|
+
*/
|
30
|
+
var google = google || {};
|
31
|
+
google.wspl = google.wspl || {};
|
32
|
+
google.wspl.gears = google.wspl.gears || {};
|
33
|
+
|
34
|
+
/**
|
35
|
+
* Inherit the prototype methods from one constructor into another.
|
36
|
+
* @param {Function} childConstructor Child class.
|
37
|
+
* @param {Function} parentConstructor Parent class.
|
38
|
+
*/
|
39
|
+
google.inherits = function(childConstructor, parentConstructor) {
|
40
|
+
function tempConstructor() {};
|
41
|
+
tempConstructor.prototype = parentConstructor.prototype;
|
42
|
+
childConstructor.prototype = new tempConstructor();
|
43
|
+
childConstructor.prototype.constructor = childConstructor;
|
44
|
+
};
|
45
|
+
|
46
|
+
/**
|
47
|
+
* Binds a context object to the function.
|
48
|
+
* @param {Function} fn The function to bind to.
|
49
|
+
* @param {Object} context The "this" object to use when the function is run.
|
50
|
+
* @return {Function} A partially-applied form of fn.
|
51
|
+
*/
|
52
|
+
google.bind = function(fn, context) {
|
53
|
+
return function() {
|
54
|
+
return fn.apply(context, arguments);
|
55
|
+
};
|
56
|
+
};
|
57
|
+
|
58
|
+
/**
|
59
|
+
* Null function used for callbacks.
|
60
|
+
* @type {Function}
|
61
|
+
*/
|
62
|
+
google.nullFunction = function() {};
|
63
|
+
|
64
|
+
/**
|
65
|
+
* Simple logging facility.
|
66
|
+
* @param {string} msg A message to write to the console.
|
67
|
+
*/
|
68
|
+
google.logger = function(msg) {
|
69
|
+
// Uncomment the below to get log messages
|
70
|
+
// May require firebug enabled to work in FireFox.
|
71
|
+
// window.console.info(msg);
|
72
|
+
};
|