Sha256: 194685319a96a63f9f264fb94cff7315873147f74157c1f256d42d7cb107a3b4

Contents?: true

Size: 1.12 KB

Versions: 15

Compression:

Stored size: 1.12 KB

Contents

module InlineSvg::TransformPipeline::Transformations
  class Transformation
    def self.create_with_value(value)
      self.new(value)
    end

    attr_reader :value

    def initialize(value)
      @value = value
    end

    def transform(*)
      raise "#transform should be implemented by subclasses of Transformation"
    end

    # Parses a document and yields the contained SVG nodeset to the given block
    # if it exists.
    #
    # Returns a Nokogiri::XML::Document.
    def with_svg(doc)
      doc = Nokogiri::XML::Document.parse(
        doc.to_html(encoding: "UTF-8"), nil, "UTF-8"
      )
      svg = doc.at_css "svg"
      yield svg if svg && block_given?
      doc
    end
  end

  class NullTransformation < Transformation
    def transform(doc)
      doc
    end
  end
end

module InlineSvg
  class CustomTransformation < InlineSvg::TransformPipeline::Transformations::Transformation
    # Inherit from this class to keep custom transformation class definitions short
    # E.g.
    # class MyTransform < InlineSvg::CustomTransformation
    #   def transform(doc)
    #     # Your code here...
    #   end
    # end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
inline_svg-1.10.0 lib/inline_svg/transform_pipeline/transformations/transformation.rb
inline_svg-1.9.0 lib/inline_svg/transform_pipeline/transformations/transformation.rb
inline_svg-1.8.0 lib/inline_svg/transform_pipeline/transformations/transformation.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/inline_svg-1.7.2/lib/inline_svg/transform_pipeline/transformations/transformation.rb
inline_svg-1.7.2 lib/inline_svg/transform_pipeline/transformations/transformation.rb
inline_svg-1.7.1 lib/inline_svg/transform_pipeline/transformations/transformation.rb
inline_svg-1.7.0 lib/inline_svg/transform_pipeline/transformations/transformation.rb
inline_svg-1.6.0 lib/inline_svg/transform_pipeline/transformations/transformation.rb
inline_svg-1.5.2 lib/inline_svg/transform_pipeline/transformations/transformation.rb
inline_svg-1.5.1 lib/inline_svg/transform_pipeline/transformations/transformation.rb
inline_svg-1.5.0 lib/inline_svg/transform_pipeline/transformations/transformation.rb
inline_svg-1.4.0 lib/inline_svg/transform_pipeline/transformations/transformation.rb
inline_svg-1.3.1 lib/inline_svg/transform_pipeline/transformations/transformation.rb
inline_svg-1.3.0 lib/inline_svg/transform_pipeline/transformations/transformation.rb
inline_svg-1.2.3 lib/inline_svg/transform_pipeline/transformations/transformation.rb