adamh-html_namespacing 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest CHANGED
@@ -12,5 +12,5 @@ lib/html_namespacing/plugin/dom_scan_jquery.compressed.js
12
12
  lib/html_namespacing/plugin/rails.rb
13
13
  lib/html_namespacing/plugin/dom_scan_jquery.js
14
14
  lib/html_namespacing/plugin/sass.rb
15
- Manifest
16
15
  html_namespacing.gemspec
16
+ Manifest
data/README.rdoc CHANGED
@@ -175,6 +175,9 @@ gain access to this method.
175
175
  <tt>:javascript_root</tt>: Root of namespaced JavaScript files, if you are
176
176
  using <tt>html_namespacing_javascript_tag()</tt> (see below).
177
177
 
178
+ <tt>:template_formats</tt>: If set (to an Array), apply HTML namespacing
179
+ under the given (String) formats. Default is <tt>['html']</tt>.
180
+
178
181
  <tt>:javascript_optional_suffix</tt>: optional suffix for your JavaScript
179
182
  files, if you are using <tt>html_namespacing_javascript_tag()</tt>. For
180
183
  instance, if <tt>:javascript_optional_suffix</tt> is <tt>'compressed'</tt> and
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('html_namespacing', '0.1.0') do |p|
5
+ Echoe.new('html_namespacing', '0.1.2') do |p|
6
6
  p.author = 'Adam Hooper'
7
7
  p.email = 'adam@adamhooper.com'
8
8
  p.summary = 'Automatic HTML namespacing'
@@ -22,56 +22,10 @@ static const char* const IGNORE_TAGS[] = {
22
22
  NULL
23
23
  };
24
24
 
25
- /*
26
- * Returns the first power of 2 which is >= the given length.
27
- */
28
25
  static int
29
- round_to_power_of_two(int i)
26
+ determine_alloc_size_of_at_least(int i)
30
27
  {
31
- int j = 1;
32
-
33
- while (j < i) {
34
- j <<= 1;
35
- }
36
-
37
- return j;
38
- }
39
-
40
- /*
41
- * Returns the number of bytes in the first utf-8 character of *utf8.
42
- */
43
- static size_t
44
- utf8_char_bytes(const char *utf8)
45
- {
46
- size_t i;
47
- const unsigned char *u;
48
-
49
- if (utf8[0] < 0x80) {
50
- return 1;
51
- }
52
-
53
- u = (const unsigned char *) utf8;
54
-
55
- for (i = 1; i < 6; i++) {
56
- if ((u[i] & 0xc0) != 0x80) {
57
- return i;
58
- }
59
- }
60
-
61
- return -1;
62
- }
63
-
64
- /*
65
- * Copies num_bytes bytes from *src_p to *dest_p, doing no bounds checking.
66
- *
67
- * Advances *dest_p and *src_p by num_bytes.
68
- */
69
- static void
70
- copy_n_bytes_and_advance(char **dest_p, const char **src_p, size_t num_bytes)
71
- {
72
- memcpy(*dest_p, *src_p, num_bytes);
73
- *dest_p += num_bytes;
74
- *src_p += num_bytes;
28
+ return i + 1024;
75
29
  }
76
30
 
