Class: Tidy
- Inherits:
-
Object
- Object
- Tidy
- Defined in:
- ext/tidy/ruby-tidy.c
Instance Attribute Summary collapse
- #access ⇒ Object
- #errors ⇒ Object readonly
Class Method Summary collapse
-
.new(hash) ⇒ Object
TODO, observe :show_warnings=>true in hash.
- .open(hash) ⇒ Object
- .path ⇒ Object
- .path=(path) ⇒ Object
Instance Method Summary collapse
- #clean(input) ⇒ Object
- #initialize ⇒ Object constructor
-
#parse(input) ⇒ Object
parse the given input and return the tidy errors and output.
Constructor Details
#initialize ⇒ Object
134 135 136 137 138 139 140 141 142 143 |
# File 'ext/tidy/ruby-tidy.c', line 134
static VALUE rb_tidy_init(VALUE self)
{
VALUE access = INT2NUM(4);
VALUE errors = rb_ary_new();
rb_iv_set(self, "@access", access);
rb_iv_set(self, "@errors", errors);
return self;
}
|
Instance Attribute Details
#access ⇒ Object
#errors ⇒ Object (readonly)
Class Method Details
.new(hash) ⇒ Object
TODO, observe :show_warnings=>true in hash
38 39 40 41 42 43 44 45 46 47 |
# File 'ext/tidy/ruby-tidy.c', line 38
static VALUE rb_tidy_new(VALUE class, VALUE hash)
{
VALUE argv[1];
TidyDoc tdoc = tidyCreate();
VALUE tdata = Data_Wrap_Struct(class, 0, rb_tidy_free, (struct _TidyDoc *)tdoc);
argv[0] = hash;
rb_obj_call_init(tdata, 0, NULL);
return tdata;
}
|
.open(hash) ⇒ Object
145 146 147 148 149 150 151 152 153 154 |
# File 'ext/tidy/ruby-tidy.c', line 145
static VALUE rb_tidy_open(VALUE class, VALUE hash)
{
VALUE tidy = rb_tidy_new(class, hash);
if (rb_block_given_p()) {
rb_yield(tidy);
}
return tidy;
}
|
.path ⇒ Object
165 166 167 168 169 170 |
# File 'ext/tidy/ruby-tidy.c', line 165
static VALUE rb_tidy_path_get(VALUE self)
{
VALUE path;
path = rb_cv_get(self, "@@path");
return path;
}
|
.path=(path) ⇒ Object
172 173 174 175 176 |
# File 'ext/tidy/ruby-tidy.c', line 172
static VALUE rb_tidy_path_set(VALUE self, VALUE path)
{
rb_cv_set(self, "@@path", path);
return Qnil;
}
|
Instance Method Details
#clean(input) ⇒ Object
156 157 158 159 160 161 162 163 |
# File 'ext/tidy/ruby-tidy.c', line 156
static VALUE rb_tidy_clean(VALUE self, VALUE input)
{
VALUE array;
array = rb_tidy_parse(self, input);
return rb_ary_entry(array, 1);
}
|
#parse(input) ⇒ Object
parse the given input and return the tidy errors and output
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'ext/tidy/ruby-tidy.c', line 50
static VALUE rb_tidy_parse(VALUE self, VALUE input)
{
VALUE array;
VALUE access;
VALUE errors;
TidyDoc tdoc;
TidyBuffer output;
TidyBuffer errbuf;
int status = 0;
int contentErrors = 0;
int contentWarnings = 0;
int accessWarnings = 0;
/* See platform.h, opaque_type for typedef convention */
Data_Get_Struct(self, struct _TidyDoc, tdoc);
tidyBufInit( &output );
tidyBufInit( &errbuf );
array = rb_ary_new();
status = tidySetErrorBuffer( tdoc, &errbuf );
access = rb_iv_get(self, "@access");
tidyOptSetInt( tdoc, TidyAccessibilityCheckLevel, NUM2UINT(access));
if (status >= 0) {
int is_input_source = 0;
is_input_source =
rb_respond_to(input, rb_intern("eof")) == Qtrue &&
rb_respond_to(input, rb_intern("getc")) == Qtrue &&
rb_respond_to(input, rb_intern("ungetc")) == Qtrue;
if (is_input_source != 0) {
TidyInputSource source;
tidyInitSource(&source, (void *)&input,
(TidyGetByteFunc)rb_tidyGetByte,
(TidyUngetByteFunc)rb_tidyUngetByte,
(TidyEOFFunc)rb_tidyIsEOF);
status = tidyParseSource(tdoc, &source);
} else {
status = tidyParseString(tdoc, StringValuePtr(input));
}
}
if (status >= 0)
status = tidyCleanAndRepair( tdoc );
if (status >= 0)
status = tidyRunDiagnostics( tdoc );
if (status >= 0)
tidyErrorSummary( tdoc );
if (status >= 0)
tidyGeneralInfo( tdoc );
if (status >= 0)
status = tidySaveBuffer( tdoc, &output );
contentErrors += tidyErrorCount( tdoc );
contentWarnings += tidyWarningCount( tdoc );
accessWarnings += tidyAccessWarningCount( tdoc );
if (contentErrors > 0 || contentWarnings > 0) {
errors = rb_str_new2(errbuf.bp);
} else {
errors = rb_ary_new2("");
}
rb_iv_set(self, "@errors", errors);
rb_ary_store(array, 0, errors);
rb_ary_store(array, 1, rb_str_new2(output.bp));
tidyBufFree( &output );
tidyBufFree( &errbuf );
return array;
}
|