{"id":20234147,"url":"https://github.com/arbmind/twofold-nodejs","last_synced_at":"2025-03-03T14:12:00.851Z","repository":{"id":66616493,"uuid":"42680328","full_name":"arBmind/Twofold-NodeJs","owner":"arBmind","description":"NodeJs based implementation of Twofold source code generating templates","archived":false,"fork":false,"pushed_at":"2015-09-17T20:34:06.000Z","size":136,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-01-14T00:33:07.517Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arBmind.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}},"created_at":"2015-09-17T20:31:08.000Z","updated_at":"2015-09-17T20:34:08.000Z","dependencies_parsed_at":"2023-03-04T09:00:17.997Z","dependency_job_id":null,"html_url":"https://github.com/arBmind/Twofold-NodeJs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arBmind%2FTwofold-NodeJs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arBmind%2FTwofold-NodeJs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arBmind%2FTwofold-NodeJs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arBmind%2FTwofold-NodeJs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arBmind","download_url":"https://codeload.github.com/arBmind/Twofold-NodeJs/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241678157,"owners_count":20001682,"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-11-14T08:08:50.510Z","updated_at":"2025-03-03T14:12:00.833Z","avatar_url":"https://github.com/arBmind.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Twofold-NodeJs\n\n### Generate correctly indented source code with the evil forces of Javascript and Node.js\n\nThis is the Node.js implementation of Twofold.\n\n**All tests pass but this code was never used in production.**\n\n[hicknhack-software/Twofold-Qt](https://github.com/hicknhack-software/Twofold-Qt) is a production ready C++ version working with Javascript.\n\n## What is the best method to generate source code?\n\n* more difficult than regular html. It requires tight controls about every whitespace and tools for indentation.\n* often requires more control structures in order to access models or AST-like structures.\n\nWe faced these challenges and Twofold is the result.\n\n## Features\n\n* indentation handling\n* source maps for generated javascript\n  * javascript exceptions and syntax errors will point into your template\n* nested source maps for generated targets\n  * positions of all the calls that lead to any target character\n* control of every generated line and every whitespace\n* fully unit and integration tested\n\n## How does it work?\n\nTwofold is basically Javascript that is extended with constructs to generate source code output.\n\n```twofold\n  \\ indented output #{interpolated} without a line break\n  | indented output #{interpolated} with a line break\n  # include \"indent_the_included_file.twofold\"\n  = change_indentation_of_javascript()\n// every line is regular javascript\n```\n\nThese control characters have to be the first non-whitespace character on each line.\nEvery whitespace before them is ignored.\nEvery whitespace after is used as the indentation. Indentation is cumulative and added to each generated line.\n\n**Hint:** Use the whitespaces before control characters to indent them in a column deeper than any surrounding javascript.\nThis gives you a visual splitter.\n\nThis is basically everything you need to know.\n\n## Example Template\n\n```twofold\n// file included.twofold\nfunction methodArgs(args) {\n  args.forEach(function(arg, i){\n    if (0!=i) {\n        // use interpolation to preserve the whitespace\n        \\#{', '}\n    }\n    // use backslash to avoid linebreaks\n        \\#{arg}\n  });\n}\nfunction showMethod(method) {\n        |function #{method.name}(#{methodArgs(method.args)}) {\n        |  #{method.body}\n        |}\n}\n```\n\n```twofold\n// file main.twofold\n#include \"included.twofold\"\n        |function #{name}Class(#{methodArgs(args)}) {\nmethods.forEach(function(method){\n        =  showMethod(method)\n});\n        |\n        |  return {\nmethods.forEach(function(method, i){\n        |    \"#{method.name}\": #{method.name}#{(i+1 \u003c methods.length) ? ',' : ''}\n});\n        |  };\n        |}\n```\n\nIf we run this template against the following data. See the BasicUsage example.\n\n```json\n{\n\"name\": \"TwofoldGenerated\",\n\"args\": [],\n\"methods\": [\n  {\n  \"name\": \"hello\",\n  \"args\": [\"greeted\"],\n  \"body\": \"console.log('Hello ' + greeted);\"\n  }\n]\n}\n```\n\nTwofold will generate the following output.\n\n```javascript\nfunction TwofoldGenerated() {\n  function hello(greeted) {\n    console.log('Hello ' + greeted);\n  }\n\n  return {\n    \"hello\": hello\n  };\n}\n```\n\n## Install\n\n```bash\nnpm install\n```\n\n## Hacking\n\nRun Tests\n```bash\nnpm test\n```\n\nRun Benchmarks\n```bash\nnpm run-script bench\n```\n\n## Roadmap\n\nTwofold is simple. We find it very useful as it is.\n\nFeel free to add your wish as an issue\n\n## License\n\nApache License Version 2.0\nSee LICENSE file for more details\n\n## Contribute\n\nIf you like this project give it a star.\nIf you don't like it or found a bug, please write an issue.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farbmind%2Ftwofold-nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farbmind%2Ftwofold-nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farbmind%2Ftwofold-nodejs/lists"}