{"id":22808972,"url":"https://github.com/ccuffs/poll-from-text","last_synced_at":"2025-06-27T23:32:56.432Z","repository":{"id":62500423,"uuid":"377922610","full_name":"ccuffs/poll-from-text","owner":"ccuffs","description":"Convenient package to create polls (questionnaires) from pure text minimally organized in lines","archived":false,"fork":false,"pushed_at":"2022-01-28T19:30:25.000Z","size":96,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-22T13:52:18.854Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/ccuffs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE-OF-CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-17T18:13:36.000Z","updated_at":"2021-10-03T22:31:52.000Z","dependencies_parsed_at":"2022-11-02T12:01:29.471Z","dependency_job_id":null,"html_url":"https://github.com/ccuffs/poll-from-text","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":"ccuffs/template-english","purl":"pkg:github/ccuffs/poll-from-text","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccuffs%2Fpoll-from-text","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccuffs%2Fpoll-from-text/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccuffs%2Fpoll-from-text/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccuffs%2Fpoll-from-text/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ccuffs","download_url":"https://codeload.github.com/ccuffs/poll-from-text/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccuffs%2Fpoll-from-text/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262351545,"owners_count":23297633,"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-12-12T11:13:05.474Z","updated_at":"2025-06-27T23:32:56.377Z","avatar_url":"https://github.com/ccuffs.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg width=\"800\" src=\".github/logo.png\" title=\"Project logo\"\u003e\u003cbr /\u003e\n    \u003cimg src=\"https://img.shields.io/maintenance/yes/2022?style=for-the-badge\" title=\"Project status\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/workflow/status/ccuffs/poll-from-text/CI?label=Build\u0026logo=github\u0026logoColor=white\u0026style=for-the-badge\" title=\"Build status\"\u003e\n\u003c/p\u003e\n\n# Introduction\n\n`poll-from-text` is a PHP package to parse semi-structured text into structured-data that can be used to build questionnaires (forms). The main goal is to allow end users to build dynamic forms, e.g. Google Forms, using plain text like they would if the forms were to be printed on paper.\n\n\u003e **NOTICE:** this package assumes a certain format in the \"pure\" text, so it might not be as generic as possible. The world has bigger problems.\n\n## ✨Features\n\n* Simple input questions (useful to create `\u003cinput type=\"text\" /\u003e` elements);\n* Question with options (useful to create `\u003cselect\u003e` elements);\n* Options with no value (only text), e.g. `- Text`, or `* Text` (like in `\u003coption\u003eText\u003c/option\u003e`);\n* Options with a value, e.g `a) Text` (value is `\"a\"`, like in `\u003coption value=\"a\"\u003eText\u003c/option\u003e`);\n* Data attributes (as JSON objects) for both questions and options, e.g. `{\"type\":\"file\"} What?` (useful to create custom form elements such as `\u003cinput type=\"file\" /\u003e`).\n\n## 🚀 Getting started\n\n### 1. Add this package to your project\n\nAt the root of your project, run:\n\n```\ncomposer require ccuffs/poll-from-text\n```\n\n### 2. Basic usage\n\nInstantiate the class `CCUFFS\\Text\\PollFromText` then call `parse()`:\n\n\u003e*Tip:* use `CCUFFS\\Text\\PollFromText::make()` if you don't want to instantiate an object.\n\n```php\n$poller = new CCUFFS\\Text\\PollFromText();\n$questions = $poller-\u003eparse('Favorite color?')\n\nvar_dump($questions);\n```\n\nThe output should be something like:\n\n```php\narray(1) {\n  [0]=\u003e\n  array(2) {\n    [\"text\"]=\u003e\n    string(15) \"Favorite color?\"\n    [\"type\"]=\u003e\n    string(5) \"input\"\n  }\n}\n```\n\nA new line (without the option marks) indicates a new question:\n\n```php\n$poller = new CCUFFS\\Text\\PollFromText();\n$questions = $poller-\u003eparse('\n    Favorite color?\n    Favorite food?\n')\n\nvar_dump($questions);\n```\n\nThe output should be something like:\n\n```php\narray(2) {\n  [0]=\u003e\n  array(2) {\n    [\"text\"]=\u003e\n    string(15) \"Favorite color?\"\n    [\"type\"]=\u003e\n    string(5) \"input\"\n  }\n  [1]=\u003e\n  array(2) {\n    [\"text\"]=\u003e\n    string(15) \"Favorite food?\"\n    [\"type\"]=\u003e\n    string(5) \"input\"\n  }  \n}\n```\n\nYou can create questions with options by prefixing lines with `-` or `*`:\n\n```php\n$poller = new CCUFFS\\Text\\PollFromText();\n$questions = $poller-\u003eparse('\n   Choose favorite color\n   - Green\n');\n\nvar_dump($questions);\n```\n\nThe output should be something like:\n\n```php\narray(1) {\n  [0]=\u003e\n  array(3) {\n    [\"text\"]=\u003e\n    string(21) \"Choose favorite color\"\n    [\"type\"]=\u003e\n    string(6) \"select\"\n    [\"options\"]=\u003e\n    array(1) {\n      [\"text\"]=\u003e\n      string(5) \"Green\",\n      [\"marker\"]=\u003e\n      string(1) \"-\"\n    }\n  }\n}\n```\n\n### 3. Advanced usage\n\nYou can create questions with options and their values by using `)`, for instance:\n\n```php\n$poller = new CCUFFS\\Text\\PollFromText();\n$questions = $poller-\u003eparse('\n   Choose favorite color\n   a) Green\n');\n\nvar_dump($questions);\n```\n\nThe output should be something like:\n\n```php\narray(1) {\n  [0]=\u003e\n  array(3) {\n    [\"text\"]=\u003e\n    string(21) \"Choose favorite color\"\n    [\"type\"]=\u003e\n    string(6) \"select\"\n    [\"options\"]=\u003e\n    array(1) {\n     [\"a\"]=\u003e\n      array(3) {\n        [\"text\"]=\u003e\n        string(5) \"Green\"\n        [\"marker\"]=\u003e\n        string(1) \"a\"\n        [\"separator\"]=\u003e\n        string(1) \")\"\n    }\n  }\n}\n```\n\nBoth questions and options accept a json string as a data field, e.g.\n\n```php\n$poller = new CCUFFS\\Text\\PollFromText();\n$questions = $poller-\u003eparse('{\"attr\":\"value\", \"attr2\":\"value\"} Type favorite color');\n\nvar_dump($questions);\n```\n\nThe output should be something like:\n\n```php\narray(1) {\n  [0]=\u003e\n  array(3) {\n    [\"text\"]=\u003e\n    string(21) \"Type favorite color\"\n    [\"type\"]=\u003e\n    string(5) \"input\"\n    [\"data\"]=\u003e\n    array(2) {\n      [\"attr\"]=\u003e\n      string(5) \"value\"\n      [\"attr2\"]=\u003e\n      string(5) \"value\"\n    }\n  }\n}\n```\n\nData attribute for an options:\n\n```php\n$poller = new CCUFFS\\Text\\PollFromText();\n$questions = $poller-\u003eparse('\n   Choose favorite color\n   {\"attr\":\"hi\"} a) Green\n');\n\nvar_dump($questions);\n```\n\nThe output should be something like:\n\n```php\narray(1) {\n  [0]=\u003e\n  array(3) {\n    [\"text\"]=\u003e\n    string(21) \"Choose favorite color\"\n    [\"type\"]=\u003e\n    string(6) \"select\"\n    [\"options\"]=\u003e\n    array(1) {\n      [\"a\"]=\u003e array(2) {\n          [\"text\"]=\u003e\n          string(5) \"Green\"\n          [\"marker\"]=\u003e\n          string(1) \"a\"\n          [\"separator\"]=\u003e\n          string(1) \")\"          \n          [\"data\"]=\u003e\n          array(1) {\n              [\"attr\"]=\u003e\n              string(2) \"hi\"\n          }\n      }\n    }\n  }\n}\n```\n\n### 3.1 Specific configuration\n\nBoth `parse()` and `make()` accept a `$config` which is an array of configuration to consider when generating the questionnaire. Below is a complete list of all available configuration options:\n\n```php\n$config = [\n    'multiline_question' =\u003e false,                   // if `true`, questions are allowed to have `\\n` in their text.\n    'attr_validation' =\u003e PollFromText::ATTR_AS_TEXT, // allow any text a attribute (no validation)\n];\n```\n\n\n### 4. Testing (related to the package development)\n\nIf you plan on changing how the package works, be sure to clone it first: \n\n```\ngit clone https://github.com/ccuffs/poll-from-text \u0026\u0026 cd poll-from-text\n```\n\nInstall dependencies\n\n```\ncomposer install\n```\n\nMake your changes. After, run the tests it to ensure nothing breaked:\n\n```\n./vendor/bin/pest\n```\n\nThere should be plenty of green marks all over 😁\n\n\n## 🤝 Contribute\n\nYour help is most welcome regardless of form! Check out the [CONTRIBUTING.md](CONTRIBUTING.md) file for all ways you can contribute to the project. For example, [suggest a new feature](https://github.com/ccuffs/poll-from-text/issues/new?assignees=\u0026labels=\u0026poll-from-text=feature_request.md\u0026title=), [report a problem/bug](https://github.com/ccuffs/poll-from-text/issues/new?assignees=\u0026labels=bug\u0026poll-from-text=bug_report.md\u0026title=), [submit a pull request](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests), or simply use the project and comment your experience. You are encourage to participate as much as possible, but stay tuned to the [code of conduct](./CODE_OF_CONDUCT.md) before making any interaction with other community members.\n\nSee the [ROADMAP.md](ROADMAP.md) file for an idea of how the project should evolve.\n\n## 🎫 License\n\nThis project is licensed under the [MIT](https://choosealicense.com/licenses/mit/) open-source license and is available for free.\n\n## 🧬 Changelog\n\nSee all changes to this project in the [CHANGELOG.md](CHANGELOG.md) file.\n\n## 🧪 Similar projects\n\nBelow is a list of interesting links and similar projects:\n\n* [Other project](https://github.com/project)\n* [Project inspiration](https://github.com/project)\n* [Similar tool](https://github.com/project)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fccuffs%2Fpoll-from-text","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fccuffs%2Fpoll-from-text","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fccuffs%2Fpoll-from-text/lists"}