Project

ruyml

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
A command line interface and a library to render erb templates using one or multiple YAML datasources.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.11
~> 10.0
 Project Readme

Gem Version Documentation License

RUYML

Ruby templating using YAML datasources

Usage

Library

  require 'ruyml'
  require 'yaml'

  content = YAML.load(File.read("file.yml"))
  r = Ruyml::Data.new(content)
  r.render("template.erb", "output.txt")

CLI

Simple usage

Given a yaml file :

alert:
  message: 'hello world !'

And an erb file :

message = "<%= alert.message.capitalize %>"

Running :

ruyml -d alert.yaml -t template.erb

Gives the following output :

message = "Hello world !"

Advanced usage

Multiple data sources

You can refer to multiple YAML datasources in a template and render it using :

ruyml -d data1.yaml,data2.yaml -t template.erb

Accessing Hash methods

When iterating over an item which is not a leaf of the YAML file, you can access methods of the Hash class directly. In case a propertie has the same name than the method you are trying to use, simply use the <method>! form.

For instance :

object:
  each:
    - attr1: val1
    - attr2: val2
    - attr3: val3
Object dump :
<%= object.each %>

Object attributes:
<% object.each! do |p, items| -%>
  <% items.each do |attr, val| -%>
    Attribute <%= attr %> has value <%= val %>
  <% end -%>
<% end -%>