{"id":21509251,"url":"https://github.com/mark24code/snippet-template","last_synced_at":"2025-06-24T19:35:48.329Z","repository":{"id":45765673,"uuid":"514237852","full_name":"Mark24Code/snippet-template","owner":"Mark24Code","description":"snippet template generator powered by ERB","archived":false,"fork":false,"pushed_at":"2022-07-16T16:05:29.000Z","size":27,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-17T15:14:49.939Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Mark24Code.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":"2022-07-15T11:03:51.000Z","updated_at":"2023-03-05T02:58:56.000Z","dependencies_parsed_at":"2022-09-02T12:01:29.499Z","dependency_job_id":null,"html_url":"https://github.com/Mark24Code/snippet-template","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/Mark24Code/snippet-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mark24Code%2Fsnippet-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mark24Code%2Fsnippet-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mark24Code%2Fsnippet-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mark24Code%2Fsnippet-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mark24Code","download_url":"https://codeload.github.com/Mark24Code/snippet-template/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mark24Code%2Fsnippet-template/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261743927,"owners_count":23203245,"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-23T21:22:35.101Z","updated_at":"2025-06-24T19:35:48.294Z","avatar_url":"https://github.com/Mark24Code.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Snippet Template \n\n## features\n\n* Snippet Template Support (base on ERB)\n* Template can nest \u0026 import each other\n* Template support local state \u0026 Parent template inject props\n* Scaffold CLI interface support run cmd to inject files into project\n\n\n# Config\n\n1. Template Search Path\n\nexample\n\n```ruby\nSnippetTemplate::Snippet.configure do |config|\n  config.snippet_path = './views'\nend\n\n```\n\n\n| config field | type | example |extra info |\n|----|----|----|----|\n|snippet_path | string\\|Array| `'./snippet'` `['.', './views']`| default: `./snippet` |\n\n\n# Conventional\n\n\n## Snippet Class\n\n`render`  provide basic inner Class\n\nsnippet class must provide\n\n* `initialize` method with `props` arguments\n* `view` method return erb template\n\nview template can access data from local instance attribute and props.\n\n\n```ruby\nrequire_relative './bin/render'\n\nmodule SnippetTemplate\n  class Demo \u003c Template\n    def initialize(props)\n      @props = props || {}\n      @state = \"Demo\"\n    end\n\n    def view\n    return %{\n\n      Hello World\n      data from local \u003c%= @state %\u003e\n      data from props \u003c%= @props %\u003e\n    }\n    end\n  end\nend\n```\n\n## Nest Snippet Template\n\n\n```ruby\nrequire_relative './bin/render'\n\nmodule SnippetTemplate\n  class Sub \u003c Template\n    def initialize(props)\n      @props = props || {}\n    end\n\n    def view\n    return %{\n      Sub Template\n      Props from Parent: \u003c%= @props[:message] %\u003e\n    }\n    end\n  end\nend\n```\n\n```ruby\nrequire_relative '../render'\n\nmodule SnippetTemplate\n  class Parent \u003c Template\n    def initialize(props)\n      @props = props || {}\n    end\n\n    def view\n    return %{\n      Parent Template\n      \u003c%= render(:sub, { message: \"hi\"}) %\u003e\n    }\n    end\n  end\nend\n```\n\nYou can use render method to call other Snippet Template.\n\nWell, it will search snippet template within `config.snippet_path`.\n\n### \u003e\u003e\u003e conventional: the name of snippet template file and it's Class name must be same. To make sure we can find the correct snippet. \u003c\u003c\u003c\n\n\n\n# CLI interface\n\n\ntry to find help\n\n```\n$./bin/scaffold.rb --help\n\nUsage: scaffold.rb [options]\n    -t, --template=Template          Choose snippet template\n    -p, --props=Props                Inject props data to template\n    -o, --output=Output              Inject files to output path\n```\n\nexample\n\n```shell\n./bin/scaffold.rb  -t react -p name:homepage,title:welcome -o dist/welcome.jsx\n```\n\nconventional:\n\n```\n--props  \u003ckey1\u003e:\u003cval1\u003e,\u003ckey2\u003e:\u003cval2\u003e, ....\n\n# will transfer to\n\n{\n  :key1: val1,\n  :key2: val2\n  ...\n}\n\n# then you can use in template\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmark24code%2Fsnippet-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmark24code%2Fsnippet-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmark24code%2Fsnippet-template/lists"}