Skip to content

Commit

Permalink
Merge pull request #338 from b4n/geniuspaste/customizable
Browse files Browse the repository at this point in the history
[GeniusPaste] Rewrite to make pastebins customizable
  • Loading branch information
frlan committed Feb 21, 2016
2 parents 3ffb00f + a459a19 commit 79fc1fa
Show file tree
Hide file tree
Showing 13 changed files with 1,045 additions and 227 deletions.
1 change: 1 addition & 0 deletions build/geniuspaste.m4
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ AC_DEFUN([GP_CHECK_GENIUSPASTE],
AC_CONFIG_FILES([
geniuspaste/Makefile
geniuspaste/data/Makefile
geniuspaste/src/Makefile
])
])
2 changes: 1 addition & 1 deletion geniuspaste/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include $(top_srcdir)/build/vars.auxfiles.mk

SUBDIRS = src
SUBDIRS = data src
plugin = geniuspaste
116 changes: 109 additions & 7 deletions geniuspaste/README
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,143 @@ GeniusPaste Plugin

About
-----
This plugin allows the user to paste the code from Geany into five different
pastebins. At the moment it supports this services:
This plugin allows the user to paste code from Geany into a configured
pastebin service. At the moment it ships with builtin support these pastebin
services, but more can be added:

* codepad.org
* tinypaste.com
* pastebin.geany.org
* dpaste.de
* sprunge.us

GeniusPaste detects automatically the syntax of the code and paste it
GeniusPaste detects automatically the syntax of the code and pastes it
with syntax highlighting enabled.
It can also display the pasted code opening a new browser tab.

Issues
------
The API of the pastebin services can be updated in every moment. It
The API of the pastebin services can be updated at every moment. It
may happen that GeniusPaste plugin could use an outdated API that meanwhile
has been deprecated.

If you get a unexpected API response during the paste process (practically
if the plugin doesn't return a link to the pasted code) write a email to me
and warn me about the changes:
if the plugin doesn't return a link to the pasted code), you will need to fix
that pastebin service configuration to use its new API. If it is a
configuration shipped with the plugin, please report the issue to:

<enrico(dot)trt(at)gmail(dot)com>

Requirements
------------
* GTK+ >= 2.12
* libsoup 2.4 >= 2.4.0

Installation
------------
This plugin is part of the geany-plugins project.
See the README file of that package.

Pastebin configuration
----------------------

Configuration for the pastebin services is looked up in one of data directories
as follows, in order: ``$GEANY_CONFIG_DIR/plugins/geniuspaste/pastebins/`` and
``$PREFIX/share/geany-plugins/geniuspaste/pastebins/`` (where
``$GEANY_CONFIG_DIR`` is ``$HOME/.config/geany`` on \*NIX; and ``$PREFIX`` is
generally either ``/usr/`` or ``/usr/local/`` under \*NIX).

If more than one configuration file declare a pastebin service of the same
name, only the first one found is used. This way, one can easily override the
configuration in a system directory with a custom one in a user directory.

Format
^^^^^^

The pastebin configuration format uses an INI-style syntax.

Placeholders
++++++++++++

Values from the `[format] section`_ and the *replace* key in the `[parse]
section`_ can contain references to placeholders with the syntax ``%name%``
(i.e. ``%contents%``).
Custom placeholders can be defined in the `[defaults] section`_.

The builtin placeholders are:

*contents*
The data to actually paste.
*language*
The language of the current document, as mapped through the `[languages]
section`_.
*title*
The base name of the current document.
*user*
The configured author name.

*[pastebin]* section
++++++++++++++++++++

The *pastebin* section is required, and must contain at least the *name* and
*url* keys.

*name*
The name of the pastebin service, as displayed to the user. This key is
required.
*url*
The URL to which submit the data. This key is required.
*method*
The HTTP method to use to submit the data. Defaults to ``POST``.

*[format]* section
++++++++++++++++++

The *format* section describes the fields of the form to send to the pastebin.
Each key in this section is a field, and each value that field's value.

*[parse]* section
+++++++++++++++++

If the *parse* section is declared, it defines the regular expression used to
parse the raw response body from the pastebin service and build the final
paste URL.

If this section doesn't exist, the URI of the response itself is used, after
any possible redirection. This is usually good for non-API pastebin services,
where the server redirects the user to the paste page.

**Warning:** If the *parse* section exists, it will be used, no matter whether
any key is actually defined. This means that a ``[parse]`` line is enough to
enable response body parsing, and it will use the default *search* and
*replace* settings.

*search*
A regular expression (PCRE) pattern to match against the pastebin
service's raw response data.
Defaults to ``^[[:space:]]*(.+?)[[:space:]]*$``, e.g. capture everything
but the leading and trailing whitespaces.
*replace*
The final URL, with regular expression capture groups from *search*
expanded. Group references use the numeric, one-digit syntax: ``\0``
refers to the whole matched text, ``\1`` to the first captured group, and
so on. Defaults to ``\1``, which works nicely with the default *search*
pattern.

*[defaults]* section
++++++++++++++++++++

The *defaults* section defines default values for some builtin `placeholders`_
or define new placeholders.

*[languages]* section
+++++++++++++++++++++

The *languages* section maps Geany's filetype names (the keys) to the pastebin
service's own name for this language. This allows to translate the filetypes
Geany knows about to ones the pastebin service understands.


License
-------
GeniusPaste is distributed under the terms of the GNU General Public
Expand Down
12 changes: 12 additions & 0 deletions geniuspaste/data/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
include $(top_srcdir)/build/vars.docs.mk
plugin = geniuspaste

pastebinsdir = $(plugindatadir)/pastebins
dist_pastebins_DATA = \
codepad.org.conf \
dpaste.de.conf \
fpaste.org.conf \
pastebin.geany.org.conf \
paste.debian.net.conf \
sprunge.us.conf \
tinypaste.com.conf
30 changes: 30 additions & 0 deletions geniuspaste/data/codepad.org.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[pastebin]
name=codepad.org
url=http://codepad.org/

[defaults]
language=Plain Text

[format]
lang=%language%
code=%contents%
submit=Submit
#private=False
#run=True

# map GeanyFileType=PastebinFileType
[languages]
# as of 2016-01-15
None=Plain Text
C=C
C++=C++
D=D
Haskell=Haskell
Lua=Lua
CAML=OCaml
PHP=PHP
Perl=Perl
Python=Python
Ruby=Ruby
Scheme=Scheme
Tcl=Tcl
64 changes: 64 additions & 0 deletions geniuspaste/data/dpaste.de.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[pastebin]
name=dpaste.de
url=http://dpaste.de/api/

[format]
title=%title%
content=%contents%
lexer=%language%
#expires=%expire%

[parse]
search=^"(.+)"$
replace=\1

[defaults]
# default language to plain which means "Code"
language=plain
expire=604800

# map GeanyFileType=PastebinFileType
[languages]
# list as of 2016-01-14
None=text
ActionScript=as
C=c
# better than nothing
C++=c
#CAML=ocaml
Clojure=clojure
COBOL=cobol
Conf=ini
CSS=css
CUDA=cuda
Diff=diff
Docbook=xml
Erlang=erlang
F77=fortran
Fortran=fortran
GLSL=C
Go=go
Haskell=haskell
HTML=html
Java=java
Javascript=js
JSON=json
LaTeX=tex
Lua=lua
Make=make
Matlab/Octave=matlab
Objective-C=objc
Perl=perl
PHP=php
PowerShell=powershell
Python=python
reStructuredText=rst
Ruby=rb
Rust=rust
Scala=scala
Sh=bash
SQL=sql
Tcl=tcl
XML=xml
YAML=yaml
Zephir=php
67 changes: 67 additions & 0 deletions geniuspaste/data/fpaste.org.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[pastebin]
name=fpaste.org
url=http://fpaste.org/

[format]
paste_data=%contents%
paste_lang=%language%
api_submit=true
mode=xml

# Optional stuff

paste_user=%user%
# expiration in seconds
#paste_expire=0

[parse]
search=<id>(.+?)</id>
replace=http://fpaste.org/\1

# map GeanyFileType=PastebinFileType
[languages]
# map for GeSHi 2015-01-14
ActionScript=Actionscript
Ada=ADA
ASM=ASM
C=C
C#=C#
C++=C++
COBOL=COBOL
Conf=INI
CSS=CSS
CUDA=C
Cython=Python
D=D
Diff=Diff
Docbook=XML
F77=Fortran
Fortran=Fortran
FreeBasic=FreeBasic
GLSL=C
Haskell=Haskell
HTML=HTML
Java=Java
Javascript=Javascript
JSON=Javascript
LaTeX=LaTeX
Lisp=Lisp
Lua=Lua
Make=Make
NSIS=NSIS
Objective-C=Objective-C
Pascal=Pascal
Perl=Perl
PHP=PHP
Po=GetText
PowerShell=PowerShell
Prolog=Prolog
Python=Python
Ruby=Ruby
Scala=Scala
Sh=Bash
SQL=SQL
Tcl=TCL
Verilog=Verilog
VHDL=VHDL
XML=XML
Loading

0 comments on commit 79fc1fa

Please sign in to comment.