Module: Campo

Defined in:
lib/campo/campo.rb,
lib/campo/plugins.rb,
lib/campo/version.rb,
lib/campo/plugins/aria.rb,
lib/campo/plugins/partial.rb,
lib/campo/plugins/jqueryvalidation.rb

Defined Under Namespace

Modules: Childish, Convenience, Helpers, Iding, Plugins Classes: Base, Fieldset, Form, Haml_Ruby_Insert, Input, Label, Legend, Literal, Option, Outputter, Select, Span, Textarea

Constant Summary

VERSION =
"0.11.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.attsObject

Returns the value of attribute atts



223
224
225
# File 'lib/campo/campo.rb', line 223

def atts
  @atts
end

Class Method Details

.constantize(camel_cased_word) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/campo/campo.rb', line 34

def self.constantize(camel_cased_word)
  names = camel_cased_word.split('::')
  names.shift if names.empty? || names.first.empty?

  constant = Object
  names.each do |name|
    constant = constant.const_defined?(name) ? constant.const_get(name,false) : constant.const_missing(name)
  end
  constant
end

.form(name, attributes = {}, &block) ⇒ Object

Probably, the first method you'll call.

Examples:

# Form with a block
form = Campo.form "form1", action: "/go/for/it/" do |f|
  f.text "Hello"
  #... more fields follow
end

Parameters:

  • name (String)

    The form's name (html) attribute.

  • attributes (optional, Hash) (defaults to: {})

    Html attributes. They can be anything you like. Defaults follow:

Options Hash (attributes):

  • :method (String) — default: "POST"

    The method attribute for the form.

See Also:



464
465
466
# File 'lib/campo/campo.rb', line 464

def self.form( name, attributes={}, &block )
  Form.new( name, attributes, &block )
end

.literal(*args, &block) ⇒ Object



355
356
357
# File 'lib/campo/campo.rb', line 355

def self.literal( *args, &block )
   Campo::Literal.new( *args, &block )
end

.output(fields, options = {}) ⇒ Object

Pass anything but the form for the first argument to not have the local variable defaults added to the top

Examples:

Campo.output form # would add the default locals
# these won't
Campo.output :partial, input_field
Campo.output false, label
Campo.output true, fieldset


367
368
369
# File 'lib/campo/campo.rb', line 367

def self.output( fields, options={} )
  Outputter.new( options.delete(:tab)  ).run( fields, options )
end

.plugin(name, options = {}) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/campo/campo.rb', line 52

def self.plugin( name, options={} )
  unless plugins.include? name
    modname = (str = name.to_s) && (str[0,1].upcase + str[1..-1])
    plugins[name] = constantize("Campo::Plugins::#{modname}").new options
    plugins[name].plugged_in
  end
end

.pluginsObject

keeps track of the current plugins



47
48
49
# File 'lib/campo/campo.rb', line 47

def self.plugins
  @plugins ||= {}
end