A general purpose template driven code generator

Overview

💩 Shit Mountain Generator

A general purpose template driven code generator
Contribute shits to your company's shit mountain more efficiently!

Quick Start

Install

pip3 install shit_mountain_generator

vscode Template Language Highlighting

The vscode extension for shit template language highlight support is now on marketplace! search for Shit Template Language in vscode extension tab to install

Create a generator script

from ShitMountainGenerator import Shitter

shitter = Shitter.from_template(path="/path/to/template.tmpl")
shits = shitter.shit(context={"your": "variable", "loop_contexts": [{"loop": "context"}, {"and": "more"}]})
print(shits)

Writing Templates

Currently, templates has the following supports:

  • variable
  • loop
  • Sub-template
  • Condition (Select-Case)

So, we will be starting with the main template:

your template content ">
<tmpl name="$main$">
  your template content
tmpl>

The name attribute can be omitted for the main template

Just relax and use indent to make it look neat. The first indent will be removed when parsing. However, please note that you should only use tab character, AKA \t, or 4 spaces to indent since the parser is assuming 4 spaces or a tab as one indent.

Now, maybe we need to replace some parts of the template with variables. So, we are going to use the variable syntax:

email = "{{ user_email }}" ">
<tmpl name="$main$">
  email = "{{ user_email }}"
tmpl>

{{ user_email }} represents the content of the variable user_email, which will be replaced later.

So, we have gone so far that we are able to generate some super simple codes.

Since the complexity of our business logic, we may need to loop over some list and generate corresponding code. And here is when sub-templates and loop operation come in.

Imagine that we are converting some data structure from a language to another, for instance, a go struct, to python data class. And we have the following structure:

type User struct {
  Id       string   `json:"id"`
  Name     string   `json:"name"`
  Password string   `json:"name"`
  Email    string   `json:"email"`
  Friends  []string `json:"friends"`
}

The above struct is exported and loaded into a parsing function of python, and we are getting the following result

context = {
  "struct_name": "User",
  "members": [
    {"name": "Id", "py_name": "id", "py_type": "str", "is_list": False},
    {"name": "Name", "py_name": "name", "py_type": "str", "is_list": False},
    {"name": "Password", "py_name": "password", "py_type": "str", "is_list": False},
    {"name": "Email", "py_name": "email", "py_type": "str", "is_list": False},
    {"name": "Friends", "py_name": "friends", "py_type": "List[str]", "is_list": True},
  ]
}

As you may noticed that we have mentioned about context in the quick-start section above. Right! We are putting this dict into the Shitter so that it shits the correct shit.

Now, we looking at some more complicated stuff. There are list of class members to generate and we apparent don't want to copy and paste these lines. So, we are gonna use the loop operation. But wait! We have got some variant for the "is_list" key! Luckily, we have condition rendering. Let's put these stuff together. And we will have the...

Complete Template Sample

[] "" {{ name }}: {{ py_type }} = {{ use(class_member_select) }} class {{ struct_name }}: {% class_member_tmpl <- members %} ">
<select name="class_member_select" var="is_list">
  <case test="True">
    []
  case>
  <case test="False">
  	""
  case>
select>

<tmpl name="class_member_tmpl">
  {{ name }}: {{ py_type }} = {{ use(class_member_select) }}
tmpl>

<tmpl name="$main$">
  class {{ struct_name }}:
  	{% class_member_tmpl <- members %}

In the above template, we have two sub-templates, class_member_tmpl and the main template and one select statement.

A select statement requires a name attribute to be referenced later in a template and a var attribute to specify which variable we are testing with. Inside the select statement, we can have unlimited numbers of case statements and one optional default statement. However, only the first matched case will be returned if we have more than one matching cases.

In the case statement, a test attribute is required. When comparing the variable and the test value, the test value will be automatically type converted to the target variable type. If a failure accurs while convering, it is assumed unequal.

If none of the specified cases are matched, the generator will go look for the default statement and an Exception will be thrown out if no defaults were found.

A select statement is referenced using the use() function with the select statement's name as argument

Sub-templates are used for loops. Use a {% %} tag to tell the generator to loop. The left side of the arrow is the sub-template to use and the right side is the context to loop over. The specified context must be an iterable and there must be Dict[str, Any] inside the context.

The sub-template is automatically fed with items of the list as context. So just go and use the variables inside that item.

