Sha256: a0ae08ed95f9ce275caafb3d0bec33d9c2c68360feb40d53de5dc16b45395323

Contents?: true

Size: 1.79 KB

Versions: 2

Compression:

Stored size: 1.79 KB

Contents

<%#
    name: headmin/fields/file
    accepts block: no
    parameters:
      form: Form object
      attribute: (string) Name of the attribute of the form model
      label: (bool) Label will not be displayed if value is false
%>

<% has_image = form.object.send(attribute) %>
<% label = local_assigns.has_key?(:label) ? label : true %>
<% disabled = local_assigns.has_key?(:disabled) ? disabled : false %>
<% required = local_assigns.has_key?(:required) && !has_image ? required : false %>
<div class="<%= ('mb-3' if label) %>">
  <%= render 'headmin/forms/fields/label', form: form, attribute: attribute, required: required if label %>

  <div class="mb-2">
    <% if form.object.send(attribute).attached? %>
      <%= image_tag(form.object.send(attribute).variant(resize_to_limit: [200, 200], quality: 70), class: 'img-thumbnail') %>
    <% else %>
      <svg class="img-thumbnail" width="200" height="200" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="A generic square placeholder image with a white border around it, making it resemble a photograph taken with an old instant camera: 200x200" preserveAspectRatio="xMidYMid slice" focusable="false">
        <title>A generic square placeholder image with a white border around it, making it resemble a photograph taken with an old instant camera</title>
        <rect width="100%" height="100%" fill="#e9ecef"></rect>
        <text x="35%" y="50%" fill="#212529" dy=".3em">200x200</text>
      </svg>
    <% end %>
  </div>

  <%= form.file_field(
        attribute,
        class: "form-control #{form_field_validation_class(form, attribute)}",
        disabled: disabled,
        required: required,
        'aria-describedby': form_field_validation_id(form, attribute))
  %>
  <%= render 'headmin/forms/fields/validation', form: form, attribute: attribute %>
</div>

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
headmin-0.1.2 app/views/headmin/forms/fields/_image.html.erb
headmin-0.1.1 app/views/headmin/forms/fields/_image.html.erb