javascript - loadhtml instead of loadUrl in electron scripts and links are not working -
i same thing in question, give data template, compile , made file
var file = 'data:text/html,' + encodeuricomponent(compiled);
all looks fine, template rendered , data, tags in head stop working, tags link or script src attribute
here doc in pouchdb id maz-63171 , give doc template:
db.get('maz-63171') .then(function(doc) { var compilefn = pug.compilefile('./pugtemplates/index.pug', { pretty: true }); var compiled = compilefn({doc: doc}); console.log(compiled); // console.log(doc); // 'file://' + __dirname + '/pugtemplates/index.pug' var file = 'data:text/html,' + encodeuricomponent(compiled); mainwindow.loadurl(file); }) .catch(function(err) { console.log(err); });
in index.pug have this
doctype html html(lang="en") head title="trucks" link(rel="stylesheet" href="../node_modules/semantic-ui/dist/semantic.min.css") //- script window.$ = window.jquery = require('jquery'); script(src="../node_modules/jquery/dist/jquery.min.js") script(src="../node_modules/semantic-ui/dist/semantic.min.js") body .ui.container .ui.grid .four.wide.column .eight.wide.column |#{doc._id} table.ui.celled.table thead tr th header th header th header tbody tr td .ui.ribbon.label first td cell td cell tr td cell td cell td cell tr td cell td cell td cell
which compiles this
<!doctype html> <html lang="en"> <head> <title>trucks</title> <link rel="stylesheet" href="../node_modules/semantic-ui/dist/semantic.min.css"> <script src="../node_modules/jquery/dist/jquery.min.js"></script> <script src="../node_modules/semantic-ui/dist/semantic.min.js"></script> </head> <body> <div class="ui container"> <div class="ui grid"> <div class="four wide column"></div> <div class="eight wide column">maz-63171</div> <table class="ui celled table"> <thead> <tr> <th>header</th> <th>header</th> <th>header</th> </tr> </thead> <tbody> <tr> <td> <div class="ui ribbon label">first</div> </td> <td>cell</td> <td>cell</td> </tr> <tr> <td>cell</td> <td>cell</td> <td>cell</td> </tr> <tr> <td>cell</td> <td>cell</td> <td>cell</td> </tr> </tbody> </table> </div> </div> </body> </html>
i 0 errors css or js files added, semantic-ui not working can see on screenshot
why happening , how fix it? think because conversion string, maybe should use other method compile templates.
electron-pug module npm seem not data locals, wait in promise , in time standard loadurl load pug template straight window without rendering it. maybe smth wrong.
Comments
Post a Comment