glue 0.41.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/History.txt +6 -0
  2. data/Manifest.txt +6 -0
  3. data/README.txt +130 -0
  4. data/Rakefile +16 -0
  5. data/lib/glue.rb +49 -72
  6. data/test/test_glue.rb +218 -0
  7. metadata +84 -100
  8. data/doc/AUTHORS +0 -13
  9. data/doc/CHANGELOG.1 +0 -354
  10. data/doc/LICENSE +0 -32
  11. data/doc/RELEASES +0 -207
  12. data/lib/glue/attribute.rb +0 -113
  13. data/lib/glue/attributeutils.rb +0 -117
  14. data/lib/glue/autoreload.rb +0 -60
  15. data/lib/glue/builder.rb +0 -57
  16. data/lib/glue/builder/xml.rb +0 -103
  17. data/lib/glue/cache.rb +0 -22
  18. data/lib/glue/cache/drb.rb +0 -51
  19. data/lib/glue/cache/file.rb +0 -78
  20. data/lib/glue/cache/memcached.rb +0 -68
  21. data/lib/glue/cache/memory.rb +0 -79
  22. data/lib/glue/cache/og.rb +0 -61
  23. data/lib/glue/configuration.rb +0 -305
  24. data/lib/glue/fixture.rb +0 -154
  25. data/lib/glue/html.rb +0 -12
  26. data/lib/glue/localization.rb +0 -129
  27. data/lib/glue/logger.rb +0 -208
  28. data/lib/glue/mail.rb +0 -160
  29. data/lib/glue/mailer.rb +0 -55
  30. data/lib/glue/mailer/incoming.rb +0 -41
  31. data/lib/glue/mailer/outgoing.rb +0 -119
  32. data/lib/glue/settings.rb +0 -3
  33. data/lib/glue/uri.rb +0 -190
  34. data/lib/glue/validation.rb +0 -447
  35. data/lib/html/document.rb +0 -63
  36. data/lib/html/node.rb +0 -480
  37. data/lib/html/tokenizer.rb +0 -103
  38. data/lib/html/version.rb +0 -11
  39. data/test/fixture/article.csv +0 -3
  40. data/test/fixture/article.yml +0 -13
  41. data/test/fixture/user.yml +0 -12
  42. data/test/glue/builder/tc_xml.rb +0 -57
  43. data/test/glue/tc_aspects.rb +0 -99
  44. data/test/glue/tc_attribute.rb +0 -112
  45. data/test/glue/tc_attribute_mixins.rb +0 -86
  46. data/test/glue/tc_builder.rb +0 -30
  47. data/test/glue/tc_configuration.rb +0 -135
  48. data/test/glue/tc_fixture.rb +0 -98
  49. data/test/glue/tc_localization.rb +0 -49
  50. data/test/glue/tc_logger.rb +0 -43
  51. data/test/glue/tc_mail.rb +0 -99
  52. data/test/glue/tc_stores.rb +0 -16
  53. data/test/glue/tc_uri.rb +0 -97
  54. data/test/glue/tc_validation.rb +0 -217
  55. data/test/public/dummy_mailer/registration.xhtml +0 -5
