kalamuna / metalsmith-jstransformer

Metalsmith JSTransformers Plugin
http://npm.im/metalsmith-jstransformer
MIT License
7 stars 9 forks source link

Options #3

Closed RobLoach closed 7 years ago

RobLoach commented 9 years ago

Allow passing in arguments stating which inputformats/transformers to process.

calebeby commented 8 years ago

Is this going to happen anytime soon?

RobLoach commented 8 years ago

Would be nice to have. Do you have any ideas of how it would be set up?

calebeby commented 8 years ago

No, I don't know how this would be done. I cannot use this extension until this feature has been added, because I need to tell stylus to use axis, jeet, and rupture.

RobLoach commented 8 years ago

What are those extensions from?

calebeby commented 8 years ago

axis, jeet, and rupture are NPM modules.

calebeby commented 8 years ago

Here is stylus' use method:

http://stylus-lang.com/docs/js.html#usefn

stylus(str)
  .use(mylib)
  .render(...)
Zearin commented 7 years ago

I really really really really want to start using metalsmith-jstransformer. It will take me back to a toolset like I used to have with DocPad, but superior in almost every way.

But I need to be able to provide options to the transformers. I like the automatic aspect of this Metalsmith plugin, but one of Metalsmith’s main attractions is the ultimate freedom it provides…and that means “let me use whatever options I want”.

What about the following?

For transforms that simply need an options passed in…

Add an extra option (alongside pattern, layoutPattern, and defaultLayout) called transformerOptions.

The transformerOptions would be an object where each key matches the name of the transformer, and each value are the options to pass to that transformer.

Example:

metalsmith.use( 
  jstransformer({
    'transformerOptions': {
      // these options will be passed to `jstransformer-marked` 
      'marked': { … }
    }
  })
);

For transformers that need configuration like @calebeby mentioned

…Unfortunately, I don’t know how to do this in any way that would scale.

Stylus has a nice .use() method, but every library has a different API, and the entire point of using JSTransformers is to normalize APIs.

If there were a way to pre-configure something, then pass it into a JSTransformer to use, that might be approaching something useful…but I think the idea needs refinement. (Or, it needs to be replaced by a better idea.)

calebeby commented 7 years ago

I don't see a problem with just passing the options to the transformers. Stylus' use is supported in jstransformers through the use property in the options.

RobLoach commented 7 years ago

Right now, it assumes you'd pass the options in through the file metadata...

styles.stylus

---
use:
  - stylus-plugin-something
---
body
    color red
    font 14px Arial, sans-serif

It would be nice to have what @Zearin provided, because then the use settings would apply to every file that is rendered through Stylus....

index.js

metalsmith.use( 
  jstransformer({
    'transformerOptions': {
      // these options will be passed to `jstransformer-stylus` 
      'stylus': {
        'use': [
          'stylus-plugin-something'
        ]
      }
    }
  })
);

styles.stylus

---
# No more `use` needed!
---
body
    color red
    font 14px Arial, sans-serif
Zearin commented 7 years ago

It would be nice to have what @Zearin provided, because then the use settings would apply to every file that is rendered through Stylus....

Exactly! I don’t want to have to add YAML frontmatter to a bunch of files because my entire project uses one Stylus plugin or another.

It’s another push for “DRY”. I should be able to specify the plugins I want Stylus to use once.

thiagodemellobueno commented 7 years ago

I'm with Zearin on this.