Beispiel #1
0
/* call-seq: emitter.indentation = level
 *
 * Set the indentation level to +level+.  The level must be less than 10 and
 * greater than 1.
 */
static VALUE set_indentation(VALUE self, VALUE level)
{
    yaml_emitter_t * emitter;
    Data_Get_Struct(self, yaml_emitter_t, emitter);

    yaml_emitter_set_indent(emitter, NUM2INT(level));

    return level;
}
Beispiel #2
0
static VALUE allocate(VALUE klass)
{
    yaml_emitter_t * emitter;

    emitter = xmalloc(sizeof(yaml_emitter_t));

    yaml_emitter_initialize(emitter);
    yaml_emitter_set_unicode(emitter, 1);
    yaml_emitter_set_indent(emitter, 2);

    return Data_Wrap_Struct(klass, 0, dealloc, emitter);
}
Beispiel #3
0
void tap_yaml_write(const char *yaml, va_list vl)
{
	yaml_parser_t parser;
	yaml_document_t document;
	yaml_emitter_t emitter;
	char buffer[8192];
	size_t length;

	if (yaml == NULL) {
		return;
	}

	length = vsnprintf(buffer, 8192, yaml, vl);

	yaml_parser_initialize(&parser);
	yaml_parser_set_input_string(&parser, (unsigned char*) buffer, length);
	if (yaml_parser_load(&parser, &document)) {
		document.start_implicit = 0;
		document.end_implicit = 0;

		tap_yaml_document_set_block_style(&document);

		yaml_emitter_initialize(&emitter);
		yaml_emitter_set_output(&emitter, tap_yaml_write_handler, NULL);
		yaml_emitter_set_indent(&emitter, 2);

		// Initial indent
		tap_puts("  ");

		yaml_emitter_open(&emitter);
		yaml_emitter_dump(&emitter, &document);
		yaml_emitter_close(&emitter);

		yaml_parser_delete(&parser);
		yaml_emitter_delete(&emitter);
		yaml_document_delete(&document);
	} else {
		fprintf(stderr, "Error: %s %s at offset %zu\n",
			parser.problem, parser.context,
			parser.problem_mark.index);
	}
}
Beispiel #4
0
/* call-seq: Psych::Emitter.new(io, options = Psych::Emitter::OPTIONS)
 *
 * Create a new Psych::Emitter that writes to +io+.
 */
static VALUE initialize(int argc, VALUE *argv, VALUE self)
{
    yaml_emitter_t * emitter;
    VALUE io, options;
    VALUE line_width;
    VALUE indent;
    VALUE canonical;

    TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);

    if (rb_scan_args(argc, argv, "11", &io, &options) == 2) {
	line_width = rb_funcall(options, id_line_width, 0);
	indent     = rb_funcall(options, id_indentation, 0);
	canonical  = rb_funcall(options, id_canonical, 0);

	yaml_emitter_set_width(emitter, NUM2INT(line_width));
	yaml_emitter_set_indent(emitter, NUM2INT(indent));
	yaml_emitter_set_canonical(emitter, Qtrue == canonical ? 1 : 0);
    }

    yaml_emitter_set_output(emitter, writer, (void *)io);

    return self;
}