Rails New

This is a wrapper over rails new attached to a repository of rails application templates located on http://rails-new.herokuapp.com. This repository stores templates to be used with this gem as a client. The main objective is to be able to make something like this:

$ rails-new my-organization/application my-new-project

or even have the ability to have two or more rails templates related to specific things:

$ rails-new my-organization/api my-new-api

To accomplish this, the repository exposes a public API using your username and the template name. For example, this url: http://rails-new.herokuapp.com/api/v1/templates/julio/application.json returns the data for the stored template julio/application created by the user julio and named application:

{
  "template": {
    "id": 1,
    "name": "application",
    "git_repository": "https://github.com/juliogarciag/rails-template",
    "git_branch": "master",
    "main_file_location": "template.rb",
    "updated_at": "2015-03-15T06:51:57.106Z",
    "arguments": [
      {
        "id": 1,
        "key": "--skip-spring",
        "has_value": false,
        "value": ""
      },
      {
        "id": 2,
        "key": "--skip-test-unit",
        "has_value": false,
        "value": ""
      },
      {
        "id": 3,
        "key": "--skip-turbolinks",
        "has_value": false,
        "value": ""
      }
    ]
  }
}

This json represents the arguments needed for this template, the repository where this is stored and the location of the template file inside of the the repository. The point is to be able to use it from this gem (or from somewhere else) to do two things (of many) that are very complex with Rails application templates:

  • Tie arguments (--skip-turbolinks, --skip-test-unit, etc) to the template. If you build a template that heavily rely on RSpec, you may want to make --skip-test-unit required as an argument. In normal usage, you should need to add the argument aside from the template argument.
  • rails new -m URL is broken by design. The command only works with super simple templates that doesn't use erb templates or copy files from somewhere else. This gem downloads the template with all the files needed to run and runs it from the file system, avoiding the problem with using urls.

And, additionally, and this is more of a side-effect, this allows us to share Rails templates built in whatever way you want with everyone.

Installation

Install running:

$ gem install rails-new-gem

Usage

Run rails-new --help for instructions.

Current Caveats

  • Right now, before running the rails new... command built with the template, the gem asks for confirmation of the command because there's always the chance of injection in maybe unexpected ways we can't simply assume don't exist. (If you can think of a way to avoid doing this, it will be really useful)
  • All templates are readable by everyone right now. We didn't think of a way to authenticate some template request right now without complicating the flow yet. This is just temporal.

Contributing with Templates while private

Create an issue with the git repository of the template, the location inside it, the name of the user you want to keep the repository within, the name of the template and the arguments you expect the template to be called with. This is just temporal until we figure out how to make it more user-friendly and secure at the same time.

Contributing with Code

  1. Fork it ( https://github.com/juliogarciag/rails-new-gem/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request