|
4 | 4 |
|
5 | 5 | use Appwrite\SDK\Language;
|
6 | 6 | use Exception;
|
| 7 | +use Twig\TwigFilter; |
7 | 8 |
|
8 | 9 | class Python extends Language
|
9 | 10 | {
|
@@ -90,119 +91,119 @@ public function getFiles(): array
|
90 | 91 | {
|
91 | 92 | return [
|
92 | 93 | [
|
93 |
| - 'scope' => 'default', |
94 |
| - 'destination' => 'README.md', |
95 |
| - 'template' => 'python/README.md.twig', |
| 94 | + 'scope' => 'default', |
| 95 | + 'destination' => 'README.md', |
| 96 | + 'template' => 'python/README.md.twig', |
96 | 97 | ],
|
97 | 98 | [
|
98 |
| - 'scope' => 'default', |
99 |
| - 'destination' => 'CHANGELOG.md', |
100 |
| - 'template' => 'python/CHANGELOG.md.twig', |
| 99 | + 'scope' => 'default', |
| 100 | + 'destination' => 'CHANGELOG.md', |
| 101 | + 'template' => 'python/CHANGELOG.md.twig', |
101 | 102 | ],
|
102 | 103 | [
|
103 |
| - 'scope' => 'default', |
104 |
| - 'destination' => 'LICENSE', |
105 |
| - 'template' => 'python/LICENSE.twig', |
| 104 | + 'scope' => 'default', |
| 105 | + 'destination' => 'LICENSE', |
| 106 | + 'template' => 'python/LICENSE.twig', |
106 | 107 | ],
|
107 | 108 | [
|
108 |
| - 'scope' => 'default', |
109 |
| - 'destination' => 'setup.py', |
110 |
| - 'template' => 'python/setup.py.twig', |
| 109 | + 'scope' => 'default', |
| 110 | + 'destination' => 'setup.py', |
| 111 | + 'template' => 'python/setup.py.twig', |
111 | 112 | ],
|
112 | 113 | [
|
113 |
| - 'scope' => 'default', |
114 |
| - 'destination' => 'setup.cfg', |
115 |
| - 'template' => 'python/setup.cfg.twig', |
| 114 | + 'scope' => 'default', |
| 115 | + 'destination' => 'setup.cfg', |
| 116 | + 'template' => 'python/setup.cfg.twig', |
116 | 117 | ],
|
117 | 118 | [
|
118 |
| - 'scope' => 'default', |
119 |
| - 'destination' => 'requirements.txt', |
120 |
| - 'template' => 'python/requirements.txt.twig', |
| 119 | + 'scope' => 'default', |
| 120 | + 'destination' => 'requirements.txt', |
| 121 | + 'template' => 'python/requirements.txt.twig', |
121 | 122 | ],
|
122 | 123 | [
|
123 |
| - 'scope' => 'default', |
124 |
| - 'destination' => '{{ spec.title | caseSnake}}/__init__.py', |
125 |
| - 'template' => 'python/package/__init__.py.twig', |
| 124 | + 'scope' => 'default', |
| 125 | + 'destination' => '{{ spec.title | caseSnake}}/__init__.py', |
| 126 | + 'template' => 'python/package/__init__.py.twig', |
126 | 127 | ],
|
127 | 128 | [
|
128 |
| - 'scope' => 'default', |
129 |
| - 'destination' => '{{ spec.title | caseSnake}}/client.py', |
130 |
| - 'template' => 'python/package/client.py.twig', |
| 129 | + 'scope' => 'default', |
| 130 | + 'destination' => '{{ spec.title | caseSnake}}/client.py', |
| 131 | + 'template' => 'python/package/client.py.twig', |
131 | 132 | ],
|
132 | 133 | [
|
133 |
| - 'scope' => 'default', |
134 |
| - 'destination' => '{{ spec.title | caseSnake}}/permission.py', |
135 |
| - 'template' => 'python/package/permission.py.twig', |
| 134 | + 'scope' => 'default', |
| 135 | + 'destination' => '{{ spec.title | caseSnake}}/permission.py', |
| 136 | + 'template' => 'python/package/permission.py.twig', |
136 | 137 | ],
|
137 | 138 | [
|
138 |
| - 'scope' => 'default', |
139 |
| - 'destination' => '{{ spec.title | caseSnake}}/role.py', |
140 |
| - 'template' => 'python/package/role.py.twig', |
| 139 | + 'scope' => 'default', |
| 140 | + 'destination' => '{{ spec.title | caseSnake}}/role.py', |
| 141 | + 'template' => 'python/package/role.py.twig', |
141 | 142 | ],
|
142 | 143 | [
|
143 |
| - 'scope' => 'default', |
144 |
| - 'destination' => '{{ spec.title | caseSnake}}/id.py', |
145 |
| - 'template' => 'python/package/id.py.twig', |
| 144 | + 'scope' => 'default', |
| 145 | + 'destination' => '{{ spec.title | caseSnake}}/id.py', |
| 146 | + 'template' => 'python/package/id.py.twig', |
146 | 147 | ],
|
147 | 148 | [
|
148 |
| - 'scope' => 'default', |
149 |
| - 'destination' => '{{ spec.title | caseSnake}}/query.py', |
150 |
| - 'template' => 'python/package/query.py.twig', |
| 149 | + 'scope' => 'default', |
| 150 | + 'destination' => '{{ spec.title | caseSnake}}/query.py', |
| 151 | + 'template' => 'python/package/query.py.twig', |
151 | 152 | ],
|
152 | 153 | [
|
153 |
| - 'scope' => 'default', |
154 |
| - 'destination' => '{{ spec.title | caseSnake}}/exception.py', |
155 |
| - 'template' => 'python/package/exception.py.twig', |
| 154 | + 'scope' => 'default', |
| 155 | + 'destination' => '{{ spec.title | caseSnake}}/exception.py', |
| 156 | + 'template' => 'python/package/exception.py.twig', |
156 | 157 | ],
|
157 | 158 | [
|
158 |
| - 'scope' => 'default', |
159 |
| - 'destination' => '{{ spec.title | caseSnake}}/input_file.py', |
160 |
| - 'template' => 'python/package/input_file.py.twig', |
| 159 | + 'scope' => 'default', |
| 160 | + 'destination' => '{{ spec.title | caseSnake}}/input_file.py', |
| 161 | + 'template' => 'python/package/input_file.py.twig', |
161 | 162 | ],
|
162 | 163 | [
|
163 |
| - 'scope' => 'default', |
164 |
| - 'destination' => '{{ spec.title | caseSnake}}/service.py', |
165 |
| - 'template' => 'python/package/service.py.twig', |
| 164 | + 'scope' => 'default', |
| 165 | + 'destination' => '{{ spec.title | caseSnake}}/service.py', |
| 166 | + 'template' => 'python/package/service.py.twig', |
166 | 167 | ],
|
167 | 168 | [
|
168 |
| - 'scope' => 'default', |
169 |
| - 'destination' => '{{ spec.title | caseSnake}}/services/__init__.py', |
170 |
| - 'template' => 'python/package/services/__init__.py.twig', |
| 169 | + 'scope' => 'default', |
| 170 | + 'destination' => '{{ spec.title | caseSnake}}/services/__init__.py', |
| 171 | + 'template' => 'python/package/services/__init__.py.twig', |
171 | 172 | ],
|
172 | 173 | [
|
173 |
| - 'scope' => 'default', |
174 |
| - 'destination' => '{{ spec.title | caseSnake}}/encoders/__init__.py', |
175 |
| - 'template' => 'python/package/services/__init__.py.twig', |
| 174 | + 'scope' => 'default', |
| 175 | + 'destination' => '{{ spec.title | caseSnake}}/encoders/__init__.py', |
| 176 | + 'template' => 'python/package/services/__init__.py.twig', |
176 | 177 | ],
|
177 | 178 | [
|
178 |
| - 'scope' => 'default', |
179 |
| - 'destination' => '{{ spec.title | caseSnake}}/enums/__init__.py', |
180 |
| - 'template' => 'python/package/services/__init__.py.twig', |
| 179 | + 'scope' => 'default', |
| 180 | + 'destination' => '{{ spec.title | caseSnake}}/enums/__init__.py', |
| 181 | + 'template' => 'python/package/services/__init__.py.twig', |
181 | 182 | ],
|
182 | 183 | [
|
183 |
| - 'scope' => 'default', |
184 |
| - 'destination' => '{{ spec.title | caseSnake}}/encoders/value_class_encoder.py', |
185 |
| - 'template' => 'python/package/encoders/value_class_encoder.py.twig', |
| 184 | + 'scope' => 'default', |
| 185 | + 'destination' => '{{ spec.title | caseSnake}}/encoders/value_class_encoder.py', |
| 186 | + 'template' => 'python/package/encoders/value_class_encoder.py.twig', |
186 | 187 | ],
|
187 | 188 | [
|
188 |
| - 'scope' => 'service', |
189 |
| - 'destination' => '{{ spec.title | caseSnake}}/services/{{service.name | caseSnake}}.py', |
190 |
| - 'template' => 'python/package/services/service.py.twig', |
| 189 | + 'scope' => 'service', |
| 190 | + 'destination' => '{{ spec.title | caseSnake}}/services/{{service.name | caseSnake}}.py', |
| 191 | + 'template' => 'python/package/services/service.py.twig', |
191 | 192 | ],
|
192 | 193 | [
|
193 |
| - 'scope' => 'method', |
194 |
| - 'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md', |
195 |
| - 'template' => 'python/docs/example.md.twig', |
| 194 | + 'scope' => 'method', |
| 195 | + 'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md', |
| 196 | + 'template' => 'python/docs/example.md.twig', |
196 | 197 | ],
|
197 | 198 | [
|
198 |
| - 'scope' => 'default', |
199 |
| - 'destination' => '.travis.yml', |
200 |
| - 'template' => 'python/.travis.yml.twig', |
| 199 | + 'scope' => 'default', |
| 200 | + 'destination' => '.travis.yml', |
| 201 | + 'template' => 'python/.travis.yml.twig', |
201 | 202 | ],
|
202 | 203 | [
|
203 |
| - 'scope' => 'enum', |
204 |
| - 'destination' => '{{ spec.title | caseSnake}}/enums/{{ enum.name | caseSnake }}.py', |
205 |
| - 'template' => 'python/package/enums/enum.py.twig', |
| 204 | + 'scope' => 'enum', |
| 205 | + 'destination' => '{{ spec.title | caseSnake}}/enums/{{ enum.name | caseSnake }}.py', |
| 206 | + 'template' => 'python/package/enums/enum.py.twig', |
206 | 207 | ],
|
207 | 208 | ];
|
208 | 209 | }
|
@@ -238,9 +239,9 @@ public function getTypeName(array $parameter, array $spec = []): string
|
238 | 239 | */
|
239 | 240 | public function getParamDefault(array $param): string
|
240 | 241 | {
|
241 |
| - $type = $param['type'] ?? ''; |
242 |
| - $default = $param['default'] ?? ''; |
243 |
| - $required = $param['required'] ?? ''; |
| 242 | + $type = $param['type'] ?? ''; |
| 243 | + $default = $param['default'] ?? ''; |
| 244 | + $required = $param['required'] ?? ''; |
244 | 245 |
|
245 | 246 | if ($required) {
|
246 | 247 | return '';
|
@@ -295,8 +296,8 @@ public function getParamDefault(array $param): string
|
295 | 296 | */
|
296 | 297 | public function getParamExample(array $param): string
|
297 | 298 | {
|
298 |
| - $type = $param['type'] ?? ''; |
299 |
| - $example = $param['example'] ?? ''; |
| 299 | + $type = $param['type'] ?? ''; |
| 300 | + $example = $param['example'] ?? ''; |
300 | 301 |
|
301 | 302 | $output = '';
|
302 | 303 |
|
@@ -342,4 +343,13 @@ public function getParamExample(array $param): string
|
342 | 343 |
|
343 | 344 | return $output;
|
344 | 345 | }
|
| 346 | + |
| 347 | + public function getFilters(): array |
| 348 | + { |
| 349 | + return [ |
| 350 | + new TwigFilter('caseEnumKey', function (string $value) { |
| 351 | + return $this->toUpperSnakeCase($value); |
| 352 | + }), |
| 353 | + ]; |
| 354 | + } |
345 | 355 | }
|
0 commit comments