Sha256: 32748c4cd76b2ec643428edabc22b3c414d8f15329c3ff5a3bd158f6c29390ba

Contents?: true

Size: 1.33 KB

Versions: 7

Compression:

Stored size: 1.33 KB

Contents

format :html do
  view :read_form do
    read_field_configs.map do |field, args|
      args[:view] = :read_formgroup
      nest field, args
    end
  end

  def read_field_configs
    edit_field_configs
  end

  view :read_formgroup, template: :haml, unknown: true, wrap: :slot

  # a formgroup has a label (with helptext) and an input
  def formgroup title, opts={}, &block
    input = opts[:input]
    wrap_with :div, formgroup_div_args(opts[:class]) do
      [formgroup_label(input, title, opts[:help]),
       editor_wrap(input, &block)]
    end
  end

  def formgroup_label input, title, help
    parts = [formgroup_title(title), formgroup_help(help)].compact
    return unless parts.present?

    form.label (input || :content), raw(parts.join("\n"))
  end

  def formgroup_title title
    title if voo&.show?(:title) && title.present?
  end

  def formgroup_div_args html_class
    div_args = { class: ["form-group", html_class].compact.join(" ") }
    div_args[:card_id] = card.id if card.real?
    div_args[:card_name] = h card.name if card.name.present?
    div_args
  end

  def formgroup_help text=nil
    return unless voo&.show?(:help) && text != false

    class_up "help-text", "help-block"
    formgroup_voo_help text
    _render_help
  end

  def formgroup_voo_help text
    voo.help = text if voo && text.present? && text.to_s != "true"
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
card-mod-edit-0.15.5 set/all/formgroup.rb
card-mod-edit-0.15.4 set/all/formgroup.rb
card-mod-edit-0.15.3 set/all/formgroup.rb
card-mod-edit-0.15.2.pre1 set/all/formgroup.rb
card-mod-edit-0.15.1.1 set/all/formgroup.rb
card-mod-edit-0.15.1 set/all/formgroup.rb
card-mod-edit-0.15.0 set/all/formgroup.rb