paste

werc .tpl file to paste github raw content

Mirrored from GitHub

git clone https://github.com/christc4/paste.git

Jump to: README.md app.rc catn2 foot.tpl


README.md

# paste

werc pastebin app

bugs:

- 200 line limit
- unable to open raw content 

catn2 is a RC script that prints line numbers enclosed in span tag, for CSS you must add

`span{user-select:none}`

core taken from <https://contrib.9front.org/sl/www/werc/sites/contrib.9front.org/sl/www/werc/apps/paste/app.rc>

example at <https://bauherren.ovh/paste/>

app.rc

fn conf_enable_wercpaste {
	paste_url=$conf_wd
	paste_dir=`{pwd}^/_werc/src 
	conf_enable_app wercpaste
    ll_add handlers_body_foot template apps/paste/foot.tpl

}

fn wercpaste_init {
	if (~ $REQUEST_METHOD POST && ~ $post_arg_url url && ~ $req_path $paste_url ) { # incoming paste 
		now=`{ date -n }
		if (~ $cksum '1715a8eb' ) { # empty paste; discard
			post_redirect $base_url^$paste_url
		}
		if not {  # save and redirect
			echo $"post_arg_paste > $paste_dir^/^$now
			post_redirect $base_url^$paste_url^$now
		}
	} 
	if not { # show a paste if there is one
		if (test -r $werc_root/$local_path && ~ $QUERY_STRING raw ) { 
				echo 'Content-type: text/plain; charset=UTF-8'; echo ''; exec cat $werc_root/$local_path
			} 
	}

	if (~ $REQUEST_METHOD GET ) { handler_body_main='begforpaste' }

}

fn begforpaste {
	echo '
	<h3>pastebin</h3>
	<form action="'$paste_url'" method="post">
	<textarea name="paste" cols="80" rows="15" required></textarea><br>
	<input type="submit" name="submit" value=Submit>
	<span style="display: none"><input type="text" name="url" value="url"> (do not change) </span>
	</form>
	'
}

catn2

#!/bin/rc

switch($#*) {
case 0
	awk '{printf("<span>%d</span>\t%s\n",NR,$0)}'
case 1 
	awk '{printf("<span>%d</span>\t%s\n",NR,$0)}' < $1
case *
	echo 'usage: catn file' >[1=2]
	echo '       catn < file' >[1=2]
	echo '       cat file | catn' >[1=2]
}

foot.tpl

% for (file in `{ls -r $paste_dir/*}) {
% link=`{echo $file | sed 's|/var/www/werc/sites/bauherren.ovh/paste/_werc/src/||g' }
<code><h3><a href=/paste/#%($"link%) class=pasteLink>%($"link%)</a></h3></code>
<pre id=%($"link%)>
%  cat $file | escape_html | catn2 
</pre><br>
% }