Git Product home page Git Product logo

rails-templates's Introduction

Nimble logo

Rails Templates


Our templates offer a rich boilerplate to jump start Rails-based application development and are based on our experience with building complex applications over the years.

Get Started

Requirements

  • Install ruby and set your local ruby version to 3.1.1
  • Install rails 7.0.3
  • Install node 16.14.2 (For creating web application)

๐Ÿ“ If running on Apple M1, to build docker image, please make sure to set platform to AMD64 by export DOCKER_DEFAULT_PLATFORM=linux/amd64

Use the template

In order to use the template, initialize a new app with the following parameters:

rails new <app_name> -m https://raw.githubusercontent.com/nimblehq/rails-templates/master/template.rb

Supported template options:

  • --api - create an api-only application

To apply the template on an existing application, run following rails command:

rails app:template LOCATION=https://raw.githubusercontent.com/nimblehq/rails-templates/master/template.rb

# To apply on an api application
rails app:template LOCATION=https://raw.githubusercontent.com/nimblehq/rails-templates/master/template.rb API=true

# To apply a specific addon
rails app:template LOCATION=https://raw.githubusercontent.com/nimblehq/rails-templates/master/template.rb ADDON=<addon name>

Available Addons:

  • docker
  • nginx
  • phrase_app
  • semaphore
  • bootstrap
  • slim
  • devise

Read more about Rails Application Template in the official Rails Guides.

How to contribute

Template structure

.
โ”œโ”€โ”€ .template
โ”‚   โ”œโ”€โ”€ addons
โ”‚   โ”‚   โ””โ”€โ”€ docker
โ”‚   โ”‚       โ”œโ”€โ”€ ...
โ”‚   โ”‚       โ””โ”€โ”€ template.rb
โ”‚   โ””โ”€โ”€ variants
โ”‚       โ”œโ”€โ”€ api
โ”‚       โ”‚   โ”œโ”€โ”€ ...
โ”‚       โ”‚   โ””โ”€โ”€ template.rb
โ”‚       โ””โ”€โ”€ web
โ”‚           โ”œโ”€โ”€ ...
โ”‚           โ””โ”€โ”€ template.rb
โ”œโ”€โ”€ app
โ”œโ”€โ”€ bin
โ”œโ”€โ”€ config
โ”œโ”€โ”€ spec
โ”œโ”€โ”€ ...
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ README.md.tt
โ””โ”€โ”€ template.rb

We keep the Rails-app-like structure. On the root, there are base project file templates. Other files including the template options are in .template folder.

There are 2 kinds of the template options:

  1. Variants - For the app main options, which are web and api.

  2. Addons - For other extra options that we can add to the project like docker or bootstrap, use the prompt ask to generate a question before generating the project.

Template files

There are 2 template file types:

  1. .tt files

    This file is used for templating the whole new file. In case if we want to create a new file that Rails does not generated.

  2. .rb files

    This is used for modifying the files that Rails has generated. The file name should be the same as on the generated app. If it is not a ruby file, append the .rb as an extension e.g. Gemfile.rb

Template specs

We are using Serverspec to test the template. For any changes made, you must add a spec for it.

Test files are located under .template/spec folder

.
โ”œโ”€โ”€ ...
โ”œโ”€โ”€ .template
โ”‚   โ”œโ”€โ”€ ...
โ”‚   โ”œโ”€โ”€ spec
โ”‚   โ”‚   โ””โ”€โ”€ addons
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ base
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ docker
โ”‚   โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ...
โ”‚   โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ template_spec.rb
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ semaphore
โ”‚   โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ...
โ”‚   โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ template_spec.rb
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ variants
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ web
โ”‚   โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ boostrap
โ”‚   โ”‚   โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ ...
โ”‚   โ”‚   โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ template_spec.rb
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ api
โ”‚   โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ addon
โ”‚   โ”‚   โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ ...
โ”‚   โ”‚   โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ template_spec.rb
โ”‚   โ”‚   โ””โ”€โ”€ base
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ...
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ template_spec.rb
โ”‚   โ”‚   โ””โ”€โ”€ variants
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ web
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ...
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ template_spec.rb
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ api
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ...
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ template_spec.rb

Template Strings

When using template string with heredoc, use the proper name following the file type / content.

This provides the meaningful context to the content and some IDEs also support to highlight the content depending on the type.

  • DOCKERFILE
  • ERB
  • HTML
  • IGNORE - For any ignore file e.g. .gitignore, .eslintignore
  • JAVASCRIPT
  • JSON
  • PROCFILE
  • RUBY
  • SCSS
  • SHELL

For other files that are not fit the types above, use the extension as the name e.g. TOOL_VERSION for .tool-version file.

For the normal string, name it after the content e.g. ERROR for template error message.

Testing the Template

To run RuboCop against the template:

.template/bin/rubocop

Any RuboCop command options can be passed:

# Run RuboCop with auto correct
.template/bin/rubocop -a

License

This project is Copyright (c) 2014 and onwards. It is free software, and may be redistributed under the terms specified in the LICENSE file.

About

Nimble

This project is maintained and funded by Nimble.

We love open source and do our part in sharing our work with the community! See our other projects or hire our team to help build your product.

rails-templates's People

Contributors

andyduong1920 avatar ankitkalia1195 avatar caherrerapa avatar fikrikarim avatar hanam1ni avatar hoangmirs avatar junan avatar lahphim avatar longnd avatar malparty avatar noor-ahmed avatar olivierobert avatar rafayet-monon avatar rafayetn avatar rosle avatar svnlto avatar thinhphan avatar tolsee avatar tteerawat avatar yutna 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.