- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我在 Windows 10 上运行的 electron-forge 应用程序中,没有呈现 ejs 模板,尽管没有可见错误。
我可以使用创建的应用程序重现该问题
electron-forge init ejs-test
import { app, BrowserWindow } from 'electron'
import * as ejse from 'ejs-electron'
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require('electron-squirrel-startup')) { // eslint-disable-line global-require
app.quit()
}
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow
const createWindow = () => {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 800,
height: 600,
})
ejse.data('testdata', 'Generated throuh EJS')
// and load the index.html of the app.
mainWindow.loadFile(`${__dirname}/index.ejs`)
// Open the DevTools.
mainWindow.webContents.openDevTools()
// Emitted when the window is closed.
mainWindow.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null
})
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow()
}
})
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<%= testdata %>
</body>
</html>
protocol.interceptBufferProtocol('file', protocolListener)
最佳答案
这与 https://github.com/electron-userland/electron-forge/issues/291 的问题相同。 .
鉴于目前缺乏文档,升级到 electron-forge v6 太难了,所以我找到了一个解决方法。
我需要使用 ejs 的原因是为了根据多语言的消息文件动态生成我的 html 代码。我首先尝试动态生成它并将 loadURL 与 'data:text/html' 协议(protocol)一起使用。但是,这会产生很多问题,因为 html 与文件路径没有关联,因此任何引用都没有
因此,我转而在构建时为每种语言生成一个 html 文件,并在运行时根据语言选择要加载的文件。
所以两个步骤:
我在 package.json 中添加了以下内容:
"scripts": {
"build" : "node build.js"
},
const ejs = require('ejs')
const fs = require('fs')
let langs = ['en', 'fr']
langs.forEach((lang) => {
let msgdata = JSON.parse(fs.readFileSync(`${__dirname}/src/messages/${lang}.json`, 'utf8'))
ejs.renderFile(`${__dirname}/src/views/pages/mindmap.ejs`,
{
'messages': msgdata,
'otherlanguage': 'fr',
},
{},
(err, str) => {
fs.writeFileSync(`${__dirname}/src/mindmap-${lang}.html`, str, 'utf8')
})
})
const { app, BrowserWindow, ipcMain } = require('electron')
const ejs = require('ejs')
const fs = require('fs')
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require('electron-squirrel-startup')) { // eslint-disable-line global-require
app.quit()
}
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow
const createWindow = () => {
// Create the browser window.
mainWindow = new BrowserWindow()
// and load the index.html of the app.
mainWindow.loadURL(`file://${__dirname}/mindmap-${lang}.html`)
// Emitted when the window is closed.
mainWindow.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null
})
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow()
}
})
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and import them here.
ipcMain.on('request-messages', (event, arg) => {
mainWindow.webContents.send('messages', msgdata)
})
关于electron - ejs-electron 不能与 Electron 锻造一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52354893/
我正在尝试包含一个 ejs 文件,其中包含用于设置我的 View 的函数。这些函数被定义为使用助手。我试过使用: 但是当我尝试使用这个文件中的函数时: 我收到错误: Reference Error
所以我想将 ejs 模板预编译成 .js 文件 var compiled = ejs.compile(source); fs.writeFileSync(target, 'myTemplateFunc
作为一个真正的 EJS 初学者,我的 html 页面中有两个图表,所以我想使用我的部分两次: 但是我需要在 ejs 内部传递一些参数来区分图形。 什么是最好的方法? 最佳答案 @Naeem Shai
这是我的问题 - 它不可读 为了让 .ejs 正常工作,到目前为止我已经添加了以下内容。我也有格式保存和更漂亮。我正在寻找获得更好格式的建议,以便我可以阅读。 "files.associations"
为什么这不起作用: value="" /> 它抛出一个引用错误,说 givenName 未定义,它可能不是,并且是条件的原因。 最佳答案 抢你要查if (locals.givenName) v
我正在尝试使用@nestjs-modules/mailer nodemailer 在 Nestjs 框架中发送电子邮件。电子邮件在正常文本下工作正常,但是当设置为使用 EJS 模板作为电子邮件正文时,
我想实现一个功能。我的应用程序是用 AngularJS 和 NodeJS 制作的。我正在发送一封电子邮件,在该电子邮件中我有一个可以单击的按钮。 " styl
这是代码,请帮忙。提前致谢。 最佳答案 else之前的标签必须与前一个标签的结束标签配对。
我最近利用了来自 github 的 github student developer package 并下载了 Atom.io。到目前为止,我一直喜欢它的功能,主要是将 ejs 文件的语法突出显示为
我正在学习编写渐进式 Web 应用程序,所有示例都使用 html 文件。我更喜欢将 EJS 与节点服务器一起使用。是否可以缓存 ejs 以便可以在本地使用? 最佳答案 简短的回答:是的。 Servic
嗨,我刚刚开始使用 EJS。现在我需要检查条件,因此我在 EJS 中使用 if 条件,但在运行时显示错误。我正在尝试的代码是
您好 我如何将变量从一个EJS页面传递到另一个EJS页面。 例如,我有这个页面 // insertion.ejs //
我在节点上使用 EJS 作为我的 View 引擎并进行快速设置。我想使用 ejs-lint 来帮助获取错误行。我以前没有使用过 linter,但是通过阅读这里的文档:https://github.co
我正在创建类似 reddit 评论部分的内容,有人可以评论某些内容,人们也可以回复该评论。 我正在使用 Node、Express、MySQL、EJS。 问题:我不知道如何制作赞成/反对部分,我不知道如
这是我的想法:我想加载一个呈现的 ejs 文件作为我的主模板 ejs 文件的主体。可能吗? 我的 app.js: router.get('/', function(req, res) { res.
我们如何在模板中转义 ejs 标签本身? 在 sails 中,我想将以下代码放入layout.ejs 但默认情况下, 内的所有内容
文件 1:ejsfunction.ejs 文件 2:file.ejs 输出: ReferenceError: 1| >> 2| funcTest is not defined 嗨,
我是 Node.js/Express/EJS 的新手。 我最近注意到,当我将参数从 Express 请求处理程序传递到 EJS View 并省略参数名称时,它会根据变量名称创建一个名称。因此,例如,在
我尝试像这样用 ejs 渲染 html const ejs = require('ejs'), fs = require('fs'), str = fs.readFileSyn
这两个网站似乎都描述了一种非常相似的基于 Javascript 的模板语言,称为 EJS。但是: ejs.co 说 E 代表“有效”并且有一个活跃的存储库 on Github . Embeddedjs
我是一名优秀的程序员,十分优秀!