arrow 1.0.7

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.
Files changed (198) hide show
  1. data/ChangeLog +1590 -0
  2. data/LICENSE +28 -0
  3. data/README +75 -0
  4. data/Rakefile +366 -0
  5. data/Rakefile.local +63 -0
  6. data/data/arrow/applets/TEMPLATE.rb.tpl +53 -0
  7. data/data/arrow/applets/args.rb +50 -0
  8. data/data/arrow/applets/config.rb +55 -0
  9. data/data/arrow/applets/error.rb +63 -0
  10. data/data/arrow/applets/files.rb +46 -0
  11. data/data/arrow/applets/inspect.rb +46 -0
  12. data/data/arrow/applets/nosuchapplet.rb +31 -0
  13. data/data/arrow/applets/status.rb +92 -0
  14. data/data/arrow/applets/test.rb +133 -0
  15. data/data/arrow/applets/tutorial/counter.rb +96 -0
  16. data/data/arrow/applets/tutorial/dingus.rb +67 -0
  17. data/data/arrow/applets/tutorial/hello.rb +34 -0
  18. data/data/arrow/applets/tutorial/hello2.rb +73 -0
  19. data/data/arrow/applets/tutorial/imgtext.rb +90 -0
  20. data/data/arrow/applets/tutorial/imgtext2.rb +286 -0
  21. data/data/arrow/applets/tutorial/index.rb +36 -0
  22. data/data/arrow/applets/tutorial/logo.rb +98 -0
  23. data/data/arrow/applets/tutorial/memcache.rb +61 -0
  24. data/data/arrow/applets/tutorial/missing.rb +37 -0
  25. data/data/arrow/applets/tutorial/protected.rb +100 -0
  26. data/data/arrow/applets/tutorial/redirector.rb +52 -0
  27. data/data/arrow/applets/tutorial/rndimages.rb +159 -0
  28. data/data/arrow/applets/tutorial/sharenotes.rb +83 -0
  29. data/data/arrow/applets/tutorial/subclassed-hello.rb +32 -0
  30. data/data/arrow/applets/tutorial/superhello.rb +72 -0
  31. data/data/arrow/applets/tutorial/timeclock.rb +78 -0
  32. data/data/arrow/applets/view-applet.rb +123 -0
  33. data/data/arrow/applets/view-template.rb +85 -0
  34. data/data/arrow/applets/wiki.rb +274 -0
  35. data/data/arrow/templates/TEMPLATE.tmpl.tpl +36 -0
  36. data/data/arrow/templates/applet-status.tmpl +153 -0
  37. data/data/arrow/templates/args-display.tmpl +120 -0
  38. data/data/arrow/templates/config/display-table.tmpl +36 -0
  39. data/data/arrow/templates/config/display.tmpl +36 -0
  40. data/data/arrow/templates/counter-deleted.tmpl +33 -0
  41. data/data/arrow/templates/counter.tmpl +59 -0
  42. data/data/arrow/templates/dingus.tmpl +55 -0
  43. data/data/arrow/templates/enumtable.tmpl +8 -0
  44. data/data/arrow/templates/error-display.tmpl +92 -0
  45. data/data/arrow/templates/filemap.tmpl +89 -0
  46. data/data/arrow/templates/hello-world-src.tmpl +34 -0
  47. data/data/arrow/templates/hello-world.tmpl +60 -0
  48. data/data/arrow/templates/imgtext/fontlist.tmpl +46 -0
  49. data/data/arrow/templates/imgtext/form.tmpl +70 -0
  50. data/data/arrow/templates/imgtext/reload-error.tmpl +40 -0
  51. data/data/arrow/templates/imgtext/reload.tmpl +55 -0
  52. data/data/arrow/templates/inspect/display.tmpl +80 -0
  53. data/data/arrow/templates/loginform.tmpl +64 -0
  54. data/data/arrow/templates/logout.tmpl +32 -0
  55. data/data/arrow/templates/memcache/display.tmpl +41 -0
  56. data/data/arrow/templates/navbar.incl +27 -0
  57. data/data/arrow/templates/nosuchapplet.tmpl +32 -0
  58. data/data/arrow/templates/printsource.tmpl +35 -0
  59. data/data/arrow/templates/protected.tmpl +36 -0
  60. data/data/arrow/templates/rndimages.tmpl +38 -0
  61. data/data/arrow/templates/service-response.tmpl +13 -0
  62. data/data/arrow/templates/sharenotes/display.tmpl +38 -0
  63. data/data/arrow/templates/status.tmpl +120 -0
  64. data/data/arrow/templates/templateviewer.tmpl +43 -0
  65. data/data/arrow/templates/test/harness.tmpl +57 -0
  66. data/data/arrow/templates/test/list.tmpl +48 -0
  67. data/data/arrow/templates/test/problem.tmpl +42 -0
  68. data/data/arrow/templates/tutorial/index.tmpl +37 -0
  69. data/data/arrow/templates/tutorial/missingapplet.tmpl +29 -0
  70. data/data/arrow/templates/view-applet-nosuch.tmpl +32 -0
  71. data/data/arrow/templates/view-applet.tmpl +40 -0
  72. data/data/arrow/templates/view-template.tmpl +83 -0
  73. data/data/arrow/templates/wiki/formerror.tmpl +47 -0
  74. data/data/arrow/templates/wiki/markup_help.incl +6 -0
  75. data/data/arrow/templates/wiki/new.tmpl +56 -0
  76. data/data/arrow/templates/wiki/new_system.tmpl +122 -0
  77. data/data/arrow/templates/wiki/sectionlist.tmpl +43 -0
  78. data/data/arrow/templates/wiki/show.tmpl +34 -0
  79. data/docs/manual/layouts/default.page +43 -0
  80. data/docs/manual/lib/api-filter.rb +81 -0
  81. data/docs/manual/lib/editorial-filter.rb +64 -0
  82. data/docs/manual/lib/examples-filter.rb +244 -0
  83. data/docs/manual/lib/links-filter.rb +117 -0
  84. data/lib/apache/fakerequest.rb +448 -0
  85. data/lib/apache/logger.rb +33 -0
  86. data/lib/arrow.rb +51 -0
  87. data/lib/arrow/acceptparam.rb +207 -0
  88. data/lib/arrow/applet.rb +725 -0
  89. data/lib/arrow/appletmixins.rb +218 -0
  90. data/lib/arrow/appletregistry.rb +590 -0
  91. data/lib/arrow/applettestcase.rb +503 -0
  92. data/lib/arrow/broker.rb +255 -0
  93. data/lib/arrow/cache.rb +176 -0
  94. data/lib/arrow/config-loaders/yaml.rb +75 -0
  95. data/lib/arrow/config.rb +615 -0
  96. data/lib/arrow/constants.rb +24 -0
  97. data/lib/arrow/cookie.rb +359 -0
  98. data/lib/arrow/cookieset.rb +108 -0
  99. data/lib/arrow/dispatcher.rb +368 -0
  100. data/lib/arrow/dispatcherloader.rb +50 -0
  101. data/lib/arrow/exceptions.rb +61 -0
  102. data/lib/arrow/fallbackhandler.rb +48 -0
  103. data/lib/arrow/formvalidator.rb +631 -0
  104. data/lib/arrow/htmltokenizer.rb +343 -0
  105. data/lib/arrow/logger.rb +488 -0
  106. data/lib/arrow/logger/apacheoutputter.rb +69 -0
  107. data/lib/arrow/logger/arrayoutputter.rb +63 -0
  108. data/lib/arrow/logger/coloroutputter.rb +111 -0
  109. data/lib/arrow/logger/fileoutputter.rb +96 -0
  110. data/lib/arrow/logger/htmloutputter.rb +54 -0
  111. data/lib/arrow/logger/outputter.rb +123 -0
  112. data/lib/arrow/mixins.rb +425 -0
  113. data/lib/arrow/monkeypatches.rb +94 -0
  114. data/lib/arrow/object.rb +117 -0
  115. data/lib/arrow/path.rb +196 -0
  116. data/lib/arrow/service.rb +447 -0
  117. data/lib/arrow/session.rb +289 -0
  118. data/lib/arrow/session/dbstore.rb +100 -0
  119. data/lib/arrow/session/filelock.rb +160 -0
  120. data/lib/arrow/session/filestore.rb +132 -0
  121. data/lib/arrow/session/id.rb +98 -0
  122. data/lib/arrow/session/lock.rb +253 -0
  123. data/lib/arrow/session/md5id.rb +42 -0
  124. data/lib/arrow/session/nulllock.rb +42 -0
  125. data/lib/arrow/session/posixlock.rb +166 -0
  126. data/lib/arrow/session/sha1id.rb +54 -0
  127. data/lib/arrow/session/store.rb +366 -0
  128. data/lib/arrow/session/usertrackid.rb +52 -0
  129. data/lib/arrow/spechelpers.rb +73 -0
  130. data/lib/arrow/template.rb +713 -0
  131. data/lib/arrow/template/attr.rb +31 -0
  132. data/lib/arrow/template/call.rb +31 -0
  133. data/lib/arrow/template/comment.rb +33 -0
  134. data/lib/arrow/template/container.rb +118 -0
  135. data/lib/arrow/template/else.rb +41 -0
  136. data/lib/arrow/template/elsif.rb +44 -0
  137. data/lib/arrow/template/escape.rb +53 -0
  138. data/lib/arrow/template/export.rb +87 -0
  139. data/lib/arrow/template/for.rb +145 -0
  140. data/lib/arrow/template/if.rb +78 -0
  141. data/lib/arrow/template/import.rb +119 -0
  142. data/lib/arrow/template/include.rb +206 -0
  143. data/lib/arrow/template/iterator.rb +208 -0
  144. data/lib/arrow/template/nodes.rb +734 -0
  145. data/lib/arrow/template/parser.rb +571 -0
  146. data/lib/arrow/template/prettyprint.rb +53 -0
  147. data/lib/arrow/template/render.rb +191 -0
  148. data/lib/arrow/template/selectlist.rb +94 -0
  149. data/lib/arrow/template/set.rb +87 -0
  150. data/lib/arrow/template/timedelta.rb +81 -0
  151. data/lib/arrow/template/unless.rb +78 -0
  152. data/lib/arrow/template/urlencode.rb +51 -0
  153. data/lib/arrow/template/yield.rb +139 -0
  154. data/lib/arrow/templatefactory.rb +125 -0
  155. data/lib/arrow/testcase.rb +567 -0
  156. data/lib/arrow/transaction.rb +608 -0
  157. data/rake/191_compat.rb +26 -0
  158. data/rake/dependencies.rb +76 -0
  159. data/rake/documentation.rb +114 -0
  160. data/rake/helpers.rb +502 -0
  161. data/rake/hg.rb +282 -0
  162. data/rake/manual.rb +787 -0
  163. data/rake/packaging.rb +129 -0
  164. data/rake/publishing.rb +278 -0
  165. data/rake/style.rb +62 -0
  166. data/rake/svn.rb +668 -0
  167. data/rake/testing.rb +187 -0
  168. data/rake/verifytask.rb +64 -0
  169. data/spec/arrow/acceptparam_spec.rb +157 -0
  170. data/spec/arrow/applet_spec.rb +575 -0
  171. data/spec/arrow/appletmixins_spec.rb +409 -0
  172. data/spec/arrow/appletregistry_spec.rb +294 -0
  173. data/spec/arrow/broker_spec.rb +153 -0
  174. data/spec/arrow/config_spec.rb +224 -0
  175. data/spec/arrow/cookieset_spec.rb +164 -0
  176. data/spec/arrow/dispatcher_spec.rb +137 -0
  177. data/spec/arrow/dispatcherloader_spec.rb +65 -0
  178. data/spec/arrow/formvalidator_spec.rb +781 -0
  179. data/spec/arrow/logger_spec.rb +346 -0
  180. data/spec/arrow/mixins_spec.rb +120 -0
  181. data/spec/arrow/service_spec.rb +645 -0
  182. data/spec/arrow/session_spec.rb +121 -0
  183. data/spec/arrow/template/iterator_spec.rb +222 -0
  184. data/spec/arrow/templatefactory_spec.rb +185 -0
  185. data/spec/arrow/transaction_spec.rb +319 -0
  186. data/spec/arrow_spec.rb +37 -0
  187. data/spec/lib/appletmatchers.rb +281 -0
  188. data/spec/lib/constants.rb +77 -0
  189. data/spec/lib/helpers.rb +41 -0
  190. data/spec/lib/matchers.rb +44 -0
  191. data/tests/cookie.tests.rb +310 -0
  192. data/tests/path.tests.rb +157 -0
  193. data/tests/session.tests.rb +111 -0
  194. data/tests/session_id.tests.rb +82 -0
  195. data/tests/session_lock.tests.rb +191 -0
  196. data/tests/session_store.tests.rb +53 -0
  197. data/tests/template.tests.rb +1360 -0
  198. metadata +339 -0
