Sha256: 77f045d46646cb35eebf8497b4fddae09bb9f35c46b03f05f4aac419b7a00070

Contents?: true

Size: 904 Bytes

Versions: 2

Compression:

Stored size: 904 Bytes

Contents

#!/usr/bin/env ruby

require "optparse"
require_relative "../lib/template-ruby"

options = {}

OptionParser.new do |opts|
  opts.banner = "Usage: template [options]"

  opts.on("-i INPUT", "--input=INPUT", "Input in the template language (String or File)") do |input|
    if File.exists?(input)
      input = File.read(input)
    end

    options[:input] = input
  end

  opts.on("-c CONTEXT", "--context=CONTEXT", "Context in the code language (String or File)") do |context|
    if File.exists?(context)
      context = File.read(context)
    end

    options[:context] = context
  end

  opts.on("-p", "--parse", "Get parser results for input") do |parse|
    options[:parse] = parse
  end
end.parse!

input = options.fetch(:input, "")
context = options.fetch(:context, "")

if options[:parse]
  pp ::Template::Parser::Template.new.parse(input)
else
  Template.render(input, context, io: $stdout)
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
code-ruby-0.2.4 bin/template
template-ruby-0.2.4 bin/template