Update example for Imba 1.3

This commit is contained in:
Sindre Aarsaether 2018-02-09 15:58:42 +01:00
parent 6b567a6160
commit 3a957df975
10 changed files with 171 additions and 44 deletions

6
.gitignore vendored
View File

@ -1,6 +1,8 @@
# Logs
logs
*.log
.DS_Store
dist/client.js
# Runtime data
pids
@ -24,6 +26,4 @@ build/Release
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
bundle.js
node_modules

View File

@ -1,14 +1,12 @@
# hello-world-imba
Tiny template for testing out Imba in the browser.
Tiny template for testing out Imba
## Getting started
```bash
git clone https://github.com/somebee/hello-world-imba.git
cd hello-world-imba
# install dependencies
npm install
npm run watch
# start webpack-dev-server and compiler
npm run dev
```
Open `index.html` in your browser (you should not need a webserver).

94
dist/index.css vendored Normal file
View File

@ -0,0 +1,94 @@
html,body {
width: 100%;
height: 100%;
margin: 0px;
font-family: Arial;
}
body {
display: flex;
font-size: 14px;
align-items: stretch;
justify-content: center;
flex-direction: column;
background: whitesmoke;
padding: 30px;
}
:focus { outline: none !important; }
.App {
background: white;
}
.vbox {
display: flex;
flex-direction: column;
justify-content: center;
align-items: stretch;
}
body,div,form,header,footer,section,input,button,nav,aside,article {
box-sizing: border-box;
}
div,section,input,ul,main,article,.grow {
flex: 1 1 auto;
}
input {
display: block;
padding: 0px 12px;
background: transparent;
border: none;
font-size: inherit;
width: 50px;
height: 24px;
}
button {
-webkit-appearance: none;
background: #4a95eb;
font-size: 13px;
display: flex;
align-items: center;
justify-content: center;
border: 0px;
padding: 2px 10px;
border-radius: 2px;
color: white;
margin: 0px 4px;
flex: 0 0 auto;
height: 24px;
}
button:hover {
background: #3a8eef;
}
header,footer {
flex: 0 0 auto;
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
padding: 10px 6px;
background: #e8e8e8;
}
ul {
list-style: none inside none;
margin: 0;
padding: 0;
padding: 10px;
}
li {
padding: 8px 12px;
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
border-bottom: 1px solid whitesmoke;
}

View File

@ -3,9 +3,9 @@
<head>
<title>Hello World</title>
<meta charset="utf-8">
<link rel="stylesheet" href="index.css" media="screen">
</head>
<body>
<!-- include your compiled bundle -->
<script src="bundle.js"></script>
<script src="client.js"></script>
</body>
</html>

View File

@ -1,12 +0,0 @@
tag HelloWorld
def render
<self>
<header>
<h1> "Hello World"
<section>
<footer>
# mount an instance of HelloWorld in root
Imba.mount <HelloWorld>

13
package-lock.json generated
View File

@ -1,13 +0,0 @@
{
"name": "hello-world-imba",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"imba": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/imba/-/imba-1.0.0.tgz",
"integrity": "sha512-qR8/5cfhMyLDpIKZce8kPdyYLTeFkEPPeAmFQtXxrfii87sOqpx7P5oGiTewKdnZ7s5oeU9aHTEFBV5ctsoIIA=="
}
}
}

View File

@ -8,11 +8,13 @@
"bugs": "https://github.com/somebee/hello-world-imba/issues",
"version": "1.0.0",
"engines": {
"node": ">=0.8.0"
"node": ">=6.0.0"
},
"scripts": {
"build": "imbapack",
"watch": "imbapack -w"
"start": "imba src/server.imba",
"dev": "webpack-dev-server --content-base dist/",
"build": "webpack",
"watch": "webpack --watch --progress --colors --display-modules"
},
"files": [],
"directories": {},
@ -23,6 +25,9 @@
},
"license": "MIT",
"dependencies": {
"imba": "^1.0.0"
"express": "^4.16.2",
"imba": "1.3.0-beta.6",
"webpack": "^3.10.0",
"webpack-dev-server": "^2.11.1"
}
}

24
src/client.imba Normal file
View File

@ -0,0 +1,24 @@
var store = {
title: ""
items: [
{title: "git clone hello-world-imba"}
{title: "npm install"}
{title: "npm run dev"}
{title: "play around"}
]
}
tag App
def addItem
data:items.push(title: data:title)
data:title = ""
Imba.mount <App[store].vbox ->
<header>
<input model='title' placeholder="New..." :keyup.enter.addItem>
<button :tap.addItem> 'Add item'
<ul> for item in data:items
<li> item:title

20
src/server.imba Normal file
View File

@ -0,0 +1,20 @@
var express = require 'express'
var server = express()
server.use(express.static('./dist'))
server.get '/' do |req,res|
var html = <html>
<head>
<title> "Imba - Hello World"
<meta charset="utf-8">
<link rel="stylesheet" href="/dist/index.css" media="screen">
<body>
<script src="/client.js">
return res.send html.toString
var port = process:env.PORT or 8080
var server = server.listen(port) do
console.log 'server is running on port ' + port

View File

@ -1,4 +1,15 @@
module.exports = [{
entry: "./index.imba",
output: { filename: "./bundle.js" }
}]
module.exports = {
module: {
rules: [
{
test: /.imba$/,
loader: 'imba/loader',
}
]
},
resolve: {
extensions: [".imba",".js", ".json"]
},
entry: "./src/client.imba",
output: { path: __dirname + '/dist', filename: "client.js" }
}