Giter Club home page Giter Club logo

gluestring's Introduction

GlueString

License: MIT

About

Glustring allows you to work with string templates flawlessly. You can create multiple Gluegun's and generate strings out your templates with just one function.

List of template with one mapping, one template with a list of mapping or a list of templates with list of mappings, All possible with one type agnostic glue_it method !

Checkout the Recipes to see how gluestring package in actions

Table of contents

  1. Install
  2. Usage
  3. Recipes

Install

pip3 install gluestring

Usage

from gluestring import Gluegun

pet_gluegun = Gluegun({
            "pups": "🐶🐶🐶",
            "kittens": "🐱🐱🐱",
            "fishes": "🐠🐠🐠",
            "octopus": "🐙🐙🐙"
        })
result = pet_gluegun.glue_it(" I Love {{pups}} more than {{octopus}}.")
print(result) 
# I Love 🐶🐶🐶 more than 🐙🐙🐙.

Recipes

List of input strings with single dictionary

name_gluegun = Gluegun({
        "name": "Fee",
        "age" : 27,
        "animal":"Kittens🐱"
})
result_list = name_gluegun.glue_it([
        "Hello my name is {{name}} and i'm {{age}}.",
        "{{name}} is good with {{animal}}!"
        ])

print(result_list[0])
print(result_list[1])

# 'Hello my name is Fee and i'm 27.'
# 'Fee is good with Kittens🐱!'

Single input string with list of dictionary

name_gluegun = Gluegun([{
        "name": "Fee",
        "animal":"Kittens🐱"
        },
        {
        "name": "Foo",
        "animal":"Puppers🐶"

        }])
result_list = name_gluegun.glue_it(
        "Hello my name is {{name}} and I love {{animal}}."
        )

print(result_list[0])
print(result_list[1])

# 'Hello my name is Fee and I love Kittens🐱.'
# 'Hello my name is Foo and I love Puppers🐶.'

List of input strings with list of dictionary

name_gluegun = Gluegun([{
        "name": "Fee",
        "animal":"Kittens🐱"
        },
        {
        "name": "Foo",
        "age":14,
        "animal":"Puppers🐶"

        }])
result_list = name_gluegun.glue_it([
        "Hello my name is {{name}} and i'm {{age}}.",
        "{{name}} is good with {{animal}}!"
        ])
print(result_string_list[0])
print(result_string_list[1])
print(result_string_list[2])
print(result_string_list[3])
# 'Hello my name is Fee and i'm NA.'
# 'Hello my name is Foo and i'm 14.'
# 'Fee is good with Kittens🐱!'
# 'Foo is good with Puppers🐶!'
  • Will not throw exception on unknown keys, will use NA, you can override it by adding a default key in the dictionary.
offer_gluegun = Gluegun({
            "offer_thirty": "30%",
            "offer_fourty": "40%",
        })
result_string = offer_gluegun.glue_it(
        "Get {{alien_offer}} off & {{offer_fourty}} off if SUPER user."
        )
print(result_string)
# 'Get NA off & 40% off if SUPER user.

gluestring's People

Contributors

aananya27 avatar tstreamdoth avatar palmiak avatar

Stargazers

Roman avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.