Skip to content

One template, several number input, returns various shape result that consists of plain svg path data!

License

Notifications You must be signed in to change notification settings

disjukr/tempath

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tempath

Tempath is a template language for path data, which is the superset of SVG Path Data syntax. Inspired by Prototypo's under the hood part.

Usage

Installation

npm install -g tempath

Command line interface

$ tempath --help

Usage: tempath <file> [argument]... [options]

file         path template file
argument     number values that be used to path property

Options:
   -h, --help   print this message

Example

$ echo "prop \$a, \$b, \$c, \$d M 0 0 L \$a+\$b \$c*\$d 6 0 Z" > sample.path

$ cat sample.path
prop $a, $b, $c, $d M 0 0 L $a+$b $c*$d 6 0 Z

$ tempath sample.path 1 2 3 4
M0,0L3,12L6,0Z

Brief Syntax Guide

Since tempath is the superset of SVG path data, you can use all feature of it.

Basic functionalities

M 0,0               # also you can use comment!
L 1,2 3,4           # command letter can be eliminated on same subsequent commands
c 5,6 7,8 9,10      # relative versions of all commands are available

Commands

Tempath code is a list of commands. You can also define your custom command with other commands.

  • set: set the variable
  • prop: define property that represent the path
  • def: define custom command
  • if: conditional execution of command
  • for: make loop
  • import: import foreign template on command

Variable

Variable name starts with $ character.

set $a, 1
set $b, 2
M $a $b     # M1,2

Property

prop command takes a value from outside, and set the value to variable.

prop $a         # Take one value from outside, just set $a by that.

prop $b 0~1     # Take one value from outside,
                # but limit the value into 1~2(inclusive).

prop $c 2       # If there is no value outside, set 2 to $c.

prop $d 3~4 5   # Default value also limited.
                # thus, set 4 when default is used

Expression

Opeator

set $a, 1 + 2 * 3       # set $a to 7
set $b, 1 < 2           # set $b to 1(true)
set $c, 1 = 2           # set $c to 0(false)
set $d, not 1 = 2       # set $d to 1
Builtin Operators
  • +
  • -
  • *
  • /
  • %
  • <
  • >
  • <=
  • >=
  • =

Function

Call the function as s-expr style.

set $a, (cos (sin 0))   # set $a to 1
Builtin functions
  • ceil
  • round
  • floor
  • sin
  • cos
  • tan
  • sqrt
  • atan2

Development

use mocha for generate parser code & test.

$ npm install -g mocha
$ mocha

License

Distributed under MIT License

About

One template, several number input, returns various shape result that consists of plain svg path data!

Resources

License

Stars

Watchers

Forks

Packages

No packages published