Sha256: 8a68d3fb85f102dc4ec3c16145d9fa5e61b1de510b28fd60c17442522c663582

Contents?: true

Size: 1.46 KB

Versions: 3

Compression:

Stored size: 1.46 KB

Contents

<%
  # headmin/forms/blocks
  #
  # ==== Options
  # * <tt>form</tt> - Form object
  # * <tt>path</tt> - Directory where to look for block templates
  # * <tt>allow</tt> - Names of block templates that can be added
  #
  # ==== Examples
  #   Basic version. This will only look for blocks in 'admin/blocks'
  #   <%= render "headmin/forms/blocks", form: form %#>
  #
  #   Define the path to look for block templates like this:
  #   <%= render "headmin/forms/blocks", form: form, path: 'admin/pages/blocks' %#>
  #
  #   Limit the types of blocks
  #   <%= render "headmin/forms/blocks", form: form, allow: ['text', 'text-image'] %#>

  path = local_assigns.has_key?(:path) ? path : nil
  allowed_block_names = local_assigns.has_key?(:allow) ? allow.map(&:to_s) : BlockService.block_names(path: path)

  templates = allowed_block_names.map { |name| BlockService.form_view(name, path: path) }
%>

<%= render 'headmin/forms/repeater', form: form, attribute: :blocks, templates: templates, label: false do |block_form, template| %>
  <% name = template ? BlockService.view_name(template) : block_form.object.name %>

  <!-- Name input of the block -->
  <%= block_form.hidden_field :name, value: name %>

  <!-- Render block form fields -->
  <% view_path = BlockService.form_view(name, path: path).gsub('/_', '/') %>
  <%= render view_path, form: block_form %>

  <!-- Label -->
  <span class="position-absolute top-0 end-0 badge bg-light text-dark">
    <%= name.titleize %>
  </span>
<% end %>

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
headmin-0.2.8 app/views/headmin/forms/_blocks.html.erb
headmin-0.2.7 app/views/headmin/forms/_blocks.html.erb
headmin-0.2.6 app/views/headmin/forms/_blocks.html.erb