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.
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
44 45 46 |
# File 'app/models/kms/asset.rb', line 44 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
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/kms/asset.rb', line 52 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
40 41 42 |
# File 'app/models/kms/asset.rb', line 40 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 |
#text_or_javascript? ⇒ Boolean
36 37 38 |
# File 'app/models/kms/asset.rb', line 36 def text_or_javascript? text_type? || javascript? end |
#text_type? ⇒ Boolean
48 49 50 |
# File 'app/models/kms/asset.rb', line 48 def text_type? content_type.start_with?("text") end |
#url ⇒ Object
18 19 20 |
# File 'app/models/kms/asset.rb', line 18 def url file.url end |