LICENSE

This project is licenced under The MIT License

Feel free to use it for whatever you are working with

Releases(1.0.0)
Owner
Kelly
A frontend dev with the knowledge of backend / fullstack dev in common words... likes: Dart | VB.NET | Python | Typescript hates: Java | Javascript
Kelly
✈️ HTML Template engine for python. Supports XSS preventation and many more!

Htmotor HTML Template Engine for Python! Installation: Open your terminal and type pip install htmotor.

Penguen 4 Aug 29, 2021
Simple reuse of partial HTML page templates in the Jinja template language for Python web frameworks.

Jinja Partials Simple reuse of partial HTML page templates in the Jinja template language for Python web frameworks. (There is also a Pyramid/Chameleo

Michael Kennedy 51 Jan 24, 2022
HTML Template Linter and Formatter. Use with Django, Jinja, Nunjucks and Handlebars templates.

Find common formatting issues and reformat HTML templates. Django · Jinja · Nunjucks · Handlebars · Mustache · GoLang Ps, --check it out on other temp

Riverside Healthcare Analytics 63 Mar 9, 2022
A string template language hosted by Python3 runtime

A string template language hosted by Python3 runtime. Conventionally, the source code of this language is written in plain text with utf-8 encoding and stored in a file with extension ".meme".

null 3 Jan 28, 2022
Cookiecutter-allpurpose-minimal-python - A simple cookiecutter template for general-purpose python projects.

cookiecutter-allpurpose-minimal-python A simple cookiecutter template for general-purpose python projects. To use, run pip install cookiecutter cookie

E. Tolga Ayan 2 Jan 24, 2022
A general-purpose wallet generator, for supported coins only

2gen A general-purpose generator for keys. Designed for all cryptocurrencies supporting the Bitcoin format of keys and addresses. Functions To enable

Vlad Usatii 1 Jan 12, 2022
A Python command-line utility for validating that the outputs of a given Declarative Form Azure Portal UI JSON template map to the input parameters of a given ARM Deployment Template JSON template

A Python command-line utility for validating that the outputs of a given Declarative Form Azure Portal UI JSON template map to the input parameters of a given ARM Deployment Template JSON template

Glenn Musa 1 Feb 3, 2022
Python bindings for ArrayFire: A general purpose GPU library.

ArrayFire Python Bindings ArrayFire is a high performance library for parallel computing with an easy-to-use API. It enables users to write scientific

ArrayFire 386 Mar 5, 2022
Implementation of self-attention mechanisms for general purpose. Focused on computer vision modules. Ongoing repository.

Self-attention building blocks for computer vision applications in PyTorch Implementation of self attention mechanisms for computer vision in PyTorch

AI Summer 754 Mar 8, 2022
Retrying is an Apache 2.0 licensed general-purpose retrying library, written in Python, to simplify the task of adding retry behavior to just about anything.

Retrying Retrying is an Apache 2.0 licensed general-purpose retrying library, written in Python, to simplify the task of adding retry behavior to just

Ray Holder 1.8k Mar 10, 2022
a general-purpose Transformer based vision backbone

Swin Transformer By Ze Liu*, Yutong Lin*, Yue Cao*, Han Hu*, Yixuan Wei, Zheng Zhang, Stephen Lin and Baining Guo. This repo is the official implement

Microsoft 7.4k Mar 15, 2022
ArrayFire: a general purpose GPU library.

ArrayFire is a general-purpose library that simplifies the process of developing software that targets parallel and massively-parallel architectures i

ArrayFire 3.8k Mar 13, 2022
General purpose GPU compute framework for cross vendor graphics cards (AMD, Qualcomm, NVIDIA & friends). Blazing fast, mobile-enabled, asynchronous and optimized for advanced GPU data processing usecases.

Vulkan Kompute The general purpose GPU compute framework for cross vendor graphics cards (AMD, Qualcomm, NVIDIA & friends). Blazing fast, mobile-enabl

The Institute for Ethical Machine Learning 818 Mar 15, 2022
Retrying is an Apache 2.0 licensed general-purpose retrying library, written in Python, to simplify the task of adding retry behavior to just about anything.

Retrying Retrying is an Apache 2.0 licensed general-purpose retrying library, written in Python, to simplify the task of adding retry behavior to just

Ray Holder 1.8k Mar 10, 2022
BYOL for Audio: Self-Supervised Learning for General-Purpose Audio Representation

BYOL for Audio: Self-Supervised Learning for General-Purpose Audio Representation This is a demo implementation of BYOL for Audio (BYOL-A), a self-sup

NTT Communication Science Laboratories 109 Mar 9, 2022
Learning General Purpose Distributed Sentence Representations via Large Scale Multi-task Learning

GenSen Learning General Purpose Distributed Sentence Representations via Large Scale Multi-task Learning Sandeep Subramanian, Adam Trischler, Yoshua B

Maluuba Inc. 305 Jan 22, 2022
A general-purpose multi-agent training framework.

MALib A general-purpose multi-agent training framework. Installation step1: build environment conda create -n malib python==3.7 -y conda activate mali

MARL @ SJTU 271 Mar 14, 2022
ImVoxelNet: Image to Voxels Projection for Monocular and Multi-View General-Purpose 3D Object Detection

ImVoxelNet: Image to Voxels Projection for Monocular and Multi-View General-Purpose 3D Object Detection This repository contains implementation of the

Visual Understanding Lab @ Samsung AI Center Moscow 138 Mar 13, 2022
A task-agnostic vision-language architecture as a step towards General Purpose Vision

Towards General Purpose Vision Systems By Tanmay Gupta, Amita Kamath, Aniruddha Kembhavi, and Derek Hoiem Overview Welcome to the official code base f

AI2 46 Mar 18, 2022
ZSL-KG is a general-purpose zero-shot learning framework with a novel transformer graph convolutional network (TrGCN) to learn class representation from common sense knowledge graphs.

ZSL-KG is a general-purpose zero-shot learning framework with a novel transformer graph convolutional network (TrGCN) to learn class representa

Bats Research 80 Feb 22, 2022
A general-purpose, flexible, and easy-to-use simulator alongside an OpenAI Gym trading environment for MetaTrader 5 trading platform (Approved by OpenAI Gym)

gym-mtsim: OpenAI Gym - MetaTrader 5 Simulator MtSim is a simulator for the MetaTrader 5 trading platform alongside an OpenAI Gym environment for rein

Mohammad Amin Haghpanah 65 Mar 11, 2022
Mathics is a general-purpose computer algebra system (CAS). It is an open-source alternative to Mathematica

Mathics is a general-purpose computer algebra system (CAS). It is an open-source alternative to Mathematica. It is free both as in "free beer" and as in "freedom".

Mathics 93 Mar 14, 2022
A repository containing several general purpose Python scripts to automate daily and common tasks.

General Purpose Scripts Introduction This repository holds a curated list of Python scripts which aim to help us automate daily and common tasks. You

GDSC RCCIIT 41 Feb 13, 2022
Unofficial PyTorch implementation of MobileViT based on paper "MobileViT: Light-weight, General-purpose, and Mobile-friendly Vision Transformer".

MobileViT RegNet Unofficial PyTorch implementation of MobileViT based on paper MOBILEVIT: LIGHT-WEIGHT, GENERAL-PURPOSE, AND MOBILE-FRIENDLY VISION TR

Hong-Jia Chen 60 Feb 26, 2022
Neural text generators like the GPT models promise a general-purpose means of manipulating texts.

Boolean Prompting for Neural Text Generators Neural text generators like the GPT models promise a general-purpose means of manipulating texts. These m

Jeffrey M. Binder 19 Feb 12, 2022
General purpose GPU compute framework for cross vendor graphics cards (AMD, Qualcomm, NVIDIA & friends)

General purpose GPU compute framework for cross vendor graphics cards (AMD, Qualcomm, NVIDIA & friends). Blazing fast, mobile-enabled, asynchronous and optimized for advanced GPU data processing usecases. Backed by the Linux Foundation.

The Kompute Project 813 Mar 12, 2022
Sodium is a general purpose programming language which is instruction-oriented

Sodium is a general purpose programming language which is instruction-oriented (a new programming concept that we are developing and devising)

Satin Wuker 22 Jan 11, 2022
General Purpose Python Library by Techman

General Purpose Python Library by Techman

Jack Hubbard 0 Feb 9, 2022
PyFlow is a general purpose visual scripting framework for python

PyFlow is a general purpose visual scripting framework for python. State Base structure of program implemented, such things as packages disco

null 1.5k Mar 11, 2022