{"id":3122,"url":"https://github.com/paulsamuels/SBConstants","last_synced_at":"2025-08-03T13:31:55.073Z","repository":{"id":6703475,"uuid":"7948923","full_name":"paulsamuels/SBConstants","owner":"paulsamuels","description":null,"archived":false,"fork":false,"pushed_at":"2017-04-21T02:31:41.000Z","size":58,"stargazers_count":311,"open_issues_count":10,"forks_count":28,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-11-20T19:07:20.525Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paulsamuels.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-02-01T00:40:12.000Z","updated_at":"2024-10-17T01:37:16.000Z","dependencies_parsed_at":"2022-07-04T15:12:23.178Z","dependency_job_id":null,"html_url":"https://github.com/paulsamuels/SBConstants","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulsamuels%2FSBConstants","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulsamuels%2FSBConstants/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulsamuels%2FSBConstants/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulsamuels%2FSBConstants/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paulsamuels","download_url":"https://codeload.github.com/paulsamuels/SBConstants/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228548567,"owners_count":17935221,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:16:32.009Z","updated_at":"2024-12-07T01:30:34.462Z","avatar_url":"https://github.com/paulsamuels.png","language":"Ruby","funding_links":[],"categories":["Tools","WebSocket","Ruby","Misc","Utility"],"sub_categories":["Web View","Other free courses","Video"],"readme":"# sbconstants\n\nGenerate a constants file by grabbing identifiers from storyboards in a project.\n\n## Installation\n\n```sh\n$ gem install sbconstants\n```\n\n## Usage\n\nFor automated use:\n\n1. Add a file in Xcode to hold your constants e.g. `PASStoryboardConstants.(h|m)`\n2. Add a build script to build phases e.g. `sbconstants path_to_constant_file`\n3. Enjoy your identifiers being added as constants to your constants file\n\nFor manual use (using swift):\n\n1. Add a file in Xcode to hold your constants e.g. `StoryboardIdentifiers.swift`\n2. Add a command to your [Makefile](https://github.com/artsy/eidolon/blob/15da1330a04615b3553779742f166b707c6ef65f/Makefile#L54) to run something similar to `sbconstants path/to/StoryboardIdentifiers.swift --source-dir path/to/Storyboards --swift`\n\n## Command line API\n\n```sh\n$ sbconstants -h\nUsage: DESTINATION_FILE [options]\n    -d, --dry-run                    Output to STDOUT\n    -p, --prefix=\u003cprefix\u003e            Only match identifiers with \u003cprefix\u003e\n    -i, --ignore=\u003cfiles_to_ignore\u003e   Comma separated list of files to ignore\n    -s, --source-dir=\u003csource\u003e        Directory containing storyboards\n    -t, --templates-dir=\u003ctemplates\u003e  Directory containing the templates to use for code formatting\n    -q, --queries=\u003cqueries\u003e          YAML file containing queries\n    -v, --verbose                    Verbose output\n    -w, --swift                      Output to a Swift File\n```\n\nAn example usage would look like:\n\n```\nsbconstants MyApp/Constants/PASStoryboardConstants.h\n```\n\n**NB** The argument is the destination file to dump the constants into - this needs to be added manually\n\nEvery time `sbconstants` is run it will parse the storyboard files and pull out any constants and then dump them into `PASStoryboardConstants.(h|m)`. This of course means that `PASStoryboardConstants.(h|m)` should not be edited by hand as it will just be clobbered any time we build.\n\nThe output of running this tool will look something like this:\n\n`PASStoryboardConstants.h`\n\n```objective-c\n// Auto generated file - any changes will be lost\n\n#import \u003cFoundation/Foundation.h\u003e\n\n#pragma mark - segue.identifier\nextern NSString * const PSBMasterToDetail;\nextern NSString * const PSBMasterToSettings;\n\n#pragma mark - storyboardNames\nextern NSString * const Main;\n\n#pragma mark - tableViewCell.reuseIdentifier\nextern NSString * const PSBAwesomeCell;\n```\n\n`PASStoryboardConstants.m`\n\n```objective-c\n// Auto generated file - any changes will be lost\n\n#import \"PASStoryboardConstants.h\"\n\n#pragma mark - segue.identifier\nNSString * const PSBMasterToDetail = @\"PSBMasterToDetail\";\nNSString * const PSBMasterToSettings = @\"PSBMasterToSettings\";\n\n#pragma mark - storyboardNames\nNSString * const Main = @\"Main\";\n\n#pragma mark - tableViewCell.reuseIdentifier\nNSString * const PSBAwesomeCell = @\"PSBAwesomeCell\";\n```\n\nUsing the `--swift` flag this would produce\n\n```swift\n// Auto generated file from SBConstants - any changes may be lost\n\npublic enum SegueIdentifier : String {\n    case PSBMasterToDetail = \"PSBMasterToDetail\"\n    case PSBMasterToSettings = \"PSBMasterToSettings\"\n}\n\npublic enum StoryboardNames : String {\n    case Main = \"Main\"\n}\n\npublic enum TableViewCellreuseIdentifier : String {\n    case PSBAwesomeCell = \"PSBAwesomeCell\"\n}\n```\n\nThe constants are grouped by where they were found in the storyboard xml e.g. `segue.identifier`. This can really help give you some context about where/what/when and why a constant exists.\n\n##Options\n\nOptions are fun and there are a few to play with - most of these options are really only any good for debugging.\n\n#### `--prefix`\n    -p, --prefix=\u003cprefix\u003e            Only match identifiers with \u003cprefix\u003e\n\nUsing the `prefix` option you can specify that you only want to grab identifiers that start with a certain prefix, which is always nice.\n\n#### `--ignore=\u003cfiles_to_ignore\u003e`\n    -i, --ignore=\u003cfiles_to_ignore\u003e   Comma separated list of files to ignore\nUsing the `ignore` option, you can specify files which will not be added to the generated constants file. If you need to ignore several files, you need to separate it with commas (`-i MainStoryboard,HelpStoryboard,CellXIB`).\n\n#### `--source-dir`\n    -s, --source-dir=\u003csource\u003e        Directory containing storyboards\n\nIf you don't want to run the tool from the root of your app for some reason you can specify the source directory to start searching for storyboard files. The search is recursive using a glob something like `\u003csource-dir\u003e/**/*.storyboard`\n\n#### ` --dry-run`\n    -d, --dry-run                    Output to STDOUT\n\nIf you just want to run the tool and not write the output to a file then this option will spit the result out to `$stdout`\n\n#### `--verbose`\n    -v, --verbose                    Verbose output\n\nPerhaps you want a little more context about where your identifiers are being grabbed from for debugging purposes. Never fear just use the `--verbose` switch and get output similar to:\n\n`sample output`\n\n```objective-c\n#pragma mark - viewController.storyboardIdentifier\n//\n//    info: MainStoryboard[line:43](viewController.storyboardIdentifier)\n// context: \u003cviewController restorationIdentifier=\"asd\" storyboardIdentifier=\"FirstViewController\" id=\"EPD-sv-vrF\" sceneMemberID=\"viewController\"\u003e\n//\nNSString * const FirstViewController = @\"FirstViewController\";\n\n```\n\n#### `--queries`\n    -q, --queries=\u003cqueries\u003e          YAML file containing queries\n\nChances are I've missed some identifiers to search for in the storyboard. You don't want to wait for the `gem` to be updated or have to fork it and fix it. Using this option you can provide a YAML file that contains a description of what identifers to search for. The current one looks something like this (NB this is a great starting point for creating your own yaml):\n\n`queries`\n\n```\n---\nsegue: identifier\nview: restorationIdentifier\n? - tableViewCell\n  - collectionViewCell\n: - reuseIdentifier\n? - navigationController\n  - viewController\n  - tableViewController\n  - collectionViewController\n: - storyboardIdentifier\n  - restorationIdentifier\n```\n\nThis looks a little funky but it's essentially groups of keys and values (both the key and the value can be an array). This actually gets expanded to the following table:\n\n    +--------------------------+-----------------------+\n    |         node             |      attribute        |\n    + -------------------------+-----------------------+\n    | segue                    | identifier            |\n    | view                     | restorationIdentifier |\n    | tableViewCell            | reuseIdentifier       |\n    | collectionViewCell       | reuseIdentifier       |\n    | navigationController     | storyboardIdentifier  |\n    | viewController           | storyboardIdentifier  |\n    | tableViewController      | storyboardIdentifier  |\n    | collectionViewController | storyboardIdentifier  |\n    | viewController           | restorationIdentifier |\n    | navigationController     | restorationIdentifier |\n    | tableViewController      | restorationIdentifier |\n    | collectionViewController | restorationIdentifier |\n    +--------------------------+-----------------------+\n\n#### `--swift`\n\n    -w, --swift                      Output to a Swift File\n\nOutputs Swift code rather than Objective-C\n\n#### `--templates-dir`\n\n    -t, --templates-dir=\u003ctemplates\u003e  Directory containing the templates to use for code formatting\n\nSee below\n\n## Custom formatting\n\nIf 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.\n\nInside your custom templates you can interpolate the `constant_name` and `constant_value` like this\n\n```objective-c\nNSString * const \u003c%= constant_name %\u003e = @\"\u003c%= constant_value %\u003e\";\n```\n\nYou 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.\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulsamuels%2FSBConstants","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaulsamuels%2FSBConstants","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulsamuels%2FSBConstants/lists"}