Module: BHM::Admin::PresentationHelper
- Defined in:
- lib/bhm/admin/presentation_helper.rb
Instance Method Summary collapse
- #default_collection_columns ⇒ Object
- #empty_row_for_collection(size = default_collection_columns.size) ⇒ Object
- #humanized_errors_on(object) ⇒ Object
- #individual_resource_links(r, name = current_resource_name, opts = {}, &blk) ⇒ Object
- #value_with_default(v, default = BHM::Admin.t(:blank_value), &blk) ⇒ Object (also: #vwd)
Instance Method Details
#default_collection_columns ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/bhm/admin/presentation_helper.rb', line 32 def default_collection_columns klass = resource_class if klass.const_defined?(:INDEX_COLUMNS) klass::INDEX_COLUMNS else klass.column_names - [:created_at, :updated_at] end end |
#empty_row_for_collection(size = default_collection_columns.size) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/bhm/admin/presentation_helper.rb', line 41 def empty_row_for_collection(size = default_collection_columns.size) return if collection.present? name = current_resource_name inner = content_tag :td, BHM::Admin.t(:empty_row, :object_name => name.downcase, :plural_object_name => name.pluralize.downcase), :colspan => (size + 1) content_tag :tr, inner, :class => 'empty' end |
#humanized_errors_on(object) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/bhm/admin/presentation_helper.rb', line 48 def humanized_errors_on(object) if object.errors[:base].present? prefix = "This #{object.class.model_name.human}" errors = content_tag(:p, "Please correct the following errors before continuing:") inner_errors = object.errors[:base].map { |e| content_tag(:li, e) }.sum(ActiveSupport::SafeBuffer.new) errors << content_tag(:ul, inner_errors) content_tag(:div, errors, :class => 'resource-base-errors') end end |
#individual_resource_links(r, name = current_resource_name, opts = {}, &blk) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bhm/admin/presentation_helper.rb', line 17 def individual_resource_links(r, name = current_resource_name, opts = {}, &blk) items = [ ml(BHM::Admin.t("buttons.show"), resource_url(r)), ml(BHM::Admin.t("buttons.edit"), edit_resource_url(r)), ml(BHM::Admin.t("buttons.destroy"), resource_url(r), :method => :delete, :confirm => BHM::Admin.t("confirmation.destroy", :object_name => name)) ] if blk.present? position = opts.fetch(:at, :before) value = capture(&blk) position == :before ? items.unshift(value) : items.push(value) end content_tag(:ul, items.join.html_safe) end |
#value_with_default(v, default = BHM::Admin.t(:blank_value), &blk) ⇒ Object Also known as: vwd
5 6 7 8 9 10 11 12 13 |
# File 'lib/bhm/admin/presentation_helper.rb', line 5 def value_with_default(v, default = BHM::Admin.t(:blank_value), &blk) inner = "" if v.present? inner = blk.present? ? capture(&blk) : v else inner = content_tag(:span, default, :class => 'default-value') end inner end |