-
Notifications
You must be signed in to change notification settings - Fork 0
/
Generate CSS.tmCommand
72 lines (64 loc) · 1.83 KB
/
Generate CSS.tmCommand
1
2
3
4
5
6
7
8
9
10
11
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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>saveActiveFile</string>
<key>command</key>
<string>#!/usr/bin/env ruby
require 'rubygems'
require 'sass'
@errors = []
Dir.chdir(ENV['TM_DIRECTORY'])
i = 1
until Dir.getwd.match(/sass\/?$/) do
if (i > 4) or (Dir.getwd == ENV['TM_PROJECT_DIRECTORY'])
puts "Can't find sass dir!"
exit
end
Dir.chdir('../')
i += 1
end
puts "Sass dir = #{Dir.getwd}"
sass_files = Dir.open('.') do |d|
d.find_all { |f| f.match /\.sass$/ }
end
sass_files.each do |sass|
css = '../' + sass.gsub(/\.sass$/, '.css')
puts "Sassifying #{sass}..."
sass_file = File.new(sass, 'r')
sass_template = sass_file.read
sass_file.close
sass_engine = Sass::Engine.new(sass_template)
begin
css_file = File.new(css, 'w')
css_file.write("/* ---------------------------------------- */\n")
css_file.write("/* THIS FILE IS AUTOMATICALLY GENERATED */\n")
css_file.write("/* CHANGES SHOULD BE MADE IN THE SASS FILES */\n")
css_file.write("/* ---------------------------------------- */\n\n\n")
css_file.write(sass_engine.render)
rescue Sass::SyntaxError => e
@errors << { :file => sass, :e => e }
ensure
css_file.close
end
end
unless @errors.empty?
puts "\nERRORS were encountered!!"
@errors.each { |err| puts "#{err[:file]}, Line #{err[:e].sass_line}: #{err[:e]}" }
end
</string>
<key>input</key>
<string>none</string>
<key>keyEquivalent</key>
<string>@r</string>
<key>name</key>
<string>Generate CSS</string>
<key>output</key>
<string>showAsTooltip</string>
<key>scope</key>
<string>source.sass</string>
<key>uuid</key>
<string>6FA7B052-B6F0-451C-8884-5537DE49CA7F</string>
</dict>
</plist>