module Esvg::Utils

Public Instance Methods

attributes(hash) click to toggle source
# File lib/esvg/utils.rb, line 11
def attributes(hash)
  att = []
  hash.each do |key, value|
    att << %Q{#{key.to_s.gsub(/_/,'-')}="#{value}"} unless value.nil?
  end
  att.join(' ')
end
compress(file) click to toggle source
# File lib/esvg/utils.rb, line 27
def compress(file)
  mtime = File.mtime(file)
  gz_file = "#{file}.gz"

  return if (File.exist?(gz_file) && File.mtime(gz_file) >= mtime)

  File.open(gz_file, "wb") do |dest|
    gz = ::Zlib::GzipWriter.new(dest, Zlib::BEST_COMPRESSION)
    gz.mtime = mtime.to_i
    IO.copy_stream(open(file), gz)
    gz.close
  end

  File.utime(mtime, mtime, gz_file)

  gz_file
end
dasherize(input) click to toggle source
# File lib/esvg/utils.rb, line 3
def dasherize(input)
  Esvg.dasherize(input)
end
sort(hash) click to toggle source
# File lib/esvg/utils.rb, line 19
def sort(hash)
  sorted = {}
  hash.sort.each do |h|
    sorted[h.first] = h.last
  end
  sorted
end
sub_path(root, path) click to toggle source
# File lib/esvg/utils.rb, line 7
def sub_path(root, path)
  path.sub(File.join(root,''),'')
end