Module: IcomoonAsWell::FileHelper

Included in:
Icomoon
Defined in:
lib/icomoon_as_well/file_helper.rb

Instance Method Summary collapse

Instance Method Details

#icomoon_dir(target_dir) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/icomoon_as_well/file_helper.rb', line 33

def icomoon_dir(target_dir)
  unless Dir.exists?("#{target_dir}/stylesheets")
    FileUtils.mkpath(File.join(target_dir, "stylesheets"))
  end
  unless Dir.exists?("#{target_dir}/stylesheets/icomoon")
    FileUtils.mkpath(File.join(target_dir, "stylesheets", "icomoon"))
  end
  "#{target_dir}/stylesheets/icomoon"
end

#parse_css(file) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/icomoon_as_well/file_helper.rb', line 5

def parse_css(file)
  icons = {}
  c = 0
  lines = file.split("\n")
  while c <= lines.count
    line = lines[c]
    c += 1
    if line.to_s =~ /^\.icon-(\S+):before\s*{\s*$/
      icon_name = $1
      value = lines[c]
      c += 1
      icon_name.gsub!(/\s+/, '')
      value.gsub!(/^\s+/, '').gsub!(/content:/, '').gsub!(/["'\\\s\;]+/, '')
      icons[icon_name] = value
    end
  end
  icons
end

#put_files(entry, names, target_dir) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/icomoon_as_well/file_helper.rb', line 23

def put_files(entry, names, target_dir)
  unless Dir.exist?(target_dir)
    FileUtils.mkpath(target_dir)
  end
  names.each do |name|
    filename = name.gsub(/^.+\//, '')
    File.open(File.join(target_dir, filename), "w"){ |file| file.write(entry[name]) }
  end
end