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” `class` - any html classes that you want on the result link or image tag. For example “class1 class2”

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

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)

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

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

Instance Attribute Details

#asObject (readonly)

Returns the value of attribute as


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

def as
  @as
end

#variant_attrsObject (readonly)

Returns the value of attribute variant_attrs


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

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], ""))

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

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