Class: Occams::Content::Tag::File
- Inherits:
-
Fragment
- Object
- Occams::Content::Tag
- Fragment
- Occams::Content::Tag::File
- Includes:
- Mixins::FileContent
- Defined in:
- lib/occams/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
Instance Attribute Summary collapse
-
#as ⇒ Object
readonly
Returns the value of attribute as.
-
#variant_attrs ⇒ Object
readonly
Returns the value of attribute variant_attrs.
Attributes inherited from Fragment
#identifier, #namespace, #options, #renderable
Attributes inherited from Occams::Content::Tag
Instance Method Summary collapse
- #form_field(object_name, view, index) {|view.safe_join([input, attachments_partial], '')| ... } ⇒ Object
-
#initialize(context:, params: [], source: nil) ⇒ File
constructor
A new instance of File.
Methods included from Mixins::FileContent
Methods inherited from Fragment
#content, #form_field_id, #fragment, #render
Methods inherited from Occams::Content::Tag
#allow_erb?, #content, #nodes, #render
Constructor Details
#initialize(context:, params: [], source: nil) ⇒ File
Returns a new instance of File.
26 27 28 29 30 31 32 |
# File 'lib/occams/content/tags/file.rb', line 26 def initialize(context:, params: [], source: nil) super @as = ['as'] || 'url' @label = ['label'] @class = ['class'] @variant_attrs = .slice('resize', 'gravity', 'crop') end |
Instance Attribute Details
#as ⇒ Object (readonly)
Returns the value of attribute as.
20 21 22 |
# File 'lib/occams/content/tags/file.rb', line 20 def as @as end |
#variant_attrs ⇒ Object (readonly)
Returns the value of attribute variant_attrs.
23 24 25 |
# File 'lib/occams/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
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/occams/content/tags/file.rb', line 34 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') = if fragment. view.render( partial: 'occams/admin/cms/fragments/form_fragment_attachments', locals: { object_name: object_name, index: index, attachments: fragment., fragment_id: identifier, multiple: false } ) end yield view.safe_join([input, ], '') end |