Giter Club home page Giter Club logo

sbconstants's Introduction

sbconstants

Generate a constants file by grabbing identifiers from storyboards in a project. See my blog post for more use cases.

Installation

$ gem install sbconstants

Usage

For automated use:

  1. Add a file in Xcode to hold your constants e.g. PASStoryboardConstants.(h|m)
  2. Add a build script to build phases
    sbconstants path_to_constant_file
  3. Enjoy your identifiers being added as constants to your constants file

For manual use (using swift):

  1. Add a file in Xcode to hold your constants e.g. StoryboardIdentifiers.swift
  2. Add a command to your Makefile to run something similar to sbconstants path/to/StoryboardIdentifiers.swift --source-dir path/to/Storyboards --swift

Command line API

$ sbconstants -h
Usage: DESTINATION_FILE [options]
    -d, --dry-run                    Output to STDOUT
    -p, --prefix=<prefix>            Only match identifiers with <prefix>
    -s, --source-dir=<source>        Directory containing storyboards
    -t, --templates-dir=<templates>  Directory containing the templates to use for code formatting
    -q, --queries=<queries>          YAML file containing queries
    -v, --verbose                    Verbose output
    -w, --swift                      Output to a Swift File

Custom formatting

If you are running tools that verify your team is sticking to coding conventions you might find that the default output might not fit your requirements. Not to fear you can provide your own templates to decide the formatting you require by passing the --templates-dir option with the path to the directory containing the templates to use.

Inside your custom templates you can interpolate the constant_name and constant_value like this

NSString * const <%= constant_name %> = @"<%= constant_value %>";

You can override how the Objective-C constants are formatted by creating objc_header.erb and objc_implementation.erb files and adding the --templates-dir flag pointing to their containing directory.

Contributing

  1. Fork it
  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 new Pull Request

sbconstants's People

Contributors

ashfurrow avatar kevboh avatar neonichu avatar orta avatar palleas avatar paulsamuels avatar

Stargazers

 avatar

Watchers

 avatar  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.