Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

command ok and readme updated for ERB support

  • Loading branch information...
commit 24f18bdaec6bf5f1519c4958a97e8c03669e537b 1 parent 85b5d92
Juan Maiz authored
Showing with 26 additions and 9 deletions.
  1. +13 −5 README.md
  2. +13 −4 lib/html2slim/command.rb
View
18 README.md
@@ -4,7 +4,7 @@
## 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!
@@ -12,7 +12,7 @@ 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
@@ -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
@@ -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.
View
17 lib/html2slim/command.rb
@@ -3,6 +3,7 @@
module HTML2Slim
class Command
+
def initialize(args)
@args = args
@options = {}
@@ -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
@@ -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
@@ -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]
Please sign in to comment.
Something went wrong with that request. Please try again.