简体   繁体   English

我希望能够通过单击超链接来加载/编辑 handlebars.js 模板(快速服务器),有什么建议吗?

[英]I would like to be able to load/edit handlebars.js templates ( express server ) by clicking on a hyperlink , any suggestions?

One of the most time-consuming portions of development on a handlebars.js app is finding the location of the template/partial that is being used for that specific piece of HTML.在 handlebars.js 应用程序开发中最耗时的部分之一是找到用于该特定 HTML 片段的模板/部分的位置。 Is there is a way to create a hyperlink on a localhost server to be able to click and open the template without having to manually search for text etc?有没有办法在本地主机服务器上创建超链接,以便能够单击并打开模板而无需手动搜索文本等?

This would also help other users editing the code as it would simplify traceability.这也将有助于其他用户编辑代码,因为它会简化可追溯性。

There could be scope for an npm module or similar to do this, just not sure the exact approach.可能有一个 npm 模块或类似的模块可以做到这一点,只是不确定确切的方法。

Likely due to the sublime / browser interface, it should perhaps be a chrome extension.可能由于 sublime / 浏览器界面,它可能应该是一个 chrome 扩展。 The other option would be to have an admin user-level interface, that allowed code editing from a modal.另一种选择是拥有一个管理员用户级界面,允许从模式编辑代码。

Please let me know if you have a solution for this, or if there is some kind of glaringly obvious simple approach that I am missing?请让我知道您是否有解决方案,或者我是否缺少某种明显明显的简单方法?

So I have managed to implement a workaround for this using Grunt.所以我已经设法使用 Grunt 实现了一个解决方法。

Basically, it adds a button in the HTML page that can be clicked in the browser that opens that handlebars template in sublime for editing.基本上,它在 HTML 页面中添加了一个按钮,可以在浏览器中单击该按钮,以在 sublime 中打开该把手模板进行编辑。 Local当地的

Express特快列车

exports.editfile = function(req, res,next) {
var filename = req.query['filename']
const { exec, spawn } = require('child_process');
exec('grunt editfile --filename='+filename, (err, stdout, stderr) => {
  if (err) {
    console.error(err);
    return;
  }
  console.log(stdout);
});
res.send('complete');
};

Grunt咕噜声

//In the grunt init
  shell: {  
    'openfile':openFile(),
    }
    grunt.loadNpmTasks('grunt-shell');
function openFile(){
    var openString = ''
    var fileName = grunt.option('filename'); //get value of target, my_module
    openString = {
        command: [
        'cd..','cd..','cd..','cd '+process.env.ROOTFOLDER,
        'sublime_text.exe "'+fileName+'"',
        ].join('&&')
    }
    return openString
}

grunt.registerTask('editfile',[
    'shell:openfile'
    ]);

Handlebars车把

<a class="btn btn-outline-warning bt-sm adminedit" style="" data-filename="{{filename}}" id="{{uniqueid}}" onclick="editFile(this.id)" href="#" class="text-warning">edit</a>
<script type="text/javascript">
function editFile(iditem){
  var editFilename = $('#'+iditem).attr("data-filename")
  $.ajax({
    url     : '/semini/admin/editfile/?filename='+editFilename,
    success : function( data ) {
      console.log('executing  : ',data)
    },
    error   : function( xhr, err ) {
      alert('Error',err);     
    }
  });   
}
</script>

Note, to get sublime to open from the CMD, you have to add an environment variable in windows.请注意,要从 CMD 打开 sublime,您必须在 windows 中添加一个环境变量。 Not too difficult, just google.难度不大,google一下。

It works great ..... but I cannot get a partial on handlebars to provide its name, and as such this only works for the first rendered page and not partials.它工作得很好......但我无法在车把上使用部分来提供它的名称,因此这仅适用于第一个呈现的页面而不适用于部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM