Popularity
0.6
Growing
Activity
4.0
-
5
3
1

Description

Glimmer DSL for XML provides Ruby DSL syntax for building XML (eXtensible Markup Language) and HTML documents.

Monthly Downloads: 160
Programming language: Ruby
License: MIT License
Tags: Template Engine     HTML     Markup     DSL     Xml    
Latest version: v1.1.0

Glimmer DSL for XML (& HTML) alternatives and similar gems

Based on the "Template Engine" category.
Alternatively, view Glimmer DSL for XML (& HTML) alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of Glimmer DSL for XML (& HTML) or a related project?

Add another 'Template Engine' Gem

README

Glimmer DSL for XML 1.2.0 (& HTML)

Gem Version Travis CI Coverage Status Maintainability Join the chat at https://gitter.im/AndyObtiva/glimmer

Glimmer DSL for XML provides Ruby syntax for building XML (eXtensible Markup Language) and HTML documents.

Within the context of desktop development, Glimmer DSL for XML is useful in providing XML data for the SWT Browser widget.

Other Glimmer DSL gems:

Setup

Please follow these instructions to make the glimmer command available on your system.

Option 1: Direct Install

Run this command to install directly:

gem install glimmer-dsl-xml -v 1.2.0

Note: 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 ...

Add require 'glimmer-dsl-xml' to your code.

When using with Glimmer DSL for SWT or Glimmer DSL for 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.2.0'

And, then run:

bundle install

Note: When using JRuby, prefix with jruby -S

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 or Glimmer DSL for 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 the html, xml, name_space, or tag keyword and add XML/HTML inside its block using Glimmer DSL for XML syntax. Once done, you may call to_s, to_xml, or to_html to get the formatted XML/HTML output.

Here are all the Glimmer XML DSL top-level keywords:

  • html: renders partial HTML just like xml (not having body/head) or full HTML document (having body/head), automatically including doctype (<!DOCTYPE html>) and surrounding content by the <html></html> tag
  • xml: renders XML/XHTML content (e.g. xml {span {'Hello'}; br}.to_s renders <span>Hello</span><br />)
  • name_space: enables namespacing html tags
  • tag: enables custom tag creation for exceptional cases (e.g. p as reserved Ruby keyword) by passing tag name as '_name' attribute

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') )

You may try the following examples in IRB after installing the glimmer-dsl-xml gem.

Just make sure to require the library and include Glimmer first:

require 'glimmer-dsl-xml'

include Glimmer

Example (full HTML document):

@html = html {
  head {
    meta(name: "viewport", content: "width=device-width, initial-scale=2.0")
  }
  body {
    h1 { "Hello, World!" }
  }
}

puts @html

Output:

<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width, initial-scale=2.0" /></head><body><h1>Hello, World!</h1></body></html>

Example (partial HTML fragment):

@html = html {
  h1 { "Hello, World!" }
}

puts @html

Output:

<h1>Hello, World!</h1>

Example (basic XML):

@xml = xml {
  greeting { "Hello, World!" }
}

puts @xml

Output:

<greeting>Hello, World!</greeting>

Example (XML namespaces using name_space keyword):

@xml = name_space(:acme) {
  product(:id => "thesis", :class => "document") {
    component(:id => "main") {
    }
  }
}

puts @xml

Output:

<acme:product id="thesis" class="document"><acme:component id="main"></acme:component></acme:product>

Example (XML namespaces using dot operator):

  @xml = xml {
    document.body(document.id => "main") {
    }
  }

  puts @xml

Output:

<document:body document:id="main"></document:body>

Example (custom tag):

puts tag(:_name => "p") {"p is a reserved keyword in Ruby"}

Output:

<p>p is a reserved keyword in Ruby</p>

Multi-DSL Support

Learn more about how to use this DSL alongside other Glimmer DSLs:

Glimmer Multi-DSL Support

Help

Issues

You may submit issues on GitHub.

Click here to submit an issue.

Chat

If you need live help, try to Join the chat at https://gitter.im/AndyObtiva/glimmer

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

Click here to view contributor commits.

License

[MIT](LICENSE.txt)

Copyright (c) 2020 - Andy Maleh.

--

Built for Glimmer (Ruby Desktop Development GUI Library).


*Note that all licence references and agreements mentioned in the Glimmer DSL for XML (& HTML) README section above are relevant to that project's source code only.