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
- #text_or_javascript? ⇒ Boolean
- #text_type? ⇒ Boolean
- #url ⇒ Object
Instance Attribute Details
#performing_plain_text ⇒ Object
Returns the value of attribute performing_plain_text.
13 14 15 |
# File 'app/models/kms/asset.rb', line 13 def performing_plain_text @performing_plain_text end |
#text ⇒ Object Also known as: content
Returns the value of attribute text.
13 14 15 |
# File 'app/models/kms/asset.rb', line 13 def text @text end |
Instance Method Details
#filename ⇒ Object
15 16 17 |
# File 'app/models/kms/asset.rb', line 15 def filename read_attribute(:file) end |
#javascript? ⇒ Boolean
45 46 47 |
# File 'app/models/kms/asset.rb', line 45 def javascript? content_type.include?("javascript") end |
#performing_plain_text? ⇒ Boolean
29 30 31 |
# File 'app/models/kms/asset.rb', line 29 def performing_plain_text? performing_plain_text end |
#store_text ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/models/kms/asset.rb', line 53 def store_text return if persisted? && !text_or_javascript? data = performing_plain_text? ? text : (file.present? ? file.read : nil) return if !text_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 end |
#stylesheet? ⇒ Boolean
41 42 43 |
# File 'app/models/kms/asset.rb', line 41 def stylesheet? content_type.include?("css") end |
#stylesheet_or_javascript? ⇒ Boolean
33 34 35 |
# File 'app/models/kms/asset.rb', line 33 def stylesheet_or_javascript? stylesheet? || javascript? end |
#text_or_javascript? ⇒ Boolean
37 38 39 |
# File 'app/models/kms/asset.rb', line 37 def text_or_javascript? text_type? || javascript? end |
#text_type? ⇒ Boolean
49 50 51 |
# File 'app/models/kms/asset.rb', line 49 def text_type? content_type.start_with?("text") end |
#url ⇒ Object
19 20 21 |
# File 'app/models/kms/asset.rb', line 19 def url file.url end |