Class: Mayu::Resources::Types::SVG

Inherits:
Base
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/mayu/resources/types/svg.rb

Constant Summary collapse

MarshalFormat =
T.type_alias { [String, String] }

Instance Method Summary collapse

Methods inherited from Base

#generate_assets, #name

Constructor Details

#initialize(resource) ⇒ SVG

Returns a new instance of SVG.



13
14
15
16
17
18
19
20
21
22
# File 'lib/mayu/resources/types/svg.rb', line 13

def initialize(resource)
  @resource = resource

  source = resource.read(encoding: "utf-8")

  content_hash = Base64.urlsafe_encode64(Digest::SHA256.digest(source))

  @filename = T.let("#{content_hash}.svg", String)
  @source = T.let(source, String)
end

Instance Method Details

#assetsObject



25
26
27
28
29
30
31
32
# File 'lib/mayu/resources/types/svg.rb', line 25

def assets
  [
    Asset.new(
      @filename,
      Generators::WriteFile.new(contents: @source, compress: true)
    )
  ]
end

#marshal_dumpObject



43
44
45
# File 'lib/mayu/resources/types/svg.rb', line 43

def marshal_dump
  [@source, @filename]
end

#marshal_load(args) ⇒ Object



48
49
50
# File 'lib/mayu/resources/types/svg.rb', line 48

def marshal_load(args)
  @source, @filename = args
end

#srcObject



38
# File 'lib/mayu/resources/types/svg.rb', line 38

def src = "/__mayu/static/#{@filename}"

#to_sObject



35
# File 'lib/mayu/resources/types/svg.rb', line 35

def to_s = src