@@ -0,0 +1,133 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # The UnitTester class, a derivative of
4
+ # Arrow::Applet. The UnitTest applet can be used to define and run tests for
5
+ # another applet by chaining through it.
6
+ #
7
+ # == Authors
8
+ #
9
+ # * Michael Granger <ged@FaerieMUD.org>
10
+ #
11
+
12
+ require 'arrow/applet'
13
+
14
+ require 'bdb'
15
+ require 'test/unit'
16
+
17
+ # Prevent Test::Unit from autorunning from its own at_exit
18
+ at_exit { Test::Unit.run = true }
19
+
20
+
21
+ ### The UnitTest applet can be used to define and run tests for another applet
22
+ ### by chaining through it.
23
+ class UnitTester < Arrow::Applet
24
+
25
+
26
+ # Default options for the BDB::Env object
27
+ EnvOptions = {
28
+ :set_timeout => 50,
29
+ :set_lk_detect => 1,
30
+ :set_verbose => true,
31
+ }
32
+
33
+ # Default flags for the BDB::Env object
34
+ EnvFlags = BDB::CREATE|BDB::INIT_TRANSACTION|BDB::RECOVER
35
+
36
+ # Applet signature
37
+ Signature = {
38
+ :name => "Unit testing applet",
39
+ :description => "The UnitTest applet can be used to define and run " +
40
+ "tests for another applet by chaining through it.",
41
+ :uri => "/test",
42
+ :maintainer => "ged@FaerieMUD.org",
43
+ :default_action => 'list',
44
+ :templates => {
45
+ :list => 'test/list.tmpl',
46
+ :testharness => "test/harness.tmpl",
47
+ :problem => "test/problem.tmpl",
48
+ },
49
+ }
50
+
51
+
52
+ ### Create a new instance of the UnitTester applet with the specified
53
+ ### +config+. It will look for its configuration values in the top-level
54
+ ### 'unittester' key if there is one.
55
+ def initialize( *args )
56
+ super
57
+
58
+ @dbenv = nil
59
+ @initError = nil
60
+
61
+ # If the app is configured in the config file, then load the database.
62
+ if @config.respond_to?( :unittester ) && false
63
+ begin
64
+ envdir = @config.unittester.dbenv
65
+ Dir.mkdir( envdir, 0755 ) if !File.exists?( envdir )
66
+ @dbenv = BDB::Env.create( envdir, EnvFlags, EnvOptions )
67
+ rescue Exception => err
68
+ @initError = err
69
+ end
70
+ else
71
+ @initError = [
72
+ "Not Configured",
73
+ "The 'unittester' section was not present or malformed in " +
74
+ @config.name + ". It should contain, at a minimum, a 'dbenv' item " +
75
+ "which specifies the path to the test database."
76
+ ]
77
+ end
78
+
79
+ end
80
+
81
+
82
+
83
+ ######
84
+ public
85
+ ######
86
+
87
+ # Run tests for the applet/s next in the chain
88
+ def delegate( txn, chain, *args )
89
+ return reportProblem( txn ) unless @dbenv
90
+
91
+ app = chain.last
92
+ tests = @dbenv.open_db( BDB::Hash, app[0].signature.name.gsub(/\W+/, '_'), nil, BDB::CREATE )
93
+
94
+ templ = self.load_template( :testharness )
95
+ templ.txn = txn
96
+ templ.tests = tests
97
+
98
+ return templ
99
+ end
100
+
101
+
102
+ # List the applets for which tests have been defined so far.
103
+ def_action :list do |txn, *args|
104
+ return reportProblem( txn ) unless @dbenv
105
+
106
+ templ = self.load_template( :list )
107
+ templ.txn = txn
108
+ return templ
109
+ end
110
+
111
+
112
+ # Auxilliary action: report a problem while loading the test harness.
113
+ def reportProblem( txn )
114
+ templ = self.load_template( :problem )
115
+ templ.err = @initErr
116
+
117
+ return templ
118
+ end
119
+
120
+
121
+
122
+ #################################################################
123
+ ### T E S T H A R N E S S C L A S S E S
124
+ #################################################################
125
+
126
+ class TestRunner
127
+ extend Test::Unit::UI::TestRunnerUtilities
128
+
129
+
130
+ end
131
+
132
+ end # class UnitTester
133
+
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # The AccessCounter class, a derivative of
4
+ # Arrow::Applet. It's a little applet for testing session persistance. It just
5
+ # increments and displays a counter which is held in a session object.
6
+ #
7
+ # == Authors
8
+ #
9
+ # * Michael Granger <ged@FaerieMUD.org>
10
+ #
11
+ # Please see the file LICENSE in the top-level directory for licensing details.
12
+ #
13
+
14
+ require 'arrow/applet'
15
+
16
+
17
+ ### An applet for testing session persistance and applet-chaining.
18
+ class AccessCounter < Arrow::Applet
19
+
20
+ # Applet signature
21
+ Signature = {
22
+ :name => "Session Access Counter",
23
+ :description => "Increments and displays a counter contained in a session object.",
24
+ :maintainer => "ged@FaerieMUD.org",
25
+ :config => {},
26
+ :templates => {
27
+ :counter => 'counter.tmpl',
28
+ :deleted => 'counter-deleted.tmpl',
29
+ },
30
+ :vargs => {},
31
+ :monitors => {},
32
+ :default_action => 'display',
33
+ }
34
+
35
+
36
+
37
+ ######
38
+ public
39
+ ######
40
+
41
+ ### When called as a chained applet, just increment two session counters and
42
+ ### hand off control to the next applet in the chain.
43
+ def delegate( txn, chain, *args )
44
+ begin
45
+ # Set up and increment this app's execution counter
46
+ txn.session[:counter] ||= 0
47
+ txn.session[:counter] += 1
48
+
49
+ # Set up and increment the delegation counter
50
+ txn.session[:delegations] ||= 0
51
+ txn.session[:delegations] += 1
52
+ rescue ::Exception => err
53
+ self.log.error "Error while setting up session: #{err.message}"
54
+ end
55
+
56
+ yield( chain )
57
+ end
58
+
59
+
60
+ ### The 'display' (default) action. Increments and displays the counter.
61
+ def_action :display do |txn, *args|
62
+ self.log.debug "In the 'display' action of the '%s' applet." %
63
+ self.signature.name
64
+
65
+ templ = self.load_template( :counter )
66
+ txn.session[:counter] ||= 0
67
+ txn.session[:counter] += 1
68
+
69
+ txn.session[:lastChild] = Process.pid
70
+
71
+ templ.session = txn.session
72
+ templ.txn = txn
73
+
74
+ txn.print( templ )
75
+
76
+ return true
77
+ end
78
+
79
+ ### Deletes the session
80
+ def_action :delete do |txn, *args|
81
+ self.log.debug "In the 'delete' action of the '%s' applet." %
82
+ self.signature.name
83
+
84
+ templ = self.load_template( :deleted )
85
+ txn.session.remove
86
+
87
+ templ.txn = txn
88
+ txn.print( templ )
89
+
90
+ return true
91
+ end
92
+
93
+
94
+ end # class AccessCounter
95
+
96
+
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # The BlueClothDingus class, a derivative of
4
+ # Arrow::Applet. It presents a text box into which one can input Markdown text,
5
+ # which when submitted will be transformed into HTML via the BlueCloth library
6
+ # and displayed.
7
+ #
8
+ # == VCS Id
9
+ #
10
+ # $Id$
11
+ #
12
+ # == Authors
13
+ #
14
+ # * Michael Granger <ged@FaerieMUD.org>
15
+ #
16
+
17
+ require 'arrow/applet'
18
+ require 'bluecloth'
19
+
20
+
21
+ ### It presents a text box into which
22
+ class BlueClothDingus < Arrow::Applet
23
+
24
+ # Applet signature
25
+ applet_name "BlueCloth Dingus"
26
+ applet_description "It presents a text box into which one can input " \
27
+ "Markdown text, which when submitted will be transformed into " \
28
+ "HTML via the BlueCloth library and displayed."
29
+ applet_maintainer "ged@FaerieMUD.org"
30
+
31
+ default_action :display
32
+
33
+
34
+
35
+ ######
36
+ public
37
+ ######
38
+
39
+ def_action :display do |txn, *args|
40
+ templ = self.load_template( :display )
41
+
42
+ if (( source = txn.vargs.valid["source"] ))
43
+ self.log.debug "Got valid source argument: %s" % source
44
+ templ.source = source
45
+ templ.output = BlueCloth.new( source ).to_html
46
+ else
47
+ self.log.debug "No valid source argument: %p" % txn.vargs
48
+ end
49
+
50
+ templ.txn = txn
51
+ templ.app = self
52
+ templ.bcmod = BlueCloth
53
+
54
+ return templ
55
+ end
56
+ template :display => 'dingus.tmpl'
57
+ validator :display => {
58
+ :required => :source,
59
+ :constraints => {
60
+ :source => /^[\x20-\x7f\r\n]+$/,
61
+ },
62
+ }
63
+
64
+
65
+ end # class BlueClothDingus
66
+
67
+
@@ -0,0 +1,34 @@
1
+ #
2
+ # A "hello world" Arrow applet
3
+ #
4
+
5
+ require 'arrow/applet'
6
+
7
+ # Define the applet class; inherit from the base applet class.
8
+ class Hello < Arrow::Applet
9
+
10
+ # Applet signature
11
+ Signature = {
12
+ :name => "Hello World",
13
+ :description => "This is yet another implementation of Hello World",
14
+ :maintainer => "ged@FaerieMUD.org",
15
+ :default_action => 'greet',
16
+ }
17
+
18
+ # Define the 'greet' (default) action
19
+ def greet_action( txn, name=nil )
20
+ name ||= "world"
21
+
22
+ return <<-EOF
23
+ <html>
24
+ <head><title>Hello</title></head>
25
+ <body><p>Hello, #{name}.</p></body>
26
+ </html>
27
+ EOF
28
+ end
29
+
30
+ end
31
+
32
+
33
+
34
+
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # The HelloWorld class, a derivative of Arrow::Applet. A
4
+ # "hello world" applet.
5
+ #
6
+ # == Authors
7
+ #
8
+ # * Michael Granger <ged@FaerieMUD.org>
9
+ #
10
+
11
+ require 'arrow/applet'
12
+
13
+
14
+ ### A "hello world" applet.
15
+ class HelloWorld < Arrow::Applet
16
+
17
+
18
+ # Applet signature
19
+ Signature = {
20
+ :name => "Hello World",
21
+ :description => %{A 'hello world' applet.},
22
+ :maintainer => "ged@FaerieMUD.org",
23
+ :default_action => 'templated',
24
+ :templates => {
25
+ :templated => 'hello-world.tmpl',
26
+ :printsource => 'hello-world-src.tmpl',
27
+ },
28
+ }
29
+
30
+
31
+
32
+ ######
33
+ public
34
+ ######
35
+
36
+ def display_action( txn, *args )
37
+ self.log.debug "In the 'display' action of the '%s' applet." %
38
+ self.signature.name
39
+
40
+ txn.content_type = "text/plain"
41
+ return "Hello world."
42
+ end
43
+
44
+
45
+ def_action :templated do |txn, *args|
46
+ self.log.debug "In the 'templated' action of the %s applet." %
47
+ self.signature.name
48
+
49
+ templ = self.load_template( :templated )
50
+ templ.txn = txn
51
+ templ.applet = self
52
+
53
+ return templ
54
+ end
55
+
56
+
57
+ def_action :printsource do |txn, *args|
58
+ self.log.debug "In the 'printsource' action of the %s applet." %
59
+ self.signature.name
60
+
61
+ src = File.read( __FILE__ ).gsub(/\t/, ' ')
62
+
63
+ templ = self.load_template( :printsource )
64
+ templ.txn = txn
65
+ templ.applet = self
66
+ templ.source = src
67
+
68
+ return templ
69
+ end
70
+
71
+ end # class HelloWorld
72
+
73
+
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # The ImageText class, a derivative of Arrow::Applet. It is
4
+ # an applet which generates an image from one or more characters of text.
5
+ #
6
+ # == VCS Id
7
+ #
8
+ # $Id$
9
+ #
10
+ # == Authors
11
+ #
12
+ # * Michael Granger <ged@FaerieMUD.org>
13
+ #
14
+
15
+ require 'GD'
16
+ require 'arrow/applet'
17
+
18
+ ### It is an applet which generates an image from one or more characters of text.
19
+ class ImageText < Arrow::Applet
20
+
21
+
22
+ # Applet signature
23
+ Signature = {
24
+ :name => "imagetext",
25
+ :description => "Generates an image from one or more characters of text.",
26
+ :maintainer => "ged@FaerieMUD.org",
27
+ :default_action => 'form',
28
+ :templates => {
29
+ :form => 'imgtext.tmpl',
30
+ },
31
+ :vargs => {
32
+ }
33
+ }
34
+
35
+
36
+
37
+ ######
38
+ public
39
+ ######
40
+
41
+ # PNG-creation action
42
+ def_action :png do |txn,*rest|
43
+ text = $1 if /([\x20-\x7e]+)/.match( rest.first )
44
+ text ||= "No text specified."
45
+
46
+ img = make_image( text )
47
+
48
+ txn.content_type = 'image/png'
49
+ return img.pngStr
50
+ end
51
+
52
+ # JPEG-creation action
53
+ def_action :jpeg do |txn,*rest|
54
+ text = $1 if /([\x20-\x7e]+)/.match( rest.first )
55
+ text ||= "No text specified."
56
+
57
+ img = make_image( text )
58
+
59
+ txn.content_type = 'image/jpeg'
60
+ return img.jpegStr( -1 )
61
+ end
62
+
63
+
64
+ #########
65
+ protected
66
+ #########
67
+
68
+ def make_image( text )
69
+ # Fetch the font and calculate the image dimensions from the text.
70
+ font = GD::Font.new( "Medium" )
71
+ width = font.width * text.length + 10
72
+ height = font.height + 10
73
+
74
+ # Make the image and colors
75
+ img = GD::Image.newTrueColor( width, height )
76
+ background= GD::Image.trueColor( 255, 255, 240 )
77
+ foreground = GD::Image.trueColor( 0, 0, 0 )
78
+
79
+ # Fill the image with the background and draw the text and a border with
80
+ # the foreground color.
81
+ img.fill( 1, 1, background )
82
+ img.string( font, 5, 5, text, foreground )
83
+ img.rectangle( 0,0, width-1, height-1, foreground )
84
+
85
+ return img
86
+ end
87
+
88
+ end # class ImageText
89
+
90
+