简体   繁体   English

将Middleman变量传递给grunt文件

[英]pass middleman variable to grunt file

My middleman template has an 'id' variable that I put my html emails job name into. 我的中间人模板有一个'id'变量,我将我的html电子邮件工作名称放入了该变量。

I know if I change my middleman erb file from index.html.erb to newName.html.erb it will output that as the final files name. 我知道如果将我的中间人erb文件从index.html.erb更改为newName.html.erb,它将输出该文件作为最终文件名。

My problem is that most of my grunt tasks require the file name I want them to run on (I've tried using *.html, but it only works for some tasks) and short of editing that in the grunt file prior to starting grunt up they won't execute if I change the erb file name. 我的问题是我的大多数grunt任务都需要我希望它们运行的​​文件名(我尝试过使用* .html,但仅适用于某些任务),而在启动grunt之前在grunt文件中没有进行编辑如果我更改erb文件名,它们将不会执行。

Is there a way to pass grunt that 'id' variable to name the file middleman is outputting and also plug that variable into the various tasks so they too accept that as what the filename? 有没有办法通过grunt这个'id'变量来命名中间人正在输出的文件,并将该变量插入各种任务中,以便他们也接受它作为文件名呢?

Here is my grunt config: 这是我的咕unt的配置:

grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        // Build html
        middleman: {
            options: {
                useBundle: true
            },
            server: {},
            build: {
                options: {
                    command: "build"
                }
            }
        },
        // Format html file
        prettify: {
            options: {
                // Task-specific options go here.
            },
            one: {
                src: 'build/index.html',
                dest: '_output/index.html'
            }
        },
        // Run the text converter
        execute: {
            simple_target_with_args: {
                options: {
                    // execute node with additional arguments
                    args: ['_output/index.html']
                },
                src: ['node_modules/node-text-converter/converter.js']
            }
        },
        'special-html': {
            compile: {
                files: {
                   '_output/index.html': '_output/index.html',
                }
            }
        },
        'phantomjs_screenshot': {
        main: {
            options: {
                delay: 1000
            },
            files: [{
                expand: true,
                cwd: '_output',
                src: ['**/*.html'],
                dest: '_output/screenshots/',
                ext: '.jpg'
            }]
        }
    }
});

您应该将变量存储在JSON文件中,然后将其导入Middleman和Grunt中。

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

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