Slide 1

Slide 1 text

Markup and Style without HTML and CSS

Slide 2

Slide 2 text

@jedschmidt http://who.jed.is [email protected]

Slide 3

Slide 3 text

2004: JA 2005: JA 2006: JA 2007: JA 2008: JA 2009: JA 2010: JA 2011: JA 2012: JA ✘JS

Slide 4

Slide 4 text

140byt.es

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

function(a){for(var v,s=0,i=a.length;i-- ;s+=v>(v=[100,500,,, ,,1,,,50,1e3,,,,,,,, ,5,,10][parseInt(a.c harAt(i),36)-12])?-v :v);return s} Parse Roman Numerals

Slide 7

Slide 7 text

function(z,s,r,i,k,n ,w){for(w=z*z,n=w;n- -;s[w-n]='!'.fontcol or('#'+k*9))for(r=i= k=0;r*r+i*i+k++

Slide 8

Slide 8 text

function R(a,i,j,m,g) {for(i=80;a[i];i--||A );for(m=10;g=a[i]=--m ;g&&R(a))for(j in a)g *=j==i||a[j]^m||i%9^j %9&&i/9^j/9&&i/27^j/2 7|i%9/3^j%9/3} Solve Sudoku

Slide 9

Slide 9 text

browserver

Slide 10

Slide 10 text

A node.js server in your browser.

Slide 11

Slide 11 text

HTTP over WebSockets

Slide 12

Slide 12 text

HTTP ALL THE THINGS

Slide 13

Slide 13 text

1. Browser connects to server 2. Server gives browser a hostname 3. Server proxies HTTP in 4. Server proxies HTTP out 5. Browser becomes a server

Slide 14

Slide 14 text

http.createServer(function(req, res){ ... }) http.get("http://jscamp.asia", function(res){ ... })

Slide 15

Slide 15 text

http.createServer(function(req, res){ ... }) http.get("http://jscamp.asia", function(res){ ... })

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

A wake-up call

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

How can we make web app development more compelling?

Slide 20

Slide 20 text

How can we make web app development easier?

Slide 21

Slide 21 text

How can we make web app development faster?

Slide 22

Slide 22 text

Let’s look at our stack.

Slide 23

Slide 23 text

1. JavaScript 2. HTML 3. CSS

Slide 24

Slide 24 text

1. Objective-C

Slide 25

Slide 25 text

1. Java

Slide 26

Slide 26 text

1. JavaScript 2. HTML 3. CSS

Slide 27

Slide 27 text

HTML and CSS are the best/worst thing about the web. /best

Slide 28

Slide 28 text

Standard

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

✔ Standard

Slide 32

Slide 32 text

✔ Standard Declarative

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

✔ Standard Declarative

Slide 37

Slide 37 text

✔ Standard Declarative ✔

Slide 38

Slide 38 text

✔ Standard Declarative JavaScript ✔

Slide 39

Slide 39 text

✔ ✘ Standard Declarative JavaScript ✔

Slide 40

Slide 40 text

✔ ✘ Standard Declarative ✔ Dynamic

Slide 41

Slide 41 text

CSS isn’t powerful enough.

Slide 42

Slide 42 text

so we pre-process.

Slide 43

Slide 43 text

Variables Mixins Functions Nested style

Slide 44

Slide 44 text

Variables Mixins Functions Nested style

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

but...

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

HTML isn’t powerful enough.

Slide 50

Slide 50 text

so we template.

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

uritemplate An UriTemplate implementation of rfc 6570 url-template utc Simple underscore.js template compiler. utml Express compliant templating for underscore.js vacuum Clean streamed templates (primarily for HTML) vash Razor syntax templates, for JS velocity.js Velocity Template Language(VTL) for JavaScript vie Editable RDFa with Backbone.js and JSON-LD view-test view-test allows you to easily test Jade and EJS templates views Views registry and rendering walrus A bolder kind of mustache. web2splash A PhoneGap splash screen generator using an HTML document weber A tool for compiling scripts, stylesheets and templates wh webfiller Webfiller puts data and styling into Web pages on the serv webhook-templates Dust.js templates for webhook payloads weld Template antimatter for javascript wings Templating library that works on the server and client clo wintersmith-nunjucks Nunjucks templates for Wintersmith woot Quickly create new projects based on custom templates xjs A templating language for node.js using xml and javascript xjst XSLT inspired JavaScript templates (with spices) xmlb XML builder templates for Node.js. xsl2yate converts xsl templates to yate yajet Template engine forked from http://www.yajet.net/ yate Yet Another Template Engine yatl JSON-based template engine yhandlebars Command line tool to precompile Handlebars templates as YU yui3boiler simple utility to initialize module source directory struc zappajs-template A working ZappaJS server with useful templates zeke a plug-able coffeescript template generator

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

{{#var}} {{#var?}} {{/var}} {{^var}} {{!var}} {{>var}} {{{var}}} {{&var}}

Slide 59

Slide 59 text

{{#var}} {{#var?}} {{/var}} {{^var}} {{!var}} {{>var}} {{{var}}} {{&var}}

Slide 60

Slide 60 text

Hello {{name}} You have just won ${{value}}! {{#in_ca}} Well, ${{taxed_value}}, after taxes. {{/in_ca}}

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

2002: Obtrusive JS 2012: Obtrusive HTML

Slide 63

Slide 63 text

[object HTMLScriptElement] [object String] [object Function] [object String] [object HTMLDivElement]

Slide 64

Slide 64 text

but...

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

1. JavaScript 2. HTML 3. CSS

Slide 72

Slide 72 text

1. JavaScript 2. Almost HTML 3. Almost CSS

Slide 73

Slide 73 text

✔ ✘ Standard Declarative ✔ Dynamic

Slide 74

Slide 74 text

1. JavaScript 2. Almost HTML 3. Almost CSS

Slide 75

Slide 75 text

1. JavaScript 2. JavaScript 3. JavaScript

Slide 76

Slide 76 text

tl;dr

Slide 77

Slide 77 text

Let’s kill CSS and HTML and resurrect them in JavaScript.

Slide 78

Slide 78 text

Let’s port CSS and HTML to the syntax of JavaScript.

Slide 79

Slide 79 text

dōmo

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

http://domo-js.com

Slide 82

Slide 82 text

1,303 minizipped bytes

Slide 83

Slide 83 text

Markup, style, and code, in one language.

Slide 84

Slide 84 text

HTML and CSS in JS syntax.

Slide 85

Slide 85 text

Stop coding CSS. Code style. Stop coding HTML. Code DOM.

Slide 86

Slide 86 text

HTML DOM JavaScript → →

Slide 87

Slide 87 text

HTML DOM JavaScript → →

Slide 88

Slide 88 text

No content

Slide 89

Slide 89 text

No content

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

No content

Slide 92

Slide 92 text

No content

Slide 93

Slide 93 text

HTML

Slide 94

Slide 94 text

Slide 95

Slide 95 text

About nodeName (string) attributes (map) childNodes (list)

Slide 96

Slide 96 text

domo.element

Slide 97

Slide 97 text

domo.element(nodeName, attributes, childNodes)

Slide 98

Slide 98 text

domo.element( "a", {href:"about.html"}, ["About"] )

Slide 99

Slide 99 text

1 function for each HTML5 element

Slide 100

Slide 100 text

A ABBR ACRONYM ADDRESS AREA ARTICLE ASIDE AUDIO B BDI BDO BIG BLOCKQUOTE BODY BR BUTTON CANVAS CAPTION CITE CODE COL COLGROUP COMMAND DATALIST DD DEL DETAILS DFN DIV DL DT EM EMBED FIELDSET FIGCAPTION FIGURE FOOTER FORM FRAME FRAMESET H1 H2 H3 H4 H5 H6 HEAD HEADER HGROUP HR HTML I IFRAME IMG INPUT INS KBD KEYGEN LABEL LEGEND LI LINK MAP MARK META METER NAV NOSCRIPT OBJECT OL OPTGROUP OPTION OUTPUT P PARAM PRE PROGRESS Q RP RT RUBY SAMP SCRIPT SECTION SELECT SMALL SOURCE SPAN SPLIT STRONG STYLE SUB SUMMARY SUP TABLE TBODY TD TEXTAREA TFOOT TH THEAD TIME TITLE TR TRACK TT UL VAR VIDEO WBR

Slide 101

Slide 101 text

domo.element( "a", {href:"about.html"}, ["About"] )

Slide 102

Slide 102 text

domo.a( {href:"about.html"}, ["About"] )

Slide 103

Slide 103 text

domo.a( {href:"about.html"}, "About" )

Slide 104

Slide 104 text

var href = "about.html" domo.a( {href: href}, "About" )

Slide 105

Slide 105 text

var href = "about.html" A({href: href}, "About")

Slide 106

Slide 106 text

var href = "about.html" var domo = domo.global(false) var A = domo.A A({href: href}, "About")

Slide 107

Slide 107 text

var href = "about.html" var {A} = domo.global(false) A({href: href}, "About")

Slide 108

Slide 108 text

href = "about.html" {A} = domo.global no A({href: href}, "About")

Slide 109

Slide 109 text

href = "about.html" {A} = domo.global no A href: href, "About"

Slide 110

Slide 110 text

href = "about.html" {A} = domo.global no A {href}, "About"

Slide 111

Slide 111 text

No content

Slide 112

Slide 112 text

meanwhile, on the server...

Slide 113

Slide 113 text

var domo = require("domo")

Slide 114

Slide 114 text

No content

Slide 115

Slide 115 text

822 minizipped bytes

Slide 116

Slide 116 text

No content

Slide 117

Slide 117 text

CSS

Slide 118

Slide 118 text

var styleSheet = STYLE({type: "text/css"}, STYLE.on("a", {color: "red"}), STYLE.on("*", {margin: 0, padding: 0}) ) alert(styleSheet.innerHTML == "a{color:red;}\n*{margin:0;padding:0;}\n")

Slide 119

Slide 119 text

var blue = "#3B5998" var gray = "#3B3B3B" var defaultRadius = 10 function roundedCorners(radius) { return { borderRadius : radius, WebkitBorderRadius : radius, MozBorderRadius : radius } } var styleSheet = STYLE({type: "text/css"}, STYLE.on("h2", {color: gray}, roundedCorners(defaultRadius)), STYLE.on("h1", {color: blue}, roundedCorners(defaultRadius * 2)) )

Slide 120

Slide 120 text

var nestedStyles = STYLE({type: "text/css"}, STYLE.on("a", {color: "red"}, STYLE.on("img", {borderWidth: 0}) ) ) var normalStyles = STYLE({type: "text/css"}, STYLE.on("a", {color: "red"}), STYLE.on("a img", {borderWidth: 0}) ) alert(nestedStyles.innerHTML == normalStyles.innerHTML)

Slide 121

Slide 121 text

No content

Slide 122

Slide 122 text

so.

Slide 123

Slide 123 text

If we are willing to let go of the surface syntax of HTML and CSS...

Slide 124

Slide 124 text

we can now:

Slide 125

Slide 125 text

1. Reduce our exposure to XSS attacks 2. Eliminate a separate compile step 3. Write our DOM code where it makes sense 4. Use JavaScript syntax everywhere 5. Decouple our syntax sugar 6. Reduce the number of moving parts 7. Reuse existing infrastructure 8. Lessen the burden of context switching

Slide 126

Slide 126 text

Thanks! @jedschmidt http://domo-js.com