Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# "Hello world" example | ||
|
||
First install : | ||
|
||
npm install | ||
npm start | ||
|
||
Then launch `http://localhost:3000/` to test |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2015 Nicolas Lochet Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is | ||
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
var t = require('llama')() | ||
, main = require('./template.js')(t) | ||
, name = t.$(data) | ||
, page = main(name) | ||
, data = document.getElementById('data') | ||
|
||
//console.log(document.getElementsByTagName('html').item(0).id) | ||
|
||
page.render() | ||
page.listen(function(id, html) { | ||
console.log('id', id, html) | ||
document.getElementById(id).innerHTML = html | ||
}) | ||
|
||
function onevent() { | ||
console.log('event', data.value) | ||
name(data.value) | ||
history.pushState(null, null, '/'+data.value) | ||
} | ||
|
||
data.addEventListener('keyup', onevent) | ||
data.addEventListener('change', onevent) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"author": "Nicolas Lochet", | ||
"name": "LlamaHelloWorld", | ||
"description": "", | ||
"version": "0.0.1", | ||
"engines": { | ||
"node": "0.12.*" | ||
}, | ||
"scripts": { | ||
"start": "node server.js", | ||
"prod": "NODE_ENV=production node server.js", | ||
"watch": "nodemon server.js" | ||
}, | ||
"dependencies": { | ||
"browserify-middleware": "^6.0.0", | ||
"express": "^4.13.1", | ||
"llama": "^0.2.2", | ||
"morgan": "^1.6.1", | ||
"serve-favicon": "^2.3.0" | ||
}, | ||
"devDependencies": {}, | ||
"optionalDependencies": {} | ||
} |
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2015 Nicolas Lochet Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is | ||
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
var express = require('express') | ||
, app = express() | ||
, router = express.Router() | ||
, morgan = require('morgan') | ||
, browserify = require('browserify-middleware') | ||
, favicon = require('serve-favicon') | ||
, t = require('llama')() | ||
, main = require('./template.js')(t) | ||
, options = {startIds:0, indent: 2} | ||
|
||
app.use(favicon(__dirname + '/public/favicon.ico')) | ||
app.use(morgan('dev')) | ||
app.use(router) | ||
|
||
router.get('/client.js', browserify('./client.js')); | ||
|
||
router.get('/', function (req, res) { | ||
var name = t.$('World') | ||
res.send(main(name).render(options)) | ||
}) | ||
|
||
router.get('/:name', function (req, res) { | ||
var name = t.$(req.params.name) | ||
res.send(main(name).render(options)) | ||
}) | ||
|
||
app.listen(3000) | ||
console.log('Server is running.\nOpen http://localhost:3000/') |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2015 Nicolas Lochet Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is | ||
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
module.exports = function (t) { | ||
return function (name) { | ||
//console.log(name() instanceof t.LlamaVar) | ||
return t.html( | ||
t.head(t.title('Hello ', name(), '!')), | ||
t.body( | ||
t.h1('Hello ', name(), '!'), | ||
t.input({$:'data', value: name().val()}), | ||
t.script({src: "./client.js"},'') | ||
) | ||
) | ||
} | ||
} |