Browse Source

Merge pull request 'Switching to GNU Guile, loading data in the example' (#3) from dev into master

Reviewed-on: #3
master
vilor 2 years ago
parent
commit
071598e266
  1. 37
      README.md
  2. 1609
      example/package-lock.json
  3. 3
      example/package.json
  4. 10
      example/src/components/footer.sxml
  5. 6
      example/src/data/vars.scm
  6. 11
      example/src/index.sxml
  7. 16
      example/webpack.config.js
  8. 27
      loader.js
  9. 1347
      package-lock.json
  10. 4
      package.json

37
README.md

@ -12,6 +12,10 @@ sxml-loader @@ -12,6 +12,10 @@ sxml-loader
Scheme XML loader for webpack.
This loader uses _GNU Guile_ as the Scheme interpreter and its _SXML_ module.
How to work with it, see the
[official manual](https://www.gnu.org/software/guile/manual/html_node/SXML.html).
Usage
-----
_See the full example in the [example](example) directory._
@ -32,29 +36,16 @@ module.exports = { @@ -32,29 +36,16 @@ module.exports = {
}
```
By default SXML will be processed by _Chicken Scheme_
with _sxml-serializer_ egg. You can use a different interpreter
by setting the loader options.
GNU Guile example:
```js
// ...
use: [
'html-loader',
{
loader: 'sxml-loader',
options: {
interpreter: 'guile',
// The "eval" flag (in the case of Guile "-c") must come last.
flags: ['-c'],
// SXML_LOADER_CONTENT will be replaced with SXML markup.
expr: '(use-modules (sxml simple))(sxml->xml SXML_LOADER_CONTENT)',
},
},
],
// ...
Options
-------
```
| Option | Description |
| ======= | ============================================================= |
| doctype | The document type at the top of the markup. `html` by default |
| ------- | ------------------------------------------------------------- |
| expr | A Scheme expression that processes your markup. |
| | Insert `SXML_LOADER_CONTENT` where you want to process |
| | the markup list. |
```
License

1609
example/package-lock.json generated

File diff suppressed because it is too large Load Diff

3
example/package.json

@ -12,6 +12,7 @@ @@ -12,6 +12,7 @@
"devDependencies": {
"html-loader": "^4.2.0",
"html-webpack-plugin": "^5.5.0",
"webpack": "^5.74.0"
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
}
}

10
example/src/components/footer.sxml

@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
'(footer
(h3 Footer)
(nav
(ul
(li
(a (@ (href "https://www.npmjs.com/package/sxml-loader"))
npm))
(li
(a (@ (href "http://git.vilor.one/vilor/sxml-loader"))
"source code")))))

6
example/src/data/vars.scm

@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
(define some-global-var "hello world!")
;;; show the interpreter an empty list
;;; to prevent `<unspecified>` from being written to the markup.
'()

11
example/src/index.sxml

@ -8,4 +8,13 @@ @@ -8,4 +8,13 @@
(h2 "List rendering")
,(map
(lambda (num) `(article "Article " ,num))
'(1 2 3)))))
'(1 2 3))
(h2 "Global data")
,(load "./src/data/vars.scm")
(pre
("some-global-var: " ,some-global-var))
(h2 Components)
,(load "./src/components/footer.sxml"))))

16
example/webpack.config.js

@ -6,25 +6,13 @@ module.exports = { @@ -6,25 +6,13 @@ module.exports = {
rules: [
{
test: /\.sxml$/,
use: [
'html-loader',
{
loader: 'sxml-loader',
/*
options: {
interpreter: 'guile',
flags: ['-c'],
expr: '(use-modules (sxml simple))(sxml->xml SXML_LOADER_CONTENT)',
},
*/
},
],
use: ['html-loader', 'sxml-loader'],
},
],
},
resolveLoader: {
alias: {
'sxml-loader': path.resolve(__dirname, '../src/loader.js'),
'sxml-loader': path.resolve(__dirname, '../loader.js'),
},
},
plugins: [

27
src/loader.js → loader.js

@ -6,17 +6,9 @@ const { validate } = require('schema-utils'); @@ -6,17 +6,9 @@ const { validate } = require('schema-utils');
const schema = {
type: 'object',
properties: {
interpreter: {
type: 'string',
default: 'chicken-csi',
},
flags: {
type: 'array',
default: ['-e'],
},
expr: {
type: 'string',
default: '(import sxml-serializer)(display (serialize-sxml SXML_LOADER_CONTENT))',
default: '(use-modules (sxml simple))(sxml->xml SXML_LOADER_CONTENT)',
},
doctype: {
type: 'string',
@ -32,26 +24,17 @@ module.exports = function(content, map, meta) { @@ -32,26 +24,17 @@ module.exports = function(content, map, meta) {
baseDataPath: 'options',
});
let interpreter = schema.properties.interpreter.default;
if (options.interpreter)
interpreter = options.interpreter;
let flags = schema.properties.flags.default;
if (options.flags)
flags = options.flags;
let doctype = schema.properties.doctype.default;
if (options.doctype)
doctype = options.doctype;
let expr = schema.properties.expr.default;
if (options.expr)
expr = options.expr;
expr = expr.replace('SXML_LOADER_CONTENT', content);
flags.push(expr);
let doctype = schema.properties.doctype.default;
if (options.doctype)
doctype = options.doctype;
const cb = this.async();
runScheme(interpreter, flags).then(data => {
runScheme('guile', ['-c', expr]).then(data => {
cb(null, `${doctype}\n${data}`, map, meta);
}).catch(err => {
console.error(err);

1347
package-lock.json generated

File diff suppressed because it is too large Load Diff

4
package.json

@ -1,8 +1,8 @@ @@ -1,8 +1,8 @@
{
"name": "sxml-loader",
"version": "0.2.1",
"version": "0.3.0",
"description": "Scheme XML loader for webpack",
"main": "src/loader.js",
"main": "loader.js",
"bugs": "http://git.vilor.one/vilor/sxml-loader/issues",
"homepage": "http://git.vilor.one/vilor/sxml-loader",
"repository": {

Loading…
Cancel
Save