Last active
August 26, 2015 17:53
-
-
Save MadcapJake/f8eafa28cb7e0f83bb21 to your computer and use it in GitHub Desktop.
Earl Grey Mithril
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
require: | |
mithril as m | |
require-macros: | |
"./MithrilNode.eg" -> [%] | |
globals: document | |
class Todo: | |
constructor(data) = | |
@description = m.prop(data.description) | |
@done = m.prop(false) | |
TodoList = Array | |
myTask = Todo({description = "Write code"}) | |
class ViewModel: | |
constructor() = | |
;; a running list of todos | |
@list = new TodoList() | |
;; a slot to store the name of a new todo before it is created | |
@description = m.prop("") | |
;; adds a todo to the list, and clears the description field | |
add = description -> | |
if description(): | |
@list.push with Todo({= description}) | |
@description("") | |
vm = ViewModel() | |
vm.description("Write code") | |
vm.add(vm.description) | |
view = -> | |
html % | |
body % | |
input % | |
button % "Add" | |
table % | |
tr % | |
td % input % type = .checkbox | |
td % input % value = vm.description() | |
m.render(document, view()) |
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
<!doctype html> | |
<title>Todo app</title> | |
<script src="index.js" charset="utf-8"></script> |
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
require: mithril | |
provide: percent as [%] | |
MithrilNode = (tags, props, Array! children) -> | |
mithril(tags.join(""), props, children) | |
macro{MithrilNode} percent = #data{x, y} -> | |
let {=> MithrilNode} = @deps | |
`[^x % ^y] where ENode = [^MithrilNode] |
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
{ | |
"name": "athelas", | |
"version": "0.0.0", | |
"description": "MithrilJS in Earl Grey", | |
"main": "index", | |
"scripts": { | |
"start": "webpack-dev-server --content-base build/ --hot", | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "Jake Russo", | |
"license": "MIT", | |
"devDependencies": { | |
"earlgrey-loader": "^0.1.4", | |
"webpack": "^1.12.0", | |
"webpack-dev-server": "^1.10.1" | |
}, | |
"dependencies": { | |
"earlgrey": "0.0.11", | |
"mithril": "^0.2.0" | |
} | |
} |
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
. | |
├── build | |
│ └── index.html | |
├── node_modules | |
│ ├── earlgrey | |
│ ├── earlgrey-loader | |
│ ├── earlify | |
│ ├── mithril | |
│ ├── webpack | |
│ └── webpack-dev-server | |
├── package.json | |
├── src | |
│ ├── index.eg | |
│ └── MithrilNode.eg | |
└── webpack.config.js |
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
module.exports = { | |
entry: { | |
app: [ './src/index.eg' ] | |
}, | |
output: { | |
path: './build', | |
publicPath: '/assets/', | |
filename: 'bundle.js' | |
}, | |
module: { | |
loaders: [ | |
{ test: /\.eg/, loader: "earlgrey-loader?es5=true&sourceMaps=inline"} | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment