# [](https://github.com/AndyObtiva/glimmer) Glimmer DSL for XML 1.0.0 (& HTML) [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-xml.svg)](http://badge.fury.io/rb/glimmer-dsl-xml) [![Travis CI](https://travis-ci.com/AndyObtiva/glimmer-dsl-xml.svg?branch=master)](https://travis-ci.com/github/AndyObtiva/glimmer-dsl-xml) [![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) [![Maintainability](https://api.codeclimate.com/v1/badges/65f487b8807f7126b803/maintainability)](https://codeclimate.com/github/AndyObtiva/glimmer-dsl-xml/maintainability) [![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [Glimmer](https://github.com/AndyObtiva/glimmer) DSL for XML provides Ruby syntax for building XML (eXtensible Markup Language) documents. Within 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/tree/master#browser-widget). Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems: - [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt): Glimmer DSL for SWT (JRuby Desktop GUI) - [glimmer-dsl-tk](https://github.com/AndyObtiva/glimmer-dsl-tk): Glimmer DSL for Tk (Ruby Desktop GUI) - [glimmer-dsl-opal](https://github.com/AndyObtiva/glimmer-dsl-opal): Glimmer DSL for Opal (Web GUI Adapter for Desktop Apps) - [glimmer-dsl-css](https://github.com/AndyObtiva/glimmer-dsl-css): Glimmer DSL for CSS (Cascading Style Sheets) ## Setup Please follow these instructions to make the `glimmer` command available on your system. ### Option 1: Direct Install Run this command to install directly: ``` jgem install glimmer-dsl-xml -v 1.0.0 ``` `jgem` is JRuby's version of `gem` command. RVM allows running `gem` as an alias. Otherwise, you may also run `jruby -S gem install ...` Add `require 'glimmer-dsl-xml'` to your code. When 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. That's it! Requiring the gem activates the Glimmer XML DSL automatically. ### Option 2: Bundler Add the following to `Gemfile` (after `glimmer-dsl-swt` and/or `glimmer-dsl-opal` if included too): ``` gem 'glimmer-dsl-xml', '~> 1.0.0' ``` And, then run: ``` jruby -S bundle install ``` Require in your code via Bundler (e.g. `require 'bundler'; Bundler.require`) or add `require 'glimmer-dsl-xml'` to your code. When 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. That's it! Requiring the gem activates the Glimmer XML DSL automatically. ## XML DSL Simply start with `html` keyword and add HTML inside its block using Glimmer DSL syntax. Once done, you may call `to_s`, `to_xml`, or `to_html` to get the formatted HTML output. Here are all the Glimmer XML DSL top-level keywords: - `html` - `tag`: enables custom tag creation for exceptional cases by passing tag name as '_name' attribute - `name_space`: enables namespacing html tags Element 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')` ) Example (basic HTML): ```ruby @xml = html { head { meta(name: "viewport", content: "width=device-width, initial-scale=2.0") } body { h1 { "Hello, World!" } } } puts @xml ``` Output: ```

Hello, World!

``` Example (explicit XML tag): ```ruby puts tag(:_name => "DOCUMENT") ``` Output: ``` ``` Example (XML namespaces using `name_space` keyword): ```ruby @xml = name_space(:w3c) { html(:id => "thesis", :class => "document") { body(:id => "main") { } } } puts @xml ``` Output: ``` ``` Example (XML namespaces using dot operator): ```ruby @xml = tag(:_name => "DOCUMENT") { document.body(document.id => "main") { } } puts @xml ``` Output: ``` ``` ## Multi-DSL Support Learn more about how to use this DSL alongside other Glimmer DSLs: [Glimmer Multi-DSL Support](https://github.com/AndyObtiva/glimmer/tree/master#multi-dsl-support) ## Help ### Issues You may submit [issues](https://github.com/AndyObtiva/glimmer-dsl-xml/issues) on [GitHub](https://github.com/AndyObtiva/glimmer-dsl-xml/issues). [Click here to submit an issue.](https://github.com/AndyObtiva/glimmer-dsl-xml/issues) ### Chat If 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&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) ## Feature Suggestions These features have been suggested. You might see them in a future version of Glimmer. You are welcome to contribute more feature suggestions. [TODO.md](TODO.md) ## Change Log [CHANGELOG.md](CHANGELOG.md) ## Contributing [CONTRIBUTING.md](CONTRIBUTING.md) ## Contributors * [Andy Maleh](https://github.com/AndyObtiva) (Founder) [Click here to view contributor commits.](https://github.com/AndyObtiva/glimmer-dsl-xml/graphs/contributors) ## License [MIT](LICENSE.txt) Copyright (c) 2020 - Andy Maleh. -- [](https://github.com/AndyObtiva/glimmer) Built for [Glimmer](https://github.com/AndyObtiva/glimmer) (Ruby Desktop Development GUI Library).