@@ -1,60 +0,0 @@
1
- require 'facet/dir/self/recurse'
2
-
3
- module Kernel
4
-
5
- # A Customized version of the autoreload from Facets. Also
6
- # checks template files, and keeps a dirty flag.
7
-
8
- def autoreload(check_interval=10, glob = '.')
9
- Thread.new(Time.now) do |start_time|
10
- check_dirty = lambda do |file,hash,file_mtime|
11
- if File.exists?(file) and (mtime = File.stat(file).mtime) > (file_mtime[file] || start_time)
12
- hash[file] = mtime
13
- end
14
- end
15
- file_mtime = {}
16
-
17
- files = []
18
- Dir.recurse(glob) do |f|
19
- if f !~ /\/_darcs\// and f =~ /(.?)\.x(.?)/
20
- files << f
21
- end
22
- end
23
-
24
- loop do
25
- need_reload = Hash.new
26
- sleep check_interval
27
- $LOADED_FEATURES.each do |feature|
28
- check_dirty.call(feature,need_reload,file_mtime)
29
- $LOAD_PATH.each {|lp| check_dirty.call(File.join(lp, feature),need_reload,file_mtime)}
30
- end
31
-
32
- unless need_reload.empty?
33
- $autoreload_dirty = true
34
- need_reload.each_pair do |file,mtime|
35
- file_mtime[file] = mtime
36
- Logger.debug "File '#{ file }' reloaded" if $DBG
37
- begin
38
- load(file)
39
- rescue Exception => e
40
- Logger.info e.inspect
41
- end
42
- end
43
- end
44
-
45
- # Check for template files.
46
-
47
- files.each do |file|
48
- if File.exists?(file) and (mtime = File.stat(file).mtime) > (file_mtime[file] || start_time)
49
- $autoreload_dirty = true
50
- file_mtime[file] = mtime
51
- Logger.debug "File '#{ file }' changed" if $DBG
52
- end
53
- end
54
-
55
- end # loop
56
-
57
- end
58
- end
59
-
60
- end
data/lib/glue/builder.rb DELETED
@@ -1,57 +0,0 @@
1
- module Glue
2
-
3
- # A Builder integrates a number of Modules containing text
4
- # manipulation utilities and provides an alternative
5
- # 'accomulation' interface.
6
-
7
- class Builder
8
-
9
- # The builder output is accomulated in the buffer.
10
-
11
- attr_accessor :buffer
12
-
13
- class << self
14
-
15
- def include_builder(*modules)
16
- for mod in modules
17
- include mod
18
- for meth in mod.public_instance_methods
19
- self.module_eval %{
20
- alias_method :_mixin_#{meth}, :#{meth}
21
- def #{meth}(*args)
22
- @buffer << _mixin_#{meth}(*args)
23
- return self
24
- end
25
- }
26
- end
27
- end
28
- end
29
- alias_method :builder, :include_builder
30
-
31
- end
32
-
33
- # Provide the target where the builder output will be
34
- # accomulated. The builder utilizes duck typing to make it
35
- # compatible with any target responding to <<.
36
-
37
- def initialize(buffer = '', options = {})
38
- @buffer = buffer
39
- end
40
-
41
- # Emit a text string.
42
-
43
- def text!(str)
44
- @buffer << str
45
-
46
- return self
47
- end
48
- alias_method :print, :text!
49
- alias_method :<<, :text!
50
-
51
- def to_s
52
- @buffer.to_s
53
- end
54
-
55
- end
56
-
57
- end
@@ -1,103 +0,0 @@
1
- require 'glue/builder'
2
-
3
- module Glue
4
-
5
- # A Builder for programmatically building XML blocks.
6
- #--
7
- # TODO: move to nitro or move mixins here.
8
- #++
9
-
10
- class XmlBuilder < Builder
11
- require 'nitro/helper/xhtml'
12
- require 'nitro/helper/form'
13
- require 'nitro/helper/table'
14
-
15
- include_builder Nitro::XhtmlHelper
16
- include_builder Nitro::TableHelper
17
- include_builder Nitro::FormHelper
18
-
19
- def method_missing(tag, *args, &block)
20
- self.class.module_eval <<-"end_eval", __FILE__, __LINE__
21
- def #{tag}(*args)
22
- attrs = args.last.is_a?(Hash) ? args.pop : nil
23
-
24
- if block_given?
25
- start_tag!('#{tag}', attrs)
26
- yield
27
- end_tag!('#{tag}')
28
- elsif (!args.empty?)
29
- start_tag!('#{tag}', attrs)
30
- @buffer << args.first.to_s
31
- end_tag!('#{tag}')
32
- else
33
- start_tag!('#{tag}', attrs, false)
34
- @buffer << ' />'
35
- end
36
-
37
- return self
38
- end
39
- end_eval
40
-
41
- self.send(tag, *args, &block)
42
- end
43
-
44
- # Emit the start (opening) tag of an element.
45
-
46
- def start_tag!(tag, attributes = nil, close = true)
47
- unless attributes
48
- if close
49
- @buffer << "<#{tag}>"
50
- else
51
- @buffer << "<#{tag}"
52
- end
53
- else
54
- @buffer << "<#{tag}"
55
- for name, value in attributes
56
- if value
57
- @buffer << %| #{name}="#{value}"|
58
- else
59
- @buffer << %| #{name}="1"|
60
- end
61
- end
62
- @buffer << ">" if close
63
- end
64
-
65
- return self
66
- end
67
-
68
- # Emit the end (closing) tag of an element.
69
-
70
- def end_tag!(tag)
71
- @buffer << "</#{tag}>"
72
-
73
- return self
74
- end
75
-
76
- # Emit a comment.
77
-
78
- def comment!(str)
79
- @buffer << "<!-- #{str} -->"
80
-
81
- return self
82
- end
83
-
84
- # Emit a processing instruction.
85
-
86
- def processing_instruction!(name, attributes = nil)
87
- unless attributes
88
- @buffer << "<?#{name} ?>"
89
- else
90
- @buffer << "<?#{name} "
91
- attributes.each do |a, v|
92
- @buffer << %[#{a}="#{v}" ]
93
- end
94
- @buffer << "?>"
95
- end
96
-
97
- return self
98
- end
99
- alias_method :pi!, :processing_instruction!
100
-
101
- end
102
-
103
- end
data/lib/glue/cache.rb DELETED
@@ -1,22 +0,0 @@
1
- module Glue
2
-
3
- # A general cache key.
4
-
5
- class CacheKey
6
- end
7
-
8
- # A general cache mechanism.
9
- #
10
- # This cache system was originaly developed for Nitro. It is
11
- # used to cache fragments, og objects (entities), sessions,
12
- # application scoped variables and more.
13
-
14
- class Cache
15
-
16
- def update(hash)
17
- hash.each { |key, value| self[key] = value }
18
- end
19
-
20
- end
21
-
22
- end
@@ -1,51 +0,0 @@
1
- require 'drb'
2
-
3
- require 'glue/cache/memory'
4
-
5
- module Glue
6
-
7
- # A cached backed in a DRb server.
8
- #
9
- # === Example
10
- #
11
- # This cache needs a corresponding DRb server. Here is how you
12
- # can setup the standard Nitro Drb server to keep a DrbCache:
13
- #
14
- # require 'glue/cache/memory'
15
- #
16
- # class MyDrbServer < Nitro::DrbServer
17
- # def setup_drb_objects
18
- # ..
19
- # @my_cache = SyncHash.new
20
- # DRb.start_service("druby://#{my_drb_address}:#{my_drb_port}", @my_cache)
21
- # ..
22
- # end
23
- # end
24
- #
25
- # MyDrbServer.start
26
-
27
- class DrbCache < MemoryCache
28
-
29
- # Initialize the cache.
30
- #
31
- # === Options
32
- #
33
- # :address = The address of the DRb cache object.
34
- # :port = The port of the DRb cache object.
35
-
36
- # The address of the Session cache / store (if distibuted).
37
-
38
- setting :address, :default => '127.0.0.1', :doc => 'The address of the Session cache'
39
-
40
- # The port of the Session DRb cache / store (if distributed).
41
-
42
- setting :port, :default => 9069, :doc => 'The port of the Session cache'
43
-
44
-
45
- def initialize(address = DrbCache.address, port = DrbCache.port)
46
- @hash = DRbObject.new(nil, "druby://#{address}:#{port}")
47
- end
48
-
49
- end
50
-
51
- end
@@ -1,78 +0,0 @@
1
- require 'uri'
2
- require 'fileutils'
3
- require 'tmpdir'
4
-
5
- module Glue
6
-
7
- class FileCache
8
-
9
- setting :basedir, :default => "#{Dir.tmpdir}/nitro_file_cache", :doc => 'The directory to store files'
10
-
11
- def initialize(name = "cache", keepalive = nil)
12
- @path = File.join(FileCache.basedir, name)
13
- @keepalive = keepalive
14
-
15
- FileUtils.mkdir_p(@path, :mode => 0700)
16
- end
17
-
18
- def []=(k,v)
19
- fn = File.join(@path, escape_filename(k.to_s) )
20
- encode_file(fn, v)
21
- end
22
- alias :set :[]=
23
-
24
- def [](k)
25
- fn = File.join(@path, escape_filename(k.to_s) )
26
- return nil unless File.exists?(fn)
27
- decode_file(fn)
28
- end
29
- alias :get :[]
30
-
31
- def delete(k)
32
- f = File.join(@path, escape_filename(k.to_s))
33
- File.delete(f) if File.exists?(f)
34
- end
35
-
36
- def gc!
37
- return unless @keepalive
38
-
39
- now = Time.now
40
- all.each do |fn|
41
- expire_time = File.stat(fn).atime + @keepalive
42
- File.delete(fn) if now > expire_time
43
- end
44
- end
45
-
46
- def all
47
- Dir.glob( File.join(@path, '*' ) )
48
- end
49
-
50
- private
51
-
52
- def decode_file(fn)
53
- val = nil
54
- File.open(fn,"rb") do |f|
55
- f.flock(File::LOCK_EX)
56
- val = Marshal.load( f.read )
57
- f.flock(File::LOCK_UN)
58
- end
59
- return val
60
- end
61
-
62
- def encode_file(fn, value)
63
- File.open(fn, "wb") do |f|
64
- f.flock(File::LOCK_EX)
65
- f.chmod(0600)
66
- f.write(Marshal.dump(value))
67
- f.flock(File::LOCK_UN)
68
- end
69
- end
70
-
71
- # need this for fat filesystems
72
- def escape_filename(fn)
73
- URI.escape(fn, /["\/:;|=,\[\]]/)
74
- end
75
-
76
- end
77
- end
78
-
@@ -1,68 +0,0 @@
1
- # specifications:
2
- # http://cvs.danga.com/browse.cgi/wcmtools/memcached/doc/protocol.txt?rev=HEAD&content-type=text/plain
3
- #
4
- # very simple (= very fast) client for memcached
5
- #
6
- # i found the Ruby-MemCache library a little bit buggy and complicated, so i made my own before
7
- # fixing it ;)
8
- #
9
- # TODO socket disconnection handling
10
- # TODO error handling
11
- # TODO multiple servers connections
12
-
13
- require "socket"
14
-
15
- module Glue
16
-
17
- class MemCached
18
-
19
- setting :address, :default => 'localhost', :doc => 'Server address'
20
- setting :port, :default => 11211, :doc => 'Server port'
21
-
22
- def initialize(name = "cache", keepalive = nil)
23
- @sock = TCPSocket.new(MemCached.address, MemCached.port)
24
- @name = name
25
- @keepalive = keepalive
26
- end
27
-
28
- def []=(k,v)
29
- if @keepalive
30
- exptime = (Time.now + @keepalive).to_i
31
- else
32
- exptime = 0
33
- end
34
-
35
- data = Marshal.dump(v)
36
- @sock.print("set #{@name}:#{k} 0 #{exptime} #{data.size}\r\n#{data}\r\n")
37
- response = @sock.gets # "STORED\r\n"
38
- v
39
- end
40
- alias :set :[]=
41
-
42
- def [](k)
43
- @sock.print("get #{@name}:#{k}\r\n")
44
- resp = @sock.gets
45
- if resp == "END\r\n"
46
- return nil
47
- end
48
-
49
- #dummy, key, flags, size
50
- size = resp.split(/ /).last.to_i
51
- raw_data = @sock.read(size)
52
- @sock.gets # \r\n
53
- @sock.gets # END\r\n
54
- Marshal.load( raw_data )
55
- end
56
- alias :get :[]
57
-
58
- def delete(k)
59
- @sock.print("delete #{@name}:#{k}\r\n")
60
- @sock.gets # "DELETED\r\n"
61
- end
62
-
63
- def gc!
64
- # garbage collection is handled by the memcache server
65
- end
66
-
67
- end
68
- end