salesforce-ux / theo

Theo is a an abstraction for transforming and formatting Design Tokens
BSD 3-Clause "New" or "Revised" License
1.96k stars 117 forks source link

How to disable token camelCase in HTML output #188

Open withinsight opened 4 years ago

withinsight commented 4 years ago

The default for token names in the html output is camelCase. I should be able to override this by setting up a setup.js file, and defining a custom formatOption.

I currently see this error:

Error: No options? at transform.chain.fold.e (/Users/{un}/{project}/node_modules/theo/lib/index.js:122:32)

Here's my setup.js:

module.exports = theo => {
  let formatOptions = {
    type: 'html',
    options: {
      transformPropName: name => name
    }
  }

  theo.convert(formatOptions).then((result) => {
    console.log(result);
  }).catch((result) => {
    console.log(result);
  });
}

As you can see I'm simply returning the token name, so it should remain unchanged.

I'm using the CLI:

theo src/lib/tokens/tokens.yml --format html --dest src/lib/tokens --setup src/lib/tokens/setup.js

How can I disable the camelCase formatting for our tokens when displayed in HTML output?

withinsight commented 4 years ago

Any examples of customizing Theo's formatOptions out there?

withinsight commented 4 years ago

Still no luck here. Anybody?!?

axyz commented 4 years ago

@withinsight I have the same issue, haven't digged too much into the code, but as far as I can tell it is not possible to pass options to the convert function.

What happen with the setup file is that it gives you the theo object so that you can decorate it before the convert function is called, but you cannot call the convert function yourself there.

I think the only options here would be to either use the full API and write a simple script to call theo.convert yourself or use registerFormat to reimplement the html format in your setup file omitting the camel case part.

But maybe some maintainer may have some more insights here.

myamolane commented 3 years ago

@withinsight Hey, this should works, take a try ~ const htmlFormat = require('theo/lib/formats/html'); theo.registerFormat( 'html', (result) => { const newResult = result.set('options', { transformPropName: (propName) => { // convert to whatevery case you want return propName; } }) return htmlFormat(newResult) } )

image

myamolane commented 3 years ago

Another way, pass the transformPropName through formatOptions image