From 0b971624e8938c3365f2c265ba667b9244a59ee8 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Sat, 24 Oct 2015 02:16:35 +0900 Subject: [PATCH] Use pretty mode by default in CLI --- lib/hamlit/cli.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/hamlit/cli.rb b/lib/hamlit/cli.rb index 3c049e50..7a31f77d 100644 --- a/lib/hamlit/cli.rb +++ b/lib/hamlit/cli.rb @@ -3,6 +3,8 @@ require 'thor' module Hamlit class CLI < Thor + class_option :style, type: :string, aliases: ['-t'], default: 'pretty' + desc 'render HAML', 'Render haml template' def render(file) code = generate_code(file) @@ -23,7 +25,7 @@ module Hamlit def generate_code(file) template = File.read(file) - Hamlit::Engine.new.call(template) + Hamlit::Engine.new(engine_options).call(template) end def generate_ast(file) @@ -31,6 +33,10 @@ module Hamlit Hamlit::Parser.new.call(template) end + def engine_options + { pretty: options['style'] == 'pretty' } + end + # Flexible default_task, compatible with haml's CLI def method_missing(*args) return super(*args) if args.length > 1