Permalink
Browse files

template resource

  • Loading branch information...
1 parent 64663d4 commit e725f03a4408f15c1d5465a141ffa4796e1feb6f @iamdefn iamdefn committed Oct 10, 2012
Showing with 33 additions and 1 deletion.
  1. +3 −1 bin/_poop
  2. +24 −0 lib/_template
  3. +5 −0 recipes/meh
  4. +1 −0 templates/feh
View
4 bin/_poop
@@ -17,7 +17,7 @@ function attr_accessor {
eval "_poop_${attr}="
eval "function ${attr} { _poop_${attr}="${dollar}1"; shift; }"
- eval "function end_${attr} { _poop_${attr}=; ${_last_end}=${attrdef}; }"
+ eval "function end_${attr} { _poop_${attr}=${attrdef}; ${_last_end}; }"
_last_end="end_${attr}"
}
@@ -62,7 +62,9 @@ attr_accessor mode
attr_accessor owner
attr_accessor group
attr_accessor path
+attr_accessor sauce
end
require 'poop/directory'
+require 'poop/template'
View
24 lib/_template
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+function template {
+ _poop_name="$1"; shift
+ _poop_resource="template"
+}
+
+function do_template {
+ : ${_poop_action:=create}
+ : ${_poop_path:=${_poop_name}}
+
+ eval "do_${_poop_resource}_${_poop_action}"
+}
+
+function do_template_create {
+ local _dollar='$'
+ local pth_source="${_poop_sauce}"
+
+ eval "cat <<EOF
+$(cat "${pth_source}" | perl -pe 's{\$\{(\w+)\}}{!!!/$1/!!!}g;
+ s{\$}{\${_dollar}}g;
+ s{!!!/(\w+)/!!!}{\${$1}}g;')
+EOF"
+}
View
5 recipes/meh
@@ -22,3 +22,8 @@ end
directory "meh"
action delete
end
+
+name="David"
+template "hello.txt"
+ sauce "templates/feh"
+end
View
1 templates/feh
@@ -0,0 +1 @@
+hello, $${name}

0 comments on commit e725f03

Please sign in to comment.