Browse Source

Merge pull request 'passing the doctype and updating the example' (#2) from dev into master

Reviewed-on: #2
master
vilor 2 years ago
parent
commit
97e6d7fa56
  1. 6
      README.md
  2. 12
      example/src/index.sxml
  3. 14
      example/webpack.config.js
  4. 2
      package.json
  5. 10
      src/loader.js

6
README.md

@ -45,9 +45,11 @@ use: [ @@ -45,9 +45,11 @@ use: [
loader: 'sxml-loader',
options: {
interpreter: 'guile',
flags: ['-c'], // "eval" flag (in Guile case "-c") should be last.
// SXML_LOADER_CONTENT will be replaced with processing SXML markup.
// 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)',
},
},

12
example/src/index.sxml

@ -1,5 +1,11 @@ @@ -1,5 +1,11 @@
'((html
`((html (@ (lang en))
(head
(title "Hello"))
(meta (@ (charset utf-8)))
(title "sxml-loader example"))
(body
(h1 "Hello World!"))))
(h1 "sxml-loader example")
(h2 "List rendering")
,(map
(lambda (num) `(article "Article " ,num))
'(1 2 3)))))

14
example/webpack.config.js

@ -6,7 +6,19 @@ module.exports = { @@ -6,7 +6,19 @@ module.exports = {
rules: [
{
test: /\.sxml$/,
use: ['html-loader', 'sxml-loader'],
use: [
'html-loader',
{
loader: 'sxml-loader',
/*
options: {
interpreter: 'guile',
flags: ['-c'],
expr: '(use-modules (sxml simple))(sxml->xml SXML_LOADER_CONTENT)',
},
*/
},
],
},
],
},

2
package.json

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

10
src/loader.js

@ -18,6 +18,10 @@ const schema = { @@ -18,6 +18,10 @@ const schema = {
type: 'string',
default: '(import sxml-serializer)(display (serialize-sxml SXML_LOADER_CONTENT))',
},
doctype: {
type: 'string',
default: '<!DOCTYPE html>',
},
},
};
@ -42,9 +46,13 @@ module.exports = function(content, map, meta) { @@ -42,9 +46,13 @@ module.exports = function(content, map, meta) {
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 => {
cb(null, data, map, meta);
cb(null, `${doctype}\n${data}`, map, meta);
}).catch(err => {
console.error(err);
});

Loading…
Cancel
Save