Skip to content

Instantly share code, notes, and snippets.

@mparker17
Last active August 24, 2018 16:13
Show Gist options
  • Save mparker17/eea2aef1760298a6ca71735700fe0541 to your computer and use it in GitHub Desktop.
Save mparker17/eea2aef1760298a6ca71735700fe0541 to your computer and use it in GitHub Desktop.
Set up a simple markdown renderer in a folder

Install

To set up this project, you will need to:

  1. install rbenv,
  2. use rbenv to install the correct version of the Ruby programming language,
  3. use the Ruby programming language's tools to install Bundler, and finally,
  4. use bundler to install this project's only dependency, Spiffy.

These steps are detailed below...

  1. Install rbenv using your computer's package manager.

    • On macOS with Homebrew:

      $ brew install rbenv
      
  2. Set up rbenv so it can install/build the ruby programming language:

     $ rbenv init
    

    Use the instructions it prints to add the rbenv shim to your shell's configuration. This shim ensures when you type ruby or gem at the command-line, you get the version of Ruby stated in a project's .ruby-version file, or the default if a .ruby-version file can't be found in the current folder or any of its ancestors.

  3. Close and re-open your shell so the configuration you added in the last step is used.

  4. Optional but recommended: run rbenv's "doctor" program to check everything is set up correctly:

     $ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
    

    rbenv-doctor will probably tell you that you don't have any ruby versions installed, but that's normal if you just installed rbenv.

  5. Install the correct version of Ruby for this project by running:

     $ rbenv install
    
  6. Install Bundler:

     $ gem install bundler
    
  7. Use Bundler to install this project's dependencies:

     $ bundle install
    

Use

  1. Create a markdown file.

    For example, the following creates a simple file named test.md that has a first-level heading which says "Hello world":

     $ echo "# Hello world" | tee -a test.md
    
  2. Run spiffy on the file to transform it into HTML:

     $ bundle exec spiffy --html on --pdf off -- $FILE
    

    ... where $FILE is the path to the file you created in step 1.

    For example, if you created test.md above, you can transform it to HTML as follows:

     $ bundle exec spiffy --html on --pdf off -- test.md
    
# Set up a simple markdown renderer in a folder
# Tested in fish, should work in bash, zsh.
# These instructions assume you have rbenv installed, but you can use rvm, rbfu, etc.
$ echo "2.3.1" | tee .ruby-version
$ rbenv install
$ gem install bundler
$ echo 'source "https://rubygems.org"
gem "spiffy"' | tee Gemfile
$ bundle install
$ echo '- markdown_files:
- \'*.md\'' | tee .spiffy.yml
# Render markdown.
$ bundle exec spiffy --html on --pdf off $file_to_convert.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment