class Myhtml2haml::Myhtml2haml

Public Instance Methods

allowed?() click to toggle source
# File lib/myhtml2haml.rb, line 27
def allowed?
  say "Location: #{Dir.pwd}"
  yes?("Are you sure? This action can't be undone")
end
closing_status() click to toggle source
# File lib/myhtml2haml.rb, line 58
def closing_status
  say 'Files Converted:'
  @file_counts.each {|key, value| say "#{key}: #{value}"}
end
convert() click to toggle source
# File lib/myhtml2haml.rb, line 77
def convert
  warning if options[:obliviate]

  files = Dir["**/*#{options[:pattern]}"]
  @file_counts = {total: files.size, converted: 0}
  files.each {|file| convert_file(file)}
  closing_status
end
convert_file(file) click to toggle source
# File lib/myhtml2haml.rb, line 49
def convert_file(file)
  file_status(file)
  unless File.directory?(file)
    Html2haml::Exec::HTML2Haml.new([file, formatted_output(file)]).parse
    @file_counts[:converted] += 1
    delete_file(file) if options[:obliviate]
  end
end
delete_file(file) click to toggle source
# File lib/myhtml2haml.rb, line 11
def delete_file(file)
  File.delete file
end
directory_name(file) click to toggle source
# File lib/myhtml2haml.rb, line 41
def directory_name(file)
  File.basename(File.dirname(file))
end
exit_app() click to toggle source
# File lib/myhtml2haml.rb, line 23
def exit_app
  abort('Aborting...')
end
file_name(file) click to toggle source
# File lib/myhtml2haml.rb, line 45
def file_name(file)
  File.basename(file.split(/\./).first)
end
file_status(file) click to toggle source
# File lib/myhtml2haml.rb, line 15
def file_status(file)
  say "Converting: #{file}"
end
formatted_output(file) click to toggle source
# File lib/myhtml2haml.rb, line 32
def formatted_output(file)
  name = ""
  name << "#{directory_name(file)}/"
  name << "#{directory_name(file)}_" if options[:dir_prefix]
  name << "#{file_name(file)}.html.haml"
  name+=".dup" if File.exist?(name)
  name
end
reset() click to toggle source
# File lib/myhtml2haml.rb, line 87
def reset
  warning
  files = Dir['**/*.haml']
  files.each {|file| File.delete file}
  say "Files deleted: #{files.size}"
end
warning() click to toggle source
# File lib/myhtml2haml.rb, line 19
def warning
  exit_app unless allowed?
end