Skip to content

Commit

Permalink
The modules are no longer declared in comments, but are wrapped by co…
Browse files Browse the repository at this point in the history
…mments. The files are ES6-compatible. Shepherd is on its way to polyfill Harmony:modules
  • Loading branch information
xcambar committed Apr 19, 2012
1 parent 98dc76a commit fd27f11
Show file tree
Hide file tree
Showing 48 changed files with 156 additions and 120 deletions.
12 changes: 6 additions & 6 deletions build/shepherd.dev.js
Expand Up @@ -1492,7 +1492,7 @@
}
function _moduleSrc(conf) {
var defer = when.defer(), moduleConf = conf || {}, rawText = conf.contents ? conf.contents : "", declaration = "";
var comments = rawText.match(/(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg);
var comments = rawText.match(/\s*\/\/\s*s6d([\s\S]*?)\/\/\s*-s6d/m);
if (!comments) {
var module = loadModule({
_internals: {
Expand All @@ -1504,9 +1504,9 @@
}
return defer.resolve(module);
}
var split = comments[0].split("\n");
var split = comments[1].split("\n");
for (var j = 0, _l2 = split.length; j < _l2; j++) {
declaration += split[j].trim().replace(/(^\/\*+)|(\*+\/?)/, "");
declaration += split[j].trim();
}
if (declaration.length) {
moduleConf = parse(declaration, moduleConf);
Expand All @@ -1519,7 +1519,7 @@
contents: rawText
};
when(applyConfiguration(usedConf)).then(function(moduleConf) {
var module = loadModule(moduleConf, moduleConf._internals.contents);
var module = loadModule(moduleConf, moduleConf._internals.contents.replace(comments[0], ""));
defer.resolve(module);
return module;
}, function(e) {
Expand Down Expand Up @@ -1680,9 +1680,9 @@
var modules = [];
for (var i = 0; i < document.scripts.length; i++) {
var script = document.scripts[i], srcAttr = script.getAttribute("type");
if (srcAttr == "text/shepherd-js") {
if (srcAttr == "harmony") {
modules.push(script);
} else if (srcAttr == "text/shepherd-js/config") {
} else if (srcAttr == "text/shepherd-config") {
confs.push(script.innerHTML.trim());
}
}
Expand Down
2 changes: 1 addition & 1 deletion build/shepherd.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/NodeJS/bootstrap.js
@@ -1,8 +1,8 @@
/*
//s6d
module nodeJSExample {
module fs is util;
import _ from '../libs/underscore.min.js';
}
*/
//-s6d

console.log(_);
4 changes: 2 additions & 2 deletions examples/jQuery/animation.js
@@ -1,8 +1,8 @@
/**
//s6d
module motion {
export rebound;
}
**/
//-s6d
var direction = {
x: 100 * Math.random(),
y: 100 * Math.random(),
Expand Down
4 changes: 2 additions & 2 deletions examples/jQuery/gear.js
@@ -1,9 +1,9 @@
/**
//s6d
module shape {
import jQuery from '../libs/jquery-1.7.1.min.js';
export gear;
}
**/
//-s6d

var $ = jQuery;

Expand Down
8 changes: 4 additions & 4 deletions examples/jQuery/index.html
Expand Up @@ -3,22 +3,22 @@
<head>
<title>Shepherding jQuery</title>

<script type="text/shepherd-js" data-src="main.js"></script>
<script type="harmony" data-src="main.js"></script>
<script type="text/javascript" src="../../build/shepherd.dev.js"></script>

<style type="text/css">
body {padding: 0;margin:0;position:fixed;top:0;bottom:0;left:0;right:0}
.info {border-bottom: 3px solid orange;background: #FFD39B;text-align: center;font-size: 1.05em;padding-top: 5px;}
.info pre {font-size: 1.2em;border: 1px solid #999;background: #DDD;display: inline;padding: 3px 20px;}
.info pre {font-size: 1.2em;border: 1px solid #999;background: #DDD;display: inline-block; text-align: left; padding: 3px 20px;}
</style>
</head>
<body>
<div class='info'>
<b>Note</b>: This demo uses a modified version of jQuery.<br />
The modification consists on a one-line addition of the following text (quotes included): <br /><br />
<pre>/*
<pre>//s6d
export jQuery;
*/
//-s6d
</pre><br /><br />
</div>
<p>Expected output: A gear falling to the bottom of the page</p>
Expand Down
4 changes: 2 additions & 2 deletions examples/jQuery/main.js
@@ -1,10 +1,10 @@
/**
//s6d
module app {
import jQuery from '../libs/jquery-1.7.1.min.js';
import rebound from './animation.js';
import gear from './gear.js';
}
**/
//-s6d

var $ = jQuery;

Expand Down
4 changes: 2 additions & 2 deletions examples/jQueryFromExternal/animation.js
@@ -1,8 +1,8 @@
/**
//s6d
module animationExample {
export rebound;
}
**/
//-s6d

var direction = {
x: 100 * Math.random(),
Expand Down
4 changes: 2 additions & 2 deletions examples/jQueryFromExternal/gear.js
@@ -1,9 +1,9 @@
/**
//s6d
module gearExample {
import jQuery from '../libs/jquery-1.7.1.min.js';
export gear;
}
**/
//-s6d

var $ = jQuery;

Expand Down
6 changes: 3 additions & 3 deletions examples/jQueryFromExternal/index.html
Expand Up @@ -4,13 +4,13 @@
<title>Shepherding jQuery fetched from an external domain</title>
<script type="text/javascript" src="../../build/shepherd.dev.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/shepherd-js/config">
<script type="text/shepherd-config">
{
modularize: 'jQuery',
noGlobal: ['jQuery', '$']
}
</script>
<script type="text/shepherd-js" data-src="./main.js"></script>
<script type="harmony" data-src="./main.js"></script>

<style type="text/css">
body {padding: 0;margin:0;position:fixed;top:0;bottom:0;left:0;right:0}
Expand All @@ -23,7 +23,7 @@
<b>Note</b>: This demo fetches jQuery from a CDN.<br />
Shepherd allows to securize the code from external domain by turning them into modules. <br />
To do so for jQuery, the following lines added to the header of your page are enough: <br /><br />
<pre>&lt;script type="text/shepherd-js"&gt;
<pre>&lt;script type="harmony"&gt;
{
modularize: 'jQuery',
noGlobal: ['jQuery', '$']
Expand Down
4 changes: 2 additions & 2 deletions examples/jQueryFromExternal/main.js
@@ -1,10 +1,10 @@
/**
//s6d
module jQueryFromExternalExample {
module $ is jQuery;
import rebound from 'animation.js';
import gear from 'gear.js';
}
**/
//-s6d

$(function () {
var ctn = $('body');
Expand Down
4 changes: 2 additions & 2 deletions examples/libs/jquery-1.7.1.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/libs/underscore.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions examples/underscore/index.html
Expand Up @@ -3,21 +3,21 @@
<head>
<title>Shepherding Underscore</title>
<script type="text/javascript" src="../../build/shepherd.dev.js"></script>
<script type="text/shepherd-js" data-src="main.js"></script>
<script type="harmony" data-src="main.js"></script>

<style type="text/css">
body {padding: 0;margin:0;}
.info {border-bottom: 3px solid orange;background: #FFD39B;text-align: center;font-size: 1.05em;padding-top: 5px;}
.info pre {font-size: 1.2em;border: 1px solid #999;background: #DDD;display: inline;padding: 3px 20px;}
.info pre {font-size: 1.2em;border: 1px solid #999;background: #DDD;display: inline-block;padding: 3px 20px;text-align:left;}
</style>
</head>
<body>
<div class='info'>
<b>Note</b>: This demo uses a modified version of Underscore.<br />
The modification consists on a one-line addition of the following text (quotes included): <br /><br />
<pre>/*
<pre>//s6d
export this._;
*/</pre><br /><br />
//-s6d</pre><br /><br />
</div>
<p>Expected output: All the public methods accessible in Underscore</p>
<ul class='methods'></ul>
Expand Down
4 changes: 2 additions & 2 deletions examples/underscore/main.js
@@ -1,8 +1,8 @@
/**
//s6d
module underscoreExample {
import _ from '../libs/underscore.min.js';
}
**/
//-s6d
var list = document.getElementsByTagName('ul')[0];
for (var i in _) {
_.hasOwnProperty(i) && (list.innerHTML += ('<li>' + i + '</li>'));
Expand Down
6 changes: 3 additions & 3 deletions examples/underscoreFromExternal/index.html
Expand Up @@ -4,14 +4,14 @@
<title>Shepherding Underscore fetched from an external domain</title>
<script type="text/javascript" src="../../build/shepherd.dev.js"></script>
<script type="text/javascript" src="https://raw.github.com/documentcloud/underscore/master/underscore-min.js"></script>
<script type="text/shepherd-js/config">
<script type="text/shepherd-config">
{
modularize: '_',
noGlobal: '_'
}
</script>

<script type="text/shepherd-js" data-src="main.js"></script>
<script type="harmony" data-src="main.js"></script>

<style type="text/css">
body {padding: 0;margin:0;}
Expand All @@ -24,7 +24,7 @@
<b>Note</b>: This demo uses Underscore fetched from an external domain (gitHub, in that case).<br />
Shepherd allows external libraries to be securized as modules.<br />
For Underscore, the required code in your header is enough:<br /><br />
<pre>&lt;script type="text/shepherd-js"&gt;
<pre>&lt;script type="harmony"&gt;
{
modularize: '_',
noGlobal: '_'
Expand Down
4 changes: 2 additions & 2 deletions examples/underscoreFromExternal/main.js
@@ -1,8 +1,8 @@
/**
//s6d
module underscoreFromExternalExample {
module Underscore is _;
}
**/
//-s6d

var list = document.getElementsByTagName('ul')[0];
for (var i in Underscore) {
Expand Down

0 comments on commit fd27f11

Please sign in to comment.