<img src=“https://badge.fury.io/rb/captains_log.svg” alt=“Gem Version” />

Captain’s Log

WARNING: Captains Log will scan any given text for code to evaluate. It is highly recommended that you do not use this against user-input. For your application’s security, please only use Captain’s Log against input from trusted administrators.

This project rocks and uses MIT-LICENSE.

Installation

  1. Add Captains Log to your application’s Gemfile

    gem 'captains_log', '0.0.1'
    

Note: It is recommended that you provide the version number as breaking changes may be released with minor version bumps.

Usage

Captain’s Log evaluates lines of Ruby embedded in larger bodies of texts, such as blog entries. As a programmer, it enables me to demonstrate functional code from blog posts stored in my database. In order to recognise these blocks of code, we use a made-up HTML tag: ‘<eval>[code to execute]</eval>`.

In your body of text, ensure that code blocks to be evaluated are concatenated onto one line and surrounded by the ‘eval` tag.

To have Captain’s Log evaluate these code blocks in your texts, use the ‘captains_log` helper:

<%= captains_log(@blog_post.body) %>

If ‘captains_log` isn’t to your tastes, you can of course surround the helper in an alternative helper of your own. On my site, I use ‘badass_digest`:

def badass_digest(content)
  captains_log(content)
end

Using your own alternative is then as easy as utilising the original:

<%= badass_digest(@blog_post.body) %>