Skip to content

Commit

Permalink
added option for html to be converted
Browse files Browse the repository at this point in the history
  • Loading branch information
t2 committed Dec 18, 2011
1 parent 0e85cb1 commit 82c521f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions rails/hamlr.thor
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'find'
require 'open3'
require 'rubygems'
begin
require 'haml'
Expand All @@ -16,18 +15,24 @@ end
class Hamlr < Thor::Group
include Thor::Actions

argument :delete, :default => true, :desc => "Delete the original erb files?"
class_option :delete, :default => true, :aliases => "-d", :type => :boolean, :desc => "Delete the original erb files?"
class_option :html, :default => true, :aliases => "-h", :type => :boolean, :desc => "Convert HTML as well?"

desc "convert all html/erb views in your project to haml"

def convert
branch_project

exts = [".erb", ".html"]
exts.delete(".html") unless options[:html]

Find.find(destination_root) do |f|
if File.extname(f).eql?(".erb")
ext = File.extname(f)
if exts.include? ext
begin
haml = Haml::Exec::HTML2Haml.new(["-r", "#{f}", "#{f.gsub(/\.erb$/, '.haml')}"])
haml = Haml::Exec::HTML2Haml.new(["-r", "#{f}", "#{f.gsub(/#{ext}$/, '.haml')}"])
haml.parse
remove_file(f) if delete
remove_file(f) if options[:delete]
rescue Exception => e
puts "Oh snap! Error: #{e.message}"
end
Expand All @@ -44,7 +49,6 @@ private
def branch_project
if using_git?
begin
`git checkout master`

This comment has been minimized.

Copy link
@t2

t2 Dec 20, 2011

Author Owner

No need to checkout master.

`git branch -D hamlr` if File.file?("#{destination_root}/.git/refs/heads/hamlr")
`git checkout -b hamlr`
rescue Exception => e
Expand Down

0 comments on commit 82c521f

Please sign in to comment.