Skip to content

Commit

Permalink
command ok and readme updated for ERB support
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomilho committed Apr 17, 2013
1 parent 85b5d92 commit 24f18bd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

## HTML2Slim

Script for converting HTML (or sHTML) files to slim (slim-lang.org).
Script for converting HTML and ERB files to slim (slim-lang.org).

It's not perfect, but certainly it helps a lot!

It's based on Hpricot. Yeah, I'm old school.

## Usage

You may convert files using the included executable `html2slim`.
You may convert files using the included executables `html2slim` and `erb2slim`.

# html2slim -h

Expand All @@ -22,7 +22,15 @@ You may convert files using the included executable `html2slim`.
-h, --help Show this message
-v, --version Print version

Alternatively, to convert files or strings on the fly in your application, you may do so by calling `HTML2Slim.convert!`.
# erb2slim -h

Usage: erb2slim INPUT_FILENAME_OR_DIRECTORY [OUTPUT_FILENAME_OR_DIRECTORY] [options]
--trace Show a full traceback on error
-d, --delete Delete ERB files
-h, --help Show this message
-v, --version Print version

Alternatively, to convert files or strings on the fly in your application, you may do so by calling `HTML2Slim.convert!(file, format)` where format is either :html or :erb.

## License

Expand All @@ -38,6 +46,6 @@ https://github.com/slim-template/html2slim

## ROADMAP

1. Improve minitests
2. ERB support, I guess...
1. ERB support is pre-alpha, and works only for 90% of the cases. Lotsa weird regexes. Gotta improve that.
2. Use temple.
3. Merge with other *2slim gems. Would be handy.
17 changes: 13 additions & 4 deletions lib/html2slim/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

module HTML2Slim
class Command

def initialize(args)
@args = args
@options = {}
Expand All @@ -23,8 +24,16 @@ def run

protected

def format
@format ||= (self.class.to_s =~ /ERB/ ? :erb : :html)
end

def command_name
@command_name ||= format == :html ? "html2slim" : "erb2slim"
end

def set_opts(opts)
opts.banner = "Usage: html2slim INPUT_FILENAME_OR_DIRECTORY [OUTPUT_FILENAME_OR_DIRECTORY] [options]"
opts.banner = "Usage: #{command_name} INPUT_FILENAME_OR_DIRECTORY [OUTPUT_FILENAME_OR_DIRECTORY] [options]"

opts.on('--trace', :NONE, 'Show a full traceback on error') do
@options[:trace] = true
Expand All @@ -36,11 +45,11 @@ def set_opts(opts)
end

opts.on_tail('-v', '--version', 'Print version') do
puts "html2slim #{HTML2Slim::VERSION}"
puts "#{command_name} #{HTML2Slim::VERSION}"
exit
end

opts.on('-d', '--delete', 'Delete HTML files') do
opts.on('-d', '--delete', "Delete #{format.upcase} files") do
@options[:delete] = true
end
end
Expand Down Expand Up @@ -81,7 +90,7 @@ def _process(file, destination = nil)

@options[:output] = slim_file && slim_file != '-' ? File.open(slim_file, 'w') : $stdout
# raise "|||#{self.class.inspect}|||"
@options[:output].puts HTML2Slim.convert!(in_file, (self.class.to_s =~ /ERB/ ? :erb : :html))
@options[:output].puts HTML2Slim.convert!(in_file, format)
@options[:output].close

File.delete(file) if @options[:delete]
Expand Down

0 comments on commit 24f18bd

Please sign in to comment.