Class: CSSSortor

Inherits:
Object
  • Object
show all
Defined in:
lib/css_sortor.rb

Overview

Add requires for other files you add to your project here, so you just need to require this one file in your bin file

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ CSSSortor

Returns a new instance of CSSSortor.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/css_sortor.rb', line 9

def initialize(options)
	@parser = CssParser::Parser.new({:sort_mode => options[:order]})
	@parser.load_file!(options[:path])
	# output

	file = File.expand_path(options[:path])
	file_name = File.basename(file, ".css")
	f_path = File.dirname(file)
	target_name = options[:target] || file_name+'_output.css'

	if check_exist(f_path + '/' +target_name) then
		raise "#{target_name} is exist now, You can not cover this file."
		return
	end

	create_file(f_path + '/' +target_name)
	puts 'Generate has been successfully.'
end

Instance Method Details

#check_exist(path) ⇒ Object



28
29
30
# File 'lib/css_sortor.rb', line 28

def check_exist(path)
	Dir.glob(path).length > 0
end

#create_file(path) ⇒ Object



32
33
34
35
36
# File 'lib/css_sortor.rb', line 32

def create_file(path)
	open(File.expand_path(path, __FILE__), 'w') { |f|
     f.puts @parser.to_s
   }
end