{"id":27193199,"url":"https://github.com/svernidub/dsl_examples","last_synced_at":"2025-07-19T19:37:39.647Z","repository":{"id":241498163,"uuid":"153548834","full_name":"svernidub/dsl_examples","owner":"svernidub","description":"Simple Ruby DSL demonstration","archived":false,"fork":false,"pushed_at":"2018-10-19T08:33:09.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-05-28T19:57:52.323Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/svernidub.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}},"created_at":"2018-10-18T02:00:31.000Z","updated_at":"2024-05-28T19:57:58.124Z","dependencies_parsed_at":"2024-05-28T19:57:57.246Z","dependency_job_id":"8e643a14-ed6f-4bae-9c9b-b78644946dda","html_url":"https://github.com/svernidub/dsl_examples","commit_stats":null,"previous_names":["svernidub/dsl_examples"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svernidub%2Fdsl_examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svernidub%2Fdsl_examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svernidub%2Fdsl_examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svernidub%2Fdsl_examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/svernidub","download_url":"https://codeload.github.com/svernidub/dsl_examples/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248091327,"owners_count":21046258,"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-04-09T18:46:48.133Z","updated_at":"2025-04-09T18:46:48.753Z","avatar_url":"https://github.com/svernidub.png","language":"Ruby","readme":"# DslExamples\n\nSimple Ruby DSL examples\n\n## How to build DSL via class methods\n\nNot real DSL exactly, but simple example how to use class methods to build DSL.\n\nSimple\n[extention](https://github.com/svernidub/dsl_examples/blob/master/lib/dsl_examples/hexdigest.rb)\nthat allows to create digest helper for any method.\n\n```ruby\nclass ClassWithHexDigests\n  extend Hexdigest\n\n  attr_reader :first_name,\n                :last_name\n\n  hexdigest_for :first_name, Digest::MD5\n  hexdigest_for :last_name,  Digest::SHA2\nend\n\nobj = ClassWithHexDigests.new('Serhii', 'Vernydub')\n\ncwh.first_name           # =\u003e \"Serhii\"\ncwh.first_name_hexdigest # =\u003e \"9ca31108f5130ccdff3bfb598a1d4966\"\ncwh.last_name            # =\u003e \"Vernydub\"\ncwh.last_name_hexdigest  # =\u003e \"0c0813b27c693bac5dc97ea8200d221f9a56bb9a9b0459b1cd915901ebb2d425\"\n```\n\n## How to build DSL via methods and blocks\n\n[Class](https://github.com/svernidub/dsl_examples/blob/master/lib/dsl_examples/html_document.rb)\n `HtmlDocument` provides ability to describe HTML documents with DSL.\n\n```ruby\nmodule DslExamples\n  class MyDocument \u003c HtmlDocument\n    def body\n      html do |h|\n        h.head do |hd|\n          hd.title text: 'Hello world'\n\n          hd.style text: \u003c\u003c-CSS\n              table, tr, td {\n                border: 1px solid black\n              }\n            CSS\n        end\n\n        h.body do |b|\n          b.h1 text: 'Hello world'\n\n          b.table do |t|\n            t.thead do |thd|\n              thd.tr do |tr|\n                tr.td text: 'Social network'\n                tr.td text: 'Search engine'\n              end\n            end\n\n            t.tbody do |tb|\n              tb.tr do |tr|\n                tr.td do |td|\n                  td.a text: 'Facebook',\n                       attributes: { href: 'https://facebook.com' }\n                end\n\n                tr.td do |td|\n                  td.a text: 'Google',\n                       attributes: { href: 'https://google.com' }\n                end\n              end\n            end\n          end\n        end\n      end\n    end\n  end\nend\n```\n\n### Improved syntax\n\n[Class](https://github.com/svernidub/dsl_examples/blob/master/lib/dsl_examples/html_pretty_document.rb)\n`HtmlPrettyDocument` is copy of `HtmlDocument` but it has one simple but useful improvement.\nIt allows us not to pass block parameter to every nested HTML-tag.\n\n```ruby\nmodule DslExamples\n  class MyPrettyDocument \u003c HtmlPrettyDocument\n    def body\n      html do\n        head do\n          title text: 'Hello world'\n\n          style text: \u003c\u003c-CSS\n              table, tr, td {\n                border: 1px solid red\n              }\n            CSS\n        end\n\n        body do\n          h1 text: 'Hello world'\n\n          table do\n            thead do\n              tr do\n                td text: 'Social network'\n                td text: 'Search engine'\n              end\n            end\n\n            tbody do\n              tr do\n                td do\n                  a text: 'Facebook',\n                    attributes: { href: 'https://facebook.com' }\n                end\n\n                td do\n                  a text: 'Google',\n                    attributes: { href: 'https://google.com' }\n                end\n              end\n            end\n          end\n        end\n      end\n    end\n  end\nend\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvernidub%2Fdsl_examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsvernidub%2Fdsl_examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvernidub%2Fdsl_examples/lists"}