module Erb4slim
Public Class Methods
_normalize_path(path)
click to toggle source
# File lib/erb4slim.rb, line 40 def self._normalize_path(path) path.gsub(/\/$/, '') end
all(path, delete = false)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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