{"id":28209807,"url":"https://github.com/darinm223/yamlate","last_synced_at":"2025-06-10T21:31:36.791Z","repository":{"id":57672652,"uuid":"46400354","full_name":"DarinM223/yamlate","owner":"DarinM223","description":"Library for dynamically evaluating YAML attributes","archived":false,"fork":false,"pushed_at":"2025-03-13T16:47:14.000Z","size":129,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-17T17:08:56.756Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","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/DarinM223.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-11-18T06:38:41.000Z","updated_at":"2025-03-13T16:47:18.000Z","dependencies_parsed_at":"2025-05-18T15:00:52.728Z","dependency_job_id":null,"html_url":"https://github.com/DarinM223/yamlate","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/DarinM223%2Fyamlate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DarinM223%2Fyamlate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DarinM223%2Fyamlate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DarinM223%2Fyamlate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DarinM223","download_url":"https://codeload.github.com/DarinM223/yamlate/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DarinM223%2Fyamlate/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259154372,"owners_count":22813590,"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":"2025-05-17T17:08:54.590Z","updated_at":"2025-06-10T21:31:36.781Z","avatar_url":"https://github.com/DarinM223.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"yamlate\n=========\n\nA cross-language interpreter library that dynamically evaluates YAML attributes given variable bindings\n\n[![Build Status](https://travis-ci.org/DarinM223/yamlate.svg)](https://travis-ci.org/DarinM223/yamlate)\n\n### What it does:\n\nGiven a mapping of variables to values, it evaluates YAML properties\nwritten in a special language dynamically. It also can update the variables in the mapping\nso it can change its \"state\".\n\nLanguage features inside YAML are prefixed with '~\u003e' so the interpreter can know to evaluate them.\n\n### Hypothetical use case:\n\nLets say that you want to gather data from around a couple thousand bug species. Each bug has different\nbehavior. Some change their wing color based on the season, and others change their wing color when another bug is nearby.\nOnce a bug changes their wing color when another bug is nearby, the other bug leaves and there is no longer another bug nearby. \n\nOne way to model this is to hardcode the bug behavior using something similar to a strategy pattern. You could create a thousand different code \nfiles for all of the bugs. \n\nOne problem with this is that writing code for every bug ties the data to the code which makes it hard for non-developers to \nunderstand the core logic and ties the data to a specific language (Java, Python, etc).\n\nAnother way is to use a markup language like XML or a data serialization format like YAML so that the data is abstracted from the code.\n\nOne problem with this is that there is a lot of complex logic and data is being transformed (the other bug leaving\nchanges the environment) so something like YAML won't be enough.\n\nWith Yamlate, you can do something like this:\n\n```yaml\ncricket:\n  wing_span: 3.5\n  wing_color:\n    - if:\n      - '~\u003e current_season == \"spring\"'\n      - do:\n        - 'red'\n        else:\n        - 'blue'\n        \nbeetle:\n  wing_span: 2.9\n  wing_color:\n    - if:\n      - '~\u003e another_beetle_nearby == 1'\n      - do:\n        - '~\u003e another_beetle_nearby = 0'\n        - 'blue'\n        else:\n        - 'red'\n\n# etc... for all of the bugs\n```\n\nThis allows you to have the advantages of YAML with the ability to model more complex logic.\n\nYou can also write a program in your favorite language (right now only python :P) to retrieve the data:\n\n```python\nlib = ctypes.cdll.LoadLibrary(\"../target/release/libyamlate.dylib\")\nyamlate = Yamlate(lib)\n\nwith yamlate.new_environment() as environment:\n    environment.set_integer('another_beetle_nearby', 1)\n    environment.set_string('current_season', 'spring')\n        \n    with open('../examples/bug.yaml', 'r') as yaml_file:\n        data = yaml_file.read()\n            \n        with yamlate.new_yaml_from_str(data) as root_yaml:\n            with root_yaml.hash_get('cricket') as cricket_yaml:\n                with cricket_yaml.hash_get('wing_color') as wing_yaml:\n                    with wing_yaml.evaluate(environment) as cricket_wing_result:\n                        # should print 'red'\n                        print cricket_wing_result.get_string()\n                                        \n            with root_yaml.hash_get('beetle') as beetle_yaml:\n                with beetle_yaml.hash_get('wing_color') as wing_yaml:\n                    with wing_yaml.evaluate(environment) as beetle_wing_result:\n                        # should print 'blue'\n                        print beetle_wing_result.get_string()\n                        \n                        # should print '0'\n                        print environment.get_integer('another_beetle_nearby')\n```\nNote: the python wrapper is pretty verbose, hopefully I can refactor it into something better\n\nFor the full example look at the python/python_example_bug.py for the python file and the examples/bug.yaml for the\nYAML file\n\n### Why Rust?\n\n* Exposes a C interface so that all languages with C FFI support (essentially all modern languages) can call into the library\n* Performance characteristics similar to C and C++\n* Safe by default (prevents not only memory problems but a whole host of other problems as well)\n* Easy testing out of the box (no confusing linking or setup problems like in C/C++)\n\n### Building\n\nYou have to use cargo to build the project into a dynamic library.\n\n```\ncargo build --release\n```\n\nThe resulting library is at ./target/release/libyamlate.dylib\n\n### Contributing\n\nContributions are welcome! Make sure that all of the existing test cases pass (from cargo test) and if you are adding features\nyou are adding additional test cases. \n\nMake sure that you are not getting any warnings from clippy.\n\nIf you are getting clippy warnings\nthere will be a line after the warning with something like this:\n\n```\nhelp: for further information visit https://github.com/Manishearth/rust-clippy/wiki#\u003cclippy_warning_here\u003e\n```\n\nYou should also make sure your code is formatted with rustfmt. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarinm223%2Fyamlate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdarinm223%2Fyamlate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarinm223%2Fyamlate/lists"}