Sha256: b00d9d8135b15e63ecff8e55a472c41974f0ca05782c1908a232d223d86347a1

Contents?: true

Size: 585 Bytes

Versions: 66

Compression:

Stored size: 585 Bytes

Contents

module Coco
  class Svg < Coco::Component
    SVG_CACHE = {}

    InvalidSvgError = Class.new(StandardError)

    attr_reader :path

    def initialize(path: nil, **kwargs)
      @path = path.gsub(".svg", "")
    end

    def svg
      SVG_CACHE[path] ||= read_svg
    end

    def read_svg
      File.read(full_path).html_safe
    rescue
      if Rails.env.development? || Rails.env.test?
        raise InvalidSvgError, "The SVG `#{full_path}` was not found"
      end
    end

    def full_path
      Coco::Engine.root.join("app/assets/build/coco/img/#{path}.svg")
    end
  end
end

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
coveragebook_components-0.16.0 app/components/coco/images/svg/svg.rb
coveragebook_components-0.15.0 app/components/coco/images/svg/svg.rb
coveragebook_components-0.14.0 app/components/coco/images/svg/svg.rb
coveragebook_components-0.13.1 app/components/coco/images/svg/svg.rb
coveragebook_components-0.13.0 app/components/coco/images/svg/svg.rb
coveragebook_components-0.12.2 app/components/coco/shared/svg/svg.rb
coveragebook_components-0.12.1 app/components/coco/shared/svg/svg.rb
coveragebook_components-0.12.0 app/components/coco/shared/svg/svg.rb
coveragebook_components-0.11.0 app/components/coco/shared/svg/svg.rb
coveragebook_components-0.10.1.beta.2 app/components/coco/shared/svg/svg.rb
coveragebook_components-0.10.1.beta.1 app/components/coco/shared/svg/svg.rb
coveragebook_components-0.10.1.beta.0 app/components/coco/shared/svg/svg.rb
coveragebook_components-0.10.0 app/components/coco/base/svg/svg.rb
coveragebook_components-0.9.1 app/components/coco/base/svg/svg.rb
coveragebook_components-0.9.0 app/components/coco/base/svg/svg.rb
coveragebook_components-0.8.9 app/components/coco/base/svg/svg.rb
coveragebook_components-0.8.8 app/components/coco/base/svg/svg.rb
coveragebook_components-0.8.7 app/components/coco/base/svg/svg.rb
coveragebook_components-0.8.6 app/components/coco/base/svg/svg.rb
coveragebook_components-0.8.5 app/components/coco/base/svg/svg.rb