Class: AttachmentField

Inherits:
Field
  • Object
show all
Defined in:
lib/generators/hot_glue/fields/attachment_field.rb

Instance Attribute Summary collapse

Attributes inherited from Field

#alt_lookup, #assoc_class, #assoc_label, #assoc_model, #assoc_name, #associations, #auth, #class_name, #default_boolean_display, #display_as, #form_labels_position, #form_placeholder_labels, #god, #hawk_keys, #hidden_create, #hidden_update, #layout_strategy, #limit, #modify_as, #name, #namespace, #object, #ownership_field, #plural, #polymorphic_parents, #pundit, #sample_file_path, #self_auth, #singular, #singular_class, #sql_type, #stimmify, #update_show_only

Instance Method Summary collapse

Methods inherited from Field

#code_to_reset_match_if_search_is_blank, #display_boolean_as, #field_error_name, #field_output, #field_view_output, #form_show_only_output, #getName, #hidden_output, #label_class, #label_for, #modified_display_output, #modify_binary?, #newline_after_field?, #prelookup_syntax, #spec_list_view_assertion, #spec_make_assertion, #spec_random_data, #spec_related_column_lets, #testing_name, #text_area_output, #viewable_output

Constructor Details

#initialize(scaffold:, name:) ⇒ AttachmentField

Returns a new instance of AttachmentField.



3
4
5
6
7
# File 'lib/generators/hot_glue/fields/attachment_field.rb', line 3

def initialize(scaffold:, name:)
  super

  @attachment_data = attachment_data
end

Instance Attribute Details

#attachment_dataObject

Returns the value of attribute attachment_data.



2
3
4
# File 'lib/generators/hot_glue/fields/attachment_field.rb', line 2

def attachment_data
  @attachment_data
end

Instance Method Details

#form_field_outputObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/generators/hot_glue/fields/attachment_field.rb', line 31

def form_field_output
  direct = attachment_data[:direct_upload]
  dropzone = attachment_data[:dropzone]
  field_result = (thumbnail ?   "<%= #{singular}.#{name}.attached? ? image_tag(#{singular}.#{name}.variant(:#{thumbnail})) : '' %>" : "") +
    "<br />\n" + (update_show_only.include?(name) ? "" : "<%= f.file_field :#{name} #{', direct_upload: true ' if direct}#{', "data-dropzone-target": "input"' if dropzone}%>")

  if dropzone
    field_result = "<div class=\"dropzone dropzone-default dz-clickable\" data-controller=\"dropzone\" data-dropzone-max-file-size=\"2\" data-dropzone-max-files=\"1\">\n  "+ field_result + "\n</div>"
  end
  return field_result
end

#line_field_outputObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/generators/hot_glue/fields/attachment_field.rb', line 43

def line_field_output
  thumbnail = attachment_data[:thumbnail]
  if thumbnail
    "<% if #{singular}.#{name}.attached? %>
  <% if !#{singular}.#{name}.variable? %>
    <span class=\"badge bg-secondary\"><%= #{singular}.#{name}.blob.content_type.split('/')[1] %></span>
  <% else %>
    <%= image_tag(#{singular}.#{name}.variant(:thumb)) %>
  <% end %>
  <% end %>"
  else
    ""
  end
end

#spec_list_view_natural_assertionObject



13
14
15
16
17
18
19
20
# File 'lib/generators/hot_glue/fields/attachment_field.rb', line 13

def spec_list_view_natural_assertion
  "within('div.#{singular}--#{name}') do
      img = page.find('img')
      expect(img['src']).to end_with('glass_button.png')
    end"

  # "expect(page).to have_content(#{singular}#{1}.#{name})"
end

#spec_setup_and_change_act(which_partial = nil) ⇒ Object



23
24
25
# File 'lib/generators/hot_glue/fields/attachment_field.rb', line 23

def spec_setup_and_change_act(which_partial = nil)
  "      attach_file(\"#{singular}[#{name.to_s}]\", \"#{sample_file_path}\")"
end

#spec_setup_let_argObject



9
10
11
# File 'lib/generators/hot_glue/fields/attachment_field.rb', line 9

def spec_setup_let_arg
  nil
end

#thumbnailObject



27
28
29
# File 'lib/generators/hot_glue/fields/attachment_field.rb', line 27

def thumbnail
  attachment_data[:thumbnail]
end