Module: Clot::FormFilters
- Included in:
- LiquidForm
- Defined in:
- lib/clot/form_filters.rb
Instance Method Summary collapse
- #concat(string1, string2) ⇒ Object
- #drop_class_to_table_item(clazz) ⇒ Object
- #form_file_item(name, errors) ⇒ Object
- #form_input_item(name, value, errors) ⇒ Object
- #form_item(tag, message, required = false) ⇒ Object
- #form_select_item(name, value, collection, errors, blank_option = nil) ⇒ Object
- #form_text_item(name, value, errors) ⇒ Object
- #get_attribute_value(prop, input) ⇒ Object
- #get_error_class(errors) ⇒ Object
- #get_id_from_name(name) ⇒ Object
- #get_selection_value(value, item) ⇒ Object
-
#input_to_text(input) ⇒ Object
note - must reconstruct from scratch…
- #set_param(tag, key, value) ⇒ Object
- #submit_button(message) ⇒ Object
Instance Method Details
#concat(string1, string2) ⇒ Object
43 44 45 |
# File 'lib/clot/form_filters.rb', line 43 def concat(string1, string2) "#{string1}#{string2}" end |
#drop_class_to_table_item(clazz) ⇒ Object
52 53 54 55 |
# File 'lib/clot/form_filters.rb', line 52 def drop_class_to_table_item(clazz) match = /_drops/.match clazz.name.tableize match.pre_match end |
#form_file_item(name, errors) ⇒ Object
93 94 95 96 |
# File 'lib/clot/form_filters.rb', line 93 def form_file_item(name, errors ) input = "<input type=\"file\" id=\"#{get_id_from_name(name)}\" name=\"#{name}\" />" input end |
#form_input_item(name, value, errors) ⇒ Object
83 84 85 86 |
# File 'lib/clot/form_filters.rb', line 83 def form_input_item(name, value, errors ) input = "<input type=\"text\" id=\"#{get_id_from_name(name)}\" name=\"#{name}\" value=\"#{value}\"#{get_error_class(errors)}/>" input end |
#form_item(tag, message, required = false) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/clot/form_filters.rb', line 4 def form_item(tag, , required = false) tag_id = get_attribute_value("id", tag) form_string = "" if tag_id form_string = " for=\"#{tag_id}\"" end if required required_string = "<span class=\"required\">*</span>" else required_string = "" end "<p><label#{form_string}>#{}#{required_string}</label>#{tag}</p>" end |
#form_select_item(name, value, collection, errors, blank_option = nil) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/clot/form_filters.rb', line 98 def form_select_item(name, value, collection, errors, blank_option = nil) prompt = "" if blank_option prompt = "<option>#{blank_option}</option>" end select = "<select id=\"#{get_id_from_name(name)}\" name=\"#{name}\"#{get_error_class(errors)}>" select += prompt collection.each do |item| @_id = @_label = item.to_s if item.respond_to?(:id) && item.respond_to?(:collection_label) @_id = item.id @_label = item.collection_label end select += "<option value=\"#{@_id}\"#{get_selection_value(value, item)}>#{@_label}</option>" end select += "</select>" end |
#form_text_item(name, value, errors) ⇒ Object
88 89 90 91 |
# File 'lib/clot/form_filters.rb', line 88 def form_text_item(name, value, errors ) text = "<textarea id=\"#{get_id_from_name(name)}\" name=\"#{name}\"#{get_error_class(errors)}>#{value}</textarea>" text end |
#get_attribute_value(prop, input) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/clot/form_filters.rb', line 57 def get_attribute_value(prop, input) prop_match = /#{prop}="([^"]*)"/.match input if prop_match prop_match[1] end end |
#get_error_class(errors) ⇒ Object
126 127 128 |
# File 'lib/clot/form_filters.rb', line 126 def get_error_class(errors) errors.blank? ? "" : ' class="error-item"' end |
#get_id_from_name(name) ⇒ Object
48 49 50 |
# File 'lib/clot/form_filters.rb', line 48 def get_id_from_name(name) name.sub("[", "_").sub("]","") end |
#get_selection_value(value, item) ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/clot/form_filters.rb', line 118 def get_selection_value(value,item) matched_value = item.to_s if item.respond_to?(:collection_label) matched_value = item.id end value.to_s == matched_value.to_s ? ' selected="true"' : '' end |
#input_to_text(input) ⇒ Object
note - must reconstruct from scratch…
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/clot/form_filters.rb', line 24 def input_to_text(input) value_match = /value="([^"]*)"/.match input if value_match value_text = value_match[1] else value_text = "" end name_match = /name="[^"]*"/.match input if name_match name_text = " #{name_match[0]}" else name_text = "" end "<textarea#{name_text}>#{value_text}</textarea>" end |
#set_param(tag, key, value) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/clot/form_filters.rb', line 65 def set_param(tag, key, value) match = /#{key}="[^"]*"/.match tag if match return match.pre_match + "#{key}=\"#{value}\"" + match.post_match end match = /(\/>|>)/.match tag if match match.pre_match + " #{key}=\"#{value}\"" + match.to_s + match.post_match else tag end end |
#submit_button(message) ⇒ Object
79 80 81 |
# File 'lib/clot/form_filters.rb', line 79 def () '<div class="form-submit-button"><input type="submit" value="' + + '"/></div>' end |