Module: HtmlNamespacing
- Defined in:
- lib/html_namespacing.rb,
lib/html_namespacing/plugin.rb,
lib/html_namespacing/plugin/sass.rb,
lib/html_namespacing/plugin/rails.rb,
ext/html_namespacing/html_namespacing_ext.c
Defined Under Namespace
Modules: Plugin
Class Method Summary collapse
-
.add_namespace_to_html(html, ns) ⇒ String
Returns new HTML string based on
htmlwith the HTML classnsto root elements. - .options ⇒ Object
Class Method Details
.add_namespace_to_html(html, ns) ⇒ String
Returns new HTML string based on html with the HTML class ns to root elements.
If html is nil, returns nil.
If ns is nil, returns html.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'ext/html_namespacing/html_namespacing_ext.c', line 29
VALUE
html_namespacing_add_namespace_to_html(
VALUE obj,
VALUE html,
VALUE ns)
{
/*
* It's almost tempting to manually allocate the RString object to save
* ourselves the stupid extra copy. (add_namespace_to_html_with_length()
* implicitly copies the string, and here we are copying it again because
* Ruby can't convert from a char* to an RString? How lame....)
*
* But for now, let's just do the extra copy (implicit in rb_str_new2) and
* be done with it.
*/
const char *html_ptr;
size_t html_len;
const char *ns_ptr;
char *ret_ptr;
size_t ret_len;
int rv;
VALUE ret;
if (TYPE(html) == T_NIL) {
return Qnil;
}
Check_Type(html, T_STRING);
if (TYPE(ns) == T_NIL) {
return html;
}
Check_Type(ns, T_STRING);
html_ptr = RSTRING_PTR(html);
html_len = RSTRING_LEN(html);
ns_ptr = RSTRING_PTR(ns);
rv = add_namespace_to_html_with_length_and_allocation_strategy(
html_ptr,
html_len,
ns_ptr,
&ret_ptr,
&ret_len,
ALLOCATION_STRATEGY);
if (rv == EINVAL) {
rb_raise(rb_eArgError, "Badly-formed HTML: %s", html_ptr);
}
if (rv != 0) {
rb_raise(rb_eRuntimeError, "Unknown error in add_namespace_to_html");
}
ret = rb_str_new(ret_ptr, ret_len);
ruby_xfree(ret_ptr);
return ret;
}
|
.options ⇒ Object
6 7 8 |
# File 'lib/html_namespacing.rb', line 6 def self. @options ||= {} end |