Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

cleaned, added actual loading of example

  • Loading branch information...
commit ab5174c5f3ad3ac63a950aaf5ff775213f9ec4a2 1 parent b0847e2
Ian Storm Taylor authored March 03, 2013
14  example/build.js
@@ -206,6 +206,12 @@ require.relative = function(parent) {
206 206
 
207 207
   return localRequire;
208 208
 };
  209
+require.register("example/index.js", function(exports, require, module){
  210
+var template = require('./template')
  211
+  , html     = template({ youAreUsingJade : true });
  212
+
  213
+document.body.innerHTML = html;
  214
+});
209 215
 require.register("example/jade-runtime.js", function(exports, require, module){
210 216
 
211 217
 jade = (function(exports){
@@ -393,10 +399,7 @@ attrs = attrs || jade.attrs; escape = escape || jade.escape; rethrow = rethrow |
393 399
 var buf = [];
394 400
 with (locals || {}) {
395 401
 var interp;
396  
-buf.push('<!DOCTYPE html><html lang="en"><head><title>');
397  
-var __val__ = pageTitle
398  
-buf.push(escape(null == __val__ ? "" : __val__));
399  
-buf.push('</title><script type="text/javascript">if (foo) {\n   bar()\n}</script></head><body><h1>Jade - node template engine</h1><div id="container">');
  402
+buf.push('<h1>Jade - node template engine</h1><div id="container">');
400 403
 if ( youAreUsingJade)
401 404
 {
402 405
 buf.push('<p>You are amazing</p>');
@@ -405,10 +408,11 @@ else
405 408
 {
406 409
 buf.push('<p>Get on it!</p>');
407 410
 }
408  
-buf.push('</div></body></html>');
  411
+buf.push('</div>');
409 412
 }
410 413
 return buf.join("");
411 414
 }
412 415
 });
  416
+require.alias("example/index.js", "example/index.js");
413 417
 
414 418
 require("example/jade-runtime")
6  example/component.json
... ...
@@ -1,6 +1,10 @@
1 1
 {
2 2
   "name": "example",
  3
+  "scripts": [
  4
+    "index.js"
  5
+  ],
3 6
   "templates": [
4 7
     "template.jade"
5  
-  ]
  8
+  ],
  9
+  "main": "index.js"
6 10
 }
11  example/index.html
... ...
@@ -0,0 +1,11 @@
  1
+<html>
  2
+  <head>
  3
+    <title>component-jade example</title>
  4
+    <script src="build.js"></script>
  5
+  </head>
  6
+  <body>
  7
+    <script>
  8
+      require('example');
  9
+    </script>
  10
+  </body>
  11
+</html>
4  example/index.js
... ...
@@ -0,0 +1,4 @@
  1
+var template = require('./template')
  2
+  , html     = template({ youAreUsingJade : true });
  3
+
  4
+document.body.innerHTML = html;
21  example/template.jade
... ...
@@ -1,15 +1,6 @@
1  
-doctype 5
2  
-html(lang="en")
3  
-  head
4  
-    title= pageTitle
5  
-    script(type='text/javascript')
6  
-      if (foo) {
7  
-         bar()
8  
-      }
9  
-  body
10  
-    h1 Jade - node template engine
11  
-    #container
12  
-      if youAreUsingJade
13  
-        p You are amazing
14  
-      else
15  
-        p Get on it!
  1
+h1 Jade - node template engine
  2
+#container
  3
+  if youAreUsingJade
  4
+    p You are amazing
  5
+  else
  6
+    p Get on it!
17  index.js
@@ -15,7 +15,7 @@ module.exports = function (builder) {
15 15
     debug('adding jade-runtime.js to %s', builder.basename);
16 16
 
17 17
     // Add our runtime to the builder, and add a require call for our runtime,
18  
-    // so it's global.
  18
+    // so it's global for all future template functions.
19 19
     var runtime = fs.readFileSync(__dirname + '/runtime.js', 'utf8');
20 20
     builder.addFile('scripts', 'jade-runtime.js', runtime);
21 21
     builder.append('require("' + builder.basename + '/jade-runtime")');
@@ -30,22 +30,21 @@ module.exports = function (builder) {
30 30
  * Compile jade.
31 31
  */
32 32
 
33  
-function compileJade (builder, callback) {
  33
+function compileJade (pkg, callback) {
34 34
   // Grab our Jade templates.
35  
-  if (!builder.conf.templates) return callback();
36  
-  var files = builder.conf.templates.filter(filterJade);
  35
+  if (!pkg.conf.templates) return callback();
  36
+  var files = pkg.conf.templates.filter(filterJade);
37 37
 
38 38
   files.forEach(function (file) {
39 39
     debug('compiling: %s', file);
40 40
 
41 41
     // Read and compile our Jade.
42  
-    var string = fs.readFileSync(builder.path(file), 'utf8')
43  
-      , js     = jade.compile(string, { client: true, compileDebug: false });
  42
+    var string = fs.readFileSync(pkg.path(file), 'utf8')
  43
+      , fn     = jade.compile(string, { client: true, compileDebug: false });
44 44
 
45  
-    // Add our new compiled version to the builder, with the same name that the
46  
-    // Jade template had.
  45
+    // Add our new compiled version to the package, with the same name.
47 46
     file = path.basename(file, path.extname(file)) + '.js';
48  
-    builder.addFile('scripts', file, 'module.exports = ' + js);
  47
+    pkg.addFile('scripts', file, 'module.exports = ' + fn);
49 48
   });
50 49
 
51 50
   callback();

0 notes on commit ab5174c

Please sign in to comment.
Something went wrong with that request. Please try again.