Sha256: 63b13728dab1220d2e1a538bf1c340c4778064ee988edbb7f41b8ade751324e5

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 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)
      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

1 entries across 1 versions & 1 rubygems

Version Path
inline_svg-1.2.2 lib/inline_svg/transform_pipeline/transformations/transformation.rb