Class: ComfortableMexicanSofa::Content::Tag::File

Inherits:
Fragment show all
Includes:
Mixins::FileContent
Defined in:
lib/comfortable_mexican_sofa/content/tags/file.rb

Overview

File tag allows attaching of file to the page. This controls how files are uploaded and then displayed on the page. Example tag:

{{ cms:file identifier, as: link, label: "My File" }}

‘as` - url (default) | link | image - render out link or image tag `label` - attach label attribute to link or image tag `resize` - imagemagic option. For example: “100x50>” `gravity` - imagemagic option. For example: “center” `crop` - imagemagic option. For example: “100x50+0+0”

Direct Known Subclasses

Files

Instance Attribute Summary collapse

Attributes inherited from Fragment

#identifier, #namespace, #options, #renderable

Attributes inherited from ComfortableMexicanSofa::Content::Tag

#context, #params, #source

Instance Method Summary collapse

Methods included from Mixins::FileContent

#content, #rails_blob_path

Methods inherited from Fragment

#content, #form_field_id, #fragment, #render

Methods inherited from ComfortableMexicanSofa::Content::Tag

#allow_erb?, #content, #nodes, #render

Constructor Details

#initialize(context:, params: [], source: nil) ⇒ File

Returns a new instance of File.

Parameters:

  • context (Comfy::Cms::WithFragments)
  • params (Array<String, {String => String}>) (defaults to: [])
  • source (String, nil) (defaults to: nil)


26
27
28
29
30
31
# File 'lib/comfortable_mexican_sofa/content/tags/file.rb', line 26

def initialize(context:, params: [], source: nil)
  super
  @as             = options["as"] || "url"
  @label          = options["label"]
  @variant_attrs  = options.slice("resize", "gravity", "crop")
end

Instance Attribute Details

#asObject (readonly)

Returns the value of attribute as.



20
21
22
# File 'lib/comfortable_mexican_sofa/content/tags/file.rb', line 20

def as
  @as
end

#variant_attrsObject (readonly)

Returns the value of attribute variant_attrs.



23
24
25
# File 'lib/comfortable_mexican_sofa/content/tags/file.rb', line 23

def variant_attrs
  @variant_attrs
end

Instance Method Details

#form_field(object_name, view, index) {|view.safe_join([input, attachments_partial], "")| ... } ⇒ Object

Yields:

  • (view.safe_join([input, attachments_partial], ""))


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/comfortable_mexican_sofa/content/tags/file.rb', line 33

def form_field(object_name, view, index)
  name    = "#{object_name}[fragments_attributes][#{index}][files]"
  input   = view.send(:file_field_tag, name, id: form_field_id, class: "form-control")

  attachments_partial =
    if fragment.attachments
      view.render(
        partial: "comfy/admin/cms/fragments/form_fragment_attachments",
        locals: {
          object_name:  object_name,
          index:        index,
          attachments:  fragment.attachments,
          fragment_id:  identifier,
          multiple:     false
        }
      )
    end

  yield view.safe_join([input, attachments_partial], "")
end