Sha256: d4c269e2e2114fc64925e6ebf9aec6497089c9aa3f23270c82c10d32d078b99b

Contents?: true

Size: 1.54 KB

Versions: 20

Compression:

Stored size: 1.54 KB

Contents

module Administrador
  class ApplicationViewHelper < Rao::ViewHelper::Base
    def engines
      Administrador::Configuration.engines
    end

    def filter_attributes_for_form(attribute_names)
      attribute_names.reject { |an| %w(id created_at updated_at).include?(an) }
    end

    def filter_attributes_for_show(attribute_names)
      attribute_names.reject { |an| %w().include?(an) }
    end

    def flash_messages
      c.render partial: 'administrador/application_view_helper/flash_messages', locals: { flash: bootstrapify_flash_keys(c.flash) }
    end

    def label_for(resource)
      Administrador::Configuration.resource_label_methods.each do |method_name|
        next unless resource.respond_to?(method_name)
        return resource.send(method_name)
      end
    end

    def render_engine_sidebars
      engines.collect do |_, engine|
        c.render partial: 'administrador/application_view_helper/render_engine_sidebars', locals: { engine: engine }
      end.join.html_safe
    end

    def body_html
      css_classes = ['administrador', c.controller.class.name.underscore.gsub('/', '-').chomp('_controller'), c.action_name].compact.join(' ')
      { class: css_classes }
    end

    private

    def bootstrapify_flash_keys(flash)
      flash.each_with_object({}) do |(key, value), memo|
        memo[map_message_type_to_context(key)] = value
      end
    end

    def map_message_type_to_context(message_type)
      { success: "success", error: "danger", alert: "warning", notice: "info" }[message_type.to_sym] || message_type.to_s
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
administrador-0.0.28.pre app/view_helpers/administrador/application_view_helper.rb
administrador-0.0.27.pre app/view_helpers/administrador/application_view_helper.rb
administrador-0.0.26.pre app/view_helpers/administrador/application_view_helper.rb
administrador-0.0.25.pre app/view_helpers/administrador/application_view_helper.rb
administrador-0.0.24.pre app/view_helpers/administrador/application_view_helper.rb
administrador-0.0.22.pre app/view_helpers/administrador/application_view_helper.rb
administrador-0.0.21.pre app/view_helpers/administrador/application_view_helper.rb
administrador-0.0.20.pre app/view_helpers/administrador/application_view_helper.rb
administrador-0.0.18.pre app/view_helpers/administrador/application_view_helper.rb
administrador-0.0.17.pre app/view_helpers/administrador/application_view_helper.rb
administrador-0.0.16.pre app/view_helpers/administrador/application_view_helper.rb
administrador-0.0.15.pre app/view_helpers/administrador/application_view_helper.rb
administrador-0.0.14.pre app/view_helpers/administrador/application_view_helper.rb
administrador-0.0.13.pre app/view_helpers/administrador/application_view_helper.rb
administrador-0.0.12.pre app/view_helpers/administrador/application_view_helper.rb
administrador-0.0.11.pre app/view_helpers/administrador/application_view_helper.rb
administrador-0.0.10.pre app/view_helpers/administrador/application_view_helper.rb
administrador-0.0.9.pre app/view_helpers/administrador/application_view_helper.rb
administrador-0.0.8.pre app/view_helpers/administrador/application_view_helper.rb
administrador-0.0.7.pre app/view_helpers/administrador/application_view_helper.rb