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.



12
13
14
# File 'app/models/kms/asset.rb', line 12

def performing_plain_text
  @performing_plain_text
end

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

#filenameObject



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

def filename
  read_attribute(:file)
end

#javascript?Boolean

Returns:

  • (Boolean)


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

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

#performing_plain_text?Boolean

Returns:

  • (Boolean)


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

def performing_plain_text?
  performing_plain_text
end

#store_textObject



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

Returns:

  • (Boolean)


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

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

#stylesheet_or_javascript?Boolean

Returns:

  • (Boolean)


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

def stylesheet_or_javascript?
  stylesheet? || javascript?
end

#text_or_javascript?Boolean

Returns:

  • (Boolean)


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

def text_or_javascript?
  text_type? || javascript?
end

#text_type?Boolean

Returns:

  • (Boolean)


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

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

#urlObject



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

def url
  file.url
end