User Tools

Site Tools


javascript:jade

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
javascript:jade [2014/03/18 00:15] – [Installing Jade] mithatjavascript:jade [2014/03/18 03:16] – [Creating Web pages] mithat
Line 33: Line 33:
 === jade.compile === === jade.compile ===
  
-You can also create function that when called will return the fragment with the ''jade.compile'' method.+You can use the ''jade.compile'' method to create a function that when called will return the fragment.
 <file javascript compileFragment.js> <file javascript compileFragment.js>
 var jade = require('jade'); var jade = require('jade');
Line 88: Line 88:
 output: <code><h1>Hello, there!</h1> output: <code><h1>Hello, there!</h1>
 <p>Nice to meet you.</p></code> <p>Nice to meet you.</p></code>
 +
 +You can (and should) also take anvantage of the callback that you can pass to ''jade.renderFile'' to handle errors:
 +<file javascript renderFragmentFile_3.js>
 +var jade = require('jade');
 +
 +options = {
 +    pretty: true
 +};
 +
 +// Render an HTML fragment from a file
 +// written in Jade.
 +// Use callback to trap errors.
 +var htmlFrag = jade.renderFile('myFrag.jade', options, function (err, html) {
 +        if (err) {
 +           throw(err);
 +        }
 +        return html;
 +    });
 +    
 +console.log(htmlFrag);
 +</file>
  
 === Writing output to file === === Writing output to file ===
Line 115: Line 136:
 </code> </code>
  
-===== Creating a simple web page =====+==== Creating web pages ====
  
 In this section, we will use Jade to build a simple but complete web page. It will serve as an introduction to some fundamental Jade language concepts. In this section, we will use Jade to build a simple but complete web page. It will serve as an introduction to some fundamental Jade language concepts.
Line 161: Line 182:
 The basic idea is that Jade uses a shorthand HTML syntax, and indentation is used to nest elements. The basic idea is that Jade uses a shorthand HTML syntax, and indentation is used to nest elements.
  
-This should be enough to make you comfortable reading the [[http://jade-lang.com/reference/|Jade Language Reference]].+This should be enough to make you comfortable reading the [[http://jade-lang.com/reference/|Jade Language Reference]], after which you should be able to compose entire web pages in Jade. 
 + 
 +<WRAP center round info 60%> 
 +More later, time permitting. 
 +</WRAP> 
  

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki