GithubHelp home page GithubHelp logo

bchao1 / griddy Goto Github PK

View Code? Open in Web Editor NEW
23.0 2.0 0.0 1.33 MB

๐Ÿ“๐Ÿ“ Generate CSS grid layouts FAST.

License: MIT License

Python 100.00%
javascript flexbox css html responsive grid-layout

griddy's Introduction

griddy: Generate CSS grid layouts FAST

๐Ÿ“๐Ÿ“ Tired of manually splitting <div>'s? Try griddy.

Setup

Build from source

git clone https://github.com/Mckinsey666/griddy.git
cd griddy
pip install .

From PyPI

pip install griddy

Usage

Defining a layout.json file

A layout .json file should follow the following syntax:

  • The json file contains one json object.
  • First level of the json object should have key root.
  • For (key, value) pairs in other levels, the keys should abide by the following conventions:
    • percentage: percentage of the children <div>'s height or width with respect to its parent's.
    • layout type: defines a column layout or a row layout (column layouts will be inside a flex container). If r is specified, the percentage is the relative height; if c is specified, the percentage is the relative width.
    • id (optional): used to prevent duplicate keys in the json object.
key = percentage + layout type + id
  • For keys in the same level, their layout types should be the same.
  • For keys in the same level, it is better that their percentage add up to 100.
  • If no more <div>s are to be splitted, set the value of the key to be null.

Sample layout.json file

{
    "root":{
        "70r":{
            "10c": null,
            "20c": {
                "10r": null,
                "90r": null
            },
            "70c": {
                "50r1": null,
                "50r2": {
                    "20c1": null,
                    "20c2": null,
                    "60c": null
                }
            }
        },
        "30r": {
            "80c": null,
            "20c": null
        }
    }
}

Play with more examples in the examples directory.

Sample index.html output

Here <div> blocks are randomly colored for the sake of clarity with the --colored flag specified.

Plain borders surrounding blocks with --border flag specified.

The above picture shows how the json file syntax associates with actual layout generated.

Generate html and css

griddy <name of the layout file>

An index.html file and a styles.css file will be generated in the current working directory. You can simply plugin the generated grid <div> (top-level <div> of class root with style width: 100%; height:100%) anywhere in your existing code.

Command-line arguments

Arguments Type Explanation
--colored bool Whether to color the <div> blocks
--border bool <div> blocks comes with borders
--show bool Show generated grid in browser

For example,

griddy layout.json --border --show

griddy's People

Contributors

bchao1 avatar

Stargazers

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