Class: Kms::Asset

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
UpdateStylesheetsText
Defined in:
app/models/kms/asset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#performing_plain_textObject

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

#textObject 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

#filenameObject



15
16
17
# File 'app/models/kms/asset.rb', line 15

def filename
  read_attribute(:file)
end

#javascript?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'app/models/kms/asset.rb', line 45

def javascript?
  content_type.include?("javascript")
end

#performing_plain_text?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/models/kms/asset.rb', line 29

def performing_plain_text?
  performing_plain_text
end

#store_textObject



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

Returns:

  • (Boolean)


41
42
43
# File 'app/models/kms/asset.rb', line 41

def stylesheet?
  content_type.include?("css")
end

#stylesheet_or_javascript?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'app/models/kms/asset.rb', line 33

def stylesheet_or_javascript?
  stylesheet? || javascript?
end

#text_or_javascript?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'app/models/kms/asset.rb', line 37

def text_or_javascript?
  text_type? || javascript?
end

#text_type?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'app/models/kms/asset.rb', line 49

def text_type?
  content_type.start_with?("text")
end

#urlObject



19
20
21
# File 'app/models/kms/asset.rb', line 19

def url
  file.url
end