Module: Campo::Convenience
- Included in:
- Base
- Defined in:
- lib/campo/campo.rb
Overview
Here to make life a bit easier and cut down on RSI.
Instance Method Summary collapse
- #bit_of_ruby(*args, &block) ⇒ Object (also: #haml_ruby_insert)
- #checkbox(name, label = nil, attributes = {}) ⇒ Object
- #fieldset(text, attributes = {}, &block) ⇒ Object
- #hidden(name, attributes = {}) ⇒ Object
- #input(name, type, label = nil, attributes = {}) ⇒ Object
- #literal(*args, &block) ⇒ Object
- #password(name, label = nil, attributes = {}) ⇒ Object
- #radio(name, label = nil, attributes = {}) ⇒ Object
- #select(*args, &block) ⇒ Object
- #submit(name = "Submit", attributes = {}) ⇒ Object
-
#text(name, label = nil, attributes = {}) ⇒ Input
Add an input with type of text.
-
#textarea(name, inner = nil, attributes = {}, &block) ⇒ Object
There is no easy way to give this convenience method in the same convention as the other methods, so this uses a hash argument for the label.
Instance Method Details
#bit_of_ruby(*args, &block) ⇒ Object Also known as: haml_ruby_insert
76 77 78 79 80 |
# File 'lib/campo/campo.rb', line 76 def bit_of_ruby( *args, &block ) tag = Campo::Haml_Ruby_Insert.new( *args, &block ) self << tag tag end |
#checkbox(name, label = nil, attributes = {}) ⇒ Object
149 150 151 |
# File 'lib/campo/campo.rb', line 149 def checkbox( name, label=nil, attributes={} ) input( name, :checkbox, label, attributes ) end |
#fieldset(text, attributes = {}, &block) ⇒ Object
69 70 71 |
# File 'lib/campo/campo.rb', line 69 def fieldset( text, attributes={}, &block ) self << Fieldset.new( text, attributes, &block ) end |
#hidden(name, attributes = {}) ⇒ Object
131 132 133 |
# File 'lib/campo/campo.rb', line 131 def hidden( name, attributes={} ) self << Campo::Input.new( name, :hidden, attributes ) end |
#input(name, type, label = nil, attributes = {}) ⇒ Object
156 157 158 159 160 161 162 163 164 165 |
# File 'lib/campo/campo.rb', line 156 def input( name, type, label=nil, attributes={} ) if label.kind_of? Hash attributes = label label = nil end field = Campo::Input.new( name, type, attributes ).labelled( label ) self << field field end |
#literal(*args, &block) ⇒ Object
88 89 90 91 92 |
# File 'lib/campo/campo.rb', line 88 def literal( *args, &block ) tag = Campo::Literal.new( *args, &block ) self << tag tag end |
#password(name, label = nil, attributes = {}) ⇒ Object
137 138 139 |
# File 'lib/campo/campo.rb', line 137 def password( name, label=nil, attributes={} ) input( name, :password, label, attributes ) end |
#radio(name, label = nil, attributes = {}) ⇒ Object
143 144 145 |
# File 'lib/campo/campo.rb', line 143 def radio( name, label=nil, attributes={} ) input( name, :radio, label, attributes ) end |
#select(*args, &block) ⇒ Object
110 111 112 113 114 |
# File 'lib/campo/campo.rb', line 110 def select( *args, &block ) select = Campo::Select.new( *args, &block ) self << select select end |
#submit(name = "Submit", attributes = {}) ⇒ Object
170 171 172 173 174 |
# File 'lib/campo/campo.rb', line 170 def submit( name="Submit", attributes={} ) submit = Campo::Input.new( name, :submit, {value: name}.merge(attributes) ) self << submit submit end |
#text(name, label = nil, attributes = {}) ⇒ Input
Add an input with type of text
126 127 128 |
# File 'lib/campo/campo.rb', line 126 def text( name, label=nil, attributes={} ) input( name, :text, label, attributes ) end |
#textarea(name, inner = nil, attributes = {}, &block) ⇒ Object
There is no easy way to give this convenience method in the same convention as the other methods, so this uses a hash argument for the label
180 181 182 183 184 185 186 187 188 189 |
# File 'lib/campo/campo.rb', line 180 def textarea( name, inner=nil, attributes={}, &block ) if inner.kind_of? Hash attributes = inner inner = nil end label = attributes.delete(:label) || attributes.delete(:labelled) textarea = Campo::Textarea.new( name, inner, attributes ).labelled( label ) self << textarea textarea end |