Skip to content

Create powerful but simple Text file templates

License

Notifications You must be signed in to change notification settings

wwdenis/HashScript

Repository files navigation

master Actions Status

HashScript

HashScript is a simple and powerful scripting language created by @wwdenis and written in .NET.

While there are so many scripting engines, most require a certain learning curve.
HashScript is intended to be lightweight, easy to learn, and still powerful.

Roadmap

  • Detailed Documentation
  • Visual Studio Code Formatter (and other IDE's)
  • Custom Data Sources

Introduction

Everything surrounded with a Hash symbol ( # ), is a Template Field, or just a Field.
A field is a placeholder for a dynamic content. HashScript gieto be lightweight, easy to learn, and still powerful.

Basic Syntax

Symbol Description
# Indicates a Field
+ Indicates a Structured Field (inside a field)
? Indicates a Conditional Field (inside a field)
! Indicates a Conditional Field (inside a field, negate)
. Indicates a Function Field or a Value Field

Field Types

Type Example Note
Content Field #Foo# A placeholder to render data.
Structured Field #+Foo# Text #+# Renders data below the data structure
Confitional Field #?Foo# Text #?# Renders when condition is True (use ! for False)
Function Field #?.Foo# Text #?# Renders when the function Foo is True
Value Field The Numbers are #.# Renders the value of a item in a collection

Conditional Fields

Conditional Field is very flexible and can work with the followiung data types:

  • Boolean: True or False
  • Number: True when greather than Zero
  • Text: True when it has length
  • Collection: True when it has items
  • Object: True when the value is not null

Function Fields

Function Field is used to give the Renderer additional data.

For example, in the ObjectValueProvider the following functions are defined:

  • .First: Returns True when the item is the first in the colection
  • .Last: Returns False when the item is the last in the colection

Syntax Example:

#+Items#
   #?.First# Foo #?#
#+# 

Examples

Type

Template

Input

Output

Content Field

Hi #Name#!!!
{ "Name": "HashScript" }
Hi HashScript!!!         

Structured Field

(Complex Object)


#+Message#
  #Greeting#, #Name# !!!
#+#

{ "Message": { 
    "Greeting": "Hello",
    "Name": "HashScript"
  }
}


Hello, HashScript


Structured Field

(Collection)


#+Languages#
  - #Name# : #Year#
#+#

{ "Languages": [
  { "Name": "HZ", "Year": "2022" },
  { "Name": "VB", "Year": "1964" },
  { "Name": "CS", "Year": "2000" }
]}

- HZ: 2022
- VB: 1964
- CS: 2000

Conditional Field

(Boolean)

Hi
#?IsDoctor#Dr.#?#
#!IsDoctor#Sr.#!#
#Name#
{ 
  "IsDoctor": false,
  "Name": "Denis"
}
Hi

Sr.
Denis

Conditional Field

(Text, Number)


Name: #Name#
#?Address# Adress: #Address# #?#
#?Email# E-mail: #Email# #?#
#?Posts# Replies: #Posts# #?#

{ 
  "Name": "Denis",
  "Email": "denis@hashscript.org",
  "Address": "",
  "Posts": 10
}

Name: Denis
  
E-mail: denis@hashscript.org
Replies: 10

Conditional Field

(Collection)


#!Messages# Empty Inbox #!#

{ 
  "Messages": []
}

Empty Inbox

Conditional Field

(Value)


#!Value# There is no value #!#

{ 
  "Value": null
}

There is no value

Special Function


#+Languages#
  #Name# #!.Last# > #!#
#+#

{ "Languages": [
  { "Name": "HZ" },
  { "Name": "VB" },
  { "Name": "CS" }
]}


HZ > VB > CS