iodine 0.7.1 → 0.7.2
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.
Potentially problematic release.
This version of iodine might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +3 -3
- data/CHANGELOG.md +8 -0
- data/bin/mustache.rb +12 -40
- data/ext/iodine/fio.c +343 -236
- data/ext/iodine/fio.h +419 -183
- data/ext/iodine/fio_cli.c +4 -5
- data/ext/iodine/fiobj_ary.c +2 -3
- data/ext/iodine/fiobj_data.c +1 -1
- data/ext/iodine/fiobj_hash.c +88 -105
- data/ext/iodine/fiobj_json.c +4 -3
- data/ext/iodine/fiobj_numbers.c +1 -1
- data/ext/iodine/fiobj_str.c +5 -5
- data/ext/iodine/fiobject.c +14 -3
- data/ext/iodine/fiobject.h +4 -0
- data/ext/iodine/http.c +62 -77
- data/ext/iodine/http1.c +9 -12
- data/ext/iodine/http_internal.c +15 -6
- data/ext/iodine/http_internal.h +0 -8
- data/ext/iodine/iodine.c +12 -25
- data/ext/iodine/iodine_defer.c +59 -54
- data/ext/iodine/iodine_http.c +4 -32
- data/ext/iodine/iodine_mustache.c +138 -16
- data/ext/iodine/iodine_mustache.h +3 -3
- data/ext/iodine/iodine_store.c +16 -21
- data/ext/iodine/mustache_parser.h +49 -5
- data/ext/iodine/redis_engine.c +31 -31
- data/ext/iodine/websockets.c +11 -5
- data/lib/iodine.rb +13 -1
- data/lib/iodine/mustache.rb +13 -41
- data/lib/iodine/version.rb +1 -1
- metadata +2 -4
- data/ext/iodine/fio_hashmap.h +0 -813
- data/ext/iodine/fio_str.h +0 -1218
data/ext/iodine/iodine.c
CHANGED
@@ -33,18 +33,19 @@ static ID call_id;
|
|
33
33
|
Idling
|
34
34
|
***************************************************************************** */
|
35
35
|
|
36
|
-
|
37
|
-
static
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
(
|
36
|
+
/* performs a Ruby state callback and clears the Ruby object's memory */
|
37
|
+
static void iodine_perform_on_idle_callback(void *blk_) {
|
38
|
+
VALUE blk = (VALUE)blk_;
|
39
|
+
IodineCaller.call(blk, call_id);
|
40
|
+
IodineStore.remove(blk);
|
41
|
+
fio_state_callback_remove(FIO_CALL_ON_IDLE, iodine_perform_on_idle_callback,
|
42
|
+
blk_);
|
42
43
|
}
|
43
44
|
|
44
45
|
/**
|
45
46
|
Schedules a single occuring event for the next idle cycle.
|
46
47
|
|
47
|
-
To schedule a reoccuring event,
|
48
|
+
To schedule a reoccuring event, reschedule the event at the end of it's
|
48
49
|
run.
|
49
50
|
|
50
51
|
i.e.
|
@@ -52,28 +53,17 @@ i.e.
|
|
52
53
|
IDLE_PROC = Proc.new { puts "idle"; Iodine.on_idle &IDLE_PROC }
|
53
54
|
Iodine.on_idle &IDLE_PROC
|
54
55
|
*/
|
55
|
-
VALUE iodine_sched_on_idle(VALUE self) {
|
56
|
+
static VALUE iodine_sched_on_idle(VALUE self) {
|
57
|
+
// clang-format on
|
56
58
|
rb_need_block();
|
57
59
|
VALUE block = rb_block_proc();
|
58
60
|
IodineStore.add(block);
|
59
|
-
|
60
|
-
|
61
|
-
fio_unlock(&iodine_on_idle_lock);
|
61
|
+
fio_state_callback_add(FIO_CALL_ON_IDLE, iodine_perform_on_idle_callback,
|
62
|
+
(void *)block);
|
62
63
|
return block;
|
63
64
|
(void)self;
|
64
65
|
}
|
65
66
|
|
66
|
-
static void iodine_on_idle(void *arg) {
|
67
|
-
(void)arg;
|
68
|
-
fio_lock(&iodine_on_idle_lock);
|
69
|
-
while (fio_ls_any(&iodine_on_idle_list)) {
|
70
|
-
VALUE block = (VALUE)fio_ls_shift(&iodine_on_idle_list);
|
71
|
-
fio_defer(iodine_perform_deferred, (void *)block, NULL);
|
72
|
-
IodineStore.remove(block);
|
73
|
-
}
|
74
|
-
fio_unlock(&iodine_on_idle_lock);
|
75
|
-
}
|
76
|
-
|
77
67
|
/* *****************************************************************************
|
78
68
|
Running Iodine
|
79
69
|
***************************************************************************** */
|
@@ -272,7 +262,4 @@ void Init_iodine(void) {
|
|
272
262
|
|
273
263
|
// initialize Pub/Sub extension (for Engines)
|
274
264
|
iodine_pubsub_init();
|
275
|
-
|
276
|
-
// register idle and finish callbacks
|
277
|
-
fio_state_callback_add(FIO_CALL_ON_IDLE, iodine_on_idle, NULL);
|
278
265
|
}
|
data/ext/iodine/iodine_defer.c
CHANGED
@@ -89,15 +89,11 @@ static void *create_ruby_thread_gvl(void *args) {
|
|
89
89
|
return (void *)IodineStore.add(rb_thread_create(defer_thread_inGVL, args));
|
90
90
|
}
|
91
91
|
|
92
|
-
/* Runs the before / after fork callbacks (if `before` is true, before runs) */
|
93
|
-
static void iodine_perform_fork_callbacks(uint8_t before);
|
94
|
-
|
95
92
|
static void *fork_using_ruby(void *ignr) {
|
96
93
|
// stop IO thread and call before_fork callbacks
|
97
94
|
if (sock_io_pthread) {
|
98
95
|
iodine_join_io_thread();
|
99
96
|
}
|
100
|
-
iodine_perform_fork_callbacks(1);
|
101
97
|
// fork
|
102
98
|
const VALUE ProcessClass = rb_const_get(rb_cObject, rb_intern2("Process", 7));
|
103
99
|
const VALUE rb_pid = IodineCaller.call(ProcessClass, rb_intern2("fork", 4));
|
@@ -112,7 +108,6 @@ static void *fork_using_ruby(void *ignr) {
|
|
112
108
|
if (!pid) {
|
113
109
|
IodineStore.after_fork();
|
114
110
|
}
|
115
|
-
iodine_perform_fork_callbacks(0);
|
116
111
|
// re-initiate IO thread
|
117
112
|
fio_defer(iodine_start_io_thread2, NULL, NULL);
|
118
113
|
return (void *)pid;
|
@@ -285,93 +280,99 @@ static VALUE iodine_defer_run_every(int argc, VALUE *argv, VALUE self) {
|
|
285
280
|
Pre/Post `fork`
|
286
281
|
***************************************************************************** */
|
287
282
|
|
288
|
-
|
289
|
-
static
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
static fio_ls_s iodine_on_shutdown_list = FIO_LS_INIT(iodine_on_shutdown_list);
|
283
|
+
/* performs a Ruby state callback without clearing the Ruby object's memory */
|
284
|
+
static void iodine_perform_state_callback_persist(void *blk_) {
|
285
|
+
VALUE blk = (VALUE)blk_;
|
286
|
+
IodineCaller.call(blk, call_id);
|
287
|
+
}
|
294
288
|
|
289
|
+
// clang-format off
|
295
290
|
/**
|
296
|
-
Sets a block of code to run before a new worker process is forked (cluster mode
|
297
|
-
|
291
|
+
Sets a block of code to run before a new worker process is forked (cluster mode only).
|
292
|
+
|
293
|
+
Code runs within the master (root) process.
|
298
294
|
*/
|
299
295
|
VALUE iodine_before_fork_add(VALUE self) {
|
296
|
+
// clang-format on
|
300
297
|
rb_need_block();
|
301
298
|
VALUE block = rb_block_proc();
|
302
299
|
IodineStore.add(block);
|
303
|
-
|
304
|
-
|
305
|
-
fio_unlock(&iodine_before_fork_lock);
|
300
|
+
fio_state_callback_add(FIO_CALL_BEFORE_FORK,
|
301
|
+
iodine_perform_state_callback_persist, (void *)block);
|
306
302
|
return block;
|
307
303
|
(void)self;
|
308
304
|
}
|
309
305
|
|
306
|
+
// clang-format off
|
310
307
|
/**
|
311
|
-
Sets a block of code to run after a new worker process is forked (cluster mode
|
312
|
-
|
308
|
+
Sets a block of code to run after a new worker process is forked (cluster mode only).
|
309
|
+
|
310
|
+
Code runs in both the parent and the child.
|
313
311
|
*/
|
314
312
|
VALUE iodine_after_fork_add(VALUE self) {
|
313
|
+
// clang-format on
|
315
314
|
rb_need_block();
|
316
315
|
VALUE block = rb_block_proc();
|
317
316
|
IodineStore.add(block);
|
318
|
-
|
319
|
-
|
320
|
-
fio_unlock(&iodine_after_fork_lock);
|
317
|
+
fio_state_callback_add(FIO_CALL_AFTER_FORK,
|
318
|
+
iodine_perform_state_callback_persist, (void *)block);
|
321
319
|
return block;
|
322
320
|
(void)self;
|
323
321
|
}
|
324
322
|
|
325
323
|
// clang-format off
|
326
324
|
/**
|
327
|
-
Sets a block of code to run
|
325
|
+
Sets a block of code to run after a new worker process is forked (cluster mode only).
|
326
|
+
|
327
|
+
Code runs in both the parent and the child.
|
328
328
|
*/
|
329
|
-
VALUE
|
329
|
+
VALUE iodine_after_fork_in_worker_add(VALUE self) {
|
330
|
+
// clang-format on
|
331
|
+
rb_need_block();
|
332
|
+
VALUE block = rb_block_proc();
|
333
|
+
IodineStore.add(block);
|
334
|
+
fio_state_callback_add(FIO_CALL_IN_CHILD,
|
335
|
+
iodine_perform_state_callback_persist, (void *)block);
|
336
|
+
return block;
|
337
|
+
(void)self;
|
338
|
+
}
|
339
|
+
|
340
|
+
// clang-format off
|
341
|
+
/**
|
342
|
+
Sets a block of code to run after a new worker process is forked (cluster mode only).
|
343
|
+
|
344
|
+
Code runs in both the parent and the child.
|
345
|
+
*/
|
346
|
+
VALUE iodine_after_fork_in_master_add(VALUE self) {
|
330
347
|
// clang-format on
|
331
348
|
rb_need_block();
|
332
349
|
VALUE block = rb_block_proc();
|
333
350
|
IodineStore.add(block);
|
334
|
-
|
335
|
-
|
336
|
-
fio_unlock(&iodine_on_shutdown_lock);
|
351
|
+
fio_state_callback_add(FIO_CALL_IN_MASTER,
|
352
|
+
iodine_perform_state_callback_persist, (void *)block);
|
337
353
|
return block;
|
338
354
|
(void)self;
|
339
355
|
}
|
340
356
|
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
357
|
+
// clang-format off
|
358
|
+
/**
|
359
|
+
Sets a block of code to run once a Worker process shuts down (both in single process mode and cluster mode).
|
360
|
+
*/
|
361
|
+
VALUE iodine_on_shutdown_add(VALUE self) {
|
362
|
+
// clang-format on
|
363
|
+
rb_need_block();
|
364
|
+
VALUE block = rb_block_proc();
|
365
|
+
IodineStore.add(block);
|
366
|
+
fio_state_callback_add(FIO_CALL_ON_FINISH,
|
367
|
+
iodine_perform_state_callback_persist, (void *)block);
|
368
|
+
return block;
|
369
|
+
(void)self;
|
349
370
|
}
|
350
371
|
|
351
372
|
/* Performs any cleanup before worker dies */
|
352
373
|
static void iodine_defer_on_finish(void *ignr) {
|
353
374
|
(void)ignr;
|
354
375
|
iodine_join_io_thread();
|
355
|
-
/* perform and clear away shutdown Procs */
|
356
|
-
fio_lock(&iodine_on_shutdown_lock);
|
357
|
-
while (fio_ls_any(&iodine_on_shutdown_list)) {
|
358
|
-
void *obj = fio_ls_shift(&iodine_on_shutdown_list);
|
359
|
-
IodineCaller.call((VALUE)(obj), call_id);
|
360
|
-
IodineStore.remove((VALUE)(obj));
|
361
|
-
}
|
362
|
-
fio_unlock(&iodine_on_shutdown_lock);
|
363
|
-
/* clear away forking Procs */
|
364
|
-
fio_lock(&iodine_before_fork_lock);
|
365
|
-
while (fio_ls_any(&iodine_before_fork_list)) {
|
366
|
-
IodineStore.remove((VALUE)fio_ls_shift(&iodine_before_fork_list));
|
367
|
-
}
|
368
|
-
fio_unlock(&iodine_before_fork_lock);
|
369
|
-
|
370
|
-
fio_lock(&iodine_after_fork_lock);
|
371
|
-
while (fio_ls_any(&iodine_after_fork_list)) {
|
372
|
-
IodineStore.remove((VALUE)fio_ls_shift(&iodine_after_fork_list));
|
373
|
-
}
|
374
|
-
fio_unlock(&iodine_after_fork_lock);
|
375
376
|
}
|
376
377
|
|
377
378
|
/* *****************************************************************************
|
@@ -391,6 +392,10 @@ void iodine_defer_initialize(void) {
|
|
391
392
|
0);
|
392
393
|
rb_define_module_function(IodineModule, "after_fork", iodine_after_fork_add,
|
393
394
|
0);
|
395
|
+
rb_define_module_function(IodineModule, "after_fork_in_worker",
|
396
|
+
iodine_after_fork_in_worker_add, 0);
|
397
|
+
rb_define_module_function(IodineModule, "after_fork_in_master",
|
398
|
+
iodine_after_fork_in_master_add, 0);
|
394
399
|
rb_define_module_function(IodineModule, "on_shutdown", iodine_on_shutdown_add,
|
395
400
|
0);
|
396
401
|
fio_state_callback_add(FIO_CALL_ON_FINISH, iodine_defer_on_finish, NULL);
|
data/ext/iodine/iodine_http.c
CHANGED
@@ -776,37 +776,6 @@ Listenninng to HTTP
|
|
776
776
|
*****************************************************************************
|
777
777
|
*/
|
778
778
|
|
779
|
-
void *iodine_print_http_msg_in_gvl(void *d_) {
|
780
|
-
// Write message
|
781
|
-
struct {
|
782
|
-
VALUE www;
|
783
|
-
VALUE port;
|
784
|
-
} *arg = d_;
|
785
|
-
if (arg->www) {
|
786
|
-
fprintf(stderr,
|
787
|
-
"Iodine HTTP Server on port %s:\n"
|
788
|
-
" * Serving static files from %s\n\n",
|
789
|
-
(arg->port ? StringValueCStr(arg->port) : "----"),
|
790
|
-
StringValueCStr(arg->www));
|
791
|
-
}
|
792
|
-
return NULL;
|
793
|
-
}
|
794
|
-
|
795
|
-
static void iodine_print_http_msg(void *www, void *port) {
|
796
|
-
if (!fio_is_master())
|
797
|
-
goto finish;
|
798
|
-
struct {
|
799
|
-
void *www;
|
800
|
-
void *port;
|
801
|
-
} data = {.www = www, .port = port};
|
802
|
-
IodineCaller.enterGVL(iodine_print_http_msg_in_gvl, (void *)&data);
|
803
|
-
finish:
|
804
|
-
if (www) {
|
805
|
-
IodineStore.remove((VALUE)www);
|
806
|
-
}
|
807
|
-
IodineStore.remove((VALUE)port);
|
808
|
-
}
|
809
|
-
|
810
779
|
static void free_iodine_http(http_settings_s *s) {
|
811
780
|
IodineStore.remove((VALUE)s->udata);
|
812
781
|
}
|
@@ -995,7 +964,10 @@ VALUE iodine_http_listen(VALUE self, VALUE opt) {
|
|
995
964
|
"static files.\n",
|
996
965
|
(port ? StringValueCStr(port) : "3000"));
|
997
966
|
}
|
998
|
-
|
967
|
+
if (www) {
|
968
|
+
fprintf(stderr, " * Serving static files from %s\n",
|
969
|
+
StringValueCStr(www));
|
970
|
+
}
|
999
971
|
|
1000
972
|
return Qtrue;
|
1001
973
|
(void)self;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
#include <ruby.h>
|
2
2
|
#define INCLUDE_MUSTACHE_IMPLEMENTATION 1
|
3
3
|
#include "mustache_parser.h"
|
4
4
|
|
@@ -7,8 +7,11 @@
|
|
7
7
|
#define FIO_INCLUDE_STR
|
8
8
|
#include <fio.h>
|
9
9
|
|
10
|
-
ID call_func_id;
|
11
|
-
ID to_s_func_id;
|
10
|
+
static ID call_func_id;
|
11
|
+
static ID to_s_func_id;
|
12
|
+
static ID filename_id;
|
13
|
+
static ID data_id;
|
14
|
+
static ID template_id;
|
12
15
|
/* *****************************************************************************
|
13
16
|
C <=> Ruby Data allocation
|
14
17
|
***************************************************************************** */
|
@@ -18,10 +21,9 @@ static size_t iodine_mustache_data_size(const void *c_) {
|
|
18
21
|
(void)c_;
|
19
22
|
}
|
20
23
|
|
21
|
-
static
|
24
|
+
static void iodine_mustache_data_free(void *c_) {
|
22
25
|
mustache_free(((mustache_s **)c_)[0]);
|
23
26
|
free((void *)c_);
|
24
|
-
return sizeof(mustache_s *);
|
25
27
|
(void)c_;
|
26
28
|
}
|
27
29
|
|
@@ -30,7 +32,7 @@ const rb_data_type_t iodine_mustache_data_type = {
|
|
30
32
|
.function =
|
31
33
|
{
|
32
34
|
.dmark = NULL,
|
33
|
-
.dfree =
|
35
|
+
.dfree = iodine_mustache_data_free,
|
34
36
|
.dsize = iodine_mustache_data_size,
|
35
37
|
},
|
36
38
|
.data = NULL,
|
@@ -44,14 +46,6 @@ static VALUE iodine_mustache_data_alloc_c(VALUE self) {
|
|
44
46
|
return TypedData_Wrap_Struct(self, &iodine_mustache_data_type, m);
|
45
47
|
}
|
46
48
|
|
47
|
-
static inline mustache_s *iodine_mustache_ruby2C(VALUE self) {
|
48
|
-
mustache_s **m = NULL;
|
49
|
-
TypedData_Get_Struct(self, mustache_s *, &iodine_mustache_data_type, m);
|
50
|
-
if (!m)
|
51
|
-
return NULL;
|
52
|
-
return m[0];
|
53
|
-
}
|
54
|
-
|
55
49
|
/* *****************************************************************************
|
56
50
|
Parser Callbacks
|
57
51
|
***************************************************************************** */
|
@@ -338,7 +332,7 @@ Rendering
|
|
338
332
|
/**
|
339
333
|
Renders the mustache template using the data provided in the `data` argument.
|
340
334
|
|
341
|
-
Returns a String.
|
335
|
+
Returns a String with the rendered template.
|
342
336
|
|
343
337
|
Raises an exception on error.
|
344
338
|
|
@@ -367,6 +361,130 @@ error:
|
|
367
361
|
rb_raise(rb_eRuntimeError, "Couldn't build template frome data.");
|
368
362
|
}
|
369
363
|
|
364
|
+
/**
|
365
|
+
Renders the mustache template found in `filename`, using the data provided in
|
366
|
+
the `data` argument.
|
367
|
+
|
368
|
+
Iodine::Mustache.render(filename, data, template = nil)
|
369
|
+
|
370
|
+
Returns a String with the rendered template.
|
371
|
+
|
372
|
+
Raises an exception on error.
|
373
|
+
|
374
|
+
template = "<h1>{{title}}</h1>"
|
375
|
+
filename = "templates/index"
|
376
|
+
data = {title: "Home"}
|
377
|
+
result = Iodine::Mustache.render(filename, data)
|
378
|
+
|
379
|
+
# filename will be used to resolve the path to any partials:
|
380
|
+
result = Iodine::Mustache.render(filename, data, template)
|
381
|
+
|
382
|
+
# OR, if we don't need partial template path resolution
|
383
|
+
result = Iodine::Mustache.render(template: template, data: data)
|
384
|
+
|
385
|
+
NOTE 1:
|
386
|
+
|
387
|
+
This function doesn't cache the template data.
|
388
|
+
|
389
|
+
The more complext the template the higher the cost of the template parsing
|
390
|
+
stage.
|
391
|
+
|
392
|
+
Consider creating a persistent template object using a new object and using the
|
393
|
+
instance {#render} method.
|
394
|
+
|
395
|
+
NOTE 2:
|
396
|
+
|
397
|
+
As one might notice, no binding is provided. Instead, a `data` Hash is assumed.
|
398
|
+
Iodine will search the Hash for any data while protecting against code
|
399
|
+
execution.
|
400
|
+
*/
|
401
|
+
static VALUE iodine_mustache_render_klass(int argc, VALUE *argv, VALUE self) {
|
402
|
+
VALUE filename = Qnil, data = Qnil, template = Qnil;
|
403
|
+
if (argc == 1) {
|
404
|
+
/* named arguments */
|
405
|
+
Check_Type(argv[0], T_HASH);
|
406
|
+
filename = rb_hash_aref(argv[0], filename_id);
|
407
|
+
data = rb_hash_aref(argv[0], data_id);
|
408
|
+
template = rb_hash_aref(argv[0], template_id);
|
409
|
+
} else {
|
410
|
+
/* regular arguments */
|
411
|
+
if (argc < 2 || argc > 3)
|
412
|
+
rb_raise(rb_eArgError, "expecting 2..3 arguments or named arguments.");
|
413
|
+
filename = argv[0];
|
414
|
+
data = argv[1];
|
415
|
+
if (argc > 2) {
|
416
|
+
template = argv[2];
|
417
|
+
}
|
418
|
+
}
|
419
|
+
if (filename == Qnil && template == Qnil)
|
420
|
+
rb_raise(rb_eArgError, "missing both template contents and file name.");
|
421
|
+
|
422
|
+
if (template != Qnil)
|
423
|
+
Check_Type(template, T_STRING);
|
424
|
+
if (filename != Qnil)
|
425
|
+
Check_Type(filename, T_STRING);
|
426
|
+
|
427
|
+
fio_str_s str = FIO_STR_INIT;
|
428
|
+
|
429
|
+
mustache_s *m = NULL;
|
430
|
+
mustache_error_en err;
|
431
|
+
m = mustache_load(.filename =
|
432
|
+
(filename == Qnil ? NULL : RSTRING_PTR(filename)),
|
433
|
+
.filename_len =
|
434
|
+
(filename == Qnil ? 0 : RSTRING_LEN(filename)),
|
435
|
+
.data = (template == Qnil ? NULL : RSTRING_PTR(template)),
|
436
|
+
.data_len = (template == Qnil ? 0 : RSTRING_LEN(template)),
|
437
|
+
.err = &err);
|
438
|
+
if (!m)
|
439
|
+
goto error;
|
440
|
+
|
441
|
+
int e = mustache_build(m, .udata1 = &str, .udata2 = (void *)data);
|
442
|
+
mustache_free(m);
|
443
|
+
if (e)
|
444
|
+
goto render_error;
|
445
|
+
fio_str_info_s i = fio_str_info(&str);
|
446
|
+
VALUE ret = rb_str_new(i.data, i.len);
|
447
|
+
fio_str_free(&str);
|
448
|
+
return ret;
|
449
|
+
|
450
|
+
error:
|
451
|
+
switch (err) {
|
452
|
+
case MUSTACHE_OK:
|
453
|
+
rb_raise(rb_eRuntimeError, "Iodine::Mustache template ok, unknown error.");
|
454
|
+
break;
|
455
|
+
case MUSTACHE_ERR_TOO_DEEP:
|
456
|
+
rb_raise(rb_eRuntimeError, "Iodine::Mustache element nesting too deep.");
|
457
|
+
break;
|
458
|
+
case MUSTACHE_ERR_CLOSURE_MISMATCH:
|
459
|
+
rb_raise(rb_eRuntimeError,
|
460
|
+
"Iodine::Mustache template error, closure mismatch.");
|
461
|
+
break;
|
462
|
+
case MUSTACHE_ERR_FILE_NOT_FOUND:
|
463
|
+
rb_raise(rb_eRuntimeError, "Iodine::Mustache template not found.");
|
464
|
+
break;
|
465
|
+
case MUSTACHE_ERR_FILE_TOO_BIG:
|
466
|
+
rb_raise(rb_eRuntimeError, "Iodine::Mustache template too big.");
|
467
|
+
break;
|
468
|
+
case MUSTACHE_ERR_FILE_NAME_TOO_LONG:
|
469
|
+
rb_raise(rb_eRuntimeError, "Iodine::Mustache template name too long.");
|
470
|
+
break;
|
471
|
+
case MUSTACHE_ERR_EMPTY_TEMPLATE:
|
472
|
+
rb_raise(rb_eRuntimeError, "Iodine::Mustache template is empty.");
|
473
|
+
break;
|
474
|
+
case MUSTACHE_ERR_UNKNOWN:
|
475
|
+
rb_raise(rb_eRuntimeError, "Iodine::Mustache unknown error.");
|
476
|
+
break;
|
477
|
+
case MUSTACHE_ERR_USER_ERROR:
|
478
|
+
rb_raise(rb_eRuntimeError, "Iodine::Mustache internal error.");
|
479
|
+
break;
|
480
|
+
}
|
481
|
+
return Qnil;
|
482
|
+
|
483
|
+
render_error:
|
484
|
+
fio_str_free(&str);
|
485
|
+
rb_raise(rb_eRuntimeError, "Couldn't build template frome data.");
|
486
|
+
}
|
487
|
+
|
370
488
|
/* *****************************************************************************
|
371
489
|
Initialize Iodine::Mustache
|
372
490
|
***************************************************************************** */
|
@@ -374,6 +492,9 @@ Initialize Iodine::Mustache
|
|
374
492
|
void iodine_init_mustache(void) {
|
375
493
|
call_func_id = rb_intern2("call", 4);
|
376
494
|
to_s_func_id = rb_intern2("to_s", 4);
|
495
|
+
filename_id = rb_intern2("filename", 8);
|
496
|
+
data_id = rb_intern2("data", 4);
|
497
|
+
template_id = rb_intern2("template", 8);
|
377
498
|
/**
|
378
499
|
Iodine::Mustache offers a logicless mustache template engine with strict HTML
|
379
500
|
escaping (more than the basic `"<>'$`).
|
@@ -419,5 +540,6 @@ void iodine_init_mustache(void) {
|
|
419
540
|
rb_define_alloc_func(tmp, iodine_mustache_data_alloc_c);
|
420
541
|
rb_define_method(tmp, "initialize", iodine_mustache_new, 1);
|
421
542
|
rb_define_method(tmp, "render", iodine_mustache_render, 1);
|
422
|
-
|
543
|
+
rb_define_singleton_method(tmp, "render", iodine_mustache_render_klass, -1);
|
544
|
+
// rb_define_module_function(tmp, "render", iodine_mustache_render_klass, 2);
|
423
545
|
}
|