{"id":16382481,"url":"https://github.com/andyobtiva/glimmer-dsl-xml","last_synced_at":"2025-03-23T03:33:21.727Z","repository":{"id":39669691,"uuid":"271674395","full_name":"AndyObtiva/glimmer-dsl-xml","owner":"AndyObtiva","description":"Glimmer DSL for XML (\u0026 HTML)","archived":false,"fork":false,"pushed_at":"2024-02-25T03:53:50.000Z","size":61,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-25T08:20:36.266Z","etag":null,"topics":["dsl","dsl-syntax","glimmer","ruby","ruby-gem","ruby-library","rubygem","xml"],"latest_commit_sha":null,"homepage":"","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/AndyObtiva.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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":"2020-06-12T00:39:02.000Z","updated_at":"2024-05-28T18:12:52.740Z","dependencies_parsed_at":"2024-02-25T04:28:15.263Z","dependency_job_id":null,"html_url":"https://github.com/AndyObtiva/glimmer-dsl-xml","commit_stats":{"total_commits":41,"total_committers":2,"mean_commits":20.5,"dds":"0.36585365853658536","last_synced_commit":"79f634cac60660b9189222b21f3156d22662274a"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndyObtiva%2Fglimmer-dsl-xml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndyObtiva%2Fglimmer-dsl-xml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndyObtiva%2Fglimmer-dsl-xml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AndyObtiva%2Fglimmer-dsl-xml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AndyObtiva","download_url":"https://codeload.github.com/AndyObtiva/glimmer-dsl-xml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244267475,"owners_count":20425835,"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":["dsl","dsl-syntax","glimmer","ruby","ruby-gem","ruby-library","rubygem","xml"],"created_at":"2024-10-11T04:05:33.714Z","updated_at":"2025-03-23T03:33:21.427Z","avatar_url":"https://github.com/AndyObtiva.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [\u003cimg src=\"https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png\" height=85 /\u003e](https://github.com/AndyObtiva/glimmer) Glimmer DSL for XML \u0026 HTML 1.4.0\n[![Gem Version](https://badge.fury.io/rb/glimmer-dsl-xml.svg)](http://badge.fury.io/rb/glimmer-dsl-xml)\n[![Travis CI](https://travis-ci.com/AndyObtiva/glimmer-dsl-xml.svg?branch=master)](https://travis-ci.com/github/AndyObtiva/glimmer-dsl-xml)\n[![Coverage Status](https://coveralls.io/repos/github/AndyObtiva/glimmer-dsl-xml/badge.svg?branch=master)](https://coveralls.io/github/AndyObtiva/glimmer-dsl-xml?branch=master)\n[![Maintainability](https://api.codeclimate.com/v1/badges/65f487b8807f7126b803/maintainability)](https://codeclimate.com/github/AndyObtiva/glimmer-dsl-xml/maintainability)\n[![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\n[Glimmer](https://github.com/AndyObtiva/glimmer) DSL for XML provides Ruby syntax for building XML (eXtensible Markup Language) and HTML documents, included in [Glimmer DSL for Web](https://github.com/AndyObtiva/glimmer-dsl-web) (Ruby in the Browser Web Frontend Framework) to use in Rails Frontend Development. It used to be part of the [Glimmer](https://github.com/AndyObtiva/glimmer) library (created in 2007), but eventually got extracted into its own project. The Ruby gem also includes an [HTML to Glimmer Converter](#html-to-glimmer-converter) (`html_to_glimmer`) to automatically convert legacy HTML code into Glimmer DSL syntax.\n\nWithin the context of desktop development, Glimmer DSL for XML is useful in providing XML data for the [SWT Browser widget](https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#browser-widget).\n\nOtherwise, it is also used in the development of [Glimmer DSL for Opal](https://github.com/AndyObtiva/glimmer-dsl-opal).\n\nLearn more about the differences between various [Glimmer](https://github.com/AndyObtiva/glimmer) DSLs by looking at the **[Glimmer DSL Comparison Table](https://github.com/AndyObtiva/glimmer#glimmer-dsl-comparison-table)**.\n\n## Setup\n\nPlease follow these instructions to make the `glimmer` command available on your system.\n\n### Option 1: Direct Install\n\nRun this command to install directly:\n```\ngem install glimmer-dsl-xml -v 1.4.0\n```\n\nNote: When using JRuby, `jgem` is JRuby's version of `gem` command. RVM allows running `gem` as an alias in JRuby. Otherwise, you may also run `jruby -S gem install ...`\n\nAdd `require 'glimmer-dsl-xml'` to your code.\n\nWhen using with [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt) or [Glimmer DSL for Opal](https://github.com/AndyObtiva/glimmer-dsl-opal), make sure it is added after `require glimmer-dsl-swt` and `require glimmer-dsl-opal` to give it a lower precedence than them when processed by the Glimmer DSL engine.\n\nThat's it! Requiring the gem activates the Glimmer XML DSL automatically.\n\n### Option 2: Bundler\n\nAdd the following to `Gemfile` (after `glimmer-dsl-swt` and/or `glimmer-dsl-opal` if included too):\n```\ngem 'glimmer-dsl-xml', '~\u003e 1.4.0'\n```\n\nAnd, then run:\n```\nbundle install\n```\n\nNote: When using JRuby, prefix with `jruby -S`\n\nRequire in your code via Bundler (e.g. `require 'bundler'; Bundler.require`) or add `require 'glimmer-dsl-xml'` to your code.\n\nWhen using with [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt) or [Glimmer DSL for Opal](https://github.com/AndyObtiva/glimmer-dsl-opal), make sure it is loaded after `glimmer-dsl-swt` and `glimmer-dsl-opal` to give it a lower precedence than them when processed by the Glimmer DSL engine.\n\nThat's it! Requiring the gem activates the Glimmer XML DSL automatically.\n\n## XML DSL\n\nSimply start with the `html`, `xml`, `name_space`, or `tag` keyword and add XML/HTML inside its block using Glimmer DSL for XML syntax.\nOnce done, you may call `to_s`, `to_xml`, or `to_html` to get the formatted XML/HTML output.\n\nHere are all the Glimmer XML DSL top-level keywords:\n- `html`: renders partial HTML just like `xml` (not having body/head) or full HTML document (having body/head), automatically including doctype (`\u003c!DOCTYPE html\u003e`) and surrounding content by the `\u003chtml\u003e\u003c/html\u003e` tag\n- `xml`: renders XML/XHTML content (e.g. `xml {span {'Hello'}; br}.to_s` renders `\u003cspan\u003eHello\u003c/span\u003e\u003cbr /\u003e`)\n- `name_space`: enables namespacing html tags\n- `tag`: enables custom tag creation for exceptional cases (e.g. `acme:window` as reserved Ruby keyword) by passing tag name as '_name' attribute\n\nElement properties are typically passed as a key/value hash (e.g. `section(id: 'main', class: 'accordion')`) . However, for properties like \"selected\" or \"checked\", you must leave value `nil` or otherwise pass in front of the hash (e.g. `input(:checked, type: 'checkbox')` )\n\nYou may try the following examples in IRB after installing the [glimmer-dsl-xml](https://rubygems.org/gems/glimmer-dsl-xml) gem.\n\nJust make sure to require the library and include Glimmer first:\n\n```ruby\nrequire 'glimmer-dsl-xml'\n\ninclude Glimmer\n```\n\nExample (full HTML document):\n\n```ruby\n@html = html {\n  head {\n    meta(name: \"viewport\", content: \"width=device-width, initial-scale=2.0\")\n  }\n  body {\n    h1 { \"Hello, World!\" }\n  }\n}\n\nputs @html\n```\n\nOutput:\n\n```\n\u003c!DOCTYPE html\u003e\u003chtml\u003e\u003chead\u003e\u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=2.0\" /\u003e\u003c/head\u003e\u003cbody\u003e\u003ch1\u003eHello, World!\u003c/h1\u003e\u003c/body\u003e\u003c/html\u003e\n```\n\nExample (partial HTML fragment):\n\n```ruby\n@html = html {\n  h1 { \"Hello, World!\" }\n}\n\nputs @html\n```\n\nOutput:\n\n```\n\u003ch1\u003eHello, World!\u003c/h1\u003e\n```\n\nExample (basic XML):\n\n```ruby\n@xml = xml {\n  greeting { \"Hello, World!\" }\n}\n\nputs @xml\n```\n\nOutput:\n\n```\n\u003cgreeting\u003eHello, World!\u003c/greeting\u003e\n```\n\nExample (XML namespaces using `name_space` keyword):\n\n```ruby\n@xml = name_space(:acme) {\n  product(:id =\u003e \"thesis\", :class =\u003e \"document\") {\n    component(:id =\u003e \"main\") {\n    }\n  }\n}\n\nputs @xml\n```\n\nOutput:\n\n```\n\u003cacme:product id=\"thesis\" class=\"document\"\u003e\u003cacme:component id=\"main\"\u003e\u003c/acme:component\u003e\u003c/acme:product\u003e\n```\n\nExample (XML namespaces using dot operator):\n\n```ruby\n  @xml = xml {\n    document.body(document.id =\u003e \"main\") {\n    }\n  }\n  \n  puts @xml\n```\n\nOutput:\n\n```\n\u003cdocument:body document:id=\"main\"\u003e\u003c/document:body\u003e\n```\n\nExample (custom tag):\n\n```ruby\nputs tag(:_name =\u003e \"acme:window\") {\"This is a window under acme inc.\"}\n```\n\nOutput:\n\n```\n\u003cacme:window\u003eThis is a window under acme inc.\u003c/acme:window\u003e\n```\n\n### HTML to Glimmer Converter\n\nThe Ruby gem includes a HTML to Glimmer converter (`html_to_glimmer`) to automatically convert legacy HTML code into Glimmer DSL syntax.\n\nPrerequisite: the `nokogiri` Ruby gem. If not already installed, run `gem install nokogiri` before using `html_to_glimmer`.\n\nScript:\n\n[bin/html_to_glimmer](/bin/html_to_glimmer)\n\nUsage:\n\n```\nhtml_to_glimmer path_to_html_file\n```\n\nExample:\n\nSuppose we have an HTML file called `input.html`:\n\n```html\n\u003chtml style='max-height: 100%'\u003e\n  \u003cbody style=\"max-height: 100%; font: 'Times New Roman', Arial;\"\u003e\n    \u003ch1 id=\"top-header\" class=\"header\" data-owner='John \"Bonham\" Doe'\u003eWelcome\u003c/h1\u003e\n    \u003cp\u003eIt is good to have \u003cstrong\u003eyou\u003c/strong\u003e in our \u003cstrong\u003e\u003cem\u003eplatform\u003c/em\u003e\u003c/strong\u003e!\u003c/p\u003e\n    \u003cform action=\"/owner\" method=\"post\"\u003e\n      \u003cinput type=\"text\" value=\"you\" /\u003e\n    \u003c/form\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\nWe can run this command:\n\n```\nhtml_to_glimmer input.html\n```\n\nPrintout:\n\n```\nConverting from HTML syntax to Glimmer DSL Ruby syntax for input file: input.html\nConverted output file: input.html.glimmer.rb\n```\n\nOutput file (`input.html.glimmer.rb`) is a runnable Ruby file containing Glimmer DSL for XML \u0026 HTML syntax:\n\n```rb\nrequire 'glimmer-dsl-xml'\n\ninclude Glimmer\n\nhtml_document = xml {\n  html(style: 'max-height: 100%') {\n    body(style: \"max-height: 100%; font: 'Times New Roman', Arial;\") {\n      h1(id: 'top-header', class: 'header', 'data-owner': 'John \"Bonham\" Doe') {\n        \"Welcome\"\n      }\n      p {\n        span {\n          \"It is good to have \"\n        }\n        strong {\n          \"you\"\n        }\n        span {\n          \" in our \"\n        }\n        strong {\n          em {\n            \"platform\"\n          }\n        }\n        span {\n          \"!\"\n        }\n      }\n      form(action: '/owner', method: 'post') {\n        input(type: 'text', value: 'you')\n      }\n    }\n  }\n}\n\nputs html_document.to_s\n```\n\nNote that text nodes are converted into `span` nodes as that is the recommended way of including them in Glimmer DSL for XML at the moment.\n\n## Glimmer Config\n\n### `xml_attribute_underscore`\n\n(default value: `'_'`)\n\nCalling the following code enables auto-conversion of xml attribute underscores into dashes in `Symbol` attribute names (but not `String` attribute names):\n\n```ruby\nGlimmer::Config.xml_attribute_underscore = '-'\n```\n\nExample:\n\n```ruby\nrequire 'glimmer-dsl-xml'\n\nGlimmer::Config.xml_attribute_underscore = '-'\n\ninclude Glimmer\n\ndocument = html {\n  body {\n    video(:data_loop, data_src: \"http://videos.org/1.mp4\")\n  }\n}\n\nputs document\n```\n    \n```\n\u003c!DOCTYPE html\u003e\u003chtml\u003e\u003cbody\u003e\u003cvideo data-src=\"http://videos.org/1.mp4\" data-loop  /\u003e\u003c/body\u003e\u003c/html\u003e\n```\n\nNote that strings are intentionally ignored to enable using underscores when needed.\n\nExample:\n\n```ruby\nrequire 'glimmer-dsl-xml'\n\nGlimmer::Config.xml_attribute_underscore = '-'\n\ninclude Glimmer\n\ndocument = html {\n  body {\n    video('data_loop', 'data_src' =\u003e \"http://videos.org/1.mp4\")\n  }\n}\n\nputs document\n```\n    \n```\n\u003c!DOCTYPE html\u003e\u003chtml\u003e\u003cbody\u003e\u003cvideo data_src=\"http://videos.org/1.mp4\" data_loop  /\u003e\u003c/body\u003e\u003c/html\u003e\n```\n\n\n## Multi-DSL Support\n\nLearn more about how to use this DSL alongside other Glimmer DSLs:\n\n[Glimmer Multi-DSL Support](https://github.com/AndyObtiva/glimmer/tree/master#multi-dsl-support)\n\n## Help\n\n### Issues\n\nYou may submit [issues](https://github.com/AndyObtiva/glimmer-dsl-xml/issues) on [GitHub](https://github.com/AndyObtiva/glimmer-dsl-xml/issues).\n\n[Click here to submit an issue.](https://github.com/AndyObtiva/glimmer-dsl-xml/issues)\n\n### Chat\n\nIf you need live help, try to [![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\n## Feature Suggestions\n\nThese features have been suggested. You might see them in a future version of Glimmer. You are welcome to contribute more feature suggestions.\n\n[TODO.md](TODO.md)\n\n## Change Log\n\n[CHANGELOG.md](CHANGELOG.md)\n\n## Contributing\n\n[CONTRIBUTING.md](CONTRIBUTING.md)\n\n## Contributors\n\n* [Andy Maleh](https://github.com/AndyObtiva) (Founder)\n\n[Click here to view contributor commits.](https://github.com/AndyObtiva/glimmer-dsl-xml/graphs/contributors)\n\n## License\n\n[MIT](LICENSE.txt)\n\nCopyright (c) 2020-2023 - Andy Maleh.\n\n--\n\n[\u003cimg src=\"https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png\" height=40 /\u003e](https://github.com/AndyObtiva/glimmer) Built for [Glimmer](https://github.com/AndyObtiva/glimmer) (Ruby Desktop Development GUI Library).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandyobtiva%2Fglimmer-dsl-xml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandyobtiva%2Fglimmer-dsl-xml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandyobtiva%2Fglimmer-dsl-xml/lists"}