Skip to content
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

WIP: thymeleaf java implementation & draft for config. renderers/processors #53

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions example/aiur.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ exports.vendor = {
scripts: []
};

exports.renderers = {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add languages like this?
with option to add configuration

with / without configuration:

exports.renderers = {
    handlebars: require("aiur-renderer-handlebars"),
    lymetheaf: [
        require("..."),
        { ... config}
    ]
}

lymetheaf: [
require("lymetheaf"),
{
prefix: __dirname
}
]
}

exports.pages = {
"": {
file: "./components/welcome.md",
Expand Down
3 changes: 3 additions & 0 deletions example/components/thing/ding.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="thing" th:text="'Lymetheaf ON'">Lymetheaf OFF</div>
<div th:text="${message}">no message</div>
<div th:replace="components/thing/thing.html :: thing"></div>
6 changes: 6 additions & 0 deletions example/components/thing/thing.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ This uses data
```thymeleaf
<div th:text="${message}">No message.</div>
```

Use the JAVA implementation "Lymetheaf"

```lymetheaf
components/thing/ding.html
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, only FileTemplateResolver implemented - for reasons

```
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scripts": {
"start": "aiur --watch --liveserve",
"start": "aiur --watch --liveserve 3000",
"compile": "aiur --fingerprint --compact"
},
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions lib/highlight_snippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ let loadLanguages = require("prismjs/components/");
module.exports = function(snippet, language) {
// (temporary) patches for missing languages
Prism.languages.thymeleaf = Prism.languages.html;
Prism.languages.lymetheaf = Prism.languages.html;

if(!Prism.languages[language]) {
loadLanguages([language]);
Expand Down
6 changes: 4 additions & 2 deletions lib/page_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ let { Parser } = require("commonmark");
let HtmlRenderer = require("./html_renderer");

module.exports = class PageRenderer {
constructor({ renderers, layout }) {
constructor({ renderers, renderersConfigs, layout }) {
this.reader = new Parser();
this.writer = new HtmlRenderer();
this.renderers = renderers;
this.renderersConfigs = renderersConfigs;
this.layout = layout;
this.snippets = [];
}
Expand All @@ -25,10 +26,11 @@ module.exports = class PageRenderer {

async renderSnippet({ page, slug, language, snippet }) {
let renderer = this.renderers[language];
let rendererConfig = this.renderersConfigs[language];
if(!renderer) {
throw new Error(`Styleguide ran across unknown language ${language} (renderer)`);
}
let html = await renderer(snippet, page.data);
let html = await renderer(snippet, page.data, rendererConfig);
return { html, page, slug };
}

Expand Down
18 changes: 16 additions & 2 deletions lib/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,24 @@ module.exports = class Site {
baseURI: baseURI,
// TODO: either make this configurable or autoload renderers on use
renderers: DEFAULTS.renderers,
renderersConfigs: {},
// TODO: make this configurable, but first find a simpler contract
generateLayout: DEFAULTS.generateLayout,
assetManager
});

let moreRenderers = require(this.source).renderers || {};
Object.keys(moreRenderers).forEach(rendererName => {
let thatNewRenderer = moreRenderers[rendererName]
if (Array.isArray(thatNewRenderer)) {
let [renderer, rendererConfig] = thatNewRenderer;
this.renderers[rendererName] = renderer;
this.renderersConfigs[rendererName] = rendererConfig
} else {
this.renderers[rendererName] = thatNewRenderer;
}
});

this.dirs = new Set();
}

Expand All @@ -51,7 +65,7 @@ module.exports = class Site {
await mkdirp(this.target);
}

let { renderers, generateLayout } = this;
let { renderers, renderersConfigs, generateLayout } = this;

let preperations = tree.map(async page => {
let filepath = path.resolve(this.target, page.slug);
Expand All @@ -70,7 +84,7 @@ module.exports = class Site {

let navigation = new Navigation({ baseURI: this.baseURI });
let layout = await generateLayout(navigation.generate(tree), this.assetManager.manifest);
let pageRenderer = new PageRenderer({ renderers, layout });
let pageRenderer = new PageRenderer({ renderers, renderersConfigs, layout });

let writes = tree.map(async page => {
let html = await pageRenderer.render(page);
Expand Down
23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,29 @@
"node": ">=8"
},
"dependencies": {
"commonmark": "^0.29.0",
"commonmark": "^0.29.1",
"complate-stream": "^0.16.9",
"donny": "^0.1.0",
"faucet-pipeline-core": "^1.3.1",
"faucet-pipeline-js": "^2.0.8",
"faucet-pipeline-jsx": "^2.0.8",
"faucet-pipeline-sass": "^1.3.0",
"faucet-pipeline-core": "^1.3.2",
"faucet-pipeline-js": "^2.0.10",
"faucet-pipeline-jsx": "^2.0.10",
"faucet-pipeline-sass": "^1.3.1",
"faucet-pipeline-static": "^1.1.0",
"handlebars": "^4.4.3",
"handlebars": "^4.7.3",
"live-server": "^1.2.1",
"metacolon": "^1.0.0",
"metacolon": "^1.1.0",
"minimist": "^1.2.0",
"mkdirp": "^0.5.1",
"parse5": "^5.1.0",
"prismjs": "^1.17.1",
"parse5": "^5.1.1",
"prismjs": "^1.19.0",
"require-from-string": "^2.0.2",
"thymeleaf": "^0.18.0"
"thymeleaf": "^0.18.1",
"lymetheaf": "git+https://github.com/blynx/aiur-processor-lymetheaf.git"
},
"devDependencies": {
"eslint-config-fnd": "^1.8.0",
"mocha": "^6.2.2",
"release-util-fnd": "^1.1.1",
"rimraf": "^3.0.0"
"rimraf": "^3.0.2"
}
}