Skip to content

Commit

Permalink
bundle css with novella
Browse files Browse the repository at this point in the history
  • Loading branch information
robotlolita committed Feb 5, 2023
1 parent 2447578 commit a6a161c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
File renamed without changes.
8 changes: 7 additions & 1 deletion stdlib/crochet.novella/crochet.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,11 @@
"requires": [],
"provides": [],
"optional": []
}
},
"assets": [
{
"path": "assets/novella.css",
"mime": "text/css"
}
]
}
9 changes: 9 additions & 0 deletions stdlib/crochet.novella/native/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ export default (ffi: ForeignInterface) => {
return ffi.box(element);
});

ffi.defun("dom.make-css", (css0) => {
const css = ffi.text_to_string(css0);
const node = document.createElement("style");
node.setAttribute("type", "text/css");
node.setAttribute("media", "screen");
node.appendChild(document.createTextNode(css));
return ffi.box(node);
});

ffi.defun("dom.text", (text) => {
const node = document.createTextNode(ffi.text_to_string(text));
return ffi.box(node);
Expand Down
5 changes: 5 additions & 0 deletions stdlib/crochet.novella/source/rendering/dom/core.crochet
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ command nvl-web-renderer-config setup do
};
self.root add-class: "novella-root";
self.root append: Screen;

let Css = package assets at: "assets/novella.css" | read-as-text;
let Css-node = nvl-dom make-css: Css;
Screen append: Css-node;

let Renderer = new nvl-web-renderer(
config -> self,
screen -> Screen,
Expand Down
3 changes: 3 additions & 0 deletions stdlib/crochet.novella/source/rendering/dom/dom-api.crochet
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ singleton nvl-dom;
type nvl-dom-node(box is unknown);


command nvl-dom make-css: (Css is text) =
new nvl-dom-node(foreign dom.make-css(Css));

command nvl-dom make: (Tag is text) class: (Class is text) =
new nvl-dom-node(foreign dom.make(Tag, Class));

Expand Down

0 comments on commit a6a161c

Please sign in to comment.