16
Using Jade, Stylus and NodeJS Together with Grunt Hybrid App Development Yagiz Nizipli Software Engineer

Hybrid Application Development

Embed Size (px)

DESCRIPTION

Hybrid Application Development with Grunt, Jade and Stylus templating engines.

Citation preview

Page 1: Hybrid Application Development

Using Jade, Stylus and NodeJS Together with Grunt

Hybrid App Development

Yagiz NizipliSoftware Engineer

Page 2: Hybrid Application Development

My Past

Computer engineer, musician, geek. But what have I really been doing for the past 2 years?

Page 3: Hybrid Application Development

Open-Source Initiative

❖ Always a fan of open-source projects.

❖ github.com/anonrig

Page 4: Hybrid Application Development

Grunt - The Javascript Task Runner

❖ Automation

❖ Minification, unit testing, linting

❖ Test-driven programming

❖ Step by step compilation

Page 5: Hybrid Application Development

Using NodeJs with Grunt

❖ Node.js is an event-driven, non-blocking i/o solution for asynchronous application development.

❖ On top of the language Javascript.

❖ An example use for Nodejs with Grunt is using file stream library in Nodejs.

❖ Require it using: var fs = require('fs');

Page 6: Hybrid Application Development

An example page for our mobile application

<head>

<title>My Application</title>

… some meta tags here …

<stylesheets/>

</head>

<body>

<script type=“text/javascript”>

myEnvironmentVariable = {};

<environment/>

</script>

</body>

Page 7: Hybrid Application Development

❖ Local, test and production

web: { input:"www/index.html", output:"www/index.html", tokens: [{ token: "<environment/>", string: fs.readFileSync('src/config/web.js').toString() }] },test: { input: "www/index.html", output: "www/index.html", tokens: [{ token: "<directives/>", string: fs.readFileSync('src/config/test.js').toString() }] },prod: {

input: "www/index.html",output: "www/index.html",tokens: [{

token: "<directives/>",string: fs.readFileSync('src/config/prod.js').toString()}]

}

Page 8: Hybrid Application Development

Why we need a template engine?

❖ Don’t waste time on markup languages.

❖ Reuse the code whenever it’s possible.

❖ Indentation is the key point.

❖ Use if compilation is inevitable.

Page 9: Hybrid Application Development

Introducing Jade

❖ Jade, accessed from jade-lang.com, is a node template engine for HTML5 and JavaScript.

❖ Enables us to use HTML without the markup functionality.

❖ Compiles Jade code to HTML5 and JS.

❖ How?

Page 10: Hybrid Application Development

An example Jade code

Jade HTML5

Page 11: Hybrid Application Development

Introducing Stylus

❖ Stylus, defined by the developers, is a expressive, robust, feature-rich CSS preprocessor.

❖ CSS without the unnecessary syntax.

❖ Enables to reuse the same CSS code for multiple rules.

❖ How?

Page 12: Hybrid Application Development

Example Stylus code

body font 12px Helvetica, Arial, sans-serif

a.button -webkit-border-radius 5px -moz-border-radius 5px border-radius 5px

fonts = helvetica, arial, sans-serif

body padding 50px font 14px/1.4 fonts

Using Stylus with setting variablesAn everyday stylus use

Page 13: Hybrid Application Development

What now?

❖ How to compile these engines without knowing?

❖ That’s why we need Grunt.

❖ Grunt offers grunt-contrib-stylus and grunt-contrib-jade tasks to compile both of these engines.

Page 14: Hybrid Application Development

An example of Grunt filegrunt.initConfig({ clean: { before: ['www/img', 'www/css', 'www/compiled'] }, jade: { compile: { options: { pretty: true, data: { debug: true } }, files: [{ cwd: "src", src: "**/*.jade", dest: "www", expand: true, ext: ".html" }] } },

stylus: { build: { options: { linenos: false, compress: true }, files: [{ expand: true, cwd: 'src/css', src: [ '**/*.styl' ], dest: 'www/css', ext: '.css' }] } },});

Page 15: Hybrid Application Development

Sample project demo

❖ github.com/anonrig/istanbul-coders

Page 16: Hybrid Application Development

Any questions?