{"id":15107750,"url":"https://github.com/hernanmd/codegenerator","last_synced_at":"2026-01-18T17:00:56.926Z","repository":{"id":28118246,"uuid":"31617175","full_name":"hernanmd/CodeGenerator","owner":"hernanmd","description":"Collection of Pharo Smalltalk utilities related with code generation","archived":false,"fork":false,"pushed_at":"2023-06-08T18:46:53.000Z","size":878,"stargazers_count":2,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-04T04:41:20.853Z","etag":null,"topics":["codegenerator","design-patterns","pharo","pharo-smalltalk","smalltalk"],"latest_commit_sha":null,"homepage":"","language":"Smalltalk","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/hernanmd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-03-03T19:35:08.000Z","updated_at":"2023-11-11T00:30:02.000Z","dependencies_parsed_at":"2024-09-20T15:32:18.441Z","dependency_job_id":"af94fc2e-c465-4658-a5a8-a4979ead43ff","html_url":"https://github.com/hernanmd/CodeGenerator","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/hernanmd/CodeGenerator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hernanmd%2FCodeGenerator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hernanmd%2FCodeGenerator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hernanmd%2FCodeGenerator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hernanmd%2FCodeGenerator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hernanmd","download_url":"https://codeload.github.com/hernanmd/CodeGenerator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hernanmd%2FCodeGenerator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28543495,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T14:59:57.589Z","status":"ssl_error","status_checked_at":"2026-01-18T14:59:46.540Z","response_time":98,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["codegenerator","design-patterns","pharo","pharo-smalltalk","smalltalk"],"created_at":"2024-09-25T21:41:23.897Z","updated_at":"2026-01-18T17:00:56.905Z","avatar_url":"https://github.com/hernanmd.png","language":"Smalltalk","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![license-badge](https://img.shields.io/badge/license-MIT-blue.svg)](https://img.shields.io/badge/license-MIT-blue.svg)\r\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)\r\n[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)\r\n\r\n# Description\r\n\r\nCodeGenerator package in Pharo Smalltalk\r\n\r\n# Installation\r\n\r\nThere are several ways to install the **CodeGenerator** package:\r\n\r\n## Core version\r\n\r\nThe Core version includes only the basic abstract classes which provide core features: A Templates protocol and Authoring holder.\r\n\r\n[//]: # (pi)\r\n```smalltalk\r\nEpMonitor disableDuring: [ \r\n\tMetacello new\t\r\n\t\tbaseline: 'CodeGenerator';\t\r\n\t\trepository: 'github://hernanmd/CodeGenerator/repository';\t\r\n\t\tload ]\r\n```\r\n\r\nEach of the following generators has installer expressions described in their own section.\r\n\r\n## Baseline String\r\n\r\nIf you are building a BaselineOf, copy and paste the following code to make use of CodeGenerator.\r\n\r\n```smalltalk\r\n...\r\nspec\t\t\t\t\r\n\tbaseline: 'CodeGenerator'\t\t\t\t\r\n\twith: [ spec repository: 'github://hernanmd/CodeGenerator/repository' ].\r\n...\r\n```\r\n\r\n# Code Generators Usage Examples\r\n\r\n## Smalltalk Generators\r\n\r\nHow to install:\r\n\r\n```smalltalk\r\nEpMonitor disableDuring: [ \r\n\tMetacello new\t\r\n\tbaseline: 'CodeGenerator';\t\r\n\trepository: 'github://hernanmd/CodeGenerator/repository';\t\r\n\tload: #('Smalltalk-Generators') ].\r\n```\r\n\r\n## Simple class with getter and setter\r\n\r\nThe following generator will create a new class in the image, adding two instance variables and creating their accessors (getters and setters):\r\n\r\n```smalltalk\r\nCGSmalltalk new\r\n\tsetCleanTarget;\r\n\ttargetClassCategory: 'MPIRunner-Core';\r\n\ttargetClass: #MPIRunner;\r\n\taddIVarsWithAccessors: #(#nproc #submitToQueue).\r\nSmalltalk tools browser openOnClass: #MPIRunner asClass.\r\n```\r\n\r\n## Class Hierarchy Generation\r\n\r\nGeneration of Class Hierarchy with three concrete subclasses, specifying a prefix for method names:\r\n\r\n```smalltalk\r\nCGStAbstractClassPattern new\r\n\tsetCleanTarget;\r\n\ttargetClassCategory: 'CGGeneratedCode-Core';\r\n\ttargetClass: #CGExampleAbstractClass2;\r\n\tconcreteClassesCount: 3;\r\n\tconcreteClassNamePattern: #CGExampleConcreteClass2;\r\n\tgenerateClasses;\r\n\toperationsCount: 3;\r\n\toperationsName: #exampleOperation;\r\n\tgenerateOperations.\r\nSmalltalk tools browser openOnClass: #CGExampleAbstractClass2 asClass.\t\t\r\n```\r\n\r\nThe resulting hierarchy is:\r\n\r\n```\r\nCGExampleAbstractClass2\r\n  CGExampleConcreteClass21\r\n  CGExampleConcreteClass22\r\n  CGExampleConcreteClass23\r\n```\r\n\r\n## Singleton Design Pattern\r\n\r\n```smalltalk\r\nCGStSingleton new\r\n\tsetCleanTarget;\r\n\ttargetClassCategory: 'SingletonEx1';\r\n\ttargetClass: #SingletonEx1;\r\n\tgenerateMethods.\r\nSmalltalk tools browser openOnClass: #SingletonEx1 asClass.\r\n```\t\r\n\t\r\n## Visitor Design Pattern\r\n\r\n```smalltalk\r\nCGStBuilderPattern uniqueInstance\r\n        setCleanTarget;\r\n        targetClassCategory: 'CGGeneratedCode-Core';\r\n        \" Abstract Builder class name (ex: UIBuilder) \"\r\n        targetClass: #CGExCarBuilder;\r\n        productNames: #('CGExFordCar' 'CGExBMWCar' 'CGExHondaCar');\r\n        builderNames: #('CGExFordBuilder' 'CGExBMWBuilder' 'CGExHondaBuilder');\r\n        familyNames: #('CGExCarEngine' 'CGExCarBody');\r\n        \" How many product parts per family ? \"\r\n        productPartsPerFamilyCount: 3;\r\n        directorClassName: #CGExCarAssembler;\r\n        generateClasses.\r\nSmalltalk tools browser openOnClass: #CGExCarBuilder asClass.\r\n```\r\n\r\n## SUnit Tests\r\n\r\nSUnit Tests Generator.\r\n\r\n```smalltalk\r\nCGSunit new\r\n\tsetCleanTarget;\r\n\tinputClass: CGSmalltalk;\r\n\ttargetTestClass: #TestCGSmalltalkExample;\r\n\ttargetTestCategory: 'CGGeneratedCode';\r\n\tgenerateSetUp: true;\r\n\tgenerateTests.\r\nSmalltalk tools browser openOnClass: #TestCGSmalltalkExample asClass.\r\n```\r\n\r\n## Convenience Methods\r\n\r\n```smalltalk\r\nCGStConvenienceMethods uniqueInstance\r\n        setCleanTarget;\r\n        parameterCount: 1;\r\n        targetSelector: #cgConvEx1;\r\n        targetClassCategory: 'ConvenienceMethodsEx';\r\n        targetClass: #ConvenienceMethodsEx;\r\n        generateMethods.\r\n```\r\n\r\n## Finite State Machine\r\n\r\n```smalltalk\r\nCGStFSM_CaseStmts1 new\r\n\tsetCleanTarget;\r\n\ttargetClassCategory: 'FSM-Core';\r\n\ttargetClass: #FSMCaseStmts1;\r\n\ttargetSelector: #someMessage;\r\n\tinitialState: #state0;\r\n\ttransitions: (Dictionary new \r\n\t\tat: #state0 put: #state1;\r\n\t\tat: #state1 put: #state0;\r\n\t\tyourself);\r\n\tgenerateMethods.\r\nSmalltalk tools browser openOnClass: #FSMCaseStmts1 asClass.\r\n```\r\n## Resource Importer\r\n\r\nThis generator open a directory selector dialog. The selected directory is used as source to scan image files and import them as Smalltalk methods. Currently supported file types are: 'jpg' 'jpeg' 'png' 'gif' 'ico' 'bmp'. For each image file, the name of the file concatenated with its extension (uppercase first extension letter) is used as method name. \r\n\r\n```smalltalk\r\nCGStImageImporter new\r\n\tsetCleanTarget;\r\n\ttargetClass: #CGExampleResources1;\r\n\ttargetClassCategory: 'CGGeneratedCode';\r\n\timport.\r\nSmalltalk tools browser openOnClass: #CGExampleResources1 asClass.\r\n```\r\n\r\nThis generator open a directory selector dialog. The selected directory is used as source to scan text files and import them as Smalltalk methods. Currently supported file types are: 'txt' 'csv'. For each image file, the name of the file concatenated with its extension (uppercase first extension letter) is used as method name. \r\n\r\n```smalltalk\r\nCGStTextImporter new\r\n\tsetCleanTarget;\r\n\ttargetClass: #CGExampleResources2;\r\n\ttargetClassCategory: 'CGGeneratedCode';\r\n\timport.\r\nSmalltalk tools browser openOnClass: #CGExampleResources2 asClass.\r\n```\r\n\r\n## Spec Generator\r\n\r\n### How to install:\r\n\r\n```smalltalk\r\nMetacello new\t\r\n  baseline: 'CodeGenerator';\t\r\n  repository: 'github://hernanmd/CodeGenerator/repository';\t\r\n  load: #('SpecUI').\r\n```\r\n\r\n### Usage example\r\n\r\n```smalltalk\r\nCGStSpec new\r\n\tsetCleanTarget;\r\n\ttargetClass: #SpecModelClass1;\r\n\ttitle: 'Example Spec 1';\r\n\tgenerateMethods.\r\nSmalltalk tools browser openOnClass: #SpecModelClass1 asClass.\r\n```\r\n\r\n## NSIS Installer Script Generator\r\n\r\nHow to install:\r\n\r\n```smalltalk\r\nMetacello new\t\r\n  baseline: 'CodeGenerator';\t\r\n  repository: 'github://hernanmd/CodeGenerator/repository';\t\r\n  load: #('NSIS').\r\n```\r\n\r\n### Usage example\r\n\r\n```smalltalk\r\nCGNSISIPharo5AppInstaller new\r\n\tproduct: 'MyProduct';\r\n\tidentity: 'MyName';\r\n\tversion: '1.0.0';\r\n\turl: 'http://www.google.com';\r\n\tlauncher: 'MyLauncher.exe';\r\n\tlicenseEnFileName: 'LICENSE_ENGLISH';\r\n\ticonFile: 'MyProduct.ico';\r\n\twelcomeBmpFile: 'MyProduct.bmp';\r\n\tsplashBMPFileName: 'Splash.bmp';\r\n\tgenerate.\r\n```\r\n\r\n## ProjectFramework Generator\r\n\r\nRequires: [ProjectFramework](https://github.com/hernanmd/ProjectFramework \"ProjectFramework\")\r\n\r\n### How to install:\r\n\r\n```smalltalk\r\nMetacello new\t\r\n  baseline: 'CodeGenerator';\t\r\n  repository: 'github://hernanmd/CodeGenerator/repository';\t\r\n  load: #('ProjectFramework').\r\n```\r\n\r\n### Usage example\r\n\r\n```smalltalk\r\nCGStProjectFramework new\r\n\tsetCleanTarget;\r\n\ttargetClassCategory: 'PFExampleCategory';\r\n\ttargetSuperclass: #PFStandardProjectWindow;\t\t\r\n\ttargetClass: #PFExampleWindow;\r\n\tapplicationClassName: #PFExampleApplicationClass;\r\n\tprojectClassName: #PFExampleProjectClass;\r\n\ttitle: 'Example Project UI';\r\n\tcloseAfterCreateProjectSetting: true;\r\n\tgenerateMethods.\r\nSmalltalk tools browser openOnClass: #PFExampleWindow asClass.\r\n```\r\n\r\n## Magritte Generator\r\n\r\n### How to install:\r\n\r\n```smalltalk\r\nMetacello new\t\r\n  baseline: 'CodeGenerator';\t\r\n  repository: 'github://hernanmd/CodeGenerator/repository';\t\r\n  load: #('ProjectFramework').\r\n```\r\n\r\n### Usage examples\r\n\r\nExample setting priorities:\r\n\r\n```smalltalk\r\nCGStMagritte new\r\n\tinputClass: ModelClass1;\r\n\ttargetClass: ModelClass1;\r\n\tsetBooleanAttributes: \t\t'instVar1' \t\t\tlabel: 'label iVar1' \t\t\tpriority: 10;\r\n\tsetDateAndTimeAttributes: \t'instVar2' \t\t\tlabel: 'label Date and Time' \tpriority: 20;\r\n\tsetDateAttributes: \t\t'instVar3' \t\t\tlabel: 'label Date' \t\t\tpriority: 30;\r\n\tsetFileAttributes: \t\t'iVarFile' \t\t\tlabel: 'label File' \t\t\tpriority: 40;\r\n\tsetMemoAttributes: \t\t'iVarMemo' \t\t\tlabel: 'label Memo' \t\t\tpriority: 50;\r\n\tsetMultiOptionAttributes: \t'iVarMultiOption' \tlabel: 'label Multi Option' \tpriority: 60;\r\n\tsetNumberAttributes: \t\t'iVarInteger' \t\tlabel: 'label Integer' \t\t\tpriority: 70.\r\nSmalltalk tools browser openOnClass: ModelClass1.\r\n```\r\n\r\nExample setting defaults:\r\n\r\n```smalltalk\r\nCGStMagritte new\r\n\tinputClass: ModelClass1;\r\n\ttargetClass: ModelClass1;\r\n\tsetBooleanAttributes: \t\t'instVar1' \t\tdefault: true\t\t\t\t\tlabel: 'label iVar1' \t\t\t\tpriority: 10;\r\n\tsetDateAndTimeAttributes: \t'instVar2' \t\tdefault: DateAndTime today \t\tlabel: 'label Date and Time'\t \tpriority: 20;\r\n\tsetDateAttributes: \t\t\t'instVar3' \t\tdefault: Date today \t\t\tlabel: 'label Date' \t\t\t\tpriority: 30;\r\n\tsetFileAttributes: \t\t\t'iVarFile' \t\t\t\t\t\t\t\t\t\tlabel: 'label File' \t\t\t\tpriority: 40;\r\n\tsetMemoAttributes: \t\t\t'iVarMemo' \t\tdefault: 'Memo'\t\t\t\t\tlabel: 'label Memo' \t\t\t\tpriority: 50;\r\n\tsetMultiOptionAttributes: \t'iVarMulti' \tdefault: #(One Two)\t\t\tlabel: 'label Multi Option'\t\t \tpriority: 60;\r\n\tsetNumberAttributes: \t\t'iVarInteger' \tdefault: 10 \t\t\t\tlabel: 'label Integer'\t \t\t\tpriority: 70.\r\nSmalltalk tools browser openOnClass: ModelClass1.\t\t\r\n``` \r\n\r\n## R Generator\r\n\r\n### How to install:\r\n\r\n```smalltalk\r\nMetacello new\t\r\n  baseline: 'CodeGenerator';\t\r\n  repository: 'github://hernanmd/CodeGenerator/repository';\t\r\n  load: #('R').\r\n```\r\n\r\n### Usage example\r\n\r\nWork in progress\r\n\r\n## Bash Generator\r\n\r\n### How to install:\r\n\r\n```smalltalk\r\nMetacello new\t\r\n  baseline: 'CodeGenerator';\t\r\n  repository: 'github://hernanmd/CodeGenerator/repository';\t\r\n  load: #('Bash').\r\n```\r\n\r\n### Usage example\r\n\r\nWork in progress\r\n\r\n# Contribute\r\n\r\n**Working on your first Pull Request?** You can learn how from this *free* series [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github)\r\n\r\nIf you have discovered a bug or have a feature suggestion, feel free to create an issue on Github.\r\nIf you have any suggestions for how this package could be improved, please get in touch or suggest an improvement using the GitHub issues page.\r\nIf you'd like to make some changes yourself, see the following:    \r\n\r\n  - Fork this repository to your own GitHub account using the web interface.\r\n  - Clone it to your local device: `git clone git@github.com:YOUR_NAME/.git`\r\n  - Do some modifications\r\n    - If you add some feature, create your feature branch: `git checkout -b MY_NEW_FEATURE`\r\n  - Test.\r\n  - Add \u003cyour GitHub username\u003e to add yourself as author below.\r\n  - Finally, submit a pull request with your changes!\r\n  - This project follows the [all-contributors specification](https://github.com/kentcdodds/all-contributors). Contributions of any kind are welcome!\r\n\r\n# License\r\n\t\r\nThis software is licensed under the MIT License.\r\n\r\nCopyright Hernán Morales Durand, 2018-2021.\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r\n\r\n# Authors\r\n\r\nHernán Morales Durand\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhernanmd%2Fcodegenerator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhernanmd%2Fcodegenerator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhernanmd%2Fcodegenerator/lists"}