Create hamlit CLI

This commit is contained in:
Takashi Kokubun 2015-10-07 21:08:56 +09:00
parent 8f6436ca9f
commit 40048687b3
3 changed files with 32 additions and 0 deletions

6
exe/hamlit Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env ruby
$:.unshift File.expand_path('../lib', __FILE__)
require 'hamlit/cli'
Hamlit::CLI.start(ARGV)

View File

@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'bundler', '~> 1.10'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'thor', '~> 0.19'
end

25
lib/hamlit/cli.rb Normal file
View File

@ -0,0 +1,25 @@
require 'hamlit'
require 'thor'
module Hamlit
class CLI < Thor
desc 'render HAML', 'Render haml template'
def render(file)
code = generate_code(file)
puts eval(code)
end
private
# Flexible default_task, compatible with haml's CLI
def method_missing(*args)
return super(*args) if args.length > 1
render(args.first.to_s)
end
def generate_code(file)
template = File.read(file)
Hamlit::Engine.new.call(template)
end
end
end