Skip to content

Commit

Permalink
ensure replace values are strings
Browse files Browse the repository at this point in the history
  • Loading branch information
nuex committed Mar 4, 2014
1 parent 6cfd075 commit ce05647
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/gm.erl
Expand Up @@ -115,15 +115,20 @@ bind_data(Template, [{Key, Value}|Rest], Options) ->
Search = lists:concat([":",atom_to_list(Key)]),
Replace = case Options of
[escape] ->
lists:concat(["'",Value,"'"]);
lists:concat(["'", stringify(Value), "'"]);
_ ->
Value
end,
NewTemplate = re:replace(Template, Search, Replace, [{return, list}]),
NewTemplate = re:replace(Template, Search, stringify(Replace), [{return, list}]),
bind_data(NewTemplate, Rest, Options);
bind_data(Template, [], _Options) ->
Template.

%% Convert the given value to a string
stringify(Value) when is_integer(Value) ->
erlang:integer_to_list(Value);
stringify(Value) ->
Value.

%% Parse an error coming from an executed os:cmd
cmd_error(Cmd) ->
Expand Down

0 comments on commit ce05647

Please sign in to comment.