module Kramdown::Options
def self.defaults
def self.defaults temp = {} @options.each {|n, o| temp[o.name] = o.default} temp end
def self.define(name, type, default, desc)
The type 'Object' should only be used if none of the other types suffices because such an
Symbol, Boolean, Array, Object), default value +default+ and the description +desc+.
Define a new option called +name+ (a Symbol) with the given +type+ (String, Integer, Float,
def self.define(name, type, default, desc) raise ArgumentError, "Option name #{name} is already used" if @options.has_key?(name) raise ArgumentError, "Invalid option type #{type} specified" if !ALLOWED_TYPES.include?(type) raise ArgumentError, "Invalid type for default value" if !(type === default) && !default.nil? @options[name] = Definition.new(name, type, default, desc) end
def self.defined?(name)
def self.defined?(name) @options.has_key?(name) end
def self.definitions
def self.definitions @options end
def self.merge(hash)
Merge the #defaults Hash with the *parsed* options from the given Hash, i.e. only valid option
def self.merge(hash) temp = defaults hash.each do |k,v| next unless @options.has_key?(k) temp[k] = parse(k, v) end temp end
def self.parse(name, data)
If +data+ already has the correct type, it is just returned. Otherwise it is converted to a
value with the correct type.
Parse the given value +data+ as if it was a value for the option +name+ and return the parsed
def self.parse(name, data) raise ArgumentError, "No option named #{name} defined" if !@options.has_key?(name) return data if @options[name].type === data data = data.to_s if @options[name].type == String data elsif @options[name].type == Integer Integer(data) elsif @options[name].type == Float Float(data) elsif @options[name].type == Symbol (data.strip.empty? ? nil : data.to_sym) elsif @options[name].type == Boolean data.downcase.strip != 'false' && !data.empty? elsif @options[name].type == Array data.split(/\s+/) end end