Module: Icomoon2Sass

Defined in:
lib/icomoon2sass.rb,
lib/icomoon2sass/version.rb,
lib/icomoon2sass/utilities.rb

Defined Under Namespace

Classes: Archive, CLI, Dir, Font, Sass, Utilities, Zip

Constant Summary collapse

VERSION =
'1.0.6'

Class Method Summary collapse

Class Method Details

.run!(source, font_path, sass_path, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/icomoon2sass.rb', line 12

def self.run!(source, font_path, sass_path, options = {})
  defaults = {
    scss: false,
    compatible: false,
    oocss: false,
    demo_path: options[:"demo-path"],
    session_path: options[:"session-path"]
  }

  options = defaults.merge options.symbolize_keys

  utilities = Icomoon2Sass::Utilities.new

  if source.end_with? '.zip'
    files = Icomoon2Sass::Zip.new source

  elsif ::Dir.exists? source
    files = Icomoon2Sass::Dir.new source

  else
    raise 'Source must be either a directory or .zip file!'

  end

  raise 'Source must contain \'selection.json\'.' unless files.files['selection.json']

  font = Icomoon2Sass::Font.new files.

  syntax = options[:scss] ? 'scss' : 'sass'

  compatible = options[:compatible] || false

  sass = Icomoon2Sass::Sass.new font, syntax, compatible


  # Save the Sass file
  utilities.create_file "#{sass_path}/_icons.#{sass.syntax}", sass.code

  if options[:oocss]
    utilities.create_file "#{sass_path}/_oocss_icons.#{sass.syntax}", sass.oocss
  end

  files.font_files.each do |filename, content|
    utilities.create_file "#{font_path}/#{filename.sub('fonts/', '')}", content
  end

  if options[:demo_path]
    files.demo_files.each do |filename, content|
      utilities.create_file "#{options[:demo_path]}/#{filename}", content
    end

    files.font_files.each do |filename, content|
      utilities.create_file "#{options[:demo_path]}/demo-files/fonts/#{filename.sub('fonts/', '')}", content
    end

    utilities.gsub_file "#{options[:demo_path]}/demo.html", /href="style.css">/, 'href="demo-files/style.css">'
  end

  if options[:session_path]
    utilities.create_file "#{options[:session_path]}/session.json", files.session_file
  end
end