Define and use macros for handling UTF-16 surrogates.
[elinks.git] / contrib / ruby / hooks.rb
blob6e0ac0bb32c778c9117e36f82c1b489a79c1cd5e
1 # = hooks.rb - ELinks/Ruby hooks
3 # == Module Constants
5 # The following global module constants are defined
7 # * ELinks::VERSION     - The ELinks version. :-P
9 # * ELinks::HOME        - The path to ELinks configuration files
11 # == Debugging Scripts
13 # When debugging you can use either
15 #       p(obj, ...)
17 # or
19 #       message(string)
21 # to print message strings. The printed strings will be shown in a message
22 # box.
25 # Called when the user enters something into the goto URL dialog.
27 # Arguments:
28 # @url          the URL entered in the goto URL dialog.
29 # @current_url  the URL currently being viewed in ELinks.
31 # Returns the URL to go to. Return nil to use the @url argument as is
32 # (leave it untouched).
34 def ELinks::goto_url_hook(url, current_url)
35     case url
36     when /^localhost$/
37         return "http://localhost/"
39     when /test-ruby/
40         # Dump the exported variables.
41         message(ELinks::VERSION + " - " + ELinks::HOME);
42         return current_url
43     end
45     return url
46 end
49 # Called when the user decides to load some document by following a link,
50 # entering an URL in the goto URL dialog, loading frames from a frameset (?)
51 # etc.
53 # Arguments:
54 # @url          the URL being followed.
56 # Returns the URL to be followed. Return nil to use the @url argument as is.
58 def ELinks::follow_url_hook(url)
59     return url
60 end
63 # Called when a HTML document has been loaded - before the document rendering
64 # begins. Makes it possible to fix up bad HTML code, remove tags etc.
66 # Arguments:
67 # @url          the URL of the document being loaded.
68 # @html         the source of the document being loaded.
70 # Returns the preformatted source of the document. Return nil to leave the
71 # document source untouched.
73 def ELinks::pre_format_html_hook(url, html)
74     if url.grep("fvwm.lair.be\/(index|viewforum)*.\.php")
75         # I don't like the fact that the <img> tags provide labels as
76         # well as span classes.  So we'll remove them.
77         html.gsub!(/(<img src.*\"No new posts\".*\>)/,"<font color=\"green\">No New Posts</font></td>")
78         html.gsub!(/(<img src.*\"New posts\".*\>)/,"<font color=\"red\">New Posts</font></td>")
79         html.gsub!(/<td><span class=\"gensmall\">([nN]o)|[Nn]ew posts\<\/span\>\<\/td\>/,"<td></td>")
80     end
81     return html
82 end
85 # Determining what proxy, if any, should be used to load a requested URL.
87 # Arguments:
88 # @url          the URL to be proxied.
90 # The hook should return one of the following:
91 # 1. "<host>:<port>" - to use the specified host and port
92 # 2. ""              - to not use any proxy
93 # 3. nil             - to use the default proxies
95 def ELinks::proxy_hook(url)
96     return nil
97 end
100 # Called when ELinks quits and can be used to do required clean-ups like
101 # removing any temporary files created by the hooks.
103 def ELinks::quit_hook