silly_templates 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/silly.rb +23 -5
- metadata +1 -1
data/lib/silly.rb
CHANGED
@@ -36,7 +36,7 @@ class Silly
|
|
36
36
|
%% Do not edit it, please! Instead edit #{t}.
|
37
37
|
|
38
38
|
-module(#{name}_silly).
|
39
|
-
-export([render
|
39
|
+
-export([render/#{parsed[:params].size == 0 ? 0 : 1}]).
|
40
40
|
#{gen_types parsed}
|
41
41
|
#{gen_function parsed}
|
42
42
|
EOF
|
@@ -68,8 +68,10 @@ EOF
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def gen_types parsed
|
71
|
-
|
72
|
-
|
71
|
+
params = parsed[:params]
|
72
|
+
return "" if params == []
|
73
|
+
individual_types = (params.map {|t| "-type #{t}() :: {#{t}, binary()}."}).join("\n")
|
74
|
+
input_type = "-type silly_input() :: #{(params.map {|t| "#{t}()"}).join(" | ")}."
|
73
75
|
"#{individual_types}\n#{input_type}\n"
|
74
76
|
end
|
75
77
|
|
@@ -78,7 +80,23 @@ EOF
|
|
78
80
|
end
|
79
81
|
|
80
82
|
def gen_function parsed
|
81
|
-
params
|
83
|
+
if parsed[:params].size == 0 then
|
84
|
+
gen_simple_function parsed
|
85
|
+
else
|
86
|
+
gen_complex_function parsed
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def gen_simple_function parsed
|
91
|
+
<<EOF
|
92
|
+
-spec render() -> binary().
|
93
|
+
render() ->
|
94
|
+
<<"#{escape(parsed[:texts].first)}">>.
|
95
|
+
EOF
|
96
|
+
end
|
97
|
+
|
98
|
+
def gen_complex_function parsed
|
99
|
+
params =<<EOF
|
82
100
|
-spec get_param(atom(), [silly_input()]) -> binary().
|
83
101
|
get_param(Param, Inputs) ->
|
84
102
|
case proplists:get_value(Param, Inputs, undefined) of
|
@@ -93,7 +111,7 @@ EOF
|
|
93
111
|
out += ",\n get_param(#{param.to_s}, Inputs)," if param
|
94
112
|
output << out
|
95
113
|
end
|
96
|
-
|
114
|
+
<<EOF
|
97
115
|
#{params}
|
98
116
|
-spec render([silly_input()]) -> binary().
|
99
117
|
render(Inputs) ->
|