Project

mallinna

0.0
No commit activity in last 3 years
No release in over 3 years
Mostly like ERB, but <%if foo%> conditional will omit whole line unless code evaluates true
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
 Project Readme

Malline

Malline is template engine targeting IOS/JunOS or generally configurations (or more accurately what ever text stuff I'm doing).

It surfaced from the need to do something like this in ERB:

interfaces {
  <%= name %> {
    description "<%if description %>";
  }
}

where description "description"; is only output if the code evaluates true, keeping the template clean in common use-case

Consider this code
require_relative './lib/malline'
require 'pry'
class Int
  attr_accessor :name, :mtu, :description, :poop
  def initialize
    @name = 'xe-1/2/3.42'
    @mtu = 1500
    @description = 'K: S-123455 - poop customer'
    @poop = true
  end
  def get_binding
    binding
  end
end

template = <<EOF
interfaces {
   <% name %> {
     mtu <%if mtu %>;
     description "<%if description %>";
   }
}
EOF

int = Int.new
cfg = Malline.run template, int.get_binding
binding.pry

Real use might look something like this:

[1] pry(main)> puts cfg
interfaces {
   xe-1/2/3.42 {
     mtu 1500;
     description "K: S-123455 - poop customer";
   }
}
=> nil
[2] pry(main)> int.mtu = 900
=> 900
[3] pry(main)> int.description = nil
=> nil
[4] pry(main)> puts Malline.run template, int.get_binding
interfaces {
   xe-1/2/3.42 {
     mtu 900;
   }
}
=> nil