diff --git a/README.md b/README.md index d44f06e..2dd9aa7 100644 --- a/README.md +++ b/README.md @@ -23,14 +23,17 @@ Build output files using mole.build() ``` -## Configuration +## Config By default, `mole` will look for a file called `mole.config.js` at the root of your project that exports the following object. -You can override the location of the config file by using `mole.config()`. - -```js -mole.config('src/mole.config.js') +```ts +type Config { + theme: string, + model?: string[], + template?: string[], + output: Output +} ``` ### Options @@ -69,7 +72,17 @@ mole.config('src/mole.config.js') An object that defines where (`file`) and how (`model`, `template`) to process the output. You can set a different `template` or `model` for each output. Name each output by using a key. -## API + ```ts + type Output { + name: { + file: string + model?: string[], + template?: string[] + } + } + ``` + +## Docs - ### Set configuration @@ -79,6 +92,12 @@ mole.config('src/mole.config.js') - `config` { string | object } path to file, or object for config + #### Example + + ```js + mole.config('src/mole.config.js') + ``` + --- - ### Set or update theme data @@ -107,63 +126,55 @@ mole.config('src/mole.config.js') - ### Use a model or template that's been registered - `mole.use( part ): void` + `mole.use(type, name, callback): void` #### Parameters - - `part` { array } : - - `type` { string } must be `'template'` or `'model'` - - `name` { string } name of the template or model - - `callback` { function | string } the body of the model or template + - `type` { string } must be `'template'` or `'model'` + - `name` { string } name of the template or model + - `callback` { function | string } the body of the model or template ---- + #### Example -- ### Render an array of templates + Using a function: - `mole.render(): string[]` + ```js + mole.use('template', 'font-size', (model, theme, name, str) => { + let scale = model[name] ---- + for (let i = 0; i < scale.length; i++) { + str` + .$font-${i} { + font-size: ${scale[i]} + }` + } -- ### Build the output files - - `mole.build()` + return str() + }) + ``` -### Types + Using a string: -- **`Config`** + ```js + mole.use('template', 'font-size', - ```ts - type Config { - theme: string, - model?: string[], - template?: string[], - output: Output - } + `.font-{{modifier}} { + font-size: {{value}}; + }` + }) ``` -- **`Output`** +--- - ```ts - type Output { - name: { - file: string - model?: string[], - template?: string[] - } - } - ``` +- ### Render an array of templates -- **`ModelCallback`** + `mole.render(): string[]` - ```ts - type ModelCallback = (theme: object, name: string, str: string) => object - ``` +--- - **`TemplateCallback`** +- ### Build the output files - ```ts - type TemplateCallback = (model: object, theme: object, name: string, str: string) => object - ``` + `mole.build()` ## Development