Sha256: 8e219a5e3ccb4e06dd8069cf94084874aed717f5baa4f2bea91c60adfbbdf4d9

Contents?: true

Size: 1.22 KB

Versions: 62

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

module Renalware
  module FormHelper
    def errors_css_class(model, attr)
      " field_with_errors" if model.errors.key?(attr)
    end

    def render_input(builder, attribute)
      renderable = builder.object.public_send(attribute)
      return unless renderable

      render input_partial_path_for(renderable),
             attribute: attribute,
             f: builder
    end

    def input_partial_path_for(renderable)
      partial_type = partial_type_for(renderable)
      "renalware/shared/documents/#{partial_type}_input"
    end

    def partial_type_for(renderable)
      if renderable.respond_to?(:to_partial_path)
        renderable.to_partial_path.split("/").last
      else
        renderable.class.name.demodulize.underscore
      end
    end

    def monospace(value, width = 5)
      content_tag(:span, class: "monospaced") do
        concat("%#{width}s" % value).gsub(/ /, " ").html_safe
      end
    end

    def save_or_cancel(form:, back_path:, submit_title: "Save", cancel_title: "cancel")
      capture do
        concat(form.submit(submit_title, class: "button"))
        concat(content_tag(:span) { " or " })
        concat(link_to(cancel_title, back_path))
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
renalware-core-2.0.113 app/helpers/renalware/form_helper.rb
renalware-core-2.0.112 app/helpers/renalware/form_helper.rb
renalware-core-2.0.111 app/helpers/renalware/form_helper.rb
renalware-core-2.0.110 app/helpers/renalware/form_helper.rb
renalware-core-2.0.109 app/helpers/renalware/form_helper.rb
renalware-core-2.0.108 app/helpers/renalware/form_helper.rb
renalware-core-2.0.106 app/helpers/renalware/form_helper.rb
renalware-core-2.0.105 app/helpers/renalware/form_helper.rb
renalware-core-2.0.104 app/helpers/renalware/form_helper.rb
renalware-core-2.0.103 app/helpers/renalware/form_helper.rb
renalware-core-2.0.102 app/helpers/renalware/form_helper.rb
renalware-core-2.0.101 app/helpers/renalware/form_helper.rb
renalware-core-2.0.100 app/helpers/renalware/form_helper.rb
renalware-core-2.0.99 app/helpers/renalware/form_helper.rb
renalware-core-2.0.98 app/helpers/renalware/form_helper.rb
renalware-core-2.0.97 app/helpers/renalware/form_helper.rb
renalware-core-2.0.96 app/helpers/renalware/form_helper.rb
renalware-core-2.0.95 app/helpers/renalware/form_helper.rb
renalware-core-2.0.94 app/helpers/renalware/form_helper.rb
renalware-core-2.0.93 app/helpers/renalware/form_helper.rb