#-*- coding: utf-8 -*-

require 'erb'
require 'ostruct'
require 'yaml'

BASE_SUBSCRIPTIONS = YAML.load(<<END_OF_YAML)
000001:
  name: Matthieu Simon-Blavier
  address:
    Domain Network Sas
    17, square Edouard VII
    75009 Paris
    FR
  email: registry@domainnetwork.fr
  membership_fee_paid_on: 2013-02-21
  notes:
    Il vient de `whois cogent.fr`.
000002:
  name: Sylvain Dufier
  address:
    ORANGE FRANCE
    13, rue de Javel
    75015 Paris
  email: sylvain.dufier@orange-ftgroup.com
  membership_fee_paid_on: 2013-05-29
    Il vient de `whois orange.fr`.
000003:
  name: Salim Gasmi
    SDV PLURIMEDIA
    15, rue de la Nuee Bleue
    67000 Strasbourg
  email: domaines@sdv.fr
  membership_fee_paid_on: 2010-01-21
    Il vient de `whois numericable.fr`.
    Et il n'est pas à jour de cotisation.
END_OF_YAML

EXTRA_SUBSCRIPTION = YAML.load(<<END_OF_YAML)
name: Franck Rohard
address:
  SOCIETE FRANCAISE DU RADIOTELEPHONE - SFR
  42, avenue de Friedland
  75008 Paris
email: domains@sfr.com
membership_fee_paid_on: 2013-04-04
notes:
  Il vient de `whois sfr.fr`.
END_OF_YAML

SUBSCRIPTION_FILE_TEMPLATE = <<'END_OF_TEMPLATE'
---
name: <%= name %>
address:
  <%= address %>
email: <%= email %>
mumbership_fee_paid_on: <%= membership_fee_paid_on %>
---

<%= notes %>
END_OF_TEMPLATE

def subscription_filename_for_id(id)
  "Membres/%06d.mdwn" % id
end

def render_subscription_file(locals)
  ERB.new(SUBSCRIPTION_FILE_TEMPLATE).result(OpenStruct.new(locals).instance_eval { binding })
end
