silly_templates 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/silly.rb +23 -5
  2. 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/1]).
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
- individual_types = (parsed[:params].map {|t| "-type #{t}() :: {#{t}, binary()}."}).join("\n")
72
- input_type = "-type silly_input() :: #{(parsed[:params].map {|t| "#{t}()"}).join(" | ")}."
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 =<<EOF
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
- <<EOF
114
+ <<EOF
97
115
  #{params}
98
116
  -spec render([silly_input()]) -> binary().
99
117
  render(Inputs) ->
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: silly_templates
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: