Class: Locomotive::EditableFile
- Inherits:
-
EditableElement
- Object
- EditableElement
- Locomotive::EditableFile
- Defined in:
- app/models/locomotive/editable_file.rb
Instance Method Summary collapse
-
#content ⇒ String
Returns the url or the path to the uploaded file if it exists.
- #copy_attributes(attributes) ⇒ Object
- #copy_attributes_from(el) ⇒ Object
- #default_content? ⇒ Boolean
-
#default_source_url ⇒ Object
fields ##.
- #remove_source=(value) ⇒ Object
- #set_default_content_from(el) ⇒ Object
-
#source ⇒ Object
behaviours ## mount_uploader :source, EditableFileUploader.
Methods inherited from EditableElement
#_run_rearrange_callbacks, #add_current_locale, #by_priority, #content_from_default=, #disabled?, #disabled_in_all_translations?, #editable?, #page, #slug
Instance Method Details
#content ⇒ String
Note:
This method is not used for the rendering, only for the back-office
Returns the url or the path to the uploaded file if it exists. Otherwise returns the default url.
26 27 28 |
# File 'app/models/locomotive/editable_file.rb', line 26 def content self.source? ? self.source.url : self.default_source_url end |
#copy_attributes(attributes) ⇒ Object
34 35 36 37 38 39 40 |
# File 'app/models/locomotive/editable_file.rb', line 34 def copy_attributes(attributes) unless self.default_content? attributes.delete(:default_source_url) end super(attributes) end |
#copy_attributes_from(el) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/locomotive/editable_file.rb', line 42 def copy_attributes_from(el) super(el) if el.source_translations.blank? self.attributes['default_source_url'] = el.attributes['default_source_url'] || {} else el.source_translations.keys.each do |locale| ::Mongoid::Fields::I18n.with_locale(locale) do self.default_source_url = el.source? ? el.source.url : el.default_source_url end end end end |
#default_content? ⇒ Boolean
30 31 32 |
# File 'app/models/locomotive/editable_file.rb', line 30 def default_content? !self.source? && self.default_source_url.present? end |
#default_source_url ⇒ Object
fields ##
11 |
# File 'app/models/locomotive/editable_file.rb', line 11 field :default_source_url, localize: true |
#remove_source=(value) ⇒ Object
66 67 68 69 70 |
# File 'app/models/locomotive/editable_file.rb', line 66 def remove_source=(value) self.source_will_change! # notify the page to run the callbacks for that element self.default_source_url = nil super end |
#set_default_content_from(el) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'app/models/locomotive/editable_file.rb', line 56 def set_default_content_from(el) super(el) locale = ::Mongoid::Fields::I18n.locale.to_s if self.attributes['default_source_url'][locale].nil? self.default_source_url = el.default_source_url end end |
#source ⇒ Object
behaviours ## mount_uploader :source, EditableFileUploader
6 |
# File 'app/models/locomotive/editable_file.rb', line 6 mount_uploader 'source', EditableFileUploader |