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. 1611
      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
Scheme XML loader for webpack. 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 Usage
----- -----
_See the full example in the [example](example) directory._ _See the full example in the [example](example) directory._
@ -32,29 +36,16 @@ module.exports = {
} }
``` ```
By default SXML will be processed by _Chicken Scheme_ Options
with _sxml-serializer_ egg. You can use a different interpreter -------
by setting the loader options. ```
| Option | Description |
GNU Guile example: | ======= | ============================================================= |
```js | doctype | The document type at the top of the markup. `html` by default |
// ... | ------- | ------------------------------------------------------------- |
use: [ | expr | A Scheme expression that processes your markup. |
'html-loader', | | Insert `SXML_LOADER_CONTENT` where you want to process |
{ | | the markup list. |
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)',
},
},
],
// ...
``` ```
License License

1611
example/package-lock.json generated

File diff suppressed because it is too large Load Diff

3
example/package.json

@ -12,6 +12,7 @@
"devDependencies": { "devDependencies": {
"html-loader": "^4.2.0", "html-loader": "^4.2.0",
"html-webpack-plugin": "^5.5.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 @@
'(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 @@
(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 @@
(h2 "List rendering") (h2 "List rendering")
,(map ,(map
(lambda (num) `(article "Article " ,num)) (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 = {
rules: [ rules: [
{ {
test: /\.sxml$/, test: /\.sxml$/,
use: [ use: ['html-loader', 'sxml-loader'],
'html-loader',
{
loader: 'sxml-loader',
/*
options: {
interpreter: 'guile',
flags: ['-c'],
expr: '(use-modules (sxml simple))(sxml->xml SXML_LOADER_CONTENT)',
},
*/
},
],
}, },
], ],
}, },
resolveLoader: { resolveLoader: {
alias: { alias: {
'sxml-loader': path.resolve(__dirname, '../src/loader.js'), 'sxml-loader': path.resolve(__dirname, '../loader.js'),
}, },
}, },
plugins: [ plugins: [

27
src/loader.js → loader.js

@ -6,17 +6,9 @@ const { validate } = require('schema-utils');
const schema = { const schema = {
type: 'object', type: 'object',
properties: { properties: {
interpreter: {
type: 'string',
default: 'chicken-csi',
},
flags: {
type: 'array',
default: ['-e'],
},
expr: { expr: {
type: 'string', type: 'string',
default: '(import sxml-serializer)(display (serialize-sxml SXML_LOADER_CONTENT))', default: '(use-modules (sxml simple))(sxml->xml SXML_LOADER_CONTENT)',
}, },
doctype: { doctype: {
type: 'string', type: 'string',
@ -32,26 +24,17 @@ module.exports = function(content, map, meta) {
baseDataPath: 'options', baseDataPath: 'options',
}); });
let interpreter = schema.properties.interpreter.default; let doctype = schema.properties.doctype.default;
if (options.interpreter) if (options.doctype)
interpreter = options.interpreter; doctype = options.doctype;
let flags = schema.properties.flags.default;
if (options.flags)
flags = options.flags;
let expr = schema.properties.expr.default; let expr = schema.properties.expr.default;
if (options.expr) if (options.expr)
expr = options.expr; expr = options.expr;
expr = expr.replace('SXML_LOADER_CONTENT', content); 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(); const cb = this.async();
runScheme(interpreter, flags).then(data => { runScheme('guile', ['-c', expr]).then(data => {
cb(null, `${doctype}\n${data}`, map, meta); cb(null, `${doctype}\n${data}`, map, meta);
}).catch(err => { }).catch(err => {
console.error(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 @@
{ {
"name": "sxml-loader", "name": "sxml-loader",
"version": "0.2.1", "version": "0.3.0",
"description": "Scheme XML loader for webpack", "description": "Scheme XML loader for webpack",
"main": "src/loader.js", "main": "loader.js",
"bugs": "http://git.vilor.one/vilor/sxml-loader/issues", "bugs": "http://git.vilor.one/vilor/sxml-loader/issues",
"homepage": "http://git.vilor.one/vilor/sxml-loader", "homepage": "http://git.vilor.one/vilor/sxml-loader",
"repository": { "repository": {

Loading…
Cancel
Save