data_doc

DEVELOPMENT STATUS:

Generates html from markdown files containing erb, including layout and headers. DSL in place for stores, attributes and simple tables, but no alternate keys. Error messages are raw, fit for technical only.

<img src=“https://secure.travis-ci.org/alilee/data_doc.png” alt=“Build Status” /> <img src=“https://gemnasium.com/alilee/data_doc.png” alt=“Dependency Status” /> <img src=“https://codeclimate.com/badge.png” />

DESCRIPTION:

Complex documents can be challenging to author, and time-consuming to achieve high levels of internal consistency. This gem offers a Domain Specific Language to embed structured data in a markdown document and then render it into configurable tables.

Note: See security implications below.

FEATURES/PROBLEMS:

  • Main document is Markdown for convenient content authoring.

  • Builds up data in relational database, facilitating review and analysis.

  • Generates HTML from Markdown, and pdf if prince is available.

  • Provides fine-grained control over the HTML headers, including CSS, for the output.

  • Simple DSL for capturing structured data.

  • Simple DSL for querying data stores and laying out in tables.

  • Command line interface

  • Simple web-page interface using sinatra

SECURITY IMPLICATIONS:

This gem uses ERB to process arbitrary ruby code provided by a user. Some sandboxing ($SAFE) is used, but you should assess and manage your level of risk.

SYNOPSIS:

$ bin/data_doc --help
Processes structured data embedded in a markdown document and then renders it into configurable tables.

Usage: data_doc [options] filename

Options are:

Specific options:
    -c, --connection FILENAME        Override document connection settings with FILENAME
    -r, --read-only                  Use data already in database rather than document data
    -d, --data-only                  Use document data but do not change database schema
    -o, --output FILENAME            Put generated output in FILENAME
    -f, --format TYPE                Select type of output from html, pdf (default: html)
    -p, --prince PATH                Path for prince pdf generator
    -v, --[no-]verbose               Run verbosely

Common options:
    -h, --help                       Show this message
        --version                    Show version
$

The data definition language looks like this:

connection adapter: sqlite3 database: '/tmp/example.db' #=>

store 'priority' do
  string 'name'
  alternate_key 'name'
end

priority name: 'high'
priority name: 'medium'
priority name: 'low'

store 'requirement' do
  string 'name'
  text 'description'
  ref 'priority', in: 'priority'
  alternate_key 'name'    
end

requirement name: "It MUST be fast", description: "It must return within 5s.", priority: 'high'
requirement name: "It MUST look good", description: "It must be blue in colour.", priority: 'medium'

The table presentation language looks like this:

present 'select * from priority' #=> '<table>...</table>'

present requirement.project('priority', 'name') do
  caption 'Table of requirements by priority'
  column_order 'name', 'priority'
  label 'priority, 'Importance'
end                              #=> '<table>...</table>'

REQUIREMENTS:

  • Tested on Ruby 1.9.3 only (so far)

  • ActiveRecord-compatible data store

  • RDiscount for Markdown

INSTALL:

gem install data_doc

LICENSE:

(The MIT License)

Copyright © 2012 Alister Lee

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.