Module: Greenmat::Render::SmartyPants

Extended by:
SmartyPants
Included in:
SmartyHTML, SmartyPants
Defined in:
lib/greenmat.rb,
ext/greenmat/gm_render.c

Overview

SmartyPants Mixin module

Implements SmartyPants.postprocess, which performs smartypants replacements on the HTML file, once it has been fully rendered.

To add SmartyPants postprocessing to your custom renderers, just mixin the module `include SmartyPants`

You can also use this as a standalone SmartyPants implementation.

Example:

# Mixin
class CoolRenderer < HTML
  include SmartyPants
  # more code here
end

# Standalone
Greenmat::Render::SmartyPants.render("you're")

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.render(text) ⇒ Object



86
87
88
# File 'lib/greenmat.rb', line 86

def self.render(text)
  postprocess text
end

Instance Method Details

#postprocess(text) ⇒ Object



544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
# File 'ext/greenmat/gm_render.c', line 544

static VALUE rb_greenmat_smartypants_render(VALUE self, VALUE text)
{
	VALUE result;
	struct buf *output_buf;

	Check_Type(text, T_STRING);

	output_buf = bufnew(128);

	sdhtml_smartypants(output_buf, (const uint8_t*)RSTRING_PTR(text), RSTRING_LEN(text));
	result = rb_enc_str_new((const char*)output_buf->data, output_buf->size, rb_enc_get(text));

	bufrelease(output_buf);
	return result;
}