wyam - How do I abstract a set of modules to a variable to be included in multiple pipelines? -


i'm trying abstract set of modules use them in multiple pipelines. have before first pipeline.

imodule[] textreplacement = new imodule[] {     replace(" -- ", "—"),     replace("--", "—"),     trace("text replacement performed...") }; 

then, in pipeline:

pipelines.add("pages",    readfiles("*.md"),    concat(textreplacement),    writefiles("*.html) ); 

when execute, text replacement performed... written console, execution flow working through 2 modules. --

  1. text replacement not occur. (or, if does, it's not persisted in documents continue down pipeline.)

  2. an empty document added document set.

the documentation concat states:

the specified modules executed empty initial document , outputs original input documents without modification concatenated results specified module sequence.

i can't figure out why is, why needed or helpful, or how rid of it. can't have empty document floating around in document set, or else causes errors in subsequent pipelines.

the trick here use linq .concat() method form single array consisting of modules specific each pipeline combined common module array that's declared before pipelines (textreplacement in example). works because ipipelinecollection.add() accepts params imodule[] array.

imodule[] textreplacement = new imodule[] {     replace(" -- ", "—"),     replace("--", "—"),     trace("text replacement performed...") };  pipelines.add("pages",     new[]     {         // modules before common set         readfiles("*.md")     }     .concat(textreplacement)  // common set     .concat(new[]     {         // modules after common set        writefiles("*.html)     })     .toarray() ); 

granted, pretty awkward. of course there other ways create single array feed ipipelinecollection.add() besides using .concat(). example, create list<imodule> before each pipeline using list<t>.add() , list<t>.addrange() create aggregate sequence of modules , convert array when creating pipeline. write extension method knows how concatenate multiple sequences single array.

in future become easier introduction of special module named modules designed purpose acts container of child modules (https://github.com/wyamio/wyam/issues/197):

modules textreplacement = modules(     replace(" -- ", "&mdash;"),     replace("--", "&mdash;"),     trace("text replacement performed...") );  pipelines.add("pages",     readfiles("*.md"),     textreplacement,     writefiles("*.html) ); 

Comments