List for cgit developers and users
 help / color / mirror / Atom feed
* Adding Filter Types to cgit [was: RFE: .so filters]
@ 2014-01-12 22:26 Jason
  2014-01-13  0:12 ` Jason
  0 siblings, 1 reply; 5+ messages in thread
From: Jason @ 2014-01-12 22:26 UTC (permalink / raw)


On Fri, Jan 10, 2014 at 6:20 PM, John Keeping <john at keeping.me.uk> wrote:
> I would have no problem including LuaJIT for this sort of thing.
> I might have a look at the Lua case over the weekend if no one beats me
> to it.

John, Florian --

The infrastructure should be just about complete now, if either of you
want to have a stab at adding Lua (or any other type) of plugin.

The steps are basically as follows:

1) Add documentation in the FILTER API section of cgitrc.5.txt
2) Add a prefix and a new_${type}_filter function in filter_specs in filter.c
3) Add a struct to filter.c called ${type}_filter whose first member
is "struct cgit_filter base".
4) Implement open_${type}_filter(), close_${type}_filter(), and
fprintf_${type}_filter(), and optionally cleanup_${type}_filter(), and
optionally call hook_write() and unhook_write(), depending on needs,
in filter.c.

The basic design of a long-lived filter, that needs to do things over
the course of several opens and closes should be:

1) In new_${type}_filter, make any allocations and setup of the
initial struct, but nothing too heavy weight, in case the filter is
never actually used on that cgit.cgi invocation.
2) In open_${type}_filter, construct any long lived processes or
allocations, if they have not already been done so. Call hook_write()
to a write_${type}_filter function. Then pass on a "filter_open(argv)"
event to the underlying filter engine.
3) In write_${type}_filter, pass on the written buffer and the length
to the underlying filter engine in a "filter_write(data, len)" event.
4) In close_${type}_filter, pass on a "filter_close()" event to the
underlying filter engine. Then call unhook_write().
5) In cleanup_${type}_filter(), deallocate and deconstruct whatever
was initialized on the first invocation to open_${type}_filter, and on
the initial construction of the object in new_${type}_filter.
6) In fprintf_${type}_filter(), reconstruct whatever deconstructed
information might have been originally taken from the configuration
line.


How does this general setup sound?

Jason


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Adding Filter Types to cgit [was: RFE: .so filters]
  2014-01-12 22:26 Adding Filter Types to cgit [was: RFE: .so filters] Jason
@ 2014-01-13  0:12 ` Jason
  2014-01-13  1:14   ` Jason
  0 siblings, 1 reply; 5+ messages in thread
From: Jason @ 2014-01-13  0:12 UTC (permalink / raw)


Welp, I've gotten to work implementing it myself. Will post status soon.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Adding Filter Types to cgit [was: RFE: .so filters]
  2014-01-13  0:12 ` Jason
@ 2014-01-13  1:14   ` Jason
  2014-01-13  2:51     ` Jason
  0 siblings, 1 reply; 5+ messages in thread
From: Jason @ 2014-01-13  1:14 UTC (permalink / raw)


Initial version committed to jd-jk/filter-infra!


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Adding Filter Types to cgit [was: RFE: .so filters]
  2014-01-13  1:14   ` Jason
@ 2014-01-13  2:51     ` Jason
  2014-01-13  3:53       ` Jason
  0 siblings, 1 reply; 5+ messages in thread
From: Jason @ 2014-01-13  2:51 UTC (permalink / raw)


This commit filter works for reversing commit messages:

buffer = ""

function filter_open()
        buffer = ""
end

function filter_close()
        html(string.reverse(buffer))
end

function filter_write(str)
        buffer = buffer .. str
end


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Adding Filter Types to cgit [was: RFE: .so filters]
  2014-01-13  2:51     ` Jason
@ 2014-01-13  3:53       ` Jason
  0 siblings, 0 replies; 5+ messages in thread
From: Jason @ 2014-01-13  3:53 UTC (permalink / raw)


zx2c4 at thinkpad ~/Projects/cgit/filters $ cat email-gravatar.lua
-- This script may be used with the email-filter or repo.email-filter
settings in cgitrc.
-- It adds gravatar icons to author names. It is designed to be used
with the lua:
-- prefix in filters. It is much faster than the corresponding python script.
--
-- Requirements:
--      luacrypto >= 0.3
--      <http://mkottman.github.io/luacrypto/>
--

require("crypto")

function filter_open(email)
        buffer = ""
        md5 = crypto.digest("md5", email:sub(2, -2):lower())
end

function filter_close()
        html("<img src='//www.gravatar.com/avatar/" .. md5 ..
"?s=16&d=retro' style='height:10pt;width:10pt'> " .. buffer)
end

function filter_write(str)
        buffer = buffer .. str
end


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-01-13  3:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-12 22:26 Adding Filter Types to cgit [was: RFE: .so filters] Jason
2014-01-13  0:12 ` Jason
2014-01-13  1:14   ` Jason
2014-01-13  2:51     ` Jason
2014-01-13  3:53       ` Jason

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).