mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Create hamlit CLI
This commit is contained in:
parent
8f6436ca9f
commit
40048687b3
3 changed files with 32 additions and 0 deletions
6
exe/hamlit
Executable file
6
exe/hamlit
Executable file
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
$:.unshift File.expand_path('../lib', __FILE__)
|
||||
require 'hamlit/cli'
|
||||
|
||||
Hamlit::CLI.start(ARGV)
|
|
@ -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
25
lib/hamlit/cli.rb
Normal 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
|
Loading…
Add table
Reference in a new issue