Class: CSSSortor
- Inherits:
-
Object
- Object
- CSSSortor
- 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
- #check_exist(path) ⇒ Object
- #create_file(path) ⇒ Object
-
#initialize(options) ⇒ CSSSortor
constructor
A new instance of CSSSortor.
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() @parser = CssParser::Parser.new({:sort_mode => [:order]}) @parser.load_file!([:path]) # output file = File.([:path]) file_name = File.basename(file, ".css") f_path = File.dirname(file) target_name = [: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.(path, __FILE__), 'w') { |f| f.puts @parser.to_s } end |