Class: Kms::Asset
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Kms::Asset
- Includes:
- UpdateStylesheetsText
- Defined in:
- app/models/kms/asset.rb
Instance Attribute Summary collapse
-
#performing_plain_text ⇒ Object
Returns the value of attribute performing_plain_text.
-
#text ⇒ Object
(also: #content)
Returns the value of attribute text.
Instance Method Summary collapse
- #filename ⇒ Object
- #javascript? ⇒ Boolean
- #performing_plain_text? ⇒ Boolean
- #store_text ⇒ Object
- #stylesheet? ⇒ Boolean
- #stylesheet_or_javascript? ⇒ Boolean
- #url ⇒ Object
Instance Attribute Details
#performing_plain_text ⇒ Object
Returns the value of attribute performing_plain_text.
12 13 14 |
# File 'app/models/kms/asset.rb', line 12 def performing_plain_text @performing_plain_text end |
#text ⇒ Object Also known as: content
Returns the value of attribute text.
12 13 14 |
# File 'app/models/kms/asset.rb', line 12 def text @text end |
Instance Method Details
#filename ⇒ Object
14 15 16 |
# File 'app/models/kms/asset.rb', line 14 def filename read_attribute(:file) end |
#javascript? ⇒ Boolean
40 41 42 |
# File 'app/models/kms/asset.rb', line 40 def javascript? content_type.include?("javascript") end |
#performing_plain_text? ⇒ Boolean
28 29 30 |
# File 'app/models/kms/asset.rb', line 28 def performing_plain_text? performing_plain_text end |
#store_text ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/models/kms/asset.rb', line 44 def store_text return if persisted? && !stylesheet_or_javascript? data = performing_plain_text? ? text : (file.present? ? file.read : nil) return if !stylesheet_or_javascript? || data.blank? sanitized_source = replace_urls(data) self.file = ::CarrierWave::SanitizedFile.new({ tempfile: StringIO.new(sanitized_source), filename: filename || file.filename }) @text = sanitized_source # no need to reset the plain_text instance variable to have the last version end |
#stylesheet? ⇒ Boolean
36 37 38 |
# File 'app/models/kms/asset.rb', line 36 def stylesheet? content_type.include?("css") end |
#stylesheet_or_javascript? ⇒ Boolean
32 33 34 |
# File 'app/models/kms/asset.rb', line 32 def stylesheet_or_javascript? stylesheet? || javascript? end |
#url ⇒ Object
18 19 20 |
# File 'app/models/kms/asset.rb', line 18 def url file.url end |