Sha256: 5958094f7c4bc2b8f3ebcc224b9699f11f0e5684fe985e04632ae3d6c42ddacf

Contents?: true

Size: 1.77 KB

Versions: 7

Compression:

Stored size: 1.77 KB

Contents

require 'action_view'
require 'action_view/helpers'

ActionView::Helpers::FormHelper.module_eval do

  def required_label(object_name, method, text = nil, options = {})
    options = {:class => "required"}.merge!(options)

    label(object_name, method, "#{label_humanize_text(object_name, method, text)} *", options)
  end


  def label_humanize_text object_name, method, text = nil
    content = text unless text.is_a?(Hash)
    if content.blank?
      content = object_name.classify.constantize.respond_to?(:human_attribute_name) ? object_name.classify.constantize.human_attribute_name(method) : method.to_s
    else
      content = content.to_s
    end
    content.humanize
  end

end

ActionView::Helpers::FormBuilder.module_eval do

  def required_label(method, text = nil, options = {})
    @template.required_label(@object_name, method, text, objectify_options(options))
  end

end

ActionView::Helpers::FormTagHelper.module_eval do

  def required_label_tag(name, text = nil, options = {})
    options = {:class => "required"}.merge!(options)
    text ||= "#{name.to_s.humanize} *"

    label_tag(name, text, options)
  end

end

# I18n labels automatically
module ActionView
  module Helpers
    class InstanceTag
      def to_label_tag(text = nil, options = {})
        options = options.stringify_keys
        name_and_id = options.dup
        add_default_name_and_id(name_and_id)
        options.delete("index")
        options["for"] ||= name_and_id["id"]
        if text.blank?
          content = method_name.humanize
          if object.class.respond_to?(:human_attribute_name)
            content = object.class.human_attribute_name(method_name)
          end
        else
          content = text.to_s
        end
        label_tag(name_and_id["id"], content, options)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
refinerycms-core-1.0.11 lib/refinery/helpers/form_helper.rb
refinerycms-core-1.0.10 lib/refinery/helpers/form_helper.rb
refinerycms-core-1.0.9 lib/refinery/helpers/form_helper.rb
refinerycms-core-1.0.8 lib/refinery/helpers/form_helper.rb
refinerycms-core-1.0.7 lib/refinery/helpers/form_helper.rb
refinerycms-core-1.0.5 lib/refinery/helpers/form_helper.rb
refinerycms-core-1.0.4 lib/refinery/helpers/form_helper.rb