SlideShare une entreprise Scribd logo
1  sur  17
& JavaScript Templating http://jade-lang.com/ @WeAreFractal
Wat? Web Template Engine - Pull in content and combine with layout & structure template to produce native web output i.e.: pull content out of a DB, process along with template to produce pure HTML output Grails gsp: <ul> <g:each in="${items}" var="item">  	<li>${item}</li>  </g:each>  </ul> ------------------------------------------------------------------------------------------------------ <ul>  <li>Grails</li>  <li>Groovy</li> </ul>
Why? Obvious one – support dynamic content  Provides if-then-else logic, iteration Separation of Concern - separate presentation from content  Modularized – break out header, footer, etc
JS - Client or Server? JS has client-side templating most notably jquery and underscore With the advent of node you get support for (more traditional?) server-side templating We chose to go with client-side, to support our efforts using Spine.js, and since we are just using websockets Interesting argument from hij1nx of nodejitsuhttp://blog.nodejitsu.com/micro-templates-are-dead
Comparison
ERB <div id="profile">  <div class="left column">  	<div id="date"> 		<%= print_date%>	 	</div>  	<div id="address"> 		<%= current_user.address%> 	</div> </div>  <div class="right column">  	<div id="email"> 		<%= current_user.email%> 	</div>  	<div id="bio"> 		<%= current_user.bio %> 	</div> </div>  </div>
{{mustache}} in Ruby   <div class="row">       {{#projects}}         <a href="{{url}}" class="block">           <h2> {{name}} </h2>           <p> {{description}} </p>         </a>       {{/projects}}     </div>
JQuery Template {{if data.length}}  <ul>  {{each data}}   <li> 	<a href="#/category/${$value._id}">    		${$value.name} 	</a> </li> {{/each}} </ul>
HAML #profile  .left.column 	#date= print_date 	#address= current_user.address.right.column 	#email= current_user.email 	#bio= current_user.bio
!!! 5  html(lang="en")  head  	title= pageTitle 	script(type='text/javascript')  	if (foo) { bar() }  body  	h1 Jade - node template engine  	#container  	- if (youAreUsingJade)  		p You are amazing  	- else  		p Get on it!
<!DOCTYPE html>  <html lang="en">  <head>  <title>Jade</title>  <script type="text/javascript">  	if (foo) { bar() }  </script>  </head>  <body>  <h1>Jade - node template engine</h1>  <div id="container">  	<p>You are amazing</p>  </div>  </body>  </html>
Jade:HTML::Coffeescript:Javascript Heavily influenced by HAML Made by https://github.com/visionmedia (core committer on express) Written in JavaScript for node Can be used client side
A tag is just a word:  html Hash for id’s:  div#mydiv Classes:  div.myclass Chain: div#foo.class1.class2 Div sugar: #foo .bar
Tag text:  p some text!  vars:  - varfoo = ‘bar’ iteration:  ,[object Object],p= obj[key]Chain: Comments: // comment >> <!-– comment --> //- comment >> will not output Block Comments: //  	#content
Stylus body { font: 12px Helvetica, Arial, sans-serif; } a.button {  	-webkit-border-radius: 5px;  	-moz-border-radius: 5px;  	border-radius: 5px;  } --------------------------------------------------- body  	font 12px Helvetica, Arial, sans-serif  a.button 	-webkit-border-radius 5px  	-moz-border-radius 5px  	border-radius 5px
Running Server Side: Cli: $ jade file.jade # compile jade template to file.html In node: varfn =jade.compile('string of jade', options); Client Side: Jade runtime client-side (jade.js) Compile to pure js functions : function anonymous(locals, attrs, escape, rethrow) { varbuf = []; with (locals || {}) { varinterp; buf.push('<p>Hello ' + escape((interp = name) == null ? '' : interp) + '</p>'); } return buf.join(""); }

Contenu connexe

Tendances

Ghghghghghg
GhghghghghgGhghghghghg
Ghghghghghg
brayan95
 
Html
HtmlHtml
Html
elsye
 
Html tags
Html tagsHtml tags
Html tags
Kumar
 
XHTML/CSS Presentation
XHTML/CSS PresentationXHTML/CSS Presentation
XHTML/CSS Presentation
joshpuckett
 

Tendances (20)

Intro to HTML and CSS
Intro to HTML and CSSIntro to HTML and CSS
Intro to HTML and CSS
 
#3 HTML & CSS [know-how]
#3 HTML & CSS [know-how]#3 HTML & CSS [know-how]
#3 HTML & CSS [know-how]
 
#1 of HTML and CSS3
#1 of HTML and CSS3 #1 of HTML and CSS3
#1 of HTML and CSS3
 
Te Vi Venir
Te Vi VenirTe Vi Venir
Te Vi Venir
 
Javascript
JavascriptJavascript
Javascript
 
Introduction to html class-1
Introduction to html class-1Introduction to html class-1
Introduction to html class-1
 
Yerma
YermaYerma
Yerma
 
Rakshat bhati
Rakshat bhatiRakshat bhati
Rakshat bhati
 
YL Intro html
YL Intro htmlYL Intro html
YL Intro html
 
HTML to FTP
HTML to FTPHTML to FTP
HTML to FTP
 
Ghghghghghg
GhghghghghgGhghghghghg
Ghghghghghg
 
HTML presentation for beginners
HTML presentation for beginnersHTML presentation for beginners
HTML presentation for beginners
 
Babitha3.css
Babitha3.cssBabitha3.css
Babitha3.css
 
Front-End Tooling
Front-End ToolingFront-End Tooling
Front-End Tooling
 
Using jQuery Templates
Using jQuery TemplatesUsing jQuery Templates
Using jQuery Templates
 
Semantics & the Mobile Web
Semantics & the Mobile WebSemantics & the Mobile Web
Semantics & the Mobile Web
 
Html
HtmlHtml
Html
 
Html tags
Html tagsHtml tags
Html tags
 
HTML X CSS
HTML X CSSHTML X CSS
HTML X CSS
 
XHTML/CSS Presentation
XHTML/CSS PresentationXHTML/CSS Presentation
XHTML/CSS Presentation
 

Similaire à Jade & Javascript templating

Optimizing Drupal for Mobile Devices
Optimizing Drupal for Mobile DevicesOptimizing Drupal for Mobile Devices
Optimizing Drupal for Mobile Devices
Sugree Phatanapherom
 
Web Scraper Shibuya.pm tech talk #8
Web Scraper Shibuya.pm tech talk #8Web Scraper Shibuya.pm tech talk #8
Web Scraper Shibuya.pm tech talk #8
Tatsuhiko Miyagawa
 
What I brought back from Austin
What I brought back from AustinWhat I brought back from Austin
What I brought back from Austin
Lisa Adkins
 

Similaire à Jade & Javascript templating (20)

Developing Gadgets
Developing GadgetsDeveloping Gadgets
Developing Gadgets
 
JWU Guest Talk: JavaScript and AJAX
JWU Guest Talk: JavaScript and AJAXJWU Guest Talk: JavaScript and AJAX
JWU Guest Talk: JavaScript and AJAX
 
KMUTNB - Internet Programming 3/7
KMUTNB - Internet Programming 3/7KMUTNB - Internet Programming 3/7
KMUTNB - Internet Programming 3/7
 
Developing and testing ajax components
Developing and testing ajax componentsDeveloping and testing ajax components
Developing and testing ajax components
 
Ajax ons2
Ajax ons2Ajax ons2
Ajax ons2
 
Html5
Html5Html5
Html5
 
HTML5 Overview
HTML5 OverviewHTML5 Overview
HTML5 Overview
 
Java Script
Java ScriptJava Script
Java Script
 
Optimizing Drupal for Mobile Devices
Optimizing Drupal for Mobile DevicesOptimizing Drupal for Mobile Devices
Optimizing Drupal for Mobile Devices
 
Web Scraper Shibuya.pm tech talk #8
Web Scraper Shibuya.pm tech talk #8Web Scraper Shibuya.pm tech talk #8
Web Scraper Shibuya.pm tech talk #8
 
Html ppt
Html pptHtml ppt
Html ppt
 
HTML5 with examples
HTML5 with examplesHTML5 with examples
HTML5 with examples
 
Html5
Html5Html5
Html5
 
HTML5 - One spec to rule them all
HTML5 - One spec to rule them allHTML5 - One spec to rule them all
HTML5 - One spec to rule them all
 
Html
HtmlHtml
Html
 
What I brought back from Austin
What I brought back from AustinWhat I brought back from Austin
What I brought back from Austin
 
Grails and Dojo
Grails and DojoGrails and Dojo
Grails and Dojo
 
Introducing YUI
Introducing YUIIntroducing YUI
Introducing YUI
 
HTML & CSS
HTML & CSSHTML & CSS
HTML & CSS
 
Lecture1 B Frames&Forms
Lecture1 B  Frames&FormsLecture1 B  Frames&Forms
Lecture1 B Frames&Forms
 

Plus de wearefractal (6)

Bdd spex
Bdd spexBdd spex
Bdd spex
 
Novajs
NovajsNovajs
Novajs
 
nodester Architecture overview & roadmap
nodester Architecture overview & roadmapnodester Architecture overview & roadmap
nodester Architecture overview & roadmap
 
Spine.js
Spine.jsSpine.js
Spine.js
 
ChanJS
ChanJSChanJS
ChanJS
 
Fusker - A NodeJS Security Framework
Fusker - A NodeJS Security FrameworkFusker - A NodeJS Security Framework
Fusker - A NodeJS Security Framework
 

Dernier

Dernier (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Jade & Javascript templating

  • 1. & JavaScript Templating http://jade-lang.com/ @WeAreFractal
  • 2. Wat? Web Template Engine - Pull in content and combine with layout & structure template to produce native web output i.e.: pull content out of a DB, process along with template to produce pure HTML output Grails gsp: <ul> <g:each in="${items}" var="item"> <li>${item}</li> </g:each> </ul> ------------------------------------------------------------------------------------------------------ <ul> <li>Grails</li> <li>Groovy</li> </ul>
  • 3. Why? Obvious one – support dynamic content Provides if-then-else logic, iteration Separation of Concern - separate presentation from content Modularized – break out header, footer, etc
  • 4. JS - Client or Server? JS has client-side templating most notably jquery and underscore With the advent of node you get support for (more traditional?) server-side templating We chose to go with client-side, to support our efforts using Spine.js, and since we are just using websockets Interesting argument from hij1nx of nodejitsuhttp://blog.nodejitsu.com/micro-templates-are-dead
  • 6. ERB <div id="profile"> <div class="left column"> <div id="date"> <%= print_date%> </div> <div id="address"> <%= current_user.address%> </div> </div> <div class="right column"> <div id="email"> <%= current_user.email%> </div> <div id="bio"> <%= current_user.bio %> </div> </div> </div>
  • 7. {{mustache}} in Ruby   <div class="row">       {{#projects}}         <a href="{{url}}" class="block">           <h2> {{name}} </h2>           <p> {{description}} </p>         </a>       {{/projects}}     </div>
  • 8. JQuery Template {{if data.length}}  <ul>  {{each data}}   <li> <a href="#/category/${$value._id}">  ${$value.name} </a> </li> {{/each}} </ul>
  • 9. HAML #profile .left.column #date= print_date #address= current_user.address.right.column #email= current_user.email #bio= current_user.bio
  • 10.
  • 11. !!! 5 html(lang="en") head title= pageTitle script(type='text/javascript') if (foo) { bar() } body h1 Jade - node template engine #container - if (youAreUsingJade) p You are amazing - else p Get on it!
  • 12. <!DOCTYPE html> <html lang="en"> <head> <title>Jade</title> <script type="text/javascript"> if (foo) { bar() } </script> </head> <body> <h1>Jade - node template engine</h1> <div id="container"> <p>You are amazing</p> </div> </body> </html>
  • 13. Jade:HTML::Coffeescript:Javascript Heavily influenced by HAML Made by https://github.com/visionmedia (core committer on express) Written in JavaScript for node Can be used client side
  • 14. A tag is just a word: html Hash for id’s: div#mydiv Classes: div.myclass Chain: div#foo.class1.class2 Div sugar: #foo .bar
  • 15.
  • 16. Stylus body { font: 12px Helvetica, Arial, sans-serif; } a.button { -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; } --------------------------------------------------- body font 12px Helvetica, Arial, sans-serif a.button -webkit-border-radius 5px -moz-border-radius 5px border-radius 5px
  • 17. Running Server Side: Cli: $ jade file.jade # compile jade template to file.html In node: varfn =jade.compile('string of jade', options); Client Side: Jade runtime client-side (jade.js) Compile to pure js functions : function anonymous(locals, attrs, escape, rethrow) { varbuf = []; with (locals || {}) { varinterp; buf.push('<p>Hello ' + escape((interp = name) == null ? '' : interp) + '</p>'); } return buf.join(""); }