Module: Erb4slim
- Defined in:
- lib/erb4slim.rb
Class Method Summary collapse
- ._normalize_path(path) ⇒ Object
- .all(path, delete = false) ⇒ Object
- .convert(input_file, delete = false) ⇒ Object
- .recursive(path, delete = false) ⇒ Object
Class Method Details
._normalize_path(path) ⇒ Object
40 41 42 |
# File 'lib/erb4slim.rb', line 40 def self._normalize_path(path) path.gsub(/\/$/, '') end |
.all(path, delete = false) ⇒ Object
35 36 37 38 |
# File 'lib/erb4slim.rb', line 35 def self.all(path, delete = false) path = _normalize_path(path) Dir.glob("#{path}/*.html.erb") { |file| convert(file, delete) } end |
.convert(input_file, delete = false) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/erb4slim.rb', line 5 def self.convert(input_file, delete = false) extension = File.extname(input_file) basename = File.basename(input_file, extension) full_name = File.join(File.dirname(input_file), basename) if extension != '.erb' puts 'Incorrect file type ! It should be filename.erb' return end result = system("html2haml #{input_file} #{full_name}.haml && haml2slim #{full_name}.haml") if result.nil? puts "Error during conversion: #{$?}" else # First clean the temporary haml file File.delete("#{full_name}.haml") if File.exist?("#{full_name}.haml") puts "File #{full_name}.slim has been successfully created" # Remove the input file if needed if delete File.delete(input_file) puts "File #{input_file} has been removed" end end end |
.recursive(path, delete = false) ⇒ Object
30 31 32 33 |
# File 'lib/erb4slim.rb', line 30 def self.recursive(path, delete = false) path = _normalize_path(path) Dir.glob("#{path}/**/*.html.erb") { |file| convert(file, delete) } end |