Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Bake with grunt.config.get #95

Closed
tnqsoft opened this issue Oct 3, 2016 · 2 comments
Closed

Generate Bake with grunt.config.get #95

tnqsoft opened this issue Oct 3, 2016 · 2 comments
Labels

Comments

@tnqsoft
Copy link

tnqsoft commented Oct 3, 2016

Hi !

How can generate bake with "grunt.config.get"?. Example:
includes/header.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="<%= grunt.config.get('pkg.description') %>">
    <meta name="keywords" content="<%= grunt.config.get('pkg.keywords') %>">
    <meta name="author" content="<%= grunt.config.get('pkg.author.name') %>">
    <link rel="icon" href="img/favicon.ico">
    <title><%= grunt.config.get('pkg.name') %></title>
   ..........

pages/home.html

<!--(bake ../includes/header.html)-->

<div class="page-header">

But when page generate by Bake, I saw in file content "home.html" contain <%= grunt.config.get('pkg.description') %>...I wanna Bake call grunt.config.get for get parameter value. I find solution in internet, and I found solution:

bake: {
    build: {
        options: {
            content: "<%= sourceDir %>/data/content.json",
            section: "en",
            process: function (content, srcpath) {
                 return grunt.template.process(content);
            }
        },
        files: [{

I resolve problem with grunt.config.get, but I have problem with options.content, it mean Bake can not generate page with content.json. File after build keep key of content file instead of value like. {{example.title}}

Help me please!. Sorry with my English!.

@david-zacharias
Copy link
Collaborator

Hi again,

generally I suggest not to overwrite the process-function, because you loose bake-functionality. But you can mix the configuration into your content object; options.content can also be a callback, so you can do something like:

bake: {
    build: {
        options: {
            content: function() {               
                var file = grunt.config.get('baseProject.data') + '/data/content.json';
                var content = grunt.file.readJSON(file);

                content['conf'] = grunt.config.get('pkg');

                return content;
            }
        }
        // ... files ...
    }
}

In the template you can access the variables like other content:

    <meta name="description" content="{{conf.description}}">

@tnqsoft
Copy link
Author

tnqsoft commented Oct 3, 2016

Amazing and Perfect!! I really like you!. Save my time.

I update Gruntfile.js for Bake.

bake: {
    build: {
        options: {
            content: function() {
                var file = grunt.config.get('sourceDir') + '/data/content.json';
                var content = grunt.file.readJSON(file);

                content['conf'] = grunt.config.get('pkg');
                content['vendorDir'] = grunt.config.get('vendorDir');

                return content;
            }
        },
...

Thank you so much!!!!!.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants