Methods
Public Class
Classes and Modules
Constants
CGI | = | Object.new | ||
CONFIGURATIONS | = | {:default=>{}} |
Hash storing all configurations. Configurations are groups of related transformers, so that you can specify a single :config option when creating a |
|
ESCAPE_TABLE | = | {'&' => '&', '<' => '<', '>' => '>', '"' => '"', "'" => '''}.freeze | ||
MAJOR | = | 2 |
The major version of |
|
MINOR | = | 4 |
The minor version of |
|
SHARED_WRAPPERS | = | [:tr, :table, :ol, :fieldset_ol] |
Transformer symbols shared by wrapper and inputs_wrapper |
|
TINY | = | 1 |
The patch version of |
|
TRANSFORMERS | = | {} |
Main hash storing the registered transformers. Maps transformer type symbols to subhashes containing the registered transformers for that type. Those subhashes should have symbol keys and values that are either classes or objects that respond to |
|
TRANSFORMER_TYPES | = | [:formatter, :serializer, :wrapper, :error_handler, :helper, :labeler, :inputs_wrapper, :tag_wrapper, :set_wrapper] |
Array of all supported transformer types. |
|
VERSION | = | "#{MAJOR}.#{MINOR}.#{TINY}".freeze |
Version constant, use |
|
VERSION_NUMBER | = | MAJOR*10000 + MINOR*100 + TINY |
The full version of |
Attributes
default_add_blank_prompt | [RW] |
The default prompt to use for the :add_blank option (default: nil). |
default_config | [RW] |
Set the default configuration to use if none is explicitly specified (default: :default). |
Public Class methods
Update the :class
entry in the attr
hash with the given classes
, adding the classes after any existing classes.
# File lib/forme.rb 106 def self.attr_classes(attr, *classes) 107 attr[:class] = merge_classes(attr[:class], *classes) 108 end
Update the :class
entry in the attr
hash with the given classes
, adding the classes before any existing classes.
# File lib/forme/bs5.rb 8 def self.attr_classes_after(attr, *classes) 9 attr[:class] = merge_classes(*classes, attr[:class]) 10 end
Call Forme::Form.form
with the given arguments and block.
# File lib/forme.rb 100 def self.form(*a, &block) 101 Form.form(*a, &block) 102 end
# File lib/forme.rb 22 def self.h(value) 23 CGI.escapeHTML(value.to_s) 24 end
Return a string that includes all given class strings
# File lib/forme.rb 111 def self.merge_classes(*classes) 112 classes.compact.join(' ') 113 end
Create a RawString
using the given string, which will disable automatic escaping for that string.
# File lib/forme.rb 117 def self.raw(s) 118 RawString.new(s) 119 end
Register a new configuration. Type is the configuration name symbol, and hash maps transformer type symbols to transformer name symbols.
# File lib/forme.rb 93 def self.register_config(type, hash) 94 CONFIGURATIONS[type] = CONFIGURATIONS[hash.fetch(:base, :default)].merge(hash) 95 end
Register a new transformer with this library. Arguments:
type |
Transformer type symbol |
sym |
Transformer name symbol |
obj/block |
Transformer to associate with this symbol. Should provide either |
# File lib/forme.rb 85 def self.register_transformer(type, sym, obj=nil, &block) 86 raise Error, "Not a valid transformer type" unless TRANSFORMERS.has_key?(type) 87 raise Error, "Must provide either block or obj, not both" if obj && block 88 TRANSFORMERS[type][sym] = obj||block 89 end
If there is a related transformer, call it with the given args
and block
. Otherwise, attempt to return the initial input without modifying it.
# File lib/forme.rb 123 def self.transform(type, trans_name, default_opts, *args, &block) 124 if trans = transformer(type, trans_name, default_opts) 125 trans.call(*args, &block) 126 else 127 case type 128 when :inputs_wrapper 129 yield 130 when :labeler, :error_handler, :wrapper, :helper, :set_wrapper, :tag_wrapper 131 args.first 132 else 133 raise Error, "No matching #{type}: #{trans_name.inspect}" 134 end 135 end 136 end
Get the related transformer for the given transformer type. Output depends on the type of trans
:
Symbol |
Assume a request for a registered transformer, so look it up in the |
Hash |
If |
nil |
Assume the default transformer for this receiver. |
otherwise |
return |
# File lib/forme.rb 146 def self.transformer(type, trans, default_opts=nil) 147 case trans 148 when Symbol 149 type = :wrapper if type == :set_wrapper || type == :tag_wrapper 150 TRANSFORMERS[type][trans] || raise(Error, "invalid #{type}: #{trans.inspect} (valid #{type}s: #{TRANSFORMERS[type].keys.map(&:inspect).join(', ')})") 151 when Hash 152 if trans.has_key?(type) 153 if v = trans[type] 154 transformer(type, v, default_opts) 155 end 156 else 157 transformer(type, nil, default_opts) 158 end 159 when nil 160 transformer(type, default_opts[type]) if default_opts 161 else 162 if trans.respond_to?(:call) 163 trans 164 else 165 raise Error, "#{type} #{trans.inspect} must respond to #call" 166 end 167 end 168 end
Returns the version as a frozen string (e.g. ‘0.1.0’)
# File lib/forme/version.rb 22 def self.version 23 VERSION 24 end