Giter Site home page Giter Site logo

cheer's Introduction

cheer travis npm/v license | Public Domain

👏 Galvanize your Markdown files with dynamic content

Introduction

Cheer is the missing modern way to do inline templating in your Markdown files through an elegant enhanced JavaScript syntax. No more outdated .md, we have you covered!

  • Simple: it's just JavaScript, with some enhancements for your own convenience
  • Async-friendly: support asynchronous calls out of the box
  • Extensible: thanks to its plugin system
  • Neat: no external templates files
  • Fast: all commands are executed in parallel

It does support the following features out-of-the-box:

Look at this simple example, it:

  1. Extracts the commands to execute between <!--- and --->
  2. Downloads the latest cheer package information through the npm registry
  3. Parses that raw text as JSON
  4. Injects the parsed JSON into the template string
  5. Places the final output between ---> and <!--->
<!--- open('http://registry.npmjs.org/cheer/latest') | json | `Latest push: ${name}@${version}` --->
Latest push: [email protected]
<!--->

Note: the parts in <!--- and ---> stays pristine, that's the whole point of inline templating, allowing future calls to replace the outdated output. This even allows you to add cheer --lint to your CI, making sure your tests breaks if your documentation is outdated!

Rationale

Who doesn't want to keep its documentation up-to-date?

Got your attention? Let's get started!

Install

npm install --global cheer

Usage - CLI

$ cheer --help

  :clap: Galvanize your Markdown files with dynamic content

  Usage
    $ cheer [options] file...

  Options
    --dry-run       Do not modify the files, but print the modifications to stdout and exit
    --lint          Do not modify the files, but lint them and exit with an error code if the files are outdated
    --print-ast     Print the AST nodes to stdout and exit
    --print-tokens  Print the Lexer tokens to stdout and exit

  Example
    $ cheer readme.md

Usage - API

fromFiles(files, options)

This convenience method allows to call the fromFile method with an array of filepaths. The calls are performed in parallel.

  • files: Array<string> — The paths of the files to iterate on
  • options: Object — The options to pass down to fromFile

Returns Promise<Array<string>> — Resolving when all the fromFile calls are done with success.

fromFile(file, $1)

This convenience method allows to call the fromBuffer method with a filepath. The current working directory ( options.cwd ) is set to the filepath directory.

  • file: string — The path of the file to galvanize
  • $1: Object — The options passed down to fromBuffer
    • $1.cwd: string — The current working directory from which the file should be resolved, set to the file directory before calling fromBuffer
    • $1.options: ...any

Returns Promise<string> — Resolving when the fromBuffer call is done with success, along with overwriting the filepath with the result.

fromBuffer(buffer, $1)

Take an input buffer and return a new transformed buffer with all the expressions executed and the results injected into the new buffer.

  • buffer: string|buffer.Buffer — The input to galvanize
  • $1: Object — The options
    • $1.cwd: string — The current working directory
    • $1.dryRun: boolean — Write the output to stdout and exit
    • $1.filepath: string — Used by some plugins
    • $1.linebreak: string — Which linebreak character should be used, inferred from the buffer by default
    • $1.lint: boolean — Check the file for outdated content, and exit with the appropriate error code. Meant to be used in a CI or in npm run prepublish
    • $1.printAst: boolean — Print the parser AST to stdout and exit
    • $1.printTokens: boolean — Print the lexer tokens to stdout and exit

Returns Promise<string> — Resolving a new transformed buffer.

Changelog

  • 1.0.0
    • Bump stable

License

Creative Commons — CC0 1.0 Universal

To the extent possible under law, Aymeric Beaumet has waived all copyright and related or neighboring rights to this work.

cheer's People

Contributors

aymericbeaumet avatar

Watchers

 avatar  avatar

cheer's Issues

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet.
We recommend using:

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.