Skip to content
Egor Tolstoy edited this page Oct 5, 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.
    • custom_name: "{{ prefix }}{{ custom_parameters.my_value }}{{ module_info.file_basename }}" - a custom name for the file which uses different parameters from Rambafile.
    • is_resource - Generamba adds this file in project like resource, and not like file reference.
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.
    • custom_name: "{{ prefix }}{{ custom_parameters.my_value }}{{ module_info.file_basename }}" - a custom name for the file which uses different parameters from Rambafile.
    • is_resource - Generamba adds this file in project like resource, and not like file reference.
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.

If you want to Generamba generate empty folder you must add in rambaspec dir path like: {name: MyDir/MySubdir}

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).
  • custom_parameters - a hash with custom parameters passed using --custom_parameters option with a generamba gen command. You can reference them like {{ custom_parameters.key1 }}.
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.product_module_name - it should be used in swift tests templates (specified in a Rambafile).
  • module_info.file_name - a name of the current file.
  • module_info.project_targets - an array of project targets (specified in a Rambafile.
  • module_info.test_targets - an array of test targets (specified in a Rambafile.

Snippets

General Snippet Information

Generamba templates support snippets. Snippet is a liquid file which contains duplicated parts of other files. Snippets are located in a snippets subdirectory in the root directory of a 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: