Giter Site home page Giter Site logo

madelyneriksen / flatware Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 34 KB

Write and use single file templates from the command line.

Home Page: https://flatware.readthedocs.io/en/latest/

License: MIT License

Python 100.00%
python3 jinja2 template template-generator code-generation

flatware's Introduction

Flatware

Build Status

Create files from plates (single file template), right from the command line.

Get Started

Let's make a plate for creating React components:

[component]
type=str
default=MyComponent
---
import React from 'react';


class {{ component }} extends React.Component {
  
  render() {
    return (
      <div>{{ component }}</div>
    )
  }
}

export default {{ component }};

Save this to ~/.plates/react-component. Now, we can install Flatware and try it out!

Install from source:

git clone https://github.com/madelyneriksen/flatware/
cd flatware
# Whatever you prefer for virtual environments
virtualenv .env
source .env/bin/activate
pip install -r requirements.txt && python setup.py install
# Now we can use flatware!
flatware react-component --component Navar > navbar.js

Congrats! You made your first plate!

Intro To Plates

Plates are files that contain configuration and a template.

Configuration in plates is similar to *.ini file syntax. Plate configuration defines command line arguments for the plate, as well as the typing and default value of each argument.

# In brackets is the name of the argument.
# Argument names are used in the command line for passing values.
[languages]

# Arguments have optional types.
# Valid values are str, int, float, and list
type=list

# You can set a default value for an argument.
# Default values are interpreted as their type (lists are space delimited)
default="python javascript rust"

# We mark the end of our configuration with three dashes and a new line
# Configuration is always at the top of a plate
---

Template syntax in plates uses Jinja2/Django syntax. Jinja2 allows plate authors to add loops, checks, and basic processing to templates easily.

{% for language in languages %}
{{ language }} programming rocks!
{% endfor %}

Jinja2 is easy to use, but a lot to cover for one README. You can read more about Jinja2 here.

Contributing

Pull requests, issues, and feature requests are always welcome! If you'd like to develop a feature, here's the steps for making your dev environment.

# First, clone this repo from source
git clone https://github.com/madelyneriksen/flatware
cd flatware
# Install our requirements locally
virtualenv .env
source .env/bin/activate
pip install -r requirements.txt
pip install -r requirements-dev.txt
# Install in dev mode
python setup.py develop
# Our tests should be working, let's check
pytest

Code is linted with the wonderful pylint as well as pycodestyle.

License

Flatware is MIT Licensed.

Special Thanks

  • Audreyr for creating cookiecutter, which inspired flatware
  • The team of contributors working on jinja2

flatware's People

Contributors

madelyneriksen avatar

Watchers

 avatar  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.