module Forme

  1. lib/forme.rb
  2. lib/forme/bs3.rb
  3. lib/forme/erb.rb
  4. lib/forme/erb_form.rb
  5. lib/forme/form.rb
  6. lib/forme/input.rb
  7. lib/forme/rails.rb
  8. lib/forme/raw.rb
  9. lib/forme/sinatra.rb
  10. lib/forme/tag.rb
  11. lib/forme/transformers/error_handler.rb
  12. lib/forme/transformers/formatter.rb
  13. lib/forme/transformers/helper.rb
  14. lib/forme/transformers/inputs_wrapper.rb
  15. lib/forme/transformers/labeler.rb
  16. lib/forme/transformers/serializer.rb
  17. lib/forme/transformers/wrapper.rb
  18. lib/forme/version.rb
  19. show all


CGI =  
CONFIGURATIONS = {:default=>{}}  

Hash storing all configurations. Configurations are groups of related transformers, so that you can specify a single :config option when creating a Form and have all of the transformers set from that.

ESCAPE_TABLE = {'&' => '&', '<' => '<', '>' => '>', '"' => '"', "'" => '''}.freeze  
MAJOR = 1  

The major version of Forme, updated only for major changes that are likely to require modification to apps using Forme.

MINOR = 11  

The minor version of Forme, updated for new feature releases of Forme.

SHARED_WRAPPERS = [:tr, :table, :ol, :fieldset_ol]  

Transformer symbols shared by wrapper and inputs_wrapper

TINY = 0  

The patch version of Forme, updated only for bug fixes from the last feature release.


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 call.

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 Forme.version instead.


The full version of Forme as a number (1.8.0 => 10800)


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

attr_classes (attr, *classes)

Update the :class entry in the attr hash with the given classes.

[show source]
    # File lib/forme.rb
 98 def self.attr_classes(attr, *classes)
 99   attr[:class] = merge_classes(attr[:class], *classes)
100 end
form (*a, &block)

Call Forme::Form.form with the given arguments and block.

[show source]
   # File lib/forme.rb
93 def self.form(*a, &block)
94   Form.form(*a, &block)
95 end
h (value)
[show source]
   # File lib/forme.rb
17 def self.h(value)
18   CGI.escapeHTML(value.to_s)
19 end
merge_classes (*classes)

Return a string that includes all given class strings

[show source]
    # File lib/forme.rb
103 def self.merge_classes(*classes)
104   classes.compact.join(' ')
105 end
raw (s)

Create a RawString using the given string, which will disable automatic escaping for that string.

[show source]
    # File lib/forme.rb
109 def self.raw(s)
111 end
register_config (type, hash)

Register a new configuration. Type is the configuration name symbol, and hash maps transformer type symbols to transformer name symbols.

[show source]
   # File lib/forme.rb
86 def self.register_config(type, hash)
87   CONFIGURATIONS[type] = CONFIGURATIONS[hash.fetch(:base, :default)].merge(hash)
88 end
register_transformer (type, sym, obj=nil, &block)

Register a new transformer with this library. Arguments:


Transformer type symbol


Transformer name symbol


Transformer to associate with this symbol. Should provide either obj or block, but not both. If obj is given, should be either a Class instance or it should respond to call. If a Class instance is given, instances of that class should respond to call, and a new instance of that class should be used for each transformation.

[show source]
   # File lib/forme.rb
78 def self.register_transformer(type, sym, obj=nil, &block)
79   raise Error, "Not a valid transformer type" unless TRANSFORMERS.has_key?(type)
80   raise Error, "Must provide either block or obj, not both" if obj && block
81   TRANSFORMERS[type][sym] = obj||block
82 end
transform (type, trans_name, default_opts, *args, &block)

If there is a related transformer, call it with the given args and block. Otherwise, attempt to return the initial input without modifying it.

[show source]
    # File lib/forme.rb
115 def self.transform(type, trans_name, default_opts, *args, &block)
116   if trans = transformer(type, trans_name, default_opts)
117*args, &block)
118   else
119     case type
120     when :inputs_wrapper
121       yield
122     when :labeler, :error_handler, :wrapper, :helper, :set_wrapper, :tag_wrapper
123       args.first
124     else
125       raise Error, "No matching #{type}: #{trans_name.inspect}"
126     end
127   end
128 end
transformer (type, trans, default_opts=nil)

Get the related transformer for the given transformer type. Output depends on the type of trans:


Assume a request for a registered transformer, so look it up in the TRANSFORRMERS hash.


If type is also a key in trans, return the related value from trans, unless the related value is nil, in which case, return nil. If type is not a key in trans, use the default transformer for the receiver.


Assume the default transformer for this receiver.


return trans directly if it responds to call, and raise an Error if not.

[show source]
    # File lib/forme.rb
138 def self.transformer(type, trans, default_opts=nil)
139   case trans
140   when Symbol
141     type = :wrapper if type == :set_wrapper || type == :tag_wrapper
142     TRANSFORMERS[type][trans] || raise(Error, "invalid #{type}: #{trans.inspect} (valid #{type}s: #{TRANSFORMERS[type]', ')})")
143   when Hash
144     if trans.has_key?(type)
145       if v = trans[type]
146         transformer(type, v, default_opts)
147       end
148     else
149       transformer(type, nil, default_opts)
150     end
151   when nil
152     transformer(type, default_opts[type]) if default_opts
153   else
154     if trans.respond_to?(:call)
155       trans
156     else
157       raise Error, "#{type} #{trans.inspect} must respond to #call"
158     end
159   end
160 end
version ()

Returns the version as a frozen string (e.g. '0.1.0')

[show source]
   # File lib/forme/version.rb
22 def self.version
24 end