Sha256: e06cd33a52eeac4a93bae739e5444e2ebea0ca2afa4a9b1ffa0302c59036a95b

Contents?: true

Size: 842 Bytes

Versions: 8

Compression:

Stored size: 842 Bytes

Contents

require 'action_view/helpers' if defined?(Rails)
require 'action_view/context' if defined?(Rails)

module InlineSvg
  module ActionView
    module Helpers
      def inline_svg(filename, transform_params={})
        begin
          svg_file = if InlineSvg::IOResource === filename
            InlineSvg::IOResource.read filename
          else
            InlineSvg::AssetFile.named filename
          end
        rescue InlineSvg::AssetFile::FileNotFound
          return "<svg><!-- SVG file not found: '#{filename}' #{extension_hint(filename)}--></svg>".html_safe
        end

        InlineSvg::TransformPipeline.generate_html_from(svg_file, transform_params).html_safe
      end

      private

      def extension_hint(filename)
        filename.ends_with?(".svg") ? "" : "(Try adding .svg to your filename) "
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
inline_svg-1.0.1 lib/inline_svg/action_view/helpers.rb
inline_svg-1.0.0 lib/inline_svg/action_view/helpers.rb
inline_svg-0.12.1 lib/inline_svg/action_view/helpers.rb
inline_svg-0.12.0 lib/inline_svg/action_view/helpers.rb
inline_svg-0.11.1 lib/inline_svg/action_view/helpers.rb
inline_svg-0.11.0 lib/inline_svg/action_view/helpers.rb
inline_svg-0.10.0 lib/inline_svg/action_view/helpers.rb
inline_svg-0.9.1 lib/inline_svg/action_view/helpers.rb