File: query.cgi

package info (click to toggle)
libwebapp-ruby 0.4-2.1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 240 kB
  • sloc: ruby: 2,245; makefile: 79
file content (50 lines) | stat: -rwxr-xr-x 1,195 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env ruby

require 'webapp'
require 'pathname'

Template = <<'End'
<html>
  <head>
    <title>query sample</title>
  </head>
  <body>
    <form _attr_action="webapp.make_relative_uri">
      Menu:
      <select name=menu multiple>
        <option selected>mizuyoukan</option>
        <option>anmitsu</option>
        <option>azukiyose</option>
      </select>
      <input type=hidden name=form_submitted value=yes>
      <input type=submit>
    </form>
    <hr>
    <p>
      Since WebApp#validate_html_query validates a query
      according to a given form,
      impossible query such as <a _attr_href="webapp.make_relative_uri(:query=>{'menu'=>'kusaya'})">kusaya</a> is
      ignored because WebApp#validate_html_query raises
      WebApp::QueryValidationFailure exception.
    </p>
    <div _if="q">
      <hr>
      <table border=1>
        <tr><th>name<th>value</tr>
        <tr _iter="q.each//key,val">
          <td _text=key>key<td _text=val>val</tr>
      </table>
    </div>
  </body>
</html>
End

WebApp {|webapp|
  begin
    q = webapp.validate_html_query(Template)
  rescue WebApp::QueryValidationFailure
    q = nil
  end

  HTree.expand_template(webapp) {Template}
}