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.
> puts "This is inline code."
> puts "But this will be part of the same code block."
=begin_code
def describe_block_code
puts "This will all be part of the same code block."
end
describe_block_code
=end_code
=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
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
Aim your shells thusly for great justice:
$ ruby -r./lib/literate_ruby -e "LiterateRuby.load('README.textile')"
(from this directory)
- 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.