Module: ActionView::Helpers
- Defined in:
- lib/awesome_form_attributes/helpers.rb
Instance Method Summary collapse
- #awesome_fileds(a, f, opts = {}) ⇒ Object
-
#boolean_collection ⇒ Object
ApplicationHelper.send(:include,SharedHelper) if defined?(ApplicationHelper).
- #default_styles_for(tag, opts = {}) ⇒ Object
- #has_displayed_names? ⇒ Boolean
- #join_content(wrapper = :td, style = {}, &lamb) ⇒ Object
- #localize_attr(sym) ⇒ Object
- #table_th_columns(wrapper = :th, style = {}) ⇒ Object
- #tag_for_attr(att) ⇒ Object
- #values_for_columns(obj, wrapper = :td, style = {}) ⇒ Object
Instance Method Details
#awesome_fileds(a, f, opts = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/awesome_form_attributes/helpers.rb', line 45 def awesome_fileds(a, f, opts = {}) obj = single_obj cur_tag = tag_for_attr(a) opts = default_styles_for(cur_tag, opts) return f.send(:check_box, a, opts) if cur_tag == 'boolean' select_tag = cur_tag == "select" val = select_tag ? klass.select_values(a, obj) : obj.send(a) select_tag ? f.send(cur_tag, a, val, opts[:opts] || {}, opts[:html_opts] || {}) : f.send(cur_tag, a, opts) end |
#boolean_collection ⇒ Object
ApplicationHelper.send(:include,SharedHelper) if defined?(ApplicationHelper)
6 7 8 |
# File 'lib/awesome_form_attributes/helpers.rb', line 6 def boolean_collection [["是", 1], ["否", 0]] end |
#default_styles_for(tag, opts = {}) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/awesome_form_attributes/helpers.rb', line 55 def default_styles_for(tag, opts = {}) { text_area: {rows: 6, cols: 50}, text_field: {}, file: {}, select: {opts: {include_blank: true}}, check_box: {}, boolean: {} }[tag.to_sym].deep_merge(opts) rescue opts end |
#has_displayed_names? ⇒ Boolean
10 11 12 |
# File 'lib/awesome_form_attributes/helpers.rb', line 10 def has_displayed_names? I18n.t(klass.displayed_columns_local_path).is_a?Hash end |
#join_content(wrapper = :td, style = {}, &lamb) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/awesome_form_attributes/helpers.rb', line 29 def join_content(wrapper = :td, style = {}, &lamb) content = klass.displayed_columns.map do |a| content_tag(wrapper, lamb.call(a), style) end.join raw content end |
#localize_attr(sym) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/awesome_form_attributes/helpers.rb', line 14 def localize_attr(sym) displayed_name = I18n.t("#{klass.displayed_columns_local_path}.#{sym.to_s}") basic_name = I18n.t("#{klass.default_local_path}.#{sym.to_s}") return displayed_name if has_displayed_names? && !(displayed_name =~ /translation missing/) basic_name end |
#table_th_columns(wrapper = :th, style = {}) ⇒ Object
21 22 23 |
# File 'lib/awesome_form_attributes/helpers.rb', line 21 def table_th_columns(wrapper = :th, style = {}) join_content(wrapper, style) {|a| localize_attr(a)} end |
#tag_for_attr(att) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/awesome_form_attributes/helpers.rb', line 36 def tag_for_attr(att) return "select" if att =~ /\_id\Z/ cs = AwesomeFormAttributes.config.config text_field = cs.delete(:default_tag) title = localize_attr(att) cur_tag_hash = cs.select {|k, v| title =~ /#{v.join("|")}/}.presence || {text_field: ""} cur_tag_hash.keys.first.to_s.gsub("_words", "") end |
#values_for_columns(obj, wrapper = :td, style = {}) ⇒ Object
25 26 27 |
# File 'lib/awesome_form_attributes/helpers.rb', line 25 def values_for_columns(obj, wrapper = :td, style = {}) join_content(wrapper, style) {|a| obj.send(a)} end |