77
31
  /*
@@ -119,57 +73,6 @@ ensure_string_length(
119
73
  return 0;
120
74
  }
121
75
 
122
- /*
123
- * Tries to copy a single utf8 character to dest, possibly reallocating.
124
- *
125
- * Arguments:
126
- * - dest: Beginning of destination string. May be reallocated during copy.
127
- * - dest_len: Amount of memory allocated to dest. May be increased during
128
- * copy.
129
- * - dest_p: Pointer to end of destination string (potentially 1 past the
130
- * allocated length of dest).
131
- * - src_p: Source string. Will be advanced.
132
- *
133
- * Returns:
134
- * - 0 on success. dest may be changed; dest_p will be incremented; src_p
135
- * will be incremented.
136
- * - ENOMEM if reallocation failed. dest, dest_p, and src_p will remain
137
- * unchanged.
138
- */
139
- static int
140
- append_next_utf8_char(
141
- char **dest,
142
- size_t *dest_len,
143
- char **dest_p,
144
- const char **src_p,
145
- HtmlNamespacingAllocationStrategy allocation_strategy)
146
- {
147
- size_t c_num_utf8_bytes;
148
- size_t dest_p_offset;
149
- size_t new_dest_len;
150
- char *new_dest;
151
- int rv;
152
-
153
- c_num_utf8_bytes = utf8_char_bytes(*src_p);
154
- new_dest = *dest;
155
- dest_p_offset = *dest_p - *dest;
156
- new_dest_len = dest_p_offset + c_num_utf8_bytes;
157
-
158
- rv = ensure_string_length(
159
- &new_dest, dest_len, new_dest_len, allocation_strategy);
160
- if (rv == ENOMEM) {
161
- return ENOMEM;
162
- }
163
- if (new_dest != *dest) {
164
- *dest = new_dest;
165
- *dest_p = new_dest + dest_p_offset;
166
- }
167
-
168
- copy_n_bytes_and_advance(dest_p, src_p, c_num_utf8_bytes);
169
-
170
- return 0;
171
- }
172
-
173
76
  /*
174
77
  * Tries to copy s into dest, possibly reallocating.
175
78
  *
@@ -191,15 +94,14 @@ append_string(
191
94
  size_t *dest_len,
192
95
  char **dest_p,
193
96
  const char *s,
97
+ size_t len,
194
98
  HtmlNamespacingAllocationStrategy allocation_strategy)
195
99
  {
196
- int len;
197
100
  int rv;
198
101
  size_t dest_p_offset;
199
102
  size_t new_dest_len;
200
103
  char *new_dest;
201
104
 
202
- len = strlen(s);
203
105
  new_dest = *dest;
204
106
  dest_p_offset = *dest_p - *dest;
205
107
  new_dest_len = dest_p_offset + len;
@@ -220,63 +122,6 @@ append_string(
220
122
  return 0;
221
123
  };
222
124
 
223
- static int
224
- append_next_chars_until(
225
- char **dest,
226
- size_t *dest_len,
227
- char **dest_p,
228
- const char **src_p,
229
- const char *until_chars,
230
- HtmlNamespacingAllocationStrategy allocation_strategy)
231
- {
232
- size_t num_bytes;
233
- size_t dest_p_offset;
234
- size_t new_dest_len;
235
- char *new_dest;
236
- int rv;
237
-
238
- num_bytes = strcspn(*src_p, until_chars);
239
- new_dest = *dest;
240
- dest_p_offset = *dest_p - *dest;
241
- new_dest_len = dest_p_offset + num_bytes;
242
-
243
- rv = ensure_string_length(
244
- &new_dest, dest_len, new_dest_len, allocation_strategy);
245
- if (rv == ENOMEM) {
246
- return ENOMEM;
247
- }
248
- if (new_dest != *dest) {
249
- *dest = new_dest;
250
- *dest_p = new_dest + dest_p_offset;
251
- }
252
-
253
- copy_n_bytes_and_advance(dest_p, src_p, num_bytes);
254
-
255
- return 0;
256
- }
257
-
258
- static int
259
- append_end_of_string(
260
- char **dest,
261
- size_t *dest_len,
262
- char **dest_p,
263
- HtmlNamespacingAllocationStrategy allocation_strategy)
264
- {
265
- int rv;
266
- const char *end = "\0";
267
-
268
- rv = append_next_utf8_char(
269
- dest, dest_len, dest_p, &end, allocation_strategy);
270
-
271
- if (rv == 0) {
272
- /* We don't add the length of '\0' */
273
- *dest_len -= 1;
274
- *dest_p -= 1;
275
- }
276
-
277
- return rv;
278
- }
279
-
280
125
  enum {
281
126
  PARSE_NORMAL,
282
127
  PARSE_OPEN_TAG,
@@ -351,20 +196,38 @@ add_namespace_to_html_with_length_and_allocation_strategy(
351
196
  HtmlNamespacingAllocationStrategy allocation_strategy)
352
197
  {
353
198
 
354
- #define APPEND_NEXT_CHAR() \
355
- if (*html && append_next_utf8_char(&r, &r_len, &r_p, &html, allocation_strategy) != 0) goto error/*;*/
356
199
  #define APPEND_STRING(s) \
357
- if (append_string(&r, &r_len, &r_p, s, allocation_strategy) != 0) goto error/*;*/
200
+ do { \
201
+ if (append_string(&r, &r_len, &r_p, s, strlen(s), allocation_strategy) != 0) goto error; \
202
+ } while (0)/*;*/
358
203
  #define APPEND_END_OF_STRING() \
359
- if (append_end_of_string(&r, &r_len, &r_p, allocation_strategy) != 0) goto error/*;*/
360
- #define APPEND_NEXT_CHARS_UNTIL(chars) \
361
- if (append_next_chars_until(&r, &r_len, &r_p, &html, chars, allocation_strategy) != 0) goto error/*;*/
204
+ do { \
205
+ if (append_string(&r, &r_len, &r_p, "", 1, allocation_strategy) != 0) goto error; \
206
+ r_len -= 1; \
207
+ r_p -= 1; \
208
+ } while (0)/*;*/
209
+ #define COPY_TO_HERE() \
210
+ do { \
211
+ if (append_string(&r, &r_len, &r_p, html_first_uncopied_p, html_p - html_first_uncopied_p, allocation_strategy) != 0) goto error; \
212
+ html_first_uncopied_p = html_p; \
213
+ } while (0)/*;*/
214
+ #define ADVANCE(n) \
215
+ do { \
216
+ if (html_p + n <= html + html_len) { \
217
+ html_p += n; \
218
+ } else { \
219
+ html_p = html + html_len; \
220
+ } \
221
+ } while (0)/*;*/
222
+ #define ADVANCE_UNTIL_ONE_OF_THESE_CHARS(chars) \
223
+ ADVANCE(strcspn(html_p, chars))/*;*/
362
224
 
363
225
  unsigned int state;
364
226
  char *r; /* Start of retval */
365
227
  char *r_p; /* Pointer in retval */
366
228
  size_t r_len; /* Length of retval */
367
- const char *html_start;
229
+ const char *html_first_uncopied_p;
230
+ const char *html_p;
368
231
  const char *open_tag_name = NULL;
369
232
  size_t open_tag_name_len = 0;
370
233
  size_t num_chars_remaining;
@@ -373,13 +236,13 @@ add_namespace_to_html_with_length_and_allocation_strategy(
373
236
  int open_tag_had_class_attribute;
374
237
  const char *open_tag_attribute_value;
375
238
 
376
- r_len = round_to_power_of_two(html_len);
239
+ r_len = determine_alloc_size_of_at_least(html_len);
377
240
  r = allocation_strategy.malloc(sizeof(char) * r_len);
378
241
  if (!r) {
379
242
  return ENOMEM;
380
243
  }
381
244
 
382
- html_start = html;
245
+ html_first_uncopied_p = html_p = html;
383
246
  state = PARSE_NORMAL;
384
247
  r_p = r;
385
248
  num_tags_open = 0;
@@ -388,63 +251,70 @@ add_namespace_to_html_with_length_and_allocation_strategy(
388
251
  open_tag_attribute_value = NULL;
389
252
 
390
253
  while (1) {
391
- num_chars_remaining = html_len - (html - html_start);
254
+ num_chars_remaining = html_len - (html_p - html);
392
255
  if (num_chars_remaining <= 0) break;
393
256
 
394
257
  switch (state) {
395
258
  case PARSE_NORMAL:
396
- if (*html == '<') {
397
- APPEND_NEXT_CHAR();
259
+ if (*html_p == '<') {
260
+ ADVANCE(1);
398
261
  if (num_chars_remaining >= 9
399
- && 0 == strncmp("![CDATA[", html, 8)) {
262
+ && 0 == strncmp("![CDATA[", html_p, 8)) {
400
263
  state = PARSE_CDATA;
401
- } else if (num_chars_remaining >= 2 && html[0] == '/') {
264
+ } else if (num_chars_remaining >= 2 && html_p[0] == '/') {
402
265
  state = PARSE_CLOSE_TAG;
403
266
  } else if (num_chars_remaining >= 4
404
- && 0 == strncmp("!--", html, 3)) {
267
+ && 0 == strncmp("!--", html_p, 3)) {
405
268
  state = PARSE_COMMENT;
406
269
  } else if (num_chars_remaining >= 9
407
- && 0 == strncmp("!DOCTYPE", html, 8)) {
270
+ && 0 == strncmp("!DOCTYPE", html_p, 8)) {
408
271
  state = PARSE_DOCTYPE;
409
272
  } else if (num_chars_remaining >= 5
410
- && 0 == strncmp("?xml", html, 4)) {
273
+ && 0 == strncmp("?xml", html_p, 4)) {
411
274
  state = PARSE_XML_DECL;
412
275
  } else {
413
- open_tag_name = html;
276
+ open_tag_name = html_p;
414
277
  state = PARSE_OPEN_TAG_NAME;
415
278
  }
416
279
  } else {
417
- APPEND_NEXT_CHARS_UNTIL("<");
280
+ ADVANCE_UNTIL_ONE_OF_THESE_CHARS("<");
418
281
  }
419
282
  break;
420
283
  case PARSE_OPEN_TAG_NAME:
421
- APPEND_NEXT_CHARS_UNTIL(WHITE_SPACE ">/");
422
- open_tag_name_len = html - open_tag_name;
284
+ ADVANCE_UNTIL_ONE_OF_THESE_CHARS(WHITE_SPACE ">/");
285
+ open_tag_name_len = html_p - open_tag_name;
423
286
  state = PARSE_OPEN_TAG;
424
287
  break;
425
288
  case PARSE_OPEN_TAG:
426
- if (*html == '/' || *html == '>') {
289
+ if (*html_p == '/' || *html_p == '>') {
427
290
  if (num_tags_open == 0 && !open_tag_had_class_attribute
428
291
  && !should_ignore_tag(open_tag_name, open_tag_name_len)) {
429
- APPEND_STRING(" class=\"");
430
- APPEND_STRING(ns);
431
- APPEND_STRING("\"");
292
+ COPY_TO_HERE();
293
+ if (*html_p == '/' && char_is_whitespace(*(html_p - 1))) {
294
+ /* We're in an empty tag with a trailing space */
295
+ APPEND_STRING("class=\"");
296
+ APPEND_STRING(ns);
297
+ APPEND_STRING("\" ");
298
+ } else {
299
+ APPEND_STRING(" class=\"");
300
+ APPEND_STRING(ns);
301
+ APPEND_STRING("\"");
302
+ }
432
303
  }
433
304
 
434
305
  open_tag_had_class_attribute = 0;
435
306
  open_tag_attribute_value = NULL;
436
307
 
437
- if (*html == '/') {
438
- APPEND_STRING(" ");
308
+ if (*html_p == '/') {
439
309
  state = PARSE_EMPTY_TAG;
440
310
  } else {
441
311
  num_tags_open++;
442
312
  state = PARSE_NORMAL;
443
313
  }
444
- APPEND_NEXT_CHAR();
445
- } else if (!char_is_whitespace(*html)) {
314
+ ADVANCE(1);
315
+ } else if (!char_is_whitespace(*html_p)) {
446
316
  if (num_chars_remaining >= 5
447
- && 0 == strncmp(html, "class", 5)) {
317
+ && 0 == strncmp(html_p, "class", 5)) {
448
318
  open_tag_attribute_is_class_attribute = 1;
449
319
  open_tag_had_class_attribute = 1;
450
320
  } else {
@@ -452,68 +322,67 @@ add_namespace_to_html_with_length_and_allocation_strategy(
452
322
  }
453
323
  state = PARSE_OPEN_TAG_ATTRIBUTE_NAME;
454
324
  } else {
455
- APPEND_NEXT_CHAR();
325
+ ADVANCE(1);
456
326
  }
457
327
  break;
458
328
  case PARSE_OPEN_TAG_ATTRIBUTE_NAME:
459
- APPEND_NEXT_CHARS_UNTIL("=");
329
+ ADVANCE_UNTIL_ONE_OF_THESE_CHARS("=");
330
+ ADVANCE(1);
460
331
  state = PARSE_OPEN_TAG_ATTRIBUTE_EQUALS;
461
- APPEND_NEXT_CHAR();
462
332
  break;
463
333
  case PARSE_OPEN_TAG_ATTRIBUTE_EQUALS:
464
- APPEND_NEXT_CHARS_UNTIL("'\"");
465
- open_tag_attribute_value = html;
334
+ ADVANCE_UNTIL_ONE_OF_THESE_CHARS("'\"");
335
+ open_tag_attribute_value = html_p;
466
336
  state = PARSE_OPEN_TAG_ATTRIBUTE_VALUE;
467
- APPEND_NEXT_CHAR();
337
+ ADVANCE(1);
468
338
  break;
469
339
  case PARSE_OPEN_TAG_ATTRIBUTE_VALUE:
470
- APPEND_NEXT_CHARS_UNTIL("'\"");
340
+ ADVANCE_UNTIL_ONE_OF_THESE_CHARS("'\"");
471
341
  /* open_tag_attribute_value is either ' or " */
472
- while (*html != *open_tag_attribute_value) {
473
- APPEND_NEXT_CHAR();
474
- APPEND_NEXT_CHARS_UNTIL("'\"");
342
+ while (*html_p != *open_tag_attribute_value) {
343
+ ADVANCE(1);
344
+ ADVANCE_UNTIL_ONE_OF_THESE_CHARS("'\"");
475
345
  }
476
346
  if (open_tag_attribute_is_class_attribute
477
347
  && num_tags_open == 0) {
348
+ COPY_TO_HERE();
478
349
  APPEND_STRING(" ");
479
350
  APPEND_STRING(ns);
480
351
  }
481
352
  open_tag_attribute_is_class_attribute = 0;
482
353
  state = PARSE_OPEN_TAG;
483
- APPEND_NEXT_CHAR();
354
+ ADVANCE(1);
484
355
  break;
485
356
  case PARSE_CLOSE_TAG:
486
- APPEND_NEXT_CHARS_UNTIL(">");
357
+ ADVANCE_UNTIL_ONE_OF_THESE_CHARS(">");
487
358
  num_tags_open--;
488
359
  open_tag_attribute_value = NULL;
489
360
  state = PARSE_NORMAL;
490
- APPEND_NEXT_CHAR();
361
+ ADVANCE(1);
491
362
  break;
492
363
  case PARSE_EMPTY_TAG:
493
364
  case PARSE_XML_DECL:
494
365
  case PARSE_DOCTYPE:
495
- APPEND_NEXT_CHARS_UNTIL(">");
366
+ ADVANCE_UNTIL_ONE_OF_THESE_CHARS(">");
367
+ ADVANCE(1);
496
368
  state = PARSE_NORMAL;
497
- APPEND_NEXT_CHAR();
498
369
  break;
499
370
  case PARSE_COMMENT:
500
- APPEND_NEXT_CHAR(); /* at least one */
501
- APPEND_NEXT_CHARS_UNTIL("-");
502
- if (*html == '-' && num_chars_remaining >= 3
503
- && 0 == strncmp("->", html, 2)) {
504
- APPEND_NEXT_CHAR();
505
- APPEND_NEXT_CHAR();
371
+ ADVANCE(1); /* at least one */
372
+ ADVANCE_UNTIL_ONE_OF_THESE_CHARS("-");
373
+ if (*html_p == '-' && num_chars_remaining >= 3
374
+ && 0 == strncmp("->", html_p, 2)) {
375
+ ADVANCE(2);
506
376
  state = PARSE_NORMAL;
507
377
  }
508
378
  /* else loop... */
509
379
  break;
510
380
  case PARSE_CDATA:
511
- APPEND_NEXT_CHAR(); /* at least one */
512
- APPEND_NEXT_CHARS_UNTIL("]");
513
- if (*html == ']' && num_chars_remaining >= 3
514
- && 0 == strncmp("]>", html, 2)) {
515
- APPEND_NEXT_CHAR();
516
- APPEND_NEXT_CHAR();
381
+ ADVANCE(1); /* at least one */
382
+ ADVANCE_UNTIL_ONE_OF_THESE_CHARS("]");
383
+ if (*html_p == ']' && num_chars_remaining >= 3
384
+ && 0 == strncmp("]>", html_p, 2)) {
385
+ ADVANCE(2);
517
386
  state = PARSE_NORMAL;
518
387
  }
519
388
  /* else loop... */
@@ -523,6 +392,7 @@ add_namespace_to_html_with_length_and_allocation_strategy(
523
392
  }
524
393
  }
525
394
 
395
+ COPY_TO_HERE();
526
396
  APPEND_END_OF_STRING();
527
397
 
528
398
  if (state != PARSE_NORMAL
@@ -2,16 +2,16 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{html_namespacing}
5
- s.version = "0.1.0"
5
+ s.version = "0.1.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Adam Hooper"]
9
- s.date = %q{2009-07-28}
9
+ s.date = %q{2009-08-10}
10
10
  s.description = %q{Inserts "class=" attributes within snippets of HTML so CSS and JavaScript can use automatic scopes}
11
11
  s.email = %q{adam@adamhooper.com}
12
12
  s.extensions = ["ext/html_namespacing/extconf.rb"]
13
13
  s.extra_rdoc_files = ["README.rdoc"]
14
- s.files = ["README.rdoc", "Rakefile", "test/c_extension_test.rb", "test/test_helper.rb", "ext/html_namespacing/extconf.rb", "ext/html_namespacing/html_namespacing.h", "ext/html_namespacing/html_namespacing.c", "ext/html_namespacing/html_namespacing_ext.c", "lib/html_namespacing.rb", "lib/html_namespacing/plugin.rb", "lib/html_namespacing/plugin/dom_scan_jquery.compressed.js", "lib/html_namespacing/plugin/rails.rb", "lib/html_namespacing/plugin/dom_scan_jquery.js", "lib/html_namespacing/plugin/sass.rb", "Manifest", "html_namespacing.gemspec"]
14
+ s.files = ["README.rdoc", "Rakefile", "test/c_extension_test.rb", "test/test_helper.rb", "ext/html_namespacing/extconf.rb", "ext/html_namespacing/html_namespacing.h", "ext/html_namespacing/html_namespacing.c", "ext/html_namespacing/html_namespacing_ext.c", "lib/html_namespacing.rb", "lib/html_namespacing/plugin.rb", "lib/html_namespacing/plugin/dom_scan_jquery.compressed.js", "lib/html_namespacing/plugin/rails.rb", "lib/html_namespacing/plugin/dom_scan_jquery.js", "lib/html_namespacing/plugin/sass.rb", "html_namespacing.gemspec", "Manifest"]
15
15
  s.has_rdoc = true
16
16
  s.homepage = %q{http://github.com/adamh/html_namespacing}
17
17
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Html_namespacing", "--main", "README.rdoc"]
@@ -31,6 +31,10 @@ module HtmlNamespacing
31
31
  @options[:javascript_optional_suffix]
32
32
  end
33
33
 
34
+ def self.template_formats
35
+ @formats ||= Set.new(@options[:template_formats] || ['html'])
36
+ end
37
+
34
38
  module Helpers
35
39
  def html_namespacing_javascript_tag(framework)
36
40
  files = html_namespacing_files
@@ -108,7 +112,7 @@ module HtmlNamespacing
108
112
 
109
113
  view.html_namespacing_rendered_paths << path_without_format_and_extension if view.respond_to?(:html_namespacing_rendered_paths)
110
114
 
111
- if format == 'html'
115
+ if HtmlNamespacing::Plugin::Rails.template_formats.include?(format)
112
116
  add_namespace_to_html(html, view)
113
117
  else
114
118
  html
@@ -24,14 +24,16 @@ class CExtensionTest < Test::Unit::TestCase
24
24
  self.define_test('nil everything', nil, nil, nil)
25
25
  self.define_test('plain text', 'hello', 'X', 'hello')
26
26
  self.define_test('regular tag', '<div>hello</div>', 'X', '<div class="X">hello</div>')
27
- self.define_test('empty tag', '<div/>', 'X', '<div class="X" />')
27
+ self.define_test('empty tag', '<div/>', 'X', '<div class="X"/>')
28
+ self.define_test('empty tag with " />"', '<div />', 'X', '<div class="X" />')
29
+ self.define_test('empty tag with " />" and class', '<div class="A" />', 'X', '<div class="A X" />')
28
30
  self.define_test('nested tag', '<div><div>hello</div></div>', 'X', '<div class="X"><div>hello</div></div>')
29
31
  self.define_test('two tags', '<div>hello</div><div>goodbye</div>', 'X', '<div class="X">hello</div><div class="X">goodbye</div>')
30
32
  self.define_test('existing class= tag with double-quotes', '<div class="foo">bar</div>', 'baz', '<div class="foo baz">bar</div>')
31
33
  self.define_test('existing class= tag with single-quotes', "<div class='foo'>bar</div>", 'baz', "<div class='foo baz'>bar</div>")
32
34
  self.define_test('other attributes are ignored', '<div id="id" class="foo" style="display:none;">bar</div>', 'baz', '<div id="id" class="foo baz" style="display:none;">bar</div>')
33
35
  self.define_test('works with utf-8', '<div class="𝞪">𝟂</div>', '𝞺', '<div class="𝞪 𝞺">𝟂</div>')
34
- self.define_test('empty tag with existing class=', '<span class="foo"/>', 'bar', '<span class="foo bar" />')
36
+ self.define_test('empty tag with existing class=', '<span class="foo"/>', 'bar', '<span class="foo bar"/>')
35
37
  self.define_test('works with newlines in tag', "<div\n\nclass\n\n=\n\n'foo'\n\n>bar</div>", 'baz', "<div\n\nclass\n\n=\n\n'foo baz'\n\n>bar</div>")
36
38
  self.define_test('works with "\'" within \'"\' attributes', '<div title="Adam\'s House" class="foo">bar</div>', 'baz', '<div title="Adam\'s House" class="foo baz">bar</div>')
37
39
  self.define_test('ignores XML prolog', '<?xml version="1.0"?><div>foo</div>', 'X', '<?xml version="1.0"?><div class="X">foo</div>')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adamh-html_namespacing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Hooper
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-28 00:00:00 -07:00
12
+ date: 2009-08-10 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -36,8 +36,8 @@ files:
36
36
  - lib/html_namespacing/plugin/rails.rb
37
37
  - lib/html_namespacing/plugin/dom_scan_jquery.js
38
38
  - lib/html_namespacing/plugin/sass.rb
39
- - Manifest
40
39
  - html_namespacing.gemspec
40
+ - Manifest
41
41
  has_rdoc: true
42
42
  homepage: http://github.com/adamh/html_namespacing
43
43
  licenses: