patch-html_namespacing 0.2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +406 -0
- data/ext/html_namespacing/extconf.rb +6 -0
- data/ext/html_namespacing/html_namespacing.c +481 -0
- data/ext/html_namespacing/html_namespacing.h +35 -0
- data/ext/html_namespacing/html_namespacing_ext.c +97 -0
- data/lib/html_namespacing.rb +9 -0
- data/lib/html_namespacing/plugin.rb +10 -0
- data/lib/html_namespacing/plugin/dom_scan_jquery.js +44 -0
- data/lib/html_namespacing/plugin/dom_scan_jquery.js.compressed +1 -0
- data/lib/html_namespacing/plugin/rails.rb +206 -0
- data/lib/html_namespacing/plugin/sass.rb +93 -0
- data/spec/c_extension_spec.rb +58 -0
- data/spec/spec_helper.rb +4 -0
- metadata +87 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
4
|
+
|
5
|
+
describe(HtmlNamespacing) do
|
6
|
+
private
|
7
|
+
|
8
|
+
def self.define_test(name, html, ns, expect)
|
9
|
+
it("should work with #{name}") do
|
10
|
+
f(html, ns).should == expect
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.define_failing_test(name, html)
|
15
|
+
it("should fail on #{name}") do
|
16
|
+
lambda { f(html, 'X') }.should raise_error(ArgumentError)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def f(html, ns)
|
21
|
+
HtmlNamespacing::add_namespace_to_html(html, ns)
|
22
|
+
end
|
23
|
+
|
24
|
+
self.define_test('nil HTML', nil, 'X', nil)
|
25
|
+
self.define_test('nil namespace', '<div>hello</div>', nil, '<div>hello</div>')
|
26
|
+
self.define_test('nil everything', nil, nil, nil)
|
27
|
+
self.define_test('plain text', 'hello', 'X', 'hello')
|
28
|
+
self.define_test('regular tag', '<div>hello</div>', 'X', '<div class="X">hello</div>')
|
29
|
+
self.define_test('empty tag', '<div/>', 'X', '<div class="X"/>')
|
30
|
+
self.define_test('empty tag with " />"', '<div />', 'X', '<div class="X" />')
|
31
|
+
self.define_test('empty tag with " />" and class', '<div class="A" />', 'X', '<div class="A X" />')
|
32
|
+
self.define_test('nested tag', '<div><div>hello</div></div>', 'X', '<div class="X"><div>hello</div></div>')
|
33
|
+
self.define_test('two tags', '<div>hello</div><div>goodbye</div>', 'X', '<div class="X">hello</div><div class="X">goodbye</div>')
|
34
|
+
self.define_test('existing class= tag with double-quotes', '<div class="foo">bar</div>', 'baz', '<div class="foo baz">bar</div>')
|
35
|
+
self.define_test('existing class= tag with single-quotes', "<div class='foo'>bar</div>", 'baz', "<div class='foo baz'>bar</div>")
|
36
|
+
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>')
|
37
|
+
self.define_test('works with utf-8', '<div class="𝞪">𝟂</div>', '𝞺', '<div class="𝞪 𝞺">𝟂</div>')
|
38
|
+
self.define_test('empty tag with existing class=', '<span class="foo"/>', 'bar', '<span class="foo bar"/>')
|
39
|
+
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>")
|
40
|
+
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>')
|
41
|
+
self.define_test('ignores XML prolog', '<?xml version="1.0"?><div>foo</div>', 'X', '<?xml version="1.0"?><div class="X">foo</div>')
|
42
|
+
self.define_test('ignores DOCTYPE', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><div>foo</div>', 'X', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><div class="X">foo</div>')
|
43
|
+
self.define_test('ignores CDATA', '<![CDATA[ignore <div class="foo">]] </div>]]><div>foo</div>', 'X', '<![CDATA[ignore <div class="foo">]] </div>]]><div class="X">foo</div>')
|
44
|
+
self.define_test('ignores comments', '<!-- blah <div class="foo">foo</div> - <span/>--><div>foo</div>', 'X', '<!-- blah <div class="foo">foo</div> - <span/>--><div class="X">foo</div>')
|
45
|
+
self.define_test('detects CDATA end delimiter correctly', '<![CDATA[ ]>< ]]>', 'X', '<![CDATA[ ]>< ]]>')
|
46
|
+
self.define_test('detects comment end delimiter correctly', '<!-- ->< -->', 'X', '<!-- ->< -->')
|
47
|
+
|
48
|
+
[ 'html', 'head', 'base', 'meta', 'title', 'link', 'script', 'noscript', 'style' ].each do |tag|
|
49
|
+
self.define_test("ignores <#{tag}> tags", "<#{tag}>foo</#{tag}>", "X", "<#{tag}>foo</#{tag}>")
|
50
|
+
end
|
51
|
+
|
52
|
+
self.define_failing_test('unclosed tag', '<div>foo')
|
53
|
+
self.define_failing_test('closing tag', 'foo</div>')
|
54
|
+
self.define_failing_test('wrong attr syntax', '<div foo=bar>foo</div>')
|
55
|
+
self.define_failing_test("missing closing '>' on last tag", '<div foo="bar">foo</div')
|
56
|
+
self.define_failing_test('end of string during attribute value', '<div foo="x')
|
57
|
+
self.define_failing_test('end of string during doctype declaration', '<!DOCTYPE')
|
58
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: patch-html_namespacing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.2.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- adamh
|
14
|
+
- oggy
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2010-04-26 00:00:00 -04:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: adamh-glob_fu
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
- 3
|
33
|
+
version: 0.0.3
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
description: Inserts "class=" attributes within snippets of HTML so CSS and JavaScript can use automatic scopes
|
37
|
+
email: adam@adamhooper.com
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions:
|
41
|
+
- ext/html_namespacing/extconf.rb
|
42
|
+
extra_rdoc_files:
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- ext/html_namespacing/html_namespacing.c
|
46
|
+
- ext/html_namespacing/html_namespacing.h
|
47
|
+
- ext/html_namespacing/html_namespacing_ext.c
|
48
|
+
- lib/html_namespacing.rb
|
49
|
+
- lib/html_namespacing/plugin.rb
|
50
|
+
- lib/html_namespacing/plugin/dom_scan_jquery.js
|
51
|
+
- lib/html_namespacing/plugin/dom_scan_jquery.js.compressed
|
52
|
+
- lib/html_namespacing/plugin/rails.rb
|
53
|
+
- lib/html_namespacing/plugin/sass.rb
|
54
|
+
- README.rdoc
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://github.com/adamh/html_namespacing
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options:
|
61
|
+
- --charset=UTF-8
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
version: "0"
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.3.6
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Automatic HTML namespacing
|
85
|
+
test_files:
|
86
|
+
- spec/c_extension_spec.rb
|
87
|
+
- spec/spec_helper.rb
|