Skip to content
This repository was archived by the owner on Sep 13, 2023. It is now read-only.

Commit b2bcf7c

Browse files
Merge pull request #21 from abelljs/next
Abell Renderer v0.2.0, Abell v0.4.0
2 parents 9b2b0be + d15b853 commit b2bcf7c

24 files changed

Lines changed: 816 additions & 142 deletions

.github/workflows/nodejs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ name: Unit Tests and ESLint
55

66
on:
77
push:
8-
branches: [main]
8+
branches: [main, next]
99
pull_request:
10-
branches: [main]
10+
branches: [main, next]
1111

1212
jobs:
1313
test:
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
matrix:
1818
node-version: [10.x, 12.x]
19-
os: ['windows-latest', 'ubuntu-latest']
19+
os: ['windows-latest', 'ubuntu-latest', 'macos-latest']
2020

2121
steps:
2222
- uses: actions/checkout@v2

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## v0.2.0
4+
5+
- Default value of props in components is now empty object instead of undefined.
6+
- Multi-line support for writing component tag.
7+
- Convert Array into String by joining the values.
8+
- Now devs would not have to write `.join` next to map, to remove commas.
9+
- Naming rule of having `.component.abell` extension, removed. Any file that ends with `.abell`, can be a component.
10+
- Filename and error line in error stack 🎉
11+
- Error when brackets and value had no space, fixed (e.g. `{{a}}`)
12+
- Nested Components
13+
- Better Error logs
14+
- Support for Abell Components when `allowComponents` flag is passed in options. (Does not support nested components yet)
15+
316
## v0.1.12
417

518
- Throw error at `execute` to avoid having vm data in error stack

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
```sh
1010
git clone https://github.com/<your-github-username>/abell-renderer
1111
cd abell-renderer
12-
npm run example main # to run example `main` from `examples/main
12+
npm run example main # to run example `main` from `examples/main`
1313
```
1414

1515
## Running Examples

bin/abell-renderer.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,22 @@ const recursiveFind = (base, ext, inputFiles, inputResult) => {
3131
return result;
3232
};
3333

34-
const createPathIfAbsent = (pathToCreate) => {
35-
if (!fs.existsSync(pathToCreate)) {
36-
fs.mkdirSync(pathToCreate);
37-
}
38-
};
34+
/**
35+
* Recursively creates the path
36+
* @param {String} pathToCreate path that you want to create
37+
*/
38+
function createPathIfAbsent(pathToCreate) {
39+
// prettier-ignore
40+
pathToCreate
41+
.split(path.sep)
42+
.reduce((prevPath, folder) => {
43+
const currentPath = path.join(prevPath, folder, path.sep);
44+
if (!fs.existsSync(currentPath)) {
45+
fs.mkdirSync(currentPath);
46+
}
47+
return currentPath;
48+
}, '');
49+
}
3950

4051
/**
4152
* @method generateHTMLFromAbell

examples/main/in.abell

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@
3636
</div>
3737
Empty bracets check:
3838
<div>{{ }}</div>
39+
40+
{{ [1, 2, 3, 67] }}
3941
</body>
4042
</html>

examples/run.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
const fs = require('fs');
1515
const path = require('path');
1616
const abellRenderer = require('../src/index.js');
17+
const { exec } = require('child_process');
1718

1819
const args = process.argv.slice(2);
1920
const exampleToRun = args[0];
@@ -25,6 +26,21 @@ if (exampleToRun === 'cli-example') {
2526
throw new Error('Use npm run example:cli to run CLI example');
2627
}
2728

29+
/**
30+
* if example has index.js, then execute index.js instead of this file.
31+
*/
32+
if (fs.existsSync(path.join(__dirname, exampleToRun, 'index.js'))) {
33+
console.log(
34+
`>> Found index.js in the examples/${exampleToRun}, running index.js`
35+
);
36+
37+
exec(`node examples/${exampleToRun}/index.js`, (err, stdout, stderr) => {
38+
console.log(stdout);
39+
console.log(stderr);
40+
});
41+
return;
42+
}
43+
2844
console.log('>> Running ' + exampleToRun);
2945

3046
// Sandox holds parameters values are used in abell file
@@ -38,7 +54,11 @@ const htmlTemplate = abellRenderer.render(
3854
sandbox,
3955
{
4056
basePath: path.join(__dirname, exampleToRun),
41-
allowRequire: true
57+
allowRequire: true,
58+
filename: path.relative(
59+
process.cwd(),
60+
path.join(__dirname, exampleToRun, 'in.abell')
61+
)
4262
}
4363
);
4464

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<AbellComponent>
2+
<template>
3+
<footer data-test="footer-component"> This is my Footer {{ props.foo }}</footer>
4+
</template>
5+
<style inlined>
6+
nav {
7+
color: #f30;
8+
}
9+
</style>
10+
<script>
11+
document.querySelector('nav').innerHTML = 'This is from JS';
12+
</script>
13+
</AbellComponent>

examples/with-components/Nav.abell

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<AbellComponent>
2+
{{
3+
const Footer = require('./Footer.abell');
4+
}}
5+
<template>
6+
<nav data-test="nav-component"> This is my Navbar {{ props.num + props.num2 }} </nav>
7+
<Footer props={ hello: 'hehehe', foo: 'hello' } />
8+
</template>
9+
<style>
10+
nav {
11+
color: #f30;
12+
}
13+
</style>
14+
<script>
15+
document.querySelector('nav').innerHTML = 'This is from JS';
16+
</script>
17+
</AbellComponent>

examples/with-components/in.abell

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{
2+
const Nav = require('./Nav.abell');
3+
}}
4+
{{ const a = 3 }}
5+
<body>
6+
<Nav
7+
props={
8+
num: 10,
9+
num2: a
10+
}
11+
/>
12+
<main data-test="main-content">Content</main>
13+
</body>

examples/with-components/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const abellRenderer = require('../../src/index.js');
5+
6+
const abellTemplate = fs.readFileSync(
7+
path.join(__dirname, 'in.abell'),
8+
'utf-8'
9+
);
10+
11+
const { html, components } = abellRenderer.render(
12+
abellTemplate,
13+
{
14+
foo: 'Hehhe'
15+
},
16+
{
17+
allowRequire: true,
18+
allowComponents: true,
19+
basePath: __dirname
20+
}
21+
);
22+
23+
console.log(components);
24+
25+
fs.writeFileSync(path.join(__dirname, 'out.html'), html);

0 commit comments

Comments
 (0)