37
Mojito and Cocktails @ddsakura

Mojito@nodejstw

Embed Size (px)

DESCRIPTION

Introduction to Mojito and Cocktails @ NodeJS Taiwan community

Citation preview

Page 1: Mojito@nodejstw

Mojito and Cocktails@ddsakura

Page 2: Mojito@nodejstw

I am…

ddsakura / 賽拉維.柯南

2

Page 3: Mojito@nodejstw

Outline

3

Page 4: Mojito@nodejstw

Cocktails is

an alcoholic mixed drink that contains

two or more ingredients — at least

one of the ingredients must be a spirit.

4

Page 5: Mojito@nodejstw

Cocktails is also

a mix of HTML5, NodeJS, CSS3, YUI

and a lot of ingenious, creative mind-

bending tricks from Yahoo!

5

Page 6: Mojito@nodejstw

Cocktails and YUI

YUI is a free, open source JavaScript

and CSS framework for building richly

interactive web applications

◦ http://developer.yahoo.com/yui/

◦ https://github.com/yui YUI3 is a foundation for Cocktails

6

Page 7: Mojito@nodejstw

Eating your own dog food

like Yahoo! Livestand.

7

Page 8: Mojito@nodejstw

Mojito is

Mojito (/moʊˈhiˈtoʊ/)

◦ It is a kind of cocktail

8

Page 9: Mojito@nodejstw

Mojito is Mojito is a MVC application framework built

on YUI 3.

One Language◦ Mojito allows developers to write client and

server components in the same language -JavaScript, using the same framework.

Two Runtimes◦ Mojito can run on the client (in the browser) and

on the server (with Node.js).

In addition, Mojito has built-in support for internationalization and testing

9

Page 13: Mojito@nodejstw

Mojito is open!

http://developer.yahoo.com/cocktails/

mojito/

https://github.com/yahoo/mojito/

13

Page 14: Mojito@nodejstw

14

Mojits

Page 15: Mojito@nodejstw
Page 16: Mojito@nodejstw

16

Page 17: Mojito@nodejstw

17

Page 18: Mojito@nodejstw
Page 19: Mojito@nodejstw

19

Page 20: Mojito@nodejstw

Mojito application concept

20

Page 21: Mojito@nodejstw

Mojito application directory

structure

21

Page 22: Mojito@nodejstw

DEMO - Hello World Install nodejs and npm

Get mojito from npm registry◦ npm install mojito -g

Create a mojito application◦ mojito create app helloworld

Create a mojit in application◦ mojito create mojit myMojit

Modify the controller.server.js◦ vi mojits/myMojit/controller.server.js

Run the mojito application◦ mojito start

Go to http://localhost:8666/@myMojit/index

22

Page 23: Mojito@nodejstw

Configuration Application

Configuration◦ The application is

configured in the application.json file in the application directory.

◦ http://developer.yahoo.com/cocktails/mojito/docs/intro/mojito_configuring.html

23

Page 24: Mojito@nodejstw

Configuration Routing

◦ In Mojito, routing is the mapping of URLs to specific mojit actions. This section will describe the routing configuration file routes.json

◦ http://developer.yahoo.com/cocktails/mojito/docs/intro/mojito_configuring.html

24

[

{

"settings": [ "master" ],

"foo index": {

"verbs": ["get"],

"path": "/",

"call": ”@myMojit.index"

}

}

]

Page 25: Mojito@nodejstw

DEMO - Routing Create the file routes.json with the following

Run the mojito application◦ mojito start

Go to http://localhost:8666/index25

[

{

"settings": ["master"],

"index_route": {

"verbs": ["get"],

"path": "/index",

"call": "@myMojit.index"

}

}

]

Page 26: Mojito@nodejstw

Template Engine

Currently, the only template system

allowed is Mustache, so the name of

view templates always contains mu

http://mustache.github.com/

26

Page 27: Mojito@nodejstw

Views in Mojito The views are HTML files that can include template tags, such as

Mustache tags, and are located in the views directory

We call these files view templates

Naming Convention for view templates

◦ {controller_function}.[{device}].{rendering_engine}.html

Example

◦ greeting.mu.html - This view template gets data from the greeting function of the controller and the calling device is determined to be a Web browser.

◦ get_photos.iphone.mu.html - This view template gets data from the get_photosfunction of the controller and the calling device is an iPhone.

◦ find_friend.android.mu.html - This view template gets data from the find_friendfunction of the controller and the calling device is Android based.

27

Page 28: Mojito@nodejstw

The tools for Multi-Device CSS3 Media Queries

Mojito view template

28

Page 29: Mojito@nodejstw

DEMO – Views for different

Devices Create index.iphone.mu.html

◦ cp index.mu.html index.iphone.mu.html

◦ vi

mojits/myMojit/views/index.iphone.mu.html

Run the mojito application

◦ mojito start

Go to http://localhost:8666/index

29

Page 30: Mojito@nodejstw

Mojito API Mojito has an API that includes addons

and methods for handling

parameters, cookies, URLs, assets, RE

ST calls, globalization/localization, and

more.

http://developer.yahoo.com/cocktails/m

ojito/docs/api_overview/

http://developer.yahoo.com/cocktails/m

ojito/api/index.html 30

Page 31: Mojito@nodejstw

Built-in Mojits

Mojito comes with the built-in utility mojitsthat make developing applications easier.

HTMLFrameMojit

◦ The HTMLFrameMojit builds the HTML skeleton of a Web page.

LazyLoadMojit

◦ This allows Mojito application to load the page quickly and then lazily load parts of the page.

http://developer.yahoo.com/cocktails/mojito/docs/topics/mojito_framework_mojits.html

31

Page 32: Mojito@nodejstw

DEMO – HTMLFrameMojit & API

32

Page 33: Mojito@nodejstw

DEMO – LazyLoad

33

Page 34: Mojito@nodejstw

Deployment

Mojito on Heroku

34

Page 35: Mojito@nodejstw

Mojito Shaker

Shaker is a static asset rollup

manager for Mojito applications.

https://github.com/yahoo/mojito-

shaker

http://developer.yahoo.com/cocktails/s

haker/

35

Page 36: Mojito@nodejstw

Conclusion Cocktails is an ecosystem mix of

HTML5, NodeJS, CSS3, YUI and relative technology

Mojito is a MVC application framework ◦ One language

◦ Two Runtimes

Mojito is available under a BSD license

A lot of docs are available, we can start from http://developer.yahoo.com/cocktails/mojito/

We also have forum to discuss this: http://developer.yahoo.com/forum/Yahoo-Mojito 36