Sha256: 4eb5db3c9c7431cb49a4776f8af46c372882f02d94a49a846ace3a2af0b11411

Contents?: true

Size: 1021 Bytes

Versions: 12

Compression:

Stored size: 1021 Bytes

Contents

# frozen_string_literal: true
class MarkdownTextareaCell < FormCellBase
  attribute :name, mandatory: true, description: "The textarea's name attribute."
  attribute :form, mandatory: true, description: 'A Rails form object.'
  attribute :value, description: "The textarea's content."
  attribute :rows, description: 'Number of rows.'
  attribute :label, description: 'A label for the form input.'

  private

  def textarea
    form.text_area options[:name], textarea_opts
  end

  def textarea_opts
    opts = {
      skip_label: true,
      rows: options[:rows] || 10,
      control_col: 'col-sm-12'.dup,
      label_col: '',
      data: { toggle: 'markdown', target: "##{preview_id}" }
    }

    opts[:value] = options[:value] if options[:value]

    opts
  end

  def form_group
    form.__send__(:form_group_builder, name, label: label) do
      yield.html_safe
    end
  end

  def preview_id
    "markdown_textarea_preview_#{name_param}"
  end

  def edit_id
    "markdown_textarea_edit_#{name_param}"
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ad2games-ui_components-2.0.14 app/cells/markdown_textarea/markdown_textarea_cell.rb
ad2games-ui_components-2.0.12 app/cells/markdown_textarea/markdown_textarea_cell.rb
ad2games-ui_components-2.0.11 app/cells/markdown_textarea/markdown_textarea_cell.rb
ad2games-ui_components-2.0.10 app/cells/markdown_textarea/markdown_textarea_cell.rb
ad2games-ui_components-2.0.9 app/cells/markdown_textarea/markdown_textarea_cell.rb
ad2games-ui_components-2.0.8 app/cells/markdown_textarea/markdown_textarea_cell.rb
ad2games-ui_components-2.0.7 app/cells/markdown_textarea/markdown_textarea_cell.rb
ad2games-ui_components-2.0.5 app/cells/markdown_textarea/markdown_textarea_cell.rb
ad2games-ui_components-2.0.4 app/cells/markdown_textarea/markdown_textarea_cell.rb
ad2games-ui_components-2.0.3 app/cells/markdown_textarea/markdown_textarea_cell.rb
ad2games-ui_components-2.0.2 app/cells/markdown_textarea/markdown_textarea_cell.rb
ad2games-ui_components-2.0.1 app/cells/markdown_textarea/markdown_textarea_cell.rb