From 616a164baff9601c46b3e048c54e0b25c0ab7c02 Mon Sep 17 00:00:00 2001 From: dvkt Date: Mon, 6 Jan 2020 11:35:19 -0800 Subject: [PATCH] ruby example --- README.md | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dd38501..9efd4bd 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ sub-directories, and binary files over gopher. any `.gph` files will be served up as [gopermaps][map] and executable `.gph` files will be run as a script with their output served to the client, like cgi! -special files: +### special files: - **header.gph**: if it exists in a directory, its content will be shown above the directory's content. put ascii art in it. @@ -33,6 +33,8 @@ any line in a `.gph` file that doesn't contain tabs (`\t`) and doesn't start with an `i` will get an `i` automatically prefixed, turning it into a gopher information item. +### dynamic content: + any `.gph` file that is marked **executable** with be run as if it were a shell script and its output will be sent to the client. it will be passed three arguments: the query string (if any, the host, and the @@ -67,6 +69,40 @@ then: [INFO] |_| |_|_| \__, |\___/| .__/|_| |_|\___|_| [INFO] |___/ |_| +### ruby on rails: + +`sh` is fun, but for serious work you need a serious scripting +language like Ruby or PHP or Node.JS: + + $ cat sizes.gph + #!/usr/bin/env ruby + + def filesize(file) + (size=File.size file) > (k=1024) ? "#{size/k}K" : "#{size}B" + end + + puts "~ file sizes ~" + spaces = 20 + Dir[__dir__ + "/*"].each do |entry| + name = File.basename entry + puts "#{name}#{' ' * (spaces - name.length)}#{filesize entry}" + end + +now you can finally share the file sizes of a directory with the world +of Gopher! + + $ phetch -r 0.0.0.0:7070/1/sizes + i~ file sizes ~ (null) 127.0.0.1 7070 + iCargo.toml 731B (null) 127.0.0.1 7070 + iLICENSE 1K (null) 127.0.0.1 7070 + iMakefile 724B (null) 127.0.0.1 7070 + itarget 288B (null) 127.0.0.1 7070 + iphd 248K (null) 127.0.0.1 7070 + iCargo.lock 2K (null) 127.0.0.1 7070 + iREADME.md 4K (null) 127.0.0.1 7070 + img 96B (null) 127.0.0.1 7070 + isizes.gph 276B (null) 127.0.0.1 7070 + isrc 224B (null) 127.0.0.1 7070 ## usage