Module: RERB::CLI
- Defined in:
- lib/rerb/cli.rb
Overview
Command Line Interface for invoking RERB
Class Method Summary collapse
Class Method Details
.parse(args) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rerb/cli.rb', line 11 def parse(args) parser = OptionParser.new do |o| o. = "Usage: werb [options...] FILE" o.on( "--template TYPE", ["umd", "iife", "nil"], "Specify which html template to use to wrap the generated code. " \ "Valid options are umd, iife, and nil.", "nil will use no template and just output raw ruby.wasm code. " \ "Defaults to umd", ) o.on( "--root NAME", "The html id of the root element to add all other DOM nodes to. " \ 'Defaults to "root"', ) o.on("-v", "--version", "Output version information and exit.") end opts = { template: "umd", document: "document", root: "root", el_prefix: "el", } parser.parse!(args, into: opts) filename = args.shift return puts parser.help if filename.nil? input = File.read(filename) case opts[:template] when "umd" res = UMDTemplater.new(filename, opts[:root]) .generate(input) when "iife" res = IIFETemplater.new(filename, opts[:root]) .generate(input) when "nil" res = Templater.new(filename, opts[:root]) .generate(input) else raise "Invalid template option. Choose between umd, iife, nil." end puts res end |