Sha256: 29aef702a44a6c3cb423a262a337186e2dc3f378ff82ae27618d8ebee317660c
Contents?: true
Size: 1.41 KB
Versions: 11
Compression:
Stored size: 1.41 KB
Contents
module Tao module Generators class IconsGenerator < Rails::Generators::Base source_root File.expand_path('../templates', __FILE__) class_option :svg_path, type: :string, default: 'app/assets/icons', desc: "Directory path containing svg source files." attr_reader :icons_html def create_icons_file @icons_html = svg_files.map {|file| " #{symbol(file)}\n"}.join template 'icons.coffee.erb', 'lib/assets/javascripts/tao/icons.coffee' end private def svg_files Dir.glob(File.expand_path(File.join(options[:svg_path], '*.svg'), destination_root)).uniq end def symbol(path) name = File.basename(path, ".*").underscore().dasherize() content = File.read(path) content.gsub(/<?.+\?>/,'') .gsub(/<!.+?>/,'') .gsub(/<title>.*<\/title>/, '') .gsub(/<desc>.*<\/desc>/, '') .gsub(/id=/,'class=') .gsub(/<svg.+?>/, %Q{<svg id="icon-#{name}" #{dimensions(content)}>}) .gsub(/svg/,'symbol') .gsub(/\sfill=".+?"/,'') .gsub(/\n/, '') # Remove endlines .gsub(/\s{2,}/, ' ') # Remove whitespace .gsub(/>\s+</, '><') # Remove whitespace between tags end def dimensions(content) dimension = content.scan(/<svg.+(viewBox=["'](.+?)["'])/).flatten %Q{#{dimension.first} width="100%" height="100%"} end end end end
Version data entries
11 entries across 11 versions & 1 rubygems