Skip to content
Beniamin edited this page Feb 18, 2016 · 9 revisions

General Information

A Generamba template usually consists of:

  • [template_name].rambaspec file, which contains the basic template configuration.
  • A number of templates (with a liquid markup) for code and test files generation.

Templates are distributed separately from the gem itself. They can be installed in either of three ways:

  • From a local directory,
  • From a remote Git repository,
  • From a shared templates catalog.

After installation templates are stored in `/Templates/ directory located in the project root directory.

.rambaspec-file Structure

General Template Information Section
  • name: rviper_controller - a name of the template. It must be equal to template root folder name.
  • summary: template description - a brief description of the template.
  • author: Rambler&Co - an author (or company) name.
  • version: 1.0.0 - a current version number. This information is not directly used by Generamba at the moment.
  • license: MIT - A license, choosed for the template.
Code Files Section
  • code_files: - a list of code files, generated by using the template.
    • name: Service/Service.h - a full path to a generated file (after it's generated) and its name. The name will be modified during a module generation using Rambafile information (e.g. RDSAuthorizationService).
    • path: Code/Service/service.h.liquid - a relative file path to a liquid template of the generating file.
Test Files Section
  • test_files: - a list of test files, generated by using the template.
    • name: Service/ServiceTests.h - a full path to a generated test (after it's generated) and its name. The name will be modified during a module generation using Rambafile information (e.g. RDSAuthorizationServiceTests).
    • path: Tests/Service/service_tests.m.liquid - a relative file path to a liquid template of the generating file.
Dependencies Section
  • dependencies: - a list of dependencies, used in the generated code (if there are any). This information don't affect anything directly at the moment, and persist due to upcoming features. Besides it, it's more convinient for the end users to see the list of the template dependencies declared in one certain place.

Template Variables

General Variables
  • prefix - a project prefix (specified in a Rambafile).
  • year - current year (determined automatically).
  • date - current date in a static format: dd/MM/yyyy (determined automatically).
Developer Information
  • developer.name - your name. It is setuped either during generamba setup or generamba gen command. You can always change it manually by modifying user preferences file (~/.generamba/user_preferences.yml).
  • developer.company - your company name (specified in a Rambafile).
Module Information
  • module_info.name - a name of the generating module (a parameter for generamba gen command).
  • module_info.description - a description of the generating module (a parameter for generamba gen command).
  • module_info.project_name - current project name (specified in a Rambafile).
  • module_info.file_name - a name of the current file.

Snippets

General Snippet Information

A Generamba template support snippets. Snippet it is liquid file with duplicated parts of views. Snippets located in snippets directory, which located in root directory of template.

  • MyTemplate
    • Code
      • viewcontroller.h.liquid
    • Tests
      • view_tests.m.liquid
    • snippets
      • header.liquid
Example

We have

viewcontroller.h.liquid

//
//  {{ prefix }}{{ module_info.name }}{{ module_info.file_name }}
//  {{ module_info.project_name }}
//
//  Created by {{ developer.name }} on {{ date }}.
//  Copyright {{ year }} {{ developer.company }}. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface {{ prefix }}{{ module_info.name }}ViewController : UIViewController

@end

Using snippets, we can rewrite it like this

header.liquid

//
//  {{ prefix }}{{ module_info.name }}{{ module_info.file_name }}
//  {{ module_info.project_name }}
//
//  Created by {{ developer.name }} on {{ date }}.
//  Copyright {{ year }} {{ developer.company }}. All rights reserved.
//

viewcontroller.h.liquid

{% include 'header' %}

#import <UIKit/UIKit.h>

@interface {{ prefix }}{{ module_info.name }}ViewController : UIViewController

@end

Creating Templates

To create a new template from scratch you can use generamba template create command.

Examples:

Clone this wiki locally