-
Notifications
You must be signed in to change notification settings - Fork 53
Coffee, and possibly horses #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from 61 commits
262df0a
72631f8
b90b072
20395a6
0759198
e99065e
5ad7a65
b18205d
cb5b527
c7973a5
a29b940
83c7f87
9359f13
e8d6c90
4cc3c45
208f16f
a190754
8698e7b
0b2412e
efb0304
aa563b7
083c14d
31b0235
79e8726
9a69b43
125926d
2f4b339
b374989
6bbf935
305e469
dd04d84
86ece34
0a691f6
95b06b6
f044309
699c133
d06b9c1
c23db3c
92cf012
cb807e4
e5bc952
41d1fc6
185820a
1795995
fdc79b8
f9d2ef0
5529034
b632b3e
8ed84b8
2806c99
d79277c
cc9588d
8a8b922
9bbc67f
0b28889
8880e2f
839a191
88463b0
01aaad3
e1e134f
47fd2c8
1abab94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| annoying people | ||
| node_modules |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| .git | ||
| .gitignore | ||
| .npmignore | ||
| .redcar | ||
| node_modules | ||
| site | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # Berliner | ||
|
|
||
| A lightweight web framework. [Read the online docs.](http://berliner.jcoglan.com) | ||
|
|
||
| ## License | ||
|
|
||
| (The MIT License) | ||
|
|
||
| Copyright (c) 2012 James Coglan | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| this software and associated documentation files (the 'Software'), to deal in | ||
| the Software without restriction, including without limitation the rights to use, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what |
||
| copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the | ||
| Software, and to permit persons to whom the Software is furnished to do so, | ||
| subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| [J,M,duc,euc,n,e,w]=[JSON,Math,decodeURIComponent,encodeURIComponent,((p)->p.replace(/\/*$/,'').replace /^\/?/,'/'),((d,s)->d[k]=(if d[k]instanceof Array then d[k].concat v else v)for k,v of s;d),(s,c)->s.split(/\s+/).map c] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pretty sure this should be |
||
| [http,url,qs,fs,async,WS,E,haml,ejs,mime]=w 'http url querystring fs async faye-websocket vault-cipher haml ejs mime',require | ||
| class A | ||
| constructor:(@request,@response,@_m)-> | ||
| [h,c]=[{},(@request.headers.cookie||'').split /\s*;\s*/];c.map((p)->q=p.split '=';h[duc q[0]]=duc q[1]);A.cipher().decrypt h.session||'',(x,j)=> | ||
| delete h.session;@params={splat:[]};@cookies=h;@session=(if x then{}else J.parse(j));@_u=url.parse(@request.url,true);@_h='Set-Cookie':[];e @,A.h;@_b=A.r.filter((r)=>r[0]==@_m&&r[2].test @_u.pathname)[0] | ||
| @_c if @_b then[@_a,d]=[[],@_u.pathname.match @_b[2]];(v=duc d[i+1];@_a.push v;if k=='*' then @params.splat.push v else @params[k]=v)for k,i in @_b[1];e @params,(if /\bapplication\/x-www-form-urlencoded\b/.test @request.headers['content-type']then qs.parse @request.body else @_u.query) | ||
| _x:(c)->@_c= =>p=@_u.pathname;if p.split('/').indexOf('..')>=0 then @response.writeHead 400,{};@response.end() else async.series A.b.filter((f)=>p.substr(0,f.c.length)==f.c).map((f)=> =>f.apply @,arguments).concat =>if @_b then c.call @,(=>@_b[3].apply @,@_a)else fs.readFile (A.public||'./public')+p,(x,f)=>if x then @response.writeHead 404,{};@response.end()else @response.writeHead 200,'Content-Length':f.length,'Content-Type':mime.lookup(p)+'; charset=utf-8';@response.end f | ||
| render:(s)->s=(if s==undefined then ''else String s);A.cipher().encrypt J.stringify(@session),(x,j)=>h={};e h,'Set-Cookie':['session=' + euc(j) + '; Path=/; HttpOnly'],'Content-Type':'text/html; charset=utf-8','Content-Length':new Buffer(s,'utf8').length if s;e h,@_h;@response.writeHead @_s||200,h;@response.end s | ||
| cookie:(c)->(v=if typeof v=='string'then value:v else v;s=euc(k)+'='+euc(v.value)+'; Path='+v.path||'/';s+='; Domain='+v.domain if v.domain;s+='; Expires='+v.expires.toGMTString() if v.expires;s+='; HttpOnly' if v.http;s+='; Secure' if v.secure;e @_h,'Set-Cookie':s)for k,v of c | ||
| e A.prototype,headers:((o)->e @_h,o),status:((n)->@_s=parseInt n,10),redirect:((u,s=303)->@status s;@headers 'Location':u;@render()),haml:((n)->A.v 'haml',n,(x,t)=>@render haml(t) @),ejs:((n,o)->A.v 'ejs',n,(x,t)=>@render ejs.render t,e o?.locals||{},A.h),puts:(s)->console.log s | ||
| e A,r:[],c:[''],context:((p,f)->@c.push n p;f @;@c.pop()),b:[],before:((b)->[email protected] '';@b.push b),h:{},helpers:((o)->e @h,o),t:{},template:((n,t)->@t[n]=t),v:((t,n,c)->if f=@t[n+'.'+t]then c null,f else fs.readFile (@views||'./views')+'/'+n+'.'+t,(x,f)->c null,f.toString()),run:((q)->http.createServer(@call).on('upgrade',@ws).listen q||4567),cipher:->new E(@session_secret) | ||
| w 'get post put delete patch head options websocket eventsource',(v)->A[v]=(p,f)->p=n(@c.join('')+n p);o=(p.match(/[\/\.](\*|:[a-z\_\$][a-z0-9\_\$]*)/g)||[]).map((s)->s.replace /^[^a-z0-9\_\$\*]*/,'');m=new RegExp('^'+p.replace(/([\/\.])/g,'\\$1').replace(/\*|:[a-z\_\$][a-z0-9\_\$]*/ig,'(.+?)')+'$');@r.push [v.toUpperCase(),o,m,f] | ||
| A.call=(req,res)->req.setEncoding 'utf8';b='';req.on('data',(s)->b+=s);req.on 'end',->req.body=b;ES=WS.EventSource;k=ES.isEventSource req;a=new A(req,res,if k then 'EVENTSOURCE' else req.method);if k then(a._x (h)->s=a.socket=new ES req,res;h();s.addEventListener 'close',->s=null)else(a._x (h)->r=h();if typeof r=='string'then @render r) | ||
| A.ws=(r,s,h)->a=new A(r,s,'WEBSOCKET');a._x (H)->w=a.socket=new WS r,s,h;H();w.addEventListener 'close',->w=null | ||
| module.exports=A | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| app = require '../berliner' | ||
|
|
||
| app.public = __dirname + '/public' | ||
| app.views = __dirname + '/views' | ||
| app.session_secret = 'abc123' | ||
|
|
||
| app.helpers | ||
| inc_counter: -> | ||
| @session.counter ||= 0 | ||
| @session.counter += 1 | ||
|
|
||
| site_name: -> | ||
| 'Awesome.net' | ||
|
|
||
| app.before (next) -> | ||
| @puts @request.method + ' ' + @request.url | ||
| next() | ||
|
|
||
| app.get '/', -> | ||
| @cookie message: {value: 'Sinatra; it’s a framework', path: '/hello'} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no. |
||
| @title = 'Almost Sinatra' | ||
| @haml 'index' | ||
|
|
||
| app.get 'hello', -> | ||
| @ejs 'hello', locals: {name: @params.name, message: @cookies.message} | ||
|
|
||
| app.get '/counter', -> | ||
| @inc_counter() | ||
| @render @session.counter | ||
|
|
||
| app.context '/auth', (auth) -> | ||
| auth.before (next) -> | ||
| if @request.headers.authorization | ||
| next() | ||
| else | ||
| @status 401 | ||
| @render 'Authorization required' | ||
|
|
||
| auth.get '/', -> | ||
| 'Secret stuff' | ||
|
|
||
| auth.delete 'info', -> | ||
| @status 418 | ||
| 'I am a teapot' | ||
|
|
||
| app.get '/words/:category/:id.:format', -> | ||
| JSON.stringify @params | ||
|
|
||
| app.get '/download/*.*', -> | ||
| @params.splat.join ', ' | ||
|
|
||
| app.put '/download/*.*', (path, ext) -> | ||
| [path, ext].join ' // ' | ||
|
|
||
| app.post '/', -> | ||
| @status 201 | ||
| @headers 'Content-Type': 'application/json' | ||
| JSON.stringify @params | ||
|
|
||
| app.get '/legacy', -> | ||
| @redirect '/hello' | ||
|
|
||
| app.options '/', -> | ||
| @headers 'Access-Control-Allow-Methods': 'GET, PUT, DELETE' | ||
| @render '' | ||
|
|
||
| app.websocket '/ws/:name', -> | ||
| @socket.onmessage = (e)=> | ||
| @socket.send @params.name + ': ' + e.data | ||
|
|
||
| app.eventsource '/ws/:name', -> | ||
| setInterval (=> @socket.send @params.name + ': PUSH!'), 5000 | ||
|
|
||
| app.template 'hello.ejs', """ | ||
| Hello <%= name %>, welcome to <%= site_name() %>! Cookie: “<%= message %>” | ||
| """ | ||
|
|
||
| app.run 4567 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| var write = function(data) { | ||
| var log = document.getElementById('log'), | ||
| li = document.createElement('li'); | ||
|
|
||
| li.innerHTML = data; | ||
| log.appendChild(li); | ||
| }; | ||
|
|
||
| var ws = new WebSocket('ws://localhost:4567/ws/awesome'); | ||
| ws.onmessage = function(e) { | ||
| write(e.data); | ||
| setTimeout(function() { ws.send('Loop') }, 2000) | ||
| }; | ||
| ws.onopen = function() { ws.send('Ping!') }; | ||
|
|
||
| var es = new EventSource('http://localhost:4567/ws/eurucamp'); | ||
| es.onmessage = function(e) { | ||
| write(e.data); | ||
| }; | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| %html | ||
| %head | ||
| %title= title | ||
| %body | ||
| %p= site_name() | ||
| %a{href: '/hello?name=World'} Say hello! | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I refuse. |
||
| %a{href: '/counter'} Show Counter | ||
| %ul{id: 'log'} | ||
| %script{src: '/socket.js'} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this line to make it merge cleanly