module Malt

Constants

VERSION

TODO: Here until bug in 1.8 is fixed.

Public Class Methods

cli(*args) click to toggle source
# File lib/malt.rb, line 76
def self.cli(*args)
  require 'optparse'
  itype, otype = nil, nil
  OptionParser.new{|o|
    o.on('-t TYPE', 'input type'){  |t| itype  = t }
    o.on('-o TYPE', 'output type'){ |t| otype = t }
    o.on('--help', '-h'       , 'display this help message'){ puts o; exit }
  }.parse!
  db, files = *args.partition{ |x| x.index('=') }
  db = db.inject({}){ |h,kv| k,v = kv.split('='); h[k] = v; h}
  files.each do |file|
    puts Malt.render(:file=>file, :type=>itype, :format=>otype)
    #file = itype ? Malt.file(file, :type=>itype) : Malt.file(file)
    #if otype
    #  puts file.render(otype, db)
    #else
    #  puts file.render(db)
    #end
  end
end
const_missing(name) click to toggle source

Access to project metadata via constants.

Calls superclass method
# File lib/malt/version.rb, line 12
def self.const_missing(name)
  key = name.to_s.downcase
  metadata[key] || super(name)
end
engine?(ext) click to toggle source

Returns `true` if the extension given is renderable.

# File lib/malt.rb, line 71
def self.engine?(ext)
  machine.engine?(ext)
end
file(file, options={}) click to toggle source

Render a file.

# File lib/malt.rb, line 17
def self.file(file, options={})
  machine.file(file, options)
end
format?(ext) click to toggle source

Returns `true` if the extension given is a recognized format.

# File lib/malt.rb, line 66
def self.format?(ext)
  machine.format?(ext)
end
machine() click to toggle source
# File lib/malt.rb, line 12
def self.machine
  @machine ||= Machine.new
end
metadata() click to toggle source

Access to project metadata.

# File lib/malt/version.rb, line 4
def self.metadata
  @metadata ||= (
    require 'yaml'
    YAML.load(File.new(File.dirname(__FILE__) + '/../malt.yml'))
  )
end
open(url, options={}) click to toggle source

Render a URL.

# File lib/malt.rb, line 27
def self.open(url, options={})
  machine.open(url, options)
end
render(params, &body) click to toggle source

Render a document.

param [Hash] params

Rendering parameters.

option params [Symbol] :to

The format to which the file/text is to be rendered.

option params [String] :file

The file to be rendered. If `:text` is not given, this file must exist on disk
so it can be read-in to fill in the `:text` option. If text is given, the file
is only used to help determine type and clarify error messages.

option params [String] :text

The text to render. This option is required unless `:file` is given.

option params [Symbol] :type

The format of the text. This will be determined automatically by the `:file`
 option if it is given and has a recognized extension. Otherwise it needs
 be explicitly provided.

option params [Hash,Object,Binding,Array] :data

The data source used for evaluation. This can be a locals hash, a scope
object or binding, or an array of a scope object/binding and locals hash.
This option is split-up into :scope and :locals before passing on to 
the redering engine.

option params [Boolean] :pass

If not a supported type return text rather than raise an error.
# File lib/malt.rb, line 61
def self.render(params, &body)
  machine.render(params, &body)
end
text(text, options={}) click to toggle source

Render text string.

# File lib/malt.rb, line 22
def self.text(text, options={})
  machine.text(text, options)
end