Sha256: d24aa5d49a3d450987aa22c28f62ef737f11fad179fe63db123eb983aff2cba6
Contents?: true
Size: 1.61 KB
Versions: 11
Compression:
Stored size: 1.61 KB
Contents
# frozen_string_literal: true module Maquina module Application module Components class ComponentBase < Phlex::HTML include ApplicationView def initialize(resource:, form:, options: {}) @resource = resource @form = form @options = options end protected def control_html options = @options.fetch(:control_html, {}) options[:class] ||= "" options[:class] += " control-error" if @resource.errors[attribute_name].any? options end def input_html(no_helpers: false) options = @options.fetch(:input_html, {}) if !no_helpers options[:maxlength] = t("helpers.maxlength.#{@resource.model_name.i18n_key}.#{attribute_name}", default: t("helpers.maxlength.default")) options[:placeholder] = t("helpers.placeholder.#{@resource.model_name.i18n_key}.#{attribute_name}", default: nil) end options end def attribute_name @attribute_name ||= @options.fetch(:name, "") end def label_css_class @options.dig(:control_html, :label_class) || "" end def help_template help = t("helpers.help.#{@resource.model_name.i18n_key}.#{attribute_name}", default: nil) return if help.blank? p(class: "help") { unsafe_raw help } end def error_template error_message = @resource.errors[attribute_name].first return if error_message.blank? p(class: "help help-error") { error_message } end end end end end
Version data entries
11 entries across 11 versions & 1 rubygems