xfabricator

Is a command line tool that generates files from mustache templates and add them directly to an xcode project.

  • Generated files can be added to specific targets & groups
  • Generated files can be added to groups automatically based on the present working directory or specified path

Installation

Add this line to your application's Gemfile:

gem 'xfabricator'

And then execute:

$ bundle

Or install it yourself as:

$ gem install xfabricator

Usage

Project configuration

This configuration file should be located somewhere in the root of your project directory. When the xfabricate CLI tool is run it will scan up the folder hierarchy until it finds this file.

.xfabricate

FabricationConfig.create_config lambda { |config|
    variables = {}
    variables[:project_variable] = "value specific to the project"
    variables[:some_interesting_value] = "another value specific to the project"

    #Any project specific variables.  This can be omitted.
    config[:variables] = variables

    #The project file to add generated files to
    config[:project_file] = "#{relative_path}/ExampleProj.xcodeproj"

    #The location of template definitions and associated files; can be absolute or relative
    config[:template_location] = "#{relative_path}/xftemplates"

    #The target to associate any generated files when no specific target is specified
    config[:default_target] = 'ExampleProj'
}

Template definitions

The template definition file should be located in the template_location specified in the .xfabricate configuration file. A file named Test.xftemplate could be used for template fabrication using the following xfabricate -t Test anywhere inside the project.

TemplateDefinition.create_definition lambda { |template_definition|
    #Declare template files and generated file names
    #Generated file names can include any project or template variable
    template_files = [
       TemplateFileDefinition.new("ExampleTemplate.h", '{{some_variable}}Widget.h'),
       TemplateFileDefinition.new("ExampleTemplate.m", '{{some_variable}}Widget.m'),
       #optionally specify a sub path relative to the group
       TemplateFileDefinition.new("example.txt", '{{another_variable}}Example.txt', 'a/deep/folder/path')
    ]

    template_definition[:template_files] = template_files

    #declare variable names and appropriate prompts to request variable values
    template_definition[:variable_prompts] = {
       some_variable: 'some_variable value:',
       a_variable_used_in_template: 'Please enter a value for the variable used in the template...'
    }
}

The template files are mustache templates with access to any variables in the project configuration or supplied at prompts defined in the template definition.

Command line tool

The following add files fabricated by the Example template to the group represented by the present working directory Fabricated files will be added to the default target specified in your .xfabricate file

> cd a/sub/path/in/your/project/dir
> xfabricate -t Example

The following add files fabricated by the Example template to the group represented by the present working directory Fabricated files will be added to the default target specified in your .xfabricate file

> cd /your/project/directory
> xfabricate -t Example -p a/sub/path/in/your/project/dir

The following add files fabricated by the Example template to the group matching the name TestGroup Fabricated files will be added to the default target specified in your .xfabricate file

> cd /your/project/directory
> xfabricate -t Example -g TestGroup
Usage: xfabricate [options]
    -t, --template=template_name     specify template to fabricate
    -a, --target=target_name         specify target to add created files
    -g, --group=group_name           specify group to add created files
    -p, --path=path_name             specify search path to find the current group

Development

After checking out the repo, run bin/setup to install dependencies. 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/nicholascross/xfabricator.

License

The gem is available as open source under the terms of the MIT License.