0.0
No commit activity in last 3 years
No release in over 3 years
Literate Ruby is a small preprocessor that allows embedding code within text files and then loading them as programs.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

Literate Ruby

This library is the first step towards a more literate Ruby syntax, similar to Haskell’s (admittedly semi-literate syntax).

Applications include: documentation files where there’s more text than code (e.g. like READMEs!), blog entries, or a minimalist story runnner.

Usage

Single lines code


> puts "This is inline code."
> puts "But this will be part of the same code block."

Block code


=begin_code
def describe_block_code
  puts "This will all be part of the same code block."
end

describe_block_code
=end_code

Loading


=begin_code
require 'pp'
require './lib/literate_ruby'

lines = LiterateRuby.load("test/fixtures/fixture.lrb")

pp lines

pp "FOO: #{FOO}"
pp "foo (method): #{foo()}"
=end_code

Parsing

If you just want access to the raw tree without eval’ing the code, do this:


=begin_code
require 'pp'
require './lib/literate_ruby'

lines = LiterateRuby.parse(File.new("test/fixtures/fixture.lrb"))

pp lines

=end_code

This file is like, so self-referential, or whatever

Aim your shells thusly for great justice:


$ ruby -r./lib/literate_ruby -e "LiterateRuby.load('README.textile')"

(from this directory)

TODOS

  • Figure out if we need/how best to finish off the LiterateRuby.require method. So someone could write library code if they so desired.
  • Possibly change or make the inline & block delimiters configurable to support different markdown languages’ code syntax.