Giter Club home page Giter Club logo

Comments (5)

david-zacharias avatar david-zacharias commented on September 15, 2024

Hey!

Have you taken a look the bake extra pages section? I think that should work for your use case.

Please let me know if you could apply this to your project.

from grunt-bake.

jroland01 avatar jroland01 commented on September 15, 2024

Hi - Thanks a lot for your reply.

I could potentially apply that. The thing is, the JSON I am using is structured according to "sections", and not as an array. My understanding is that the _foreach statement in bake extra pages goes through items in an array, not through "sections". So I would require the same feature as in bake extra pages, but with the ability to go through "sections" instead of items in an array (e.g. a "mix" of _foreach and _section statement features).

Just to give you some background : I am using grunt-frontmatter to extract frontmatter from a list of markdown files, and it generates that JSON file with filenames as "sections" (so I have little control over how it is structured) :

{
  "filename1": {
    "language": "fr",
    "name": "name1",
    "description": "description1" 
  },
  "filename2": {
    "language": "fr",
    "name": "name2",
    "description": "description2" 
  },
...
}

What do you think ? Thanks a lot in advance !

from grunt-bake.

david-zacharias avatar david-zacharias commented on September 15, 2024

If the data you have is not matching the requirements grunt-bake has, you can transform the data by using a function for options.content:

options: {
    content: function() {
        var file = './data/content.json';
        var content = grunt.file.readJSON(file);

        return _.values(content); // e.g. http://underscorejs.org/#values
    }
},

You could also do some sorting and mixin the keys (filename1, filename2, ...) as a property so they become available in the templates:

return _.chain(content)
    .mapObject(function (section, filename) {
        return _.extend({}, section, {
            filename: filename
        });
    })
    .values()
    .sortBy('name')
    .value();

from grunt-bake.

jroland01 avatar jroland01 commented on September 15, 2024

Thanks a lot ! I will look into your suggestions. Alternatively I will input my data directly in the required format for grunt-bake / bake extra pages.

from grunt-bake.

david-zacharias avatar david-zacharias commented on September 15, 2024

Hope you found a suitable solution. I will close this issue, since it is not a feature or bug. But I will create one feature issue for supporting iteration over objects in _foreach

from grunt-bake.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.