Module: Campo

Defined in:
lib/campo.rb,
lib/campo/version.rb

Defined Under Namespace

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

Constant Summary collapse

VERSION =
"0.3.2"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.attsObject

Returns the value of attribute atts.



158
159
160
# File 'lib/campo.rb', line 158

def atts
  @atts
end

Class Method Details

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

Generally, 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:



305
306
307
# File 'lib/campo.rb', line 305

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

.literal(*args, &block) ⇒ Object



230
231
232
# File 'lib/campo.rb', line 230

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

.output(*args) ⇒ 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


241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/campo.rb', line 241

def self.output( *args )
  s = <<STR
- atts = {} if atts.nil?
- atts.default = {} if atts.default.nil?
- inners = {} if inners.nil?
- inners.default = "" if inners.default.nil?
- i = 0 # for tabindex

STR


  # default to true
  whole_form = if args.first.kind_of? Campo::Base 
    true
  else 
    args.shift
    false
  end
  
  output = Base.output( *args )
  output = s + output if whole_form
  output
end