Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate dependencies on jquery, and underscore. #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Meteor.startup(function() {
var dom = $('script[type="text/inject-data"]', document);
var injectedDataString = $.trim(dom.text());
var injectedDataString = ""
var scriptTags = document.getElementsByTagName("script");

for (var i = 0; i < scriptTags.length; i++) {
if (scriptTags[i].getAttribute("type") == "text/inject-data") {
injectedDataString = scriptTags[i].innerHTML.replace(/(^\s+|\s+$)/g, "");
break;
}
}

InjectData._data = InjectData._decode(injectedDataString) || {};
});

Expand Down
1 change: 0 additions & 1 deletion lib/inject.html

This file was deleted.

11 changes: 5 additions & 6 deletions lib/server.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
var http = Npm.require('http');

var templateText = Assets.getText('lib/inject.html');
var injectDataTemplate = _.template(templateText);

// custome API
// custom API
InjectData.pushData = function pushData(res, key, value) {
if(!res._injectPayload) {
res._injectPayload = {};
Expand All @@ -15,7 +12,9 @@ InjectData.pushData = function pushData(res, key, value) {

InjectData.getData = function getData(res, key) {
if(res._injectPayload) {
return _.clone(res._injectPayload[key]);
var data = res._injectPayload[key];
var clonedData = EJSON.parse(EJSON.stringify(data));
return clonedData;
} else {
return null;
}
Expand Down Expand Up @@ -50,7 +49,7 @@ InjectData._hijackWriteIfNeeded = function(res) {

// inject data
var data = InjectData._encode(res._injectPayload);
var injectHtml = injectDataTemplate({data: data});
var injectHtml = '<script type="text/inject-data">' + data + '</script>';

// if this is a buffer, convert it to string
chunk = chunk.toString();
Expand Down
7 changes: 1 addition & 6 deletions package.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ Package.onTest(function(api) {
function configure (api) {
api.versionsFrom('[email protected]');

api.use(['ejson', 'underscore'], ['server', 'client']);
api.use('jquery', 'client');

api.addFiles([
'lib/inject.html',
], 'server', {isAsset: true});
api.use('ejson', ['server', 'client']);

api.addFiles([
'lib/namespace.js',
Expand Down
11 changes: 7 additions & 4 deletions tests/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ Tinytest.add(
};

Picker.route(path, function(params, req, res, next) {
_.each(sendingData, function(val, key) {
InjectData.pushData(res, key, val);
});
for (var key in sendingData) {
if (sendingData.hasOwnProperty(key)) {
InjectData.pushData(res, key, sendingData[key]);
}
}
next();
});

Expand Down Expand Up @@ -130,7 +132,8 @@ function getInjectedData(path) {
var url = urlResolve(process.env.ROOT_URL, path);
var res = HTTP.get(url);

var matched = res.content.match(/data">(.*)<\/script/);
var matched = res.content.match(/data">(.*?)<\/script/);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the change here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The query makes it non-greedy. Previously it was matching additional tags. See http://regexr.com/3cu6c

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.


if(matched) {
var encodedData = matched[1];
return InjectData._decode(encodedData);
Expand Down