glue 0.41.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/Manifest.txt +6 -0
- data/README.txt +130 -0
- data/Rakefile +16 -0
- data/lib/glue.rb +49 -72
- data/test/test_glue.rb +218 -0
- metadata +84 -100
- data/doc/AUTHORS +0 -13
- data/doc/CHANGELOG.1 +0 -354
- data/doc/LICENSE +0 -32
- data/doc/RELEASES +0 -207
- data/lib/glue/attribute.rb +0 -113
- data/lib/glue/attributeutils.rb +0 -117
- data/lib/glue/autoreload.rb +0 -60
- data/lib/glue/builder.rb +0 -57
- data/lib/glue/builder/xml.rb +0 -103
- data/lib/glue/cache.rb +0 -22
- data/lib/glue/cache/drb.rb +0 -51
- data/lib/glue/cache/file.rb +0 -78
- data/lib/glue/cache/memcached.rb +0 -68
- data/lib/glue/cache/memory.rb +0 -79
- data/lib/glue/cache/og.rb +0 -61
- data/lib/glue/configuration.rb +0 -305
- data/lib/glue/fixture.rb +0 -154
- data/lib/glue/html.rb +0 -12
- data/lib/glue/localization.rb +0 -129
- data/lib/glue/logger.rb +0 -208
- data/lib/glue/mail.rb +0 -160
- data/lib/glue/mailer.rb +0 -55
- data/lib/glue/mailer/incoming.rb +0 -41
- data/lib/glue/mailer/outgoing.rb +0 -119
- data/lib/glue/settings.rb +0 -3
- data/lib/glue/uri.rb +0 -190
- data/lib/glue/validation.rb +0 -447
- data/lib/html/document.rb +0 -63
- data/lib/html/node.rb +0 -480
- data/lib/html/tokenizer.rb +0 -103
- data/lib/html/version.rb +0 -11
- data/test/fixture/article.csv +0 -3
- data/test/fixture/article.yml +0 -13
- data/test/fixture/user.yml +0 -12
- data/test/glue/builder/tc_xml.rb +0 -57
- data/test/glue/tc_aspects.rb +0 -99
- data/test/glue/tc_attribute.rb +0 -112
- data/test/glue/tc_attribute_mixins.rb +0 -86
- data/test/glue/tc_builder.rb +0 -30
- data/test/glue/tc_configuration.rb +0 -135
- data/test/glue/tc_fixture.rb +0 -98
- data/test/glue/tc_localization.rb +0 -49
- data/test/glue/tc_logger.rb +0 -43
- data/test/glue/tc_mail.rb +0 -99
- data/test/glue/tc_stores.rb +0 -16
- data/test/glue/tc_uri.rb +0 -97
- data/test/glue/tc_validation.rb +0 -217
- data/test/public/dummy_mailer/registration.xhtml +0 -5
data/lib/glue/html.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
module Glue
|
2
|
-
module Html
|
3
|
-
def self.cleanup(buf)
|
4
|
-
out = buf.dup
|
5
|
-
elements = "input|img|br|hr|link|style|render|include|inject|base|meta"
|
6
|
-
out.gsub! /<textarea ([^>]*)><\/textarea>/, '<textarea \1>#{}</textarea>'
|
7
|
-
out.gsub! /<(#{elements}) ([^>]*)><\/\1>/, '<\1 \2 />'
|
8
|
-
out.gsub! /<(#{elements})><\/\1>/, '<\1 />'
|
9
|
-
out
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
data/lib/glue/localization.rb
DELETED
@@ -1,129 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
require 'facets/more/aspects'
|
4
|
-
|
5
|
-
module Glue
|
6
|
-
|
7
|
-
# Represents a locale.
|
8
|
-
#--
|
9
|
-
# TODO: initialize translation map from a yaml file.
|
10
|
-
#++
|
11
|
-
|
12
|
-
class Locale
|
13
|
-
|
14
|
-
# The localization map.
|
15
|
-
|
16
|
-
attr_accessor :map
|
17
|
-
|
18
|
-
def initialize(map)
|
19
|
-
parse_hash(map)
|
20
|
-
end
|
21
|
-
|
22
|
-
# Transalte the given key.
|
23
|
-
#
|
24
|
-
# [+args+]
|
25
|
-
# An array of arguments. The first argument
|
26
|
-
# is the translation key. If additional arguments
|
27
|
-
# are provided they are used for sprintf
|
28
|
-
# interpolation.
|
29
|
-
#--
|
30
|
-
# THINK: Possibly avoid the creation of the
|
31
|
-
# array by making the api less elegant.
|
32
|
-
#++
|
33
|
-
|
34
|
-
def translate(*args)
|
35
|
-
if xlated = @map[args.shift]
|
36
|
-
if xlated.is_a?(String)
|
37
|
-
args.empty? ? xlated : sprintf(xlated, *args)
|
38
|
-
else
|
39
|
-
xlated.call(*args)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
alias_method :[], :translate
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def parse_hash(map)
|
48
|
-
@map = map
|
49
|
-
end
|
50
|
-
|
51
|
-
def parse_yaml(yaml)
|
52
|
-
raise 'Not implemented'
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
# Localization support.
|
58
|
-
#
|
59
|
-
# === Example
|
60
|
-
#
|
61
|
-
# locale_en = {
|
62
|
-
# 'See you' => 'See you',
|
63
|
-
# :long_paragraph => 'The best new books, up to 30% reduced price',
|
64
|
-
# :price => 'Price: %d %s',
|
65
|
-
# :proc_price => proc { |value, cur| "Price: #{value} #{cur}" }
|
66
|
-
# }
|
67
|
-
#
|
68
|
-
# locale_de = {
|
69
|
-
# 'See you' => 'Auf wieder sehen',
|
70
|
-
# :long_paragraph => 'Die besten neuer buecher, bis zu 30% reduziert',
|
71
|
-
# ...
|
72
|
-
# }
|
73
|
-
#
|
74
|
-
# Localization.add(:en => locale_en, :de => locale_de)
|
75
|
-
#
|
76
|
-
# lc = Localization.get
|
77
|
-
# lc['See you'] -> See you
|
78
|
-
# lc[:price, 100, 'euro'] -> Price: 100 euro
|
79
|
-
# lc = Localization.get[:de]
|
80
|
-
# lc['See you'] -> Auf wiedersehen
|
81
|
-
#
|
82
|
-
# To make localization even more easier, a LocalizationAspect
|
83
|
-
# is provide provided. Additional transformation macros are
|
84
|
-
# provided if you require 'nitro/compiler/localization'
|
85
|
-
|
86
|
-
class Localization
|
87
|
-
|
88
|
-
class << self
|
89
|
-
|
90
|
-
# A hash of the available locales.
|
91
|
-
|
92
|
-
attr_accessor :locales
|
93
|
-
|
94
|
-
def add(map = {})
|
95
|
-
for key, locale in map
|
96
|
-
if locale.is_a?(String)
|
97
|
-
# this is the name of the localization file.
|
98
|
-
locale = YAML.load(File.read(locale))
|
99
|
-
end
|
100
|
-
@locales[key.to_s] = Locale.new(locale)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
alias_method :locales=, :add
|
104
|
-
|
105
|
-
# Return the localization hash for the given
|
106
|
-
# locale.
|
107
|
-
|
108
|
-
def get(locale = :en)
|
109
|
-
locale ||= 'en'
|
110
|
-
@locales[locale.to_s]
|
111
|
-
end
|
112
|
-
alias_method :locale, :get
|
113
|
-
alias_method :[], :get
|
114
|
-
|
115
|
-
end
|
116
|
-
|
117
|
-
@locales = {}
|
118
|
-
|
119
|
-
end
|
120
|
-
|
121
|
-
# Localization Aspect for Nitro controllers.
|
122
|
-
|
123
|
-
module LocalizationAspect
|
124
|
-
def localize
|
125
|
-
@lc = Localization[@context.session[:LOCALE]]
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
end
|
data/lib/glue/logger.rb
DELETED
@@ -1,208 +0,0 @@
|
|
1
|
-
require 'logger'
|
2
|
-
|
3
|
-
# A simple extension of the Ruby logger. Mainly for
|
4
|
-
# compatibility purposes.
|
5
|
-
#
|
6
|
-
# === Convention
|
7
|
-
#
|
8
|
-
# When using debug level logger messages always append 'if $DBG'
|
9
|
-
# at the end. This hack is needed because Ruby does not support
|
10
|
-
# lazy evaluation (lisp macros).
|
11
|
-
#--
|
12
|
-
# THINK: some people think, this extension is dangerous,
|
13
|
-
# investigate.
|
14
|
-
#++
|
15
|
-
|
16
|
-
class Logger
|
17
|
-
alias_method :devel, :debug
|
18
|
-
alias_method :fine, :debug
|
19
|
-
|
20
|
-
# Prints a trace message to DEBUGLOG (at debug level).
|
21
|
-
# Useful for emitting the value of variables, etc. Use
|
22
|
-
# like this:
|
23
|
-
#
|
24
|
-
# x = y = 5
|
25
|
-
# trace 'x' # -> 'x = 5'
|
26
|
-
# trace 'x ** y' # -> 'x ** y = 3125'
|
27
|
-
#
|
28
|
-
# If you have a more complicated value, like an array of
|
29
|
-
# hashes, then you'll probably want to use an alternative
|
30
|
-
# output format. For instance:
|
31
|
-
#
|
32
|
-
# trace 'value', :yaml
|
33
|
-
#
|
34
|
-
# Valid output format values (the _style_ parameter) are:
|
35
|
-
#
|
36
|
-
# :p :inspect
|
37
|
-
# :pp (pretty-print, using 'pp' library)
|
38
|
-
# :s :to_s
|
39
|
-
# :y :yaml :to_yaml (using the 'yaml' library')
|
40
|
-
#
|
41
|
-
# The default is <tt>:p</tt>.
|
42
|
-
#
|
43
|
-
# CREDITS:
|
44
|
-
#
|
45
|
-
# This code comes straight from the dev-utils Gem.
|
46
|
-
# Author: Gavin Sinclair <gsinclair@soyabean.com.au>
|
47
|
-
|
48
|
-
def trace(expr, style=:p)
|
49
|
-
unless expr.respond_to? :to_str
|
50
|
-
warn "trace: Can't evaluate the given value: #{caller.first}"
|
51
|
-
else
|
52
|
-
require 'facet/binding/self/of_caller'
|
53
|
-
|
54
|
-
Binding.of_caller do |b|
|
55
|
-
value = b.eval(expr.to_str)
|
56
|
-
formatter = TRACE_STYLES[style] || :inspect
|
57
|
-
case formatter
|
58
|
-
when :pp then require 'pp'
|
59
|
-
when :y, :yaml, :to_yaml then require 'yaml'
|
60
|
-
end
|
61
|
-
value_s = value.send(formatter)
|
62
|
-
message = "#{expr} = #{value_s}"
|
63
|
-
lines = message.split(/\n/)
|
64
|
-
indent = " "
|
65
|
-
debug(lines.shift)
|
66
|
-
lines.each do |line|
|
67
|
-
debug(indent + line)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
TRACE_STYLES = {} # :nodoc:
|
74
|
-
TRACE_STYLES.update(
|
75
|
-
:pp => :pp_s, :s => :to_s, :p => :inspect,
|
76
|
-
:y => :to_yaml, :yaml => :to_yaml,
|
77
|
-
:inspect => :inspect, :to_yaml => :to_yaml
|
78
|
-
)
|
79
|
-
|
80
|
-
# Dictate the way in which this logger should format the
|
81
|
-
# messages it displays. This method requires a block. The
|
82
|
-
# block should return formatted strings given severity,
|
83
|
-
# timestamp, msg, progname.
|
84
|
-
#
|
85
|
-
# === Example
|
86
|
-
#
|
87
|
-
# logger = Logger.new
|
88
|
-
# logger.setup_format do |severity, timestamp, msg, progname|
|
89
|
-
# "#{progname}@#{timestamp} - #{severity}::#{msg}"
|
90
|
-
# end
|
91
|
-
|
92
|
-
def setup_format(&format_proc)
|
93
|
-
raise 'Formating block needed' unless format_proc
|
94
|
-
@format_proc = format_proc
|
95
|
-
end
|
96
|
-
|
97
|
-
private
|
98
|
-
|
99
|
-
# hackish use of *args, give me some love.
|
100
|
-
|
101
|
-
alias_method :old_format_message, :format_message # :nodoc:
|
102
|
-
def format_message(*args) # :nodoc:
|
103
|
-
@format_proc ? @format_proc.call(*args) : old_format_message(*args)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
# Global logger interface. This provides an alternative
|
108
|
-
# Singleton interface to the Logger.
|
109
|
-
|
110
|
-
class Logger
|
111
|
-
|
112
|
-
SIMPLE_FORMAT = "%5s: %s\n"
|
113
|
-
@@global_logger = Logger.new(STDERR)
|
114
|
-
@@global_logger.setup_format do |severity, timestamp, progname, msg|
|
115
|
-
SIMPLE_FORMAT % [severity, msg]
|
116
|
-
end
|
117
|
-
|
118
|
-
# Set the global Logger.
|
119
|
-
|
120
|
-
def self.set(logger)
|
121
|
-
if logger.is_a?(String) || logger.is_a?(IO)
|
122
|
-
@@global_logger = Logger.new(logger)
|
123
|
-
elsif logger.is_a?(Logger)
|
124
|
-
@@global_logger = logger
|
125
|
-
else
|
126
|
-
raise ArgumentError
|
127
|
-
end
|
128
|
-
|
129
|
-
@@global_logger.setup_format do |severity, timestamp, progname, msg|
|
130
|
-
SIMPLE_FORMAT % [severity, msg]
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def self.get
|
135
|
-
@@global_logger
|
136
|
-
end
|
137
|
-
|
138
|
-
def self.warn(str)
|
139
|
-
@@global_logger.warn(str)
|
140
|
-
end
|
141
|
-
|
142
|
-
def self.info(str)
|
143
|
-
@@global_logger.info(str)
|
144
|
-
end
|
145
|
-
|
146
|
-
def self.debug(str)
|
147
|
-
@@global_logger.debug(str)
|
148
|
-
end
|
149
|
-
|
150
|
-
def self.error(str)
|
151
|
-
@@global_logger.error(str)
|
152
|
-
end
|
153
|
-
|
154
|
-
#--
|
155
|
-
# Saddly have to duplicate the code to make
|
156
|
-
# Binding.of_caller work.
|
157
|
-
#++
|
158
|
-
|
159
|
-
def self.trace(expr, style=:p)
|
160
|
-
unless expr.respond_to? :to_str
|
161
|
-
warn "trace: Can't evaluate the given value: #{caller.first}"
|
162
|
-
else
|
163
|
-
require 'facet/binding/self/of_caller'
|
164
|
-
|
165
|
-
Binding.of_caller do |b|
|
166
|
-
value = eval(expr.to_str, b)
|
167
|
-
formatter = TRACE_STYLES[style] || :inspect
|
168
|
-
case formatter
|
169
|
-
when :pp then require 'pp'
|
170
|
-
when :y, :yaml, :to_yaml then require 'yaml'
|
171
|
-
end
|
172
|
-
value_s = value.send(formatter)
|
173
|
-
message = "#{expr} = #{value_s}"
|
174
|
-
lines = message.split(/\n/)
|
175
|
-
indent = " "
|
176
|
-
debug(lines.shift)
|
177
|
-
lines.each do |line|
|
178
|
-
debug(indent + line)
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
module Glue
|
186
|
-
|
187
|
-
# UNDER CONSTRUCTION.
|
188
|
-
#
|
189
|
-
# Add logging capabilities to the including class.
|
190
|
-
#
|
191
|
-
# === Examples
|
192
|
-
#
|
193
|
-
# Og.log_info 'Hello' => '[Og] Hello'
|
194
|
-
# Render.log_info ...
|
195
|
-
# In Render:
|
196
|
-
# log_info '...'
|
197
|
-
|
198
|
-
module Logging
|
199
|
-
=begin
|
200
|
-
def self.included base
|
201
|
-
[ :info, :debug ].each do |l|
|
202
|
-
|
203
|
-
end
|
204
|
-
end
|
205
|
-
=end
|
206
|
-
end
|
207
|
-
|
208
|
-
end
|
data/lib/glue/mail.rb
DELETED
@@ -1,160 +0,0 @@
|
|
1
|
-
require 'net/smtp'
|
2
|
-
|
3
|
-
module Glue
|
4
|
-
|
5
|
-
# Encapsulates an email message.
|
6
|
-
|
7
|
-
class Mail
|
8
|
-
|
9
|
-
# The default charset.
|
10
|
-
|
11
|
-
setting :default_charset, :default => 'utf-8', :doc => 'The default character set'
|
12
|
-
|
13
|
-
# Encode the subject?
|
14
|
-
|
15
|
-
setting :encode_subject, :default => false, :doc => 'Encode the subject?'
|
16
|
-
|
17
|
-
# Sender, can be an array.
|
18
|
-
|
19
|
-
attr_accessor :from
|
20
|
-
|
21
|
-
# The list of the recipients, can be arrays.
|
22
|
-
|
23
|
-
attr_accessor :to, :cc, :bcc
|
24
|
-
|
25
|
-
# The subject
|
26
|
-
|
27
|
-
attr_accessor :subject
|
28
|
-
|
29
|
-
# The body of the message.
|
30
|
-
|
31
|
-
attr_accessor :body
|
32
|
-
|
33
|
-
# Reply to.
|
34
|
-
|
35
|
-
attr_accessor :reply_to
|
36
|
-
|
37
|
-
# Sent on
|
38
|
-
|
39
|
-
attr_accessor :sent_on
|
40
|
-
|
41
|
-
# Encode the subject?
|
42
|
-
|
43
|
-
attr_accessor :encode_subject
|
44
|
-
|
45
|
-
# The charset used to encode the message.
|
46
|
-
|
47
|
-
attr_accessor :charset
|
48
|
-
|
49
|
-
# Additional headers
|
50
|
-
|
51
|
-
attr_accessor :headers
|
52
|
-
|
53
|
-
def initialize(from = nil, to = nil, subject = nil, body = nil)
|
54
|
-
@from, @to, @subject, @body = from, to, subject, body
|
55
|
-
@headers = {}
|
56
|
-
end
|
57
|
-
|
58
|
-
def parse_headers
|
59
|
-
@from = @headers['From']
|
60
|
-
@to = @headers['To']
|
61
|
-
@cc = @headers['Cc']
|
62
|
-
@bcc = @headers['Bcc']
|
63
|
-
@subject = @headers['Subject']
|
64
|
-
end
|
65
|
-
|
66
|
-
# Accept string or IO.
|
67
|
-
|
68
|
-
def self.new_from_encoded(encoded)
|
69
|
-
if encoded.is_a? String
|
70
|
-
require 'stringio'
|
71
|
-
encoded = StringIO.new(encoded)
|
72
|
-
end
|
73
|
-
|
74
|
-
f = encoded
|
75
|
-
|
76
|
-
# the following code is copied from mailread.rb
|
77
|
-
|
78
|
-
unless defined? f.gets
|
79
|
-
f = open(f, "r")
|
80
|
-
opened = true
|
81
|
-
end
|
82
|
-
|
83
|
-
_headers = {}
|
84
|
-
_body = []
|
85
|
-
begin
|
86
|
-
while line = f.gets()
|
87
|
-
line.chop!
|
88
|
-
next if /^From /=~line # skip From-line
|
89
|
-
break if /^$/=~line # end of header
|
90
|
-
|
91
|
-
if /^(\S+?):\s*(.*)/=~line
|
92
|
-
(attr = $1).capitalize!
|
93
|
-
_headers[attr] = $2
|
94
|
-
elsif attr
|
95
|
-
line.sub!(/^\s*/, '')
|
96
|
-
_headers[attr] += "\n" + line
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
return unless line
|
101
|
-
|
102
|
-
while line = f.gets()
|
103
|
-
break if /^From /=~line
|
104
|
-
_body.push(line)
|
105
|
-
end
|
106
|
-
ensure
|
107
|
-
f.close if opened
|
108
|
-
end
|
109
|
-
|
110
|
-
mail = Mail.new
|
111
|
-
mail.headers = _headers
|
112
|
-
mail.body = _body.join("\n")
|
113
|
-
mail.parse_headers
|
114
|
-
|
115
|
-
return mail
|
116
|
-
end
|
117
|
-
|
118
|
-
def [](key)
|
119
|
-
@headers[key]
|
120
|
-
end
|
121
|
-
|
122
|
-
def []=(key, value)
|
123
|
-
@headers[key] = value
|
124
|
-
end
|
125
|
-
|
126
|
-
# Returns the Mail message in encoded format.
|
127
|
-
|
128
|
-
def encoded
|
129
|
-
raise 'No body defined' unless @body
|
130
|
-
raise 'No sender defined' unless @from
|
131
|
-
raise 'No recipients defined' unless @to
|
132
|
-
|
133
|
-
# gmosx: From is typically NOT an array.
|
134
|
-
|
135
|
-
from = @from.is_a?(Array) ? @from.join(', ') : @from
|
136
|
-
buf = "From: #{from}\n"
|
137
|
-
|
138
|
-
to = @to.is_a?(Array) ? @to.join(', ') : @to
|
139
|
-
buf << "To: #{to}\n"
|
140
|
-
|
141
|
-
if @cc
|
142
|
-
cc = @cc.is_a?(Array) ? @cc.join(', ') : @cc
|
143
|
-
buf << "Cc: #{cc}\n"
|
144
|
-
end
|
145
|
-
|
146
|
-
if @bcc
|
147
|
-
bcc = @bcc.is_a?(Array) ? @bcc.join(', ') : @bcc
|
148
|
-
buf << "Bcc: #{bcc}\n"
|
149
|
-
end
|
150
|
-
|
151
|
-
buf << "Subject: #@subject\n" if @subject
|
152
|
-
|
153
|
-
buf << "\n"
|
154
|
-
buf << @body
|
155
|
-
|
156
|
-
return buf
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
end
|