Sha256: 99cb3f9cf1f3faab9c167f90776455563767907088ac907c32b4943229dec066

Contents?: true

Size: 1.05 KB

Versions: 6

Compression:

Stored size: 1.05 KB

Contents

#!/usr/bin/env ruby

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

options = { timeout: 0 }

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

  opts.on("-t TIMEOUT", "--timeout=TIMEOUT", "Set timeout in seconds") do |timeout|
    options[:timeout] = timeout.to_f
  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, timeout: options[:timeout])
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
template-ruby-0.4.0 bin/template
code-ruby-0.4.0 bin/template
template-ruby-0.3.1 bin/template
code-ruby-0.3.1 bin/template
template-ruby-0.3.0 bin/template
code-ruby-0.3.0 bin/template