Last active
October 24, 2017 02:49
-
-
Save myun2/2137acc66d4f7e1f537c81aec8c9ed88 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class @MeaveCss | |
constructor: () -> | |
@content = '' | |
add: (selector, prop, value) -> | |
@content += selector + "{" + prop + ":" + value + "}" | |
render: () -> | |
@content |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generated by CoffeeScript 1.12.7 | |
(function() { | |
this.MeaveCss = (function() { | |
function MeaveCss() { | |
this.content = ''; | |
} | |
MeaveCss.prototype.add = function(selector, prop, value) { | |
return this.content += selector + "{" + prop + ":" + value + "}"; | |
}; | |
MeaveCss.prototype.render = function() { | |
return this.content; | |
}; | |
return MeaveCss; | |
})(); | |
}).call(this); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class @MeaveHtml | |
constructor: (body = '', head = '') -> | |
@head = head | |
@body = body | |
render: () -> | |
'<!DOCTYPE html><html><head>' + @head + | |
'</head><body>' + @body + '</body></html>' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generated by CoffeeScript 1.12.7 | |
(function() { | |
this.MeaveHtml = (function() { | |
function MeaveHtml(body, head) { | |
if (body == null) { | |
body = ''; | |
} | |
if (head == null) { | |
head = ''; | |
} | |
this.head = head; | |
this.body = body; | |
} | |
MeaveHtml.prototype.render = function() { | |
return '<!DOCTYPE html><html><head>' + this.head + '</head><body>' + this.body + '</body></html>'; | |
}; | |
return MeaveHtml; | |
})(); | |
}).call(this); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class @Meave | |
constructor: () -> | |
@document = document |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generated by CoffeeScript 1.12.7 | |
(function() { | |
this.Meave = (function() { | |
function Meave() { | |
this.document = document; | |
} | |
return Meave; | |
})(); | |
}).call(this); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MeaveCss = require('./css') .MeaveCss | |
MeaveTag = require('./tag') .MeaveTag | |
MeaveHtml = require('./html').MeaveHtml | |
class MeaveServer | |
constructor: (port, host = "localhost") -> | |
@port = port | |
@host = host | |
start: () -> | |
http = require('http') | |
server = http.createServer() | |
server.on 'request', (q, r) -> | |
r.writeHead 200, {'Content-Type': 'text/html'} | |
css = new MeaveCss() | |
css.add('*','margin', 0) | |
css.add('*','padding', 0) | |
style_tag = new MeaveTag('style', css.render()).render() | |
body = new MeaveTag('h1', 'hello world').render() | |
r.write new MeaveHtml(body, style_tag).render() | |
console.log q.headers.host + ' -> hello world' | |
r.end() | |
server.listen @port, @host | |
server = new MeaveServer(8906, "0.0.0.0") | |
server.start() | |
console.log "Started at 0.0.0.0:8906" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generated by CoffeeScript 1.12.7 | |
(function() { | |
var MeaveCss, MeaveHtml, MeaveServer, MeaveTag, server; | |
MeaveCss = require('./css').MeaveCss; | |
MeaveTag = require('./tag').MeaveTag; | |
MeaveHtml = require('./html').MeaveHtml; | |
MeaveServer = (function() { | |
function MeaveServer(port, host) { | |
if (host == null) { | |
host = "localhost"; | |
} | |
this.port = port; | |
this.host = host; | |
} | |
MeaveServer.prototype.start = function() { | |
var http, server; | |
http = require('http'); | |
server = http.createServer(); | |
server.on('request', function(q, r) { | |
var body, css, style_tag; | |
r.writeHead(200, { | |
'Content-Type': 'text/html' | |
}); | |
css = new MeaveCss(); | |
css.add('*', 'margin', 0); | |
css.add('*', 'padding', 0); | |
style_tag = new MeaveTag('style', css.render()).render(); | |
body = new MeaveTag('h1', 'hello world').render(); | |
r.write(new MeaveHtml(body, style_tag).render()); | |
console.log(q.headers.host + ' -> hello world'); | |
return r.end(); | |
}); | |
return server.listen(this.port, this.host); | |
}; | |
return MeaveServer; | |
})(); | |
server = new MeaveServer(8906, "0.0.0.0"); | |
server.start(); | |
console.log("Started at 0.0.0.0:8906"); | |
}).call(this); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class @MeaveTag | |
constructor: (name, content, attributes = "") -> | |
@name = name | |
@content = content | |
@attributes = if attributes then " " + attributes else "" | |
render: () -> | |
"<#{@name}#{@attributes}>#{@content}</#{@name}>" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generated by CoffeeScript 1.12.7 | |
(function() { | |
this.MeaveTag = (function() { | |
function MeaveTag(name, content, attributes) { | |
if (attributes == null) { | |
attributes = ""; | |
} | |
this.name = name; | |
this.content = content; | |
this.attributes = attributes ? " " + attributes : ""; | |
} | |
MeaveTag.prototype.render = function() { | |
return "<" + this.name + this.attributes + ">" + this.content + "</" + this.name + ">"; | |
}; | |
return MeaveTag; | |
})(); | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment