{"id":25003799,"url":"https://github.com/lpogic/extree","last_synced_at":"2025-09-14T15:26:19.741Z","repository":{"id":224042568,"uuid":"762188773","full_name":"lpogic/extree","owner":"lpogic","description":"Convenient creation of tree structures in Ruby","archived":false,"fork":false,"pushed_at":"2024-05-29T20:43:24.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-19T11:30:15.681Z","etag":null,"topics":["ruby","tree-structure"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lpogic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-02-23T09:08:06.000Z","updated_at":"2024-05-29T20:43:28.000Z","dependencies_parsed_at":"2025-02-04T22:39:14.216Z","dependency_job_id":"3f04c1f4-cb7d-4fd3-bf46-231026b4c67f","html_url":"https://github.com/lpogic/extree","commit_stats":null,"previous_names":["lpogic/extree"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lpogic/extree","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lpogic%2Fextree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lpogic%2Fextree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lpogic%2Fextree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lpogic%2Fextree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lpogic","download_url":"https://codeload.github.com/lpogic/extree/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lpogic%2Fextree/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275122976,"owners_count":25409351,"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","status":"online","status_checked_at":"2025-09-14T02:00:10.474Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["ruby","tree-structure"],"created_at":"2025-02-04T22:39:07.737Z","updated_at":"2025-09-14T15:26:19.416Z","avatar_url":"https://github.com/lpogic.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"extree - DSL for building various data structures\n===\n\nXML-like data definition build in ruby code.\n\n\nInstallation\n---\n```\ngem install extree\n```\n\nUsage\n---\n### 1. Simple tree building\n```RUBY\nrequire 'extree'\n\nclass Tree\n  include Extree\n  \n  def initialize value = nil, \u0026b\n    @value = value\n    @nodes = []\n    # sets self as current scope and call given block\n    scope! \u0026b\n  end\n\n  # define special scoping method\n  def! :tr do |value = nil, \u0026b|\n    @nodes \u003c\u003c Tree.new(value, \u0026b)\n  end\n\n  # print the tree in more human readable form\n  def inspect depth = 0\n    spaces = \" \" * (depth \u003c\u003c 1)\n    nodes = @nodes.empty? ? \"\" : \"\\n#{@nodes.map{ _1.inspect(depth + 1)}.join(\"\\n\")}\\n#{spaces}\"\n    \"#{spaces}\u003c#{@value}#{nodes}\u003e\"\n  end\nend\n\ntree = Tree.new do\n  tr! 1\n  tr! 2 do\n    tr! 3\n  end\n  tr! 4 do\n    tr! 5 do\n      tr! 6\n    end\n  end\n  tr! 7\nend\n\np tree\n\n# Output:\n# \u003c\n#   \u003c1\u003e\n#   \u003c2\n#     \u003c3\u003e\n#   \u003e\n#   \u003c4\n#     \u003c5\n#       \u003c6\u003e\n#     \u003e\n#   \u003e\n#   \u003c7\u003e\n# \u003e\n```\n\n### 2. HTML in Ruby\n```RUBY\nrequire 'extree'\n\nmodule Parent\n  include Extree\n\n  def! :div do |**na, \u0026b|\n    element = Element.new \"div\"\n    scope! element, **na, \u0026b\n    push_element element\n  end\n\n  def! :span do |**na, \u0026b|\n    element = Element.new \"span\"\n    scope! element, **na, \u0026b\n    push_element element\n  end\n\n  def push_element element\n    element\n  end\nend\n\nclass Element\n  include Parent\n\n  def initialize tag\n    @attributes = {}\n    @children = []\n    @tag = tag\n  end\n\n  def push_element element\n    @children \u003c\u003c element\n  end\n\n  def class=(classs)\n    @attributes[:class] = classs\n  end\n\n  def id=(id)\n    @attributes[:id] = id\n  end\n\n  def to_html depth = 0\n    spaces = \" \" * (depth \u003c\u003c 1)\n    attributes = @attributes.map{|k, v| \" #{k}='#{v}'\" }.join\n    children = @children.map{|ch| \"\\n\" + ch.to_html(depth + 1) }.join\n    \"#{spaces}\u003c#{@tag}#{attributes}\u003e#{children}#{ \"\\n#{spaces}\" if !@children.empty? }\u003c/#{@tag}\u003e\"\n  end\nend\n\ninclude Parent\n\n#######################################################\n\n@first_div_id = \"first-div-id\"\n\nhtml = div! class: \"dividor\" do\n  span! id: :spanner do\n    div! class: \"first\", id: @first_div_id\n    div! class: \"second\"\n  end\nend\n\nputs html.to_html\n\n# Output:\n# \u003cdiv class='dividor'\u003e\n#   \u003cspan id='spanner'\u003e\n#     \u003cdiv class='first' id='first-div-id'\u003e\u003c/div\u003e\n#     \u003cdiv class='second'\u003e\u003c/div\u003e\n#   \u003c/span\u003e\n# \u003c/div\u003e\n```\n\n\nAuthors\n---\n- Łukasz Pomietło (oficjalnyadreslukasza@gmail.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flpogic%2Fextree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flpogic%2Fextree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flpogic%2Fextree/lists"}