Skip to content

jmptrader/pangaea

 
 

Repository files navigation

pangaea

Powerful pre-processor for text files - powered by JavaScript.

Pangaea works on any kind of text file including HTML pages, source code files, documents, etc. The easy-to-use command line tool lets you effortlessly bake Pangaea into your build process, providing you with an extremely powerful text pre-processor wherever you need it.

How it works

This is just a normal text file that has pangaea scripts embedded, e.g. JavaScript:

<pangaea type="text/javascript">
  function name(){
    return "Pangaea";
  }
</pangaea>

We can call the scripts to get the name, which is <%= name() %>.

Other JavaScript also works, so we know that 5 + 10 is <%= 5 + 10 %>.

The above file, when processed will output as:

This is just a normal text file that has scripts embedded:

We can call the scripts to get the name, which is Pangaea.

Other JavaScript also works, so we know that 5 + 10 is 15.

Usage

Embedding JavaScript

To embed JavaScript, just use the <pangaea> script tag like this:

<pangaea type="text/javascript">
  // code goes here
</pangaea>

For inline script that will print out the return, use the <%= and %> special tags:

My name is <%= name %>.

Command line tool

The pangaea command reads from the standard in pipe, and writes to the standard out pipe.

cat ./example/source.txt | pangaea >> ./example/output.txt

Or you can use it in an interactive mode:

pangaea
  • See some examples of how you can use Pangaea.

Parameters

Pangaea supports parameters that are made available to your scripts via the $$params global object. You can specify parameters using the -params flag and a URL encoded query string:

pangaea -params="name=Mat&age=30"

This will make the $$params["name"] and $$params["age"] variables available to your scripts.

  • All parameter values are strings, if you want to use other types you can cast them in your code.

Built-in methods

Pangaea comes with a series of useful built-in methods that would otherwise be impossible when running JavaScript in the browser.

$$contentsOf - loads the contents of a file

(string) $$contentsOf(filename)
<pangaea type="text/javascript">
  var name = $$contentsOf("name.txt");
</pangaea>
My name is <%= name %>.

$$run - runs a shell command and returns the result

(string) $$run(command, [arg1, [arg2, [arg3...]]])
<pangaea type="text/javascript">
  var now = $$run("date");
</pangaea>
The date is <%= now %>.

Download latest

Check out releases, or download the source and build from source using go install.

Rules

  • Keep <pangaea type="text/javascript"> and </pangaea> tags on their own lines
  • Please report any issues
  • There are no rules

Development

To build and run the command inside the cmd directory, do:

clear; go build -o pangaea; cat ./example/source.txt | ./pangaea >> ./example/output.txt

About

Powerful pre-processor for any kind of text file - powered by JavaScript

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 93.6%
  • Shell 6.4%