Skip to content

Commit 77dec29

Browse files
committed
Convert text plugin to use question mark instead of bang for the strip option, and confirm code works for a built xdomain case.
1 parent 39653fa commit 77dec29

7 files changed

Lines changed: 19 additions & 13 deletions

File tree

docs/api.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,9 @@ <h3><a name="text">Specify a Text File Dependency</a><span class="sectionMark">&
414414

415415
<p>Notice the .html and .css suffixes to specify the extension of the file. The "some/module" part of the path will be resolved according to normal module name resolution: it will use the <strong>baseUrl</strong> and <strong>paths</strong> <a href="#config">configuration options</a> to map that name to a path.</p>
416416

417-
<p>For HTML/XML/SVG files, there is another option. You can pass !strip, which strips XML declarations so that external SVG and XML documents can be added to a document without worry. Also, if the string is an HTML document, only the part inside the body tag is returned. Example:</p>
417+
<p>For HTML/XML/SVG files, there is another option. You can pass ?strip, which strips XML declarations so that external SVG and XML documents can be added to a document without worry. Also, if the string is an HTML document, only the part inside the body tag is returned. Example:</p>
418418

419-
<pre><code>require(["text!some/module.html!strip"],
419+
<pre><code>require(["text!some/module.html?strip"],
420420
function(html) {
421421
//the html variable will be the text of the
422422
//some/module.html file, but only the part

tasks.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ Release Notes
55
See the optimization.html for the requireLib example.
66
- New optimizer/node/rhino adapter: r.js
77
- Removed support for lib in packages.
8-
8+
- text plugin API changed? Uses ?strip instead of !strip now.
99
Next release
1010
--------------
1111

1212
- text plugins after a build load xdomain?
13+
- Send impl to list
1314

1415
- relative modules IDs?
1516
- excludeShallow not excluding files loaded with the text plugin: email thread. Exclusions.
@@ -19,6 +20,8 @@ Next release
1920

2021
- empty: protocol support for build profiles?
2122

23+
- Put in helpful error in r.js if running it without -o option.
24+
2225
- replacement for modify that intercepts callbacks, holds off until another module loads them?
2326
- A way to show dependency graph too?
2427
- Minify the require.js files with UglifyJS.

tests/text/separate.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
//Stub file for testing optimization of all plugin resources in a build.
2+
define(['text!resources/sample.html?strip'], function () {});

tests/text/subwidget.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require.def("subwidget",
2-
["text!subwidget.html!strip", "text!subwidget2.html"],
2+
["text!subwidget.html?strip", "text!subwidget2.html"],
33
function(template, template2) {
44
return {
55
name: "subwidget",

tests/text/text.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
text: "../../text"
1313
} //, priority: ['widgetlayer']
1414
},
15-
["require", "widget", "local", "text!resources/sample.html!strip"],
15+
["require", "widget", "local", "text!resources/sample.html?strip"],
1616
function(require, widget, local, sampleText) {
1717
doh.register(
1818
"text",

tests/text/textOnly.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
text: "../../text"
1313
}
1414
},
15-
["text!resources/sample.html!strip"],
15+
["text!resources/sample.html?strip"],
1616
function(sampleText) {
1717
doh.register(
1818
"textOnly",

text.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138

139139
/**
140140
* Parses a resource name into its component parts. Resource names
141-
* look like: module/name.ext!strip, where the !strip part is
141+
* look like: module/name.ext?strip, where the ?strip part is
142142
* optional.
143143
* @param {String} name the resource name
144144
* @returns {Object} with properties "moduleName", "ext" and "strip"
@@ -149,7 +149,7 @@
149149
modName = name.substring(0, index),
150150
ext = name.substring(index + 1, name.length);
151151

152-
index = ext.indexOf("!");
152+
index = ext.indexOf("?");
153153
if (index !== -1) {
154154
//Pull off the strip arg.
155155
strip = ext.substring(index + 1, ext.length);
@@ -201,15 +201,16 @@
201201
},
202202

203203
load: function (name, req, onLoad, config) {
204-
//Name has format: some.module.filext!strip
204+
//Name has format: some.module.filext?strip
205205
//The strip part is optional.
206206
//if strip is present, then that means only get the string contents
207207
//inside a body tag in an HTML string. For XML/SVG content it means
208208
//removing the <?xml ...?> declarations so the content can be inserted
209209
//into the current doc without problems.
210210

211211
var parsed = text.parseName(name),
212-
url = req.toUrl(parsed.moduleName + "." + parsed.ext);
212+
nonStripName = parsed.moduleName + '.' + parsed.ext,
213+
url = req.toUrl(nonStripName);
213214

214215
//Load the text. Use XHR if possible and in a browser.
215216
if (!hasLocation || text.canUseXhr(url)) {
@@ -220,8 +221,8 @@
220221
//Need to fetch the resource across domains. Assume
221222
//the resource has been optimized into a JS module. Fetch
222223
//by the module name + extension, but do not include the
223-
//!strip part to avoid file system issues.
224-
req([name], function (content) {
224+
//?strip part to avoid file system issues.
225+
req([nonStripName], function (content) {
225226
text.finishLoad(parsed.moduleName + '.' + parsed.ext,
226227
parsed.strip, content, onLoad, config);
227228
});
@@ -246,7 +247,7 @@
246247

247248
//Leverage own load() method to load plugin value, but only
248249
//write out values that do not have the strip argument,
249-
//to avoid any potential issues with ! in file names.
250+
//to avoid any potential issues with ? in file names.
250251
text.load(nonStripName, req, function (value) {
251252
//Use own write() method to construct full module value.
252253
text.write(pluginName, nonStripName, function (contents) {

0 commit comments

Comments
 (0)