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.19.8 app/components/coco/images/svg/svg.rb
coveragebook_components-0.19.7 app/components/coco/images/svg/svg.rb
coveragebook_components-0.19.6 app/components/coco/images/svg/svg.rb
coveragebook_components-0.19.5 app/components/coco/images/svg/svg.rb
coveragebook_components-0.19.4 app/components/coco/images/svg/svg.rb
coveragebook_components-0.19.3 app/components/coco/images/svg/svg.rb
coveragebook_components-0.19.2 app/components/coco/images/svg/svg.rb
coveragebook_components-0.19.1 app/components/coco/images/svg/svg.rb
coveragebook_components-0.19.0 app/components/coco/images/svg/svg.rb
coveragebook_components-0.18.8 app/components/coco/images/svg/svg.rb
coveragebook_components-0.18.7 app/components/coco/images/svg/svg.rb
coveragebook_components-0.18.0 app/components/coco/images/svg/svg.rb
coveragebook_components-0.17.7 app/components/coco/images/svg/svg.rb
coveragebook_components-0.17.6 app/components/coco/images/svg/svg.rb
coveragebook_components-0.17.5 app/components/coco/images/svg/svg.rb
coveragebook_components-0.17.4 app/components/coco/images/svg/svg.rb
coveragebook_components-0.17.3 app/components/coco/images/svg/svg.rb
coveragebook_components-0.17.2 app/components/coco/images/svg/svg.rb
coveragebook_components-0.17.1 app/components/coco/images/svg/svg.rb
coveragebook_components-0.17.0 app/components/coco/images/svg/svg.rb