Newer
Older
2019-madoka / root / textcode.rb
@mamadoka mamadoka on 5 Nov 2019 1 KB create CGI textform
#!/usr/bin/env ruby
# coding: utf-8

require'cgi'
require'open3'
c = CGI.new(:accept_charset => "UTF-8")

print"Content-type: text/html; charset=utf-8\n\n"

coderead = c["example"]

cmd = "ruby -e '#{coderead}'"
o,e,s = Open3.capture3(cmd) #o,e,s = 実行結果、エラー文、プロセス?

print <<EOF
<DOCTYPE html>
  <head> 
    <meta charset=utf-8>
    <title>テキストエディタ読み込み</title>
    <link rel="stylesheet" type="text/css" href="root/editor.css">
    <style>
<!--
-->
    </style>
  </head>
  <body>
EOF


puts("<h1>入力したコード</h1>")
printf("<textarea name=\"example\" readonly=\"readonly\">%s</textarea>", coderead)


puts("<h1>実行結果</h1>")
puts("<div>")
printf("<pre>%s<pre>", o) #evalでRubyコードとして読み込む
puts("</div>")


if e == ""  
  puts("<h2>エラー文はありません!!おめでとう!!</h2>")
else
    puts("<h2>エラー文</h2>")
    printf("<p>%s</p>\n", e) 
end

puts("<a href=\"/editor.rb\">戻る</a>")
puts("</body>\n</html>")