Sha256: f88c3d285931da19f8b9c1f2c4f2459261e6e983b957c9610e5fc408101c373f

Contents?: true

Size: 845 Bytes

Versions: 18

Compression:

Stored size: 845 Bytes

Contents

# frozen_string_literal: true

module Renalware
  module DefinitionListHelper
    class DefinitionList < SimpleDelegator
      include ActionView::Helpers::TagHelper
      include ActionView::Helpers::TextHelper
      include ActionView::Context

      def initialize(model)
        @model_klass = model.class
        super(model)
      end

      def definition(attribute, label = nil)
        text = label || @model_klass.human_attribute_name(attribute)
        value = __getobj__.public_send(attribute)
        value = yield(value) if value.present? && block_given?
        capture do
          concat tag.dt(text)
          concat tag.dd(value)
        end
      end
    end

    def definition_list_for(model, size: :large)
      tag.dl(class: "dl-horizontal #{size}") do
        yield DefinitionList.new(model)
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/helpers/renalware/definition_list_helper.rb
renalware-core-2.1.0 app/helpers/renalware/definition_list_helper.rb
renalware-core-2.0.167 app/helpers/renalware/definition_list_helper.rb
renalware-core-2.0.166 app/helpers/renalware/definition_list_helper.rb
renalware-core-2.0.165 app/helpers/renalware/definition_list_helper.rb
renalware-core-2.0.164 app/helpers/renalware/definition_list_helper.rb
renalware-core-2.0.163 app/helpers/renalware/definition_list_helper.rb
renalware-core-2.0.162 app/helpers/renalware/definition_list_helper.rb
renalware-core-2.0.161 app/helpers/renalware/definition_list_helper.rb
renalware-core-2.0.160 app/helpers/renalware/definition_list_helper.rb
renalware-core-2.0.159 app/helpers/renalware/definition_list_helper.rb
renalware-core-2.0.158 app/helpers/renalware/definition_list_helper.rb
renalware-core-2.0.157 app/helpers/renalware/definition_list_helper.rb
renalware-core-2.0.156 app/helpers/renalware/definition_list_helper.rb
renalware-core-2.0.155 app/helpers/renalware/definition_list_helper.rb
renalware-core-2.0.153 app/helpers/renalware/definition_list_helper.rb
renalware-core-2.0.152 app/helpers/renalware/definition_list_helper.rb
renalware-core-2.0.151 app/helpers/renalware/definition_list_helper.rb