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.8.4 app/components/coco/base/svg/svg.rb
coveragebook_components-0.8.3 app/components/coco/base/svg/svg.rb
coveragebook_components-0.8.2 app/components/coco/base/svg/svg.rb
coveragebook_components-0.8.1 app/components/coco/base/svg/svg.rb
coveragebook_components-0.8.0 app/components/coco/base/svg/svg.rb
coveragebook_components-0.8.0.beta.3 app/components/coco/base/svg/svg.rb
coveragebook_components-0.8.0.beta.2 app/components/coco/base/svg/svg.rb
coveragebook_components-0.8.0.beta.1 app/components/coco/base/svg/svg.rb
coveragebook_components-0.7.10 app/components/coco/base/svg/svg.rb
coveragebook_components-0.7.9 app/components/coco/base/svg/svg.rb
coveragebook_components-0.7.8 app/components/coco/base/svg/svg.rb
coveragebook_components-0.7.7 app/components/coco/base/svg/svg.rb
coveragebook_components-0.7.6 app/components/coco/base/svg/svg.rb
coveragebook_components-0.7.5 app/components/coco/base/svg/svg.rb
coveragebook_components-0.7.4 app/components/coco/base/svg/svg.rb
coveragebook_components-0.7.3 app/components/coco/base/svg/svg.rb
coveragebook_components-0.7.2 app/components/coco/base/svg/svg.rb
coveragebook_components-0.7.1 app/components/coco/base/svg/svg.rb
coveragebook_components-0.7.0 app/components/coco/base/svg/svg.rb
coveragebook_components-0.6.5 app/components/coco/base/svg/svg.rb