【问题标题】:Can gulp receive a string as input instead of file?gulp 可以接收字符串作为输入而不是文件吗?
【发布时间】:2017-03-01 20:13:21
【问题描述】:

我从 Python 生成 html 字符串,它们是 Foundation for Email 的输入。 (我的 Python 函数采用 Foundation for Email 模板并用每个用户的用户数据填充它)。

我的节点服务器应该接收这个 html 字符串,并且对于它们中的每一个,使用运行 gulpFoundation for Email 编译它以获取指定目录中的文件,并为它们中的每一个生成一个内联和缩小的 html 文件。

我的 Python 服务器应该通过读取文件或通过 api 调用接收此 html,并发送电子邮件。

我正在考虑将 html 传递给 Foundation for Email(运行 gulp)并将其输出传回 Python 服务器的最佳方法。

我在考虑是否应该通过 API 调用将 html 字符串传递给 Node 服务器,并通过对 Python 服务器的 API 调用将输出从 Node 服务器传递到 Python,但我不确定这是否可行或推荐gulp.

我可以这样做吗?这是一个好方法吗?或者我应该在指定路径中创建html文件,编译文件,然后使用输出文件发送电子邮件?

【问题讨论】:

    标签: node.js email gulp zurb-foundation


    【解决方案1】:

    您可以使用 gulp-file 模块 (https://github.com/alexmingoia/gulp-file) - 这允许您从可以像往常一样通过管道传输的字符串/缓冲区制作乙烯基文件流(就像 gulp.src 所做的那样)。


    示例代码

    var gulp = require('gulp');
    var file = require('gulp-file')
    
    gulp.task('test', function() {
        return file([{
            name: 'sample.txt',
            source: 'Hello Mars'  
        }, {
            name: 'sample1.txt',
            source: 'Hello World'  
        }], { src: true })
            .pipe(gulp.dest('output'))
    });
    

    【讨论】:

      猜你喜欢
      • 2020-01-10
      • 2011-01-20
      • 2021-09-24
      • 2015-08-15
      • 1970-01-01
      • 2012-01-16
      • 1970-01-01
      • 2011-02-21
      • 2017-10-18
      相关资源
      最近更新 更多