class DragonflySvg::Plugin

Public Instance Methods

call(app, options = {}) click to toggle source
# File lib/dragonfly_svg/plugin.rb, line 14
def call(app, options = {})
  # Analysers
  app.add_analyser :svg_properties, Analysers::SvgProperties.new

  %w[ format
      width
      height
      id
  ].each do |name|
    app.add_analyser(name) { |c| c.analyse(:svg_properties)[name] }
  end

  app.add_analyser(:aspect_ratio) { |c| c.analyse(:width).to_f / c.analyse(:height).to_f }
  app.add_analyser(:portrait) { |c| c.analyse(:aspect_ratio) < 1.0 }
  app.add_analyser(:landscape) { |c| !c.analyse(:portrait) }

  # Aliases
  app.define(:portrait?) { portrait }
  app.define(:landscape?) { landscape }

  # Processors
  app.add_processor :extend_ids, Processors::ExtendIds.new
  app.add_processor :remove_namespaces, Processors::RemoveNamespaces.new
  app.add_processor :set_attribute, Processors::SetAttribute.new
  app.add_processor :set_dimensions, Processors::SetDimensions.new
  app.add_processor :set_namespace, Processors::SetNamespace.new
  app.add_processor :set_preserve_aspect_ratio, Processors::SetPreserveAspectRatio.new
  app.add_processor :set_tag_value, Processors::SetTagValue.new
  app.add_processor :set_view_box, Processors::SetViewBox.new
end