GithubHelp home page GithubHelp logo

phatjam98 / boxybox Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 26 KB

Code exercise demonstrating gem creation and usage, using existing libraries(gems) and playing around in a terminal

License: MIT License

Ruby 98.31% Shell 0.68% C 1.02%

boxybox's Introduction

Boxybox

Need to create boxes in boxes in boxes in boxes? Great news! You've found a gem that does just that. This is a dive into the world of command line apps using TTY focusing on the tty-box and supporting gems. This has been done in a way to extend out the customization of each box quite easily by adding additional root properties to the boxes. For the purpose of this exercise I've chosen to stick with just the examples given in the challenge as well as the ability to craft new box nesting patterns by supplying custom JSON configs.

Installation

Add this line to your application's Gemfile:

gem 'boxybox'

And then execute:

$ bundle

Or install it yourself as:

$ gem install boxybox

Usage

To print one of the 4 provided examples along with the config json used to construct the boxes use the following command

$ boxybox boxes -e example1 -p

This is helpful when wanting to understand the config syntax with clear examples.

$ boxybox boxes -f ~/some_config.json

Use the above command if you wish to pass in a custom JSON config.

Configuration

The following example shows how boxes can be configured using JSON. There is a top level boxes object which represents our outer or parent box. Each box may have children boxes in a horizontal or vertical pattern which is designated by the direction property. children are given as an array with content boxes using the content propery. The examples given follow the examples given in the project requirements, however content can be populated with text and all boxes will scale properly.

While this may be a bit overkill, using JSON in this way allows for more complicated structures in the future. As this gem utilizes the tty toolset, specifically the tty-box gem, many properties may be passed through and included in the future with relative ease.

{
  "boxes": {
    "direction": "vertical",
    "children": [
      {
        "direction": "horizontal",
        "children": [
          {
            "direction": "vertical",
            "children": [
              {
                "content": " "
              },
              {
                "content": " "
              }
            ]
          },
          {
            "content": " "
          },
          {
            "content": " "
          }
        ]
      },
      {
        "content": " "
      },
      {
        "content": " "
      },
      {
        "direction": "horizontal",
        "children": [
          {
            "content": " "
          },
          {
            "content": " "
          }
        ]
      }
    ]
  }
}

The above config will print out the following:

+-------------------------+
|                         |
| +---------------------+ |
| |                     | |
| | +-------++---++---+ | |
| | |       ||   ||   | | |
| | | +---+ ||   ||   | | |
| | | |   | ||   ||   | | |
| | | |   | |+---++---+ | |
| | | |   | |           | |
| | | +---+ |           | |
| | | +---+ |           | |
| | | |   | |           | |
| | | |   | |           | |
| | | |   | |           | |
| | | +---+ |           | |
| | |       |           | |
| | |       |           | |
| | +-------+           | |
| |                     | |
| +---------------------+ |
| +---+                   |
| |   |                   |
| |   |                   |
| |   |                   |
| +---+                   |
| +---+                   |
| |   |                   |
| |   |                   |
| |   |                   |
| +---+                   |
| +------------+          |
| |            |          |
| | +---++---+ |          |
| | |   ||   | |          |
| | |   ||   | |          |
| | |   ||   | |          |
| | +---++---+ |          |
| |            |          |
| +------------+          |
|                         |
|                         |
|                         |
|                         |
+-------------------------+

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/boxybox. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

Code of Conduct

Everyone interacting in the Boxybox project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Copyright

Copyright (c) 2020 Travis Carter. See MIT License for further details.

boxybox's People

Contributors

phatjam98 avatar

Watchers

 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.