Sha256: 0f7c0ea0b60d943d75219c40b16460458dedbdd100d3ceb3b339b9af3a3e4a88
Contents?: true
Size: 1.73 KB
Versions: 7
Compression:
Stored size: 1.73 KB
Contents
require "fileutils" require "esvg/version" require "esvg/utils" require "esvg/svgs" require "esvg/svg" if defined?(Rails) require "esvg/helpers" require "esvg/railties" end module Esvg extend self def new(options={}) @svgs ||=[] @svgs << Svgs.new(options) @svgs.last end def svgs @svgs end def use(name, options={}) if symbol = find_symbol(name, options) html_safe symbol.use options end end def use_tag(name, options={}) if symbol = find_symbol(name, options) html_safe symbol.use_tag options end end def embed(names=nil) html_safe find_svgs(names).map{|s| s.embed_script(names) }.join end def build_paths(names=nil) find_svgs(names).map{|s| s.build_paths(names) }.flatten end def find_svgs(names=nil) @svgs.select {|s| s.buildable_svgs(names) } end def find_symbol(name, options={}) if group = @svgs.find {|s| s.find_symbol(name, options[:fallback]) } group.find_symbol(name, options[:fallback]) end end def rails? defined?(Rails) end def html_safe(input) input = input.html_safe if rails? input end def precompile_assets if rails? && defined?(Rake) ::Rake::Task['assets:precompile'].enhance do Svgs.new(gzip: true, print: true).build end end end # Determine if an NPM module is installed by checking paths with `npm bin` # Returns path to binary if installed def node_module(cmd) @modules ||={} return @modules[cmd] if !@modules[cmd].nil? local = "$(npm bin)/#{cmd}" global = "$(npm -g bin)/#{cmd}" @modules[cmd] = if Open3.capture3(local)[2].success? local elsif Open3.capture3(global)[2].success? global else false end end end
Version data entries
7 entries across 7 versions & 1 rubygems
Version | Path |
---|---|
esvg-4.3.5 | lib/esvg.rb |
esvg-4.3.4 | lib/esvg.rb |
esvg-4.3.3 | lib/esvg.rb |
esvg-4.3.2 | lib/esvg.rb |
esvg-4.3.1 | lib/esvg.rb |
esvg-4.3.0 | lib/esvg.rb |
esvg-4.2.5 | lib/esvg.rb |