Code Monkey home page Code Monkey logo

ruby_xml_template's Introduction

Ruby XML Template (RXT) DSL

This repo contains code to accompany the article: How To Make A DSL, Hygienically

RXT is Ruby DSL for XML templates. It turns this:

xml version: '1.0', encoding: 'UTF-8'

weather at: @time.iso8601 do
  description @description
  temperature "#{@temp} C"
  wind do
    velocity "#{@wind_vel} kts"
    direction @wind_direction
  end
end

Into this:

<?xml version="1.0" encoding="UTF-8"?>
<weather at="2016-11-29T22:54:15+11:00">
  <description>Bright &amp; sunny.</description>
  <temperature>18.3 C</temperature>
  <wind>
    <velocity>14 kts</velocity>
    <direction>SSE</direction>
  </wind>
</weather>

Running The Code

First install the dependencies:

bundle install

Then you can run the DSL with:

bundle exec ruby run.rb

Or run the tests with

bundle exec rspec rxt_spec.rb

ruby_xml_template's People

Contributors

tomdalling avatar

Stargazers

Seth Strawbridge avatar Qingfeng Frank Duan avatar Arturo Puente avatar Dmitry Polushkin avatar John-Patrick Di Cosola avatar

Watchers

 avatar James Cloos avatar

ruby_xml_template's Issues

It seems like you'd be helped by Docile

Hi Tom,

It looks as though most of the code in rxt.rb is repeating the Docile gem, but missing some edge cases (such as fallback from the DSL object's contexts to the closure context of the DSL block, which is what let's you refer to closed-over values and methods in Docile DSL blocks).

I suggest you might be doing both yourself, and your community of readers, a nice favor if you posted a comparison using the Docile gem, and maybe highlighted some of the extra bits it would make possible over "rolling your own" solution like this every single time a developer considers implementing a DSL.

Cheers,
-Marc

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.