Sha256: 629f45189c1818e18302de8b36077c72f67e838bfc0d385bcc2516c5d600ea26

Contents?: true

Size: 878 Bytes

Versions: 4

Compression:

Stored size: 878 Bytes

Contents

#!/usr/bin/env ruby

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

options = {}

OptionParser.new do |opts|
  opts.banner = "Usage: #{$PROGRAM_NAME} [options]"

  opts.on("-i INPUT", "--input=INPUT", "Input in the template language") 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") 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

4 entries across 4 versions & 1 rubygems

Version Path
template-ruby-0.2.3 bin/template
template-ruby-0.2.2 bin/template
template-ruby-0.2.1 bin/template
template-ruby-0.2.0 bin/template