Module: Malt

Extended by:
Kernel
Defined in:
lib/malt.rb,
lib/malt/kernel.rb,
lib/malt/markup.rb,
lib/malt/tilted.rb,
lib/malt/engines.rb,
lib/malt/formats.rb,
lib/malt/machine.rb,
lib/malt/version.rb,
lib/malt/template.rb,
lib/malt/conversions.rb,
lib/malt/engines/abstract.rb,
lib/malt/formats/abstract.rb,
lib/malt/formats/abstract_template.rb

Defined Under Namespace

Modules: Conversions, Engine, Format, Kernel, Tilted Classes: Machine, Malted, Markup, NoEngineError, Template

Constant Summary collapse

VERSION =

TODO: Here until bug in 1.8 is fixed.

['version']

Class Method Summary collapse

Class Method Details

.cli(*args) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# 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) ⇒ Object

Access to project metadata via constants.



12
13
14
15
# File 'lib/malt/version.rb', line 12

def self.const_missing(name)
  key = name.to_s.downcase
  [key] || super(name)
end

.engine?(ext) ⇒ Boolean

Returns ‘true` if the extension given is renderable.

Returns:

  • (Boolean)


71
72
73
# File 'lib/malt.rb', line 71

def self.engine?(ext)
  machine.engine?(ext)
end

.file(file, options = {}) ⇒ Object

Render a file.



17
18
19
# File 'lib/malt.rb', line 17

def self.file(file, options={})
  machine.file(file, options)
end

.format?(ext) ⇒ Boolean

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

Returns:

  • (Boolean)


66
67
68
# File 'lib/malt.rb', line 66

def self.format?(ext)
  machine.format?(ext)
end

.machineObject



12
13
14
# File 'lib/malt.rb', line 12

def self.machine
  @machine ||= Machine.new
end

.metadataObject

Access to project metadata.



4
5
6
7
8
9
# File 'lib/malt/version.rb', line 4

def self.
  @metadata ||= (
    require 'yaml'
    YAML.load(File.new(File.dirname(__FILE__) + '/../malt.yml'))
  )
end

.open(url, options = {}) ⇒ Object

Render a URL.



27
28
29
# File 'lib/malt.rb', line 27

def self.open(url, options={})
  machine.open(url, options)
end

.render(params, &body) ⇒ Object

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.


61
62
63
# File 'lib/malt.rb', line 61

def self.render(params, &body)
  machine.render(params, &body)
end

.text(text, options = {}) ⇒ Object

Render text string.



22
23
24
# File 'lib/malt.rb', line 22

def self.text(text, options={})
  machine.text(text, options)
end