glue 0.17.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +26 -0
- data/Rakefile +1 -1
- data/doc/RELEASES +6 -1
- data/lib/glue.rb +2 -2
- data/lib/glue/attribute.rb +2 -2
- data/lib/glue/logger.rb +5 -7
- data/lib/glue/number.rb +2 -2
- data/lib/glue/sanitize.rb +48 -0
- data/lib/html/document.rb +63 -0
- data/lib/html/node.rb +480 -0
- data/lib/html/tokenizer.rb +103 -0
- data/lib/html/version.rb +11 -0
- metadata +9 -30
- data/lib/glue/cache.rb +0 -136
- data/lib/glue/dynamic_include.rb +0 -45
- data/lib/glue/inflector.rb +0 -91
- data/test/glue/tc_cache.rb +0 -45
- data/vendor/README +0 -11
- data/vendor/binding_of_caller.rb +0 -81
- data/vendor/blankslate.rb +0 -53
- data/vendor/breakpoint.rb +0 -523
- data/vendor/breakpoint_client.rb +0 -196
- data/vendor/extensions/_base.rb +0 -153
- data/vendor/extensions/_template.rb +0 -36
- data/vendor/extensions/all.rb +0 -21
- data/vendor/extensions/array.rb +0 -68
- data/vendor/extensions/binding.rb +0 -224
- data/vendor/extensions/class.rb +0 -50
- data/vendor/extensions/continuation.rb +0 -71
- data/vendor/extensions/enumerable.rb +0 -250
- data/vendor/extensions/hash.rb +0 -23
- data/vendor/extensions/io.rb +0 -58
- data/vendor/extensions/kernel.rb +0 -42
- data/vendor/extensions/module.rb +0 -114
- data/vendor/extensions/numeric.rb +0 -230
- data/vendor/extensions/object.rb +0 -164
- data/vendor/extensions/ostruct.rb +0 -41
- data/vendor/extensions/string.rb +0 -316
- data/vendor/extensions/symbol.rb +0 -28
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'strscan'
|
2
|
+
|
3
|
+
module HTML#:nodoc:
|
4
|
+
|
5
|
+
# A simple HTML tokenizer. It simply breaks a stream of text into tokens, where each
|
6
|
+
# token is a string. Each string represents either "text", or an HTML element.
|
7
|
+
#
|
8
|
+
# This currently assumes valid XHTML, which means no free < or > characters.
|
9
|
+
#
|
10
|
+
# Usage:
|
11
|
+
#
|
12
|
+
# tokenizer = HTML::Tokenizer.new(text)
|
13
|
+
# while token = tokenizer.next
|
14
|
+
# p token
|
15
|
+
# end
|
16
|
+
class Tokenizer#:nodoc:
|
17
|
+
|
18
|
+
# The current (byte) position in the text
|
19
|
+
attr_reader :position
|
20
|
+
|
21
|
+
# The current line number
|
22
|
+
attr_reader :line
|
23
|
+
|
24
|
+
# Create a new Tokenizer for the given text.
|
25
|
+
def initialize(text)
|
26
|
+
@scanner = StringScanner.new(text)
|
27
|
+
@position = 0
|
28
|
+
@line = 0
|
29
|
+
@current_line = 1
|
30
|
+
end
|
31
|
+
|
32
|
+
# Return the next token in the sequence, or +nil+ if there are no more tokens in
|
33
|
+
# the stream.
|
34
|
+
def next
|
35
|
+
return nil if @scanner.eos?
|
36
|
+
@position = @scanner.pos
|
37
|
+
@line = @current_line
|
38
|
+
if @scanner.check(/<\S/)
|
39
|
+
update_current_line(scan_tag)
|
40
|
+
else
|
41
|
+
update_current_line(scan_text)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
# Treat the text at the current position as a tag, and scan it. Supports
|
48
|
+
# comments, doctype tags, and regular tags, and ignores less-than and
|
49
|
+
# greater-than characters within quoted strings.
|
50
|
+
def scan_tag
|
51
|
+
tag = @scanner.getch
|
52
|
+
if @scanner.scan(/!--/) # comment
|
53
|
+
tag << @scanner.matched
|
54
|
+
tag << @scanner.scan_until(/--\s*>/)
|
55
|
+
elsif @scanner.scan(/!/) # doctype
|
56
|
+
tag << @scanner.matched
|
57
|
+
tag << consume_quoted_regions
|
58
|
+
else
|
59
|
+
tag << consume_quoted_regions
|
60
|
+
end
|
61
|
+
tag
|
62
|
+
end
|
63
|
+
|
64
|
+
# Scan all text up to the next < character and return it.
|
65
|
+
def scan_text
|
66
|
+
@scanner.getch + (@scanner.scan(/[^<]*/) || "")
|
67
|
+
end
|
68
|
+
|
69
|
+
# Counts the number of newlines in the text and updates the current line
|
70
|
+
# accordingly.
|
71
|
+
def update_current_line(text)
|
72
|
+
@current_line += text.scan(/\r\n|\r|\n/).length
|
73
|
+
text
|
74
|
+
end
|
75
|
+
|
76
|
+
# Skips over quoted strings, so that less-than and greater-than characters
|
77
|
+
# within the strings are ignored.
|
78
|
+
def consume_quoted_regions
|
79
|
+
text = ""
|
80
|
+
loop do
|
81
|
+
match = @scanner.scan_until(/['"<>]/) or break
|
82
|
+
|
83
|
+
delim = @scanner.matched
|
84
|
+
if delim == "<"
|
85
|
+
match = match.chop
|
86
|
+
@scanner.pos -= 1
|
87
|
+
end
|
88
|
+
|
89
|
+
text << match
|
90
|
+
break if delim == "<" || delim == ">"
|
91
|
+
|
92
|
+
# consume the conqued region
|
93
|
+
while match = @scanner.scan_until(/[\\#{delim}]/)
|
94
|
+
text << match
|
95
|
+
break if @scanner.matched == delim
|
96
|
+
text << @scanner.getch # skip the escaped character
|
97
|
+
end
|
98
|
+
end
|
99
|
+
text
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
data/lib/html/version.rb
ADDED
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
|
|
3
3
|
specification_version: 1
|
4
4
|
name: glue
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2005-
|
6
|
+
version: 0.18.0
|
7
|
+
date: 2005-06-01
|
8
8
|
summary: Glue utilities
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- doc/LICENSE
|
37
37
|
- doc/AUTHORS
|
38
38
|
- lib/glue
|
39
|
+
- lib/html
|
39
40
|
- lib/glue.rb
|
40
41
|
- lib/glue/logger.rb
|
41
42
|
- lib/glue/array.rb
|
@@ -43,18 +44,20 @@ files:
|
|
43
44
|
- lib/glue/flexob.rb
|
44
45
|
- lib/glue/hash.rb
|
45
46
|
- lib/glue/property.rb
|
46
|
-
- lib/glue/
|
47
|
+
- lib/glue/sanitize.rb
|
47
48
|
- lib/glue/number.rb
|
48
|
-
- lib/glue/dynamic_include.rb
|
49
49
|
- lib/glue/aspects.rb
|
50
50
|
- lib/glue/misc.rb
|
51
51
|
- lib/glue/time.rb
|
52
52
|
- lib/glue/attribute.rb
|
53
|
-
- lib/glue/cache.rb
|
54
53
|
- lib/glue/string.rb
|
55
54
|
- lib/glue/object.rb
|
56
55
|
- lib/glue/mixins.rb
|
57
56
|
- lib/glue/pool.rb
|
57
|
+
- lib/html/document.rb
|
58
|
+
- lib/html/node.rb
|
59
|
+
- lib/html/version.rb
|
60
|
+
- lib/html/tokenizer.rb
|
58
61
|
- test/glue
|
59
62
|
- test/glue/tc_strings.rb
|
60
63
|
- test/glue/tc_validation.rb
|
@@ -63,33 +66,9 @@ files:
|
|
63
66
|
- test/glue/tc_logger.rb
|
64
67
|
- test/glue/tc_aspects.rb
|
65
68
|
- test/glue/tc_property_type_checking.rb
|
66
|
-
- test/glue/tc_cache.rb
|
67
69
|
- test/glue/tc_hash.rb
|
68
70
|
- test/glue/tc_attribute.rb
|
69
71
|
- test/glue/tc_property.rb
|
70
|
-
- vendor/extensions
|
71
|
-
- vendor/binding_of_caller.rb
|
72
|
-
- vendor/breakpoint.rb
|
73
|
-
- vendor/blankslate.rb
|
74
|
-
- vendor/README
|
75
|
-
- vendor/breakpoint_client.rb
|
76
|
-
- vendor/extensions/kernel.rb
|
77
|
-
- vendor/extensions/array.rb
|
78
|
-
- vendor/extensions/enumerable.rb
|
79
|
-
- vendor/extensions/hash.rb
|
80
|
-
- vendor/extensions/module.rb
|
81
|
-
- vendor/extensions/numeric.rb
|
82
|
-
- vendor/extensions/ostruct.rb
|
83
|
-
- vendor/extensions/class.rb
|
84
|
-
- vendor/extensions/symbol.rb
|
85
|
-
- vendor/extensions/string.rb
|
86
|
-
- vendor/extensions/object.rb
|
87
|
-
- vendor/extensions/io.rb
|
88
|
-
- vendor/extensions/all.rb
|
89
|
-
- vendor/extensions/_base.rb
|
90
|
-
- vendor/extensions/binding.rb
|
91
|
-
- vendor/extensions/continuation.rb
|
92
|
-
- vendor/extensions/_template.rb
|
93
72
|
test_files: []
|
94
73
|
rdoc_options:
|
95
74
|
- "--main"
|
@@ -115,5 +94,5 @@ dependencies:
|
|
115
94
|
-
|
116
95
|
- ">="
|
117
96
|
- !ruby/object:Gem::Version
|
118
|
-
version: 0.7.
|
97
|
+
version: 0.7.2
|
119
98
|
version:
|
data/lib/glue/cache.rb
DELETED
@@ -1,136 +0,0 @@
|
|
1
|
-
# * George Moschovitis <gm@navel.gr>
|
2
|
-
# * Anastasios Koutoumanos <ak@navel.gr>
|
3
|
-
|
4
|
-
module Glue
|
5
|
-
|
6
|
-
# A cache utilizing a simple LRU (Least Recently Used) policy.
|
7
|
-
# The items managed by this cache must respond to the #key method.
|
8
|
-
# Attempts to optimize reads rather than inserts!
|
9
|
-
#
|
10
|
-
# LRU semantics are enforced by inserting the items in a queue.
|
11
|
-
# The lru item is always at the tail. Two special sentinels
|
12
|
-
# (head, tail) are used to simplify (?) the code.
|
13
|
-
|
14
|
-
class LRUCache < Hash
|
15
|
-
|
16
|
-
# Mix this in your class to make LRU-managable.
|
17
|
-
|
18
|
-
module Item
|
19
|
-
attr_accessor :lru_key, :lru_prev, :lru_next
|
20
|
-
end
|
21
|
-
|
22
|
-
# head-tail sentinels
|
23
|
-
|
24
|
-
class Sentinel; include Item; end
|
25
|
-
|
26
|
-
# the maximum number of items in the cache.
|
27
|
-
|
28
|
-
attr_accessor :max_items
|
29
|
-
|
30
|
-
# the head sentinel
|
31
|
-
|
32
|
-
attr :head
|
33
|
-
|
34
|
-
# the tail sentinel, tail.prev points to the lru item.
|
35
|
-
|
36
|
-
attr :tail
|
37
|
-
|
38
|
-
def initialize(max_items)
|
39
|
-
@max_items = max_items
|
40
|
-
lru_clear()
|
41
|
-
end
|
42
|
-
|
43
|
-
# Lookup an item in the cache.
|
44
|
-
|
45
|
-
def [](key)
|
46
|
-
if item = super
|
47
|
-
return lru_touch(item)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# The inserted item is considered mru!
|
52
|
-
|
53
|
-
def []=(key, item)
|
54
|
-
item = super
|
55
|
-
item.lru_key = key
|
56
|
-
lru_insert(item)
|
57
|
-
end
|
58
|
-
|
59
|
-
# Delete an item from the cache.
|
60
|
-
|
61
|
-
def delete(key)
|
62
|
-
if item = super
|
63
|
-
lru_delete(item)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
# Clear the cache.
|
68
|
-
|
69
|
-
def clear
|
70
|
-
super
|
71
|
-
lru_clear()
|
72
|
-
end
|
73
|
-
|
74
|
-
# The first (mru) element in the cache.
|
75
|
-
|
76
|
-
def first
|
77
|
-
@head.lru_next
|
78
|
-
end
|
79
|
-
|
80
|
-
# The last (lru) element in the cache.
|
81
|
-
|
82
|
-
def last
|
83
|
-
@tail.lru_prev
|
84
|
-
end
|
85
|
-
alias_method :lru, :last
|
86
|
-
|
87
|
-
private
|
88
|
-
|
89
|
-
# Delete an item from the lru list.
|
90
|
-
|
91
|
-
def lru_delete(item)
|
92
|
-
lru_join(item.lru_prev, item.lru_next)
|
93
|
-
return item
|
94
|
-
end
|
95
|
-
|
96
|
-
# Join two items in the lru list.
|
97
|
-
# Return y to allow for chaining.
|
98
|
-
|
99
|
-
def lru_join(x, y)
|
100
|
-
x.lru_next = y
|
101
|
-
y.lru_prev = x
|
102
|
-
return y
|
103
|
-
end
|
104
|
-
|
105
|
-
# Append a child item to a parent item in the lru list
|
106
|
-
# (Re)inserts the child in the list.
|
107
|
-
|
108
|
-
def lru_append(parent, child)
|
109
|
-
lru_join(child, parent.lru_next)
|
110
|
-
lru_join(parent, child)
|
111
|
-
end
|
112
|
-
|
113
|
-
# Insert an item
|
114
|
-
|
115
|
-
def lru_insert(item)
|
116
|
-
delete(last.lru_key) if size() > @max_items
|
117
|
-
lru_append(@head, item)
|
118
|
-
end
|
119
|
-
|
120
|
-
# Touch an item, make mru!
|
121
|
-
# Returns the item.
|
122
|
-
|
123
|
-
def lru_touch(item)
|
124
|
-
lru_append(@head, lru_delete(item))
|
125
|
-
end
|
126
|
-
|
127
|
-
# Clear the lru.
|
128
|
-
|
129
|
-
def lru_clear
|
130
|
-
@head = Sentinel.new
|
131
|
-
@tail = Sentinel.new
|
132
|
-
lru_join(@head, @tail)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
end
|
data/lib/glue/dynamic_include.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
# = Dynamic include
|
2
|
-
#
|
3
|
-
# Allows you to include dyanamic mixins.
|
4
|
-
#
|
5
|
-
# === Example
|
6
|
-
#
|
7
|
-
# module Mixin
|
8
|
-
# def self.append_dynamic_features(base, options)
|
9
|
-
# base.class_eval %{
|
10
|
-
# def hello
|
11
|
-
# puts 'Hello from #{options[:name]}'
|
12
|
-
# end
|
13
|
-
# }
|
14
|
-
# end
|
15
|
-
# end
|
16
|
-
#
|
17
|
-
# class MyClass
|
18
|
-
# include Mixin, :name => 'tml'
|
19
|
-
# end
|
20
|
-
#
|
21
|
-
# m = MyClass.new
|
22
|
-
# m.hello -> 'Hello from tml'
|
23
|
-
#
|
24
|
-
# * George Moschovitis <gm@navel.gr>
|
25
|
-
# (c) 2004-2005 Navel, all rights reserved.
|
26
|
-
# $Id: dynamic_include.rb 1 2005-04-11 11:04:30Z gmosx $
|
27
|
-
|
28
|
-
class Module
|
29
|
-
|
30
|
-
alias_method :__include_without_options__, :include
|
31
|
-
|
32
|
-
def include(*args)
|
33
|
-
options = args.last.is_a?(Hash) ? args.pop : {}
|
34
|
-
|
35
|
-
for mod in args
|
36
|
-
if mod.respond_to?(:append_dynamic_features)
|
37
|
-
mod.append_dynamic_features(self, options)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
__include_without_options__(*args)
|
42
|
-
end
|
43
|
-
alias_method :dynamic_include, :include
|
44
|
-
|
45
|
-
end
|
data/lib/glue/inflector.rb
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
# Code from RubyOnRails (http://www.rubyonrails.com)
|
2
|
-
# Copyright (c) 2004-2005 David Heinemeier Hansson.
|
3
|
-
|
4
|
-
module Glue
|
5
|
-
|
6
|
-
# The Inflector transforms words from singular to plural,
|
7
|
-
# class names to table names, modulized class names to ones without,
|
8
|
-
# and class names to foreign keys.
|
9
|
-
|
10
|
-
module Inflector
|
11
|
-
extend self
|
12
|
-
|
13
|
-
def pluralize(word)
|
14
|
-
result = word.dup
|
15
|
-
plural_rules.each do |(rule, replacement)|
|
16
|
-
break if result.gsub!(rule, replacement)
|
17
|
-
end
|
18
|
-
return result
|
19
|
-
end
|
20
|
-
|
21
|
-
def singularize(word)
|
22
|
-
result = word.dup
|
23
|
-
singular_rules.each do |(rule, replacement)|
|
24
|
-
break if result.gsub!(rule, replacement)
|
25
|
-
end
|
26
|
-
return result
|
27
|
-
end
|
28
|
-
|
29
|
-
def camelize(lower_case_and_underscored_word)
|
30
|
-
lower_case_and_underscored_word.gsub(/(^|_)(.)/){$2.upcase}
|
31
|
-
end
|
32
|
-
|
33
|
-
def underscore(camel_cased_word)
|
34
|
-
camel_cased_word.gsub(/([A-Z]+)([A-Z])/,'\1_\2').gsub(/([a-z])([A-Z])/,'\1_\2').downcase
|
35
|
-
end
|
36
|
-
|
37
|
-
def demodulize(class_name_in_module)
|
38
|
-
class_name_in_module.gsub(/^.*::/, '')
|
39
|
-
end
|
40
|
-
|
41
|
-
def foreign_key(class_name, separate_class_name_and_id_with_underscore = true)
|
42
|
-
Inflector.underscore(Inflector.demodulize(class_name)) +
|
43
|
-
(separate_class_name_and_id_with_underscore ? "_id" : "id")
|
44
|
-
end
|
45
|
-
|
46
|
-
# Convert a class to a name.
|
47
|
-
|
48
|
-
def name(klass)
|
49
|
-
Inflector.underscore(Inflector.demodulize(klass.to_s))
|
50
|
-
end
|
51
|
-
|
52
|
-
# Convert a class to a name in plural
|
53
|
-
|
54
|
-
def plural_name(klass)
|
55
|
-
Inflector.pluralize(Inflector.underscore(Inflector.demodulize(klass.to_s)))
|
56
|
-
end
|
57
|
-
|
58
|
-
private
|
59
|
-
def plural_rules #:doc:
|
60
|
-
[
|
61
|
-
[/(x|ch|ss)$/, '\1es'], # search, switch, fix, box, process, address
|
62
|
-
[/([^aeiouy]|qu)y$/, '\1ies'], # query, ability, agency
|
63
|
-
[/(?:([^f])fe|([lr])f)$/, '\1\2ves'], # half, safe, wife
|
64
|
-
[/sis$/, 'ses'], # basis, diagnosis
|
65
|
-
[/([ti])um$/, '\1a'], # datum, medium
|
66
|
-
[/person$/, 'people'], # person, salesperson
|
67
|
-
[/man$/, 'men'], # man, woman, spokesman
|
68
|
-
[/child$/, 'children'], # child
|
69
|
-
[/s$/, 's'], # no change (compatibility)
|
70
|
-
[/$/, 's']
|
71
|
-
]
|
72
|
-
end
|
73
|
-
|
74
|
-
def singular_rules #:doc:
|
75
|
-
[
|
76
|
-
[/(x|ch|ss)es$/, '\1'],
|
77
|
-
[/([^aeiouy]|qu)ies$/, '\1y'],
|
78
|
-
[/([lr])ves$/, '\1f'],
|
79
|
-
[/([^f])ves$/, '\1fe'],
|
80
|
-
[/(analy|ba|diagno|parenthe|progno|synop|the)ses$/, '\1sis'],
|
81
|
-
[/([ti])a$/, '\1um'],
|
82
|
-
[/people$/, 'person'],
|
83
|
-
[/men$/, 'man'],
|
84
|
-
[/status$/, 'status'],
|
85
|
-
[/children$/, 'child'],
|
86
|
-
[/s$/, '']
|
87
|
-
]
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|