emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/webpaste 6ea53d0 123/298: Added support for custom handler


From: ELPA Syncer
Subject: [nongnu] elpa/webpaste 6ea53d0 123/298: Added support for custom handler of how to build the post data for providers
Date: Thu, 9 Dec 2021 18:59:57 -0500 (EST)

branch: elpa/webpaste
commit 6ea53d0e67c1a11007e269752b3fdbeefc8eab6c
Author: Elis Axelsson <elis.axelsson@gmail.com>
Commit: Elis Axelsson <elis.axelsson@gmail.com>

    Added support for custom handler of how to build the post data for providers
---
 webpaste.el | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/webpaste.el b/webpaste.el
index 373b292..09cd686 100644
--- a/webpaste.el
+++ b/webpaste.el
@@ -91,6 +91,14 @@ each run.")
                     (replace-regexp-in-string "\n$" "" data)))))
   "Predefined success callback for providers returning a string with URL.")
 
+(defvar webpaste/providers-default-post-field-lambda
+  (lambda (text post-field post-data)
+    (cl-pushnew (cons post-field text) post-data)
+
+    post-data)
+  "Predefined lambda for building post fields.")
+
+
 
 
 (cl-defun webpaste-provider (&key uri
@@ -99,6 +107,7 @@ each run.")
                                   (post-data '())
                                   (sync nil)
                                   post-field
+                                  (post-field-lambda 
webpaste/providers-default-post-field-lambda)
                                   error-lambda
                                   success-lambda)
   "Function to create the lambda function for a provider.
@@ -115,6 +124,9 @@ Usage:
 :post-field     Name of the field to insert the code into.
 :sync           Set to t to wait until request is done.  Defaults to nil.  This
                 should only be used for debugging purposes.
+:post-field-lambda Function that builds and returns the post data that should 
be
+                   sent to the provider.  It should accept the parameter TEXT
+                   only which contains the content that should be sent.
 :success-lambda Callback sent to `request', look up how to write these in the
                 documentation for `request'.
 :error-lambda   Callback sent to `request', look up how to write these in the
@@ -126,13 +138,10 @@ Usage:
     "Paste TEXT to provider"
 
     (prog1 nil
-      ;; Local variable post-data
-      (cl-pushnew (cons post-field text) post-data)
-
       ;; Do request
       (request uri
                :type type
-               :data post-data
+               :data (funcall post-field-lambda text post-field post-data)
                :parser parser
                :success success-lambda
                :sync sync



reply via email to

[Prev in Thread] Current Thread [Next in Thread]