fbrctr / fabricator

A tool for building website UI toolkits and style guides
http://fbrctr.github.io/
MIT License
1.11k stars 124 forks source link

General notes for collection of materials #281

Open mahish opened 7 years ago

mahish commented 7 years ago

Hey, first let me thank you for this amazing framework. I do rly enjoy it:)

I would love to have possibility to show general notes for whole group of materials, e.g. notes for lists:

└── materials
    └── components
        └── lists
            ├── ordered.html
            └── unordered.html

Taken the logic behind the notes system (notes in front matter or in .md files with the same name), I would expect it should work something like this:

└── materials
    └── components
        └── lists
            ├── ordered.html
            └── unordered.html
        └── lists.md

But actually I would like more this one:

└── materials
    └── components
        └── lists
            ├── lists.md (or notes.md)
            ├── ordered.html
            └── unordered.html

Anyway, I didn't find a way to do it by myself. Any hint?

GuerillaRadio commented 7 years ago

I agree this is much needed. Has anyone figured out a way to add notes to groups of materials (i.e. a materials folder)?

mahish commented 7 years ago

I ended up with a workaround. Basically I duplicated & modifed notes functionality in fabricator-assembler/index.js which you can find in node_modules. Then used it once in the first material item within the group/collection in the same way as you would use notes. You just need to prepare your include templates.

// get material front-matter, omit `notes`
var localData = _.omit(fileMatter.data, ['notes', 'collectionNotes']);

// trim whitespace from material content
var content = fileMatter.content.replace(/^(\s*(\r?\n|\r))+|(\s*(\r?\n|\r))+$/g, '');

// capture meta data for the material
if (!isSubCollection) {
  assembly.materials[collection].items[key] = {
    filename: id,
    name: toTitleCase(id),
    notes: (fileMatter.data.notes) ? md.render(fileMatter.data.notes) : '',
    data: localData
  };
} else {
  assembly.materials[parent].items[collection].items[key] = {
    filename: id,
    name: toTitleCase(id.split('.')[1]),
    notes: (fileMatter.data.notes) ? md.render(fileMatter.data.notes) : '',
    collectionNotes: (fileMatter.data.collectionNotes) ? md.render(fileMatter.data.collectionNotes) : '',
    data: localData
  };
}

Check the index.js, lines 325-345 in fabricator-assembler repo.

Hope it helps.