Skip to content

Commit

Permalink
template resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Bombadil committed Oct 10, 2012
1 parent 64663d4 commit e725f03
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bin/_poop
Expand Up @@ -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}"
}

Expand Down Expand Up @@ -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'
24 changes: 24 additions & 0 deletions 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"
}
5 changes: 5 additions & 0 deletions recipes/meh
Expand Up @@ -22,3 +22,8 @@ end
directory "meh"
action delete
end

name="David"
template "hello.txt"
sauce "templates/feh"
end
1 change: 1 addition & 0 deletions templates/feh
@@ -0,0 +1 @@
hello, $${name}

0 comments on commit e725f03

Please sign in to comment.