List for cgit developers and users
 help / color / mirror / Atom feed
From: tim.nordell at logicpd.com (Tim Nordell)
Subject: [PATCH 1/3] ui-repolist: Add section filter
Date: Fri, 26 Feb 2016 14:58:57 -0600	[thread overview]
Message-ID: <1456520339-32708-2-git-send-email-tim.nordell@logicpd.com> (raw)
In-Reply-To: <1456520339-32708-1-git-send-email-tim.nordell@logicpd.com>

This allows custom links to be added into the section headers by
configuring a filter to be applied in the repository list.

Signed-off-by: Tim Nordell <tim.nordell at logicpd.com>

 create mode 100644 filters/section-example.lua

diff --git a/cgit.c b/cgit.c
index 87ba811..7dac332 100644
--- a/cgit.c
+++ b/cgit.c
@@ -234,6 +234,8 @@ static void config_cb(const char *name, const char *value)
 		ctx.cfg.email_filter = cgit_new_filter(value, EMAIL);
 	else if (!strcmp(name, "owner-filter"))
 		ctx.cfg.owner_filter = cgit_new_filter(value, OWNER);
+	else if (!strcmp(name, "section-filter"))
+		ctx.cfg.section_filter = cgit_new_filter(value, SECTION);
 	else if (!strcmp(name, "auth-filter"))
 		ctx.cfg.auth_filter = cgit_new_filter(value, AUTH);
 	else if (!strcmp(name, "embedded"))
diff --git a/cgit.h b/cgit.h
index b2b2ae9..f0ac36b 100644
--- a/cgit.h
+++ b/cgit.h
@@ -55,7 +55,7 @@ typedef enum {
 } diff_type;
 
 typedef enum {
-	ABOUT, COMMIT, SOURCE, EMAIL, AUTH, OWNER
+	ABOUT, COMMIT, SOURCE, EMAIL, AUTH, OWNER, SECTION
 } filter_type;
 
 struct cgit_filter {
@@ -272,6 +272,7 @@ struct cgit_config {
 	struct cgit_filter *source_filter;
 	struct cgit_filter *email_filter;
 	struct cgit_filter *owner_filter;
+	struct cgit_filter *section_filter;
 	struct cgit_filter *auth_filter;
 };
 
diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 3bca0ab..113b7a0 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -404,6 +404,13 @@ section::
 	after this option will inherit the current section name. Default value:
 	none.
 
+section-filter::
+	Specifies a command which will be invoked to format section headings.
+	The command will get the section on its STDIN, and the STDOUT from the
+	command will be included verbatim as the section heading.
+	Default value: none.
+	See also: "FILTER API".
+
 section-sort::
 	Flag which, when set to "1", will sort the sections on the repository
 	listing by name. Set this flag to "0" if the order in the cgitrc file should
@@ -695,6 +702,11 @@ owner filter::
 	standard input and the filter is expected to write to standard
 	output.  The output is included in the Owner column.
 
+section filter::
+	This filter is given no arguments.  The section text is avilable on
+	standard input and the filter is expected to write to standard
+	output.  The output is included in the section heading.
+
 source filter::
 	This filter is given a single parameter: the filename of the source
 	file to filter. The filter can use the filename to determine (for
diff --git a/filter.c b/filter.c
index 949c931..952336f 100644
--- a/filter.c
+++ b/filter.c
@@ -436,6 +436,7 @@ struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype)
 			argument_count = 1;
 			break;
 
+		case SECTION:
 		case COMMIT:
 		default:
 			argument_count = 0;
diff --git a/filters/section-example.lua b/filters/section-example.lua
new file mode 100644
index 0000000..76076b2
--- /dev/null
+++ b/filters/section-example.lua
@@ -0,0 +1,33 @@
+-- This script is an example of an section-filter.  It replaces the
+-- section title with several links for each subdirectory represented
+-- within the section title.  (It's intended to be used where the section
+-- title is also the same as the path to the repository, similar to
+-- the output from the "section-from-path" option.)  This script may
+-- be used with the section-filter setting in cgitrc with the `lua:`
+-- prefix.
+
+function gen_link(name, path)
+end
+
+function filter_open()
+	buffer = ""
+end
+
+function filter_close()
+	path = "/"
+	cnt = 0
+	for i in string.gmatch(buffer, "[^/]+") do
+		if cnt > 0 then
+			html("/")
+		end
+		path = path .. i .. "/"
+		html(string.format("<a href=\"%s%s\" class=reposection>%s</a>",
+			os.getenv("SCRIPT_NAME"), path, i))
+		cnt = cnt + 1
+	end
+	return 0
+end
+
+function filter_write(str)
+	buffer = buffer .. str
+end
diff --git a/ui-repolist.c b/ui-repolist.c
index 30915df..7af77e0 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -322,7 +322,11 @@ void cgit_print_repolist(void)
 		     strcmp(section, last_section)))) {
 			htmlf("<tr class='nohover'><td colspan='%d' class='reposection'>",
 			      columns);
+			if (ctx.cfg.section_filter)
+				cgit_open_filter(ctx.cfg.section_filter);
 			html_txt(section);
+			if (ctx.cfg.section_filter)
+				cgit_close_filter(ctx.cfg.section_filter);
 			html("</td></tr>");
 			last_section = section;
 		}
-- 
2.4.9



  reply	other threads:[~2016-02-26 20:58 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-26 20:58 [PATCH 0/3] ui-repolist: Support additional formatting for sections tim.nordell
2016-02-26 20:58 ` tim.nordell [this message]
2016-02-28 12:51   ` [PATCH 1/3] ui-repolist: Add section filter john
2016-02-26 20:58 ` [PATCH 2/3] ui-repolist: Restructure internal logic to be more extensible tim.nordell
2016-02-28 13:02   ` john
2016-02-29 20:51     ` tim.nordell
2016-02-26 20:58 ` [PATCH 3/3] ui-repolist: Support a trimmed view when several sections are present tim.nordell
2016-03-04 23:24 ` [PATCH v2 0/8] ui-repolist: Support additional formatting for sections tim.nordell
2016-03-04 23:24   ` [PATCH v2 1/8] ui-repolist: Add section filter tim.nordell
2016-03-04 23:24   ` [PATCH v2 2/8] ui-repolist: Remove conditional around print_header() tim.nordell
2016-03-04 23:24   ` [PATCH v2 3/8] ui-repolist: Create context structure for cgit_print_repolist() tim.nordell
2016-03-04 23:24   ` [PATCH v2 4/8] ui-repolist: Move HTML generation into helper functions tim.nordell
2016-03-04 23:29   ` [PATCH v2 5/8] ui-repolist: Factor out logic for emitting a new section heading tim.nordell
2016-03-04 23:30   ` [PATCH v2 6/8] ui-repolist: Remove assignment of section to repolist_ctx tim.nordell
2016-03-04 23:30   ` [PATCH v2 7/8] ui-repolist: Restructure internal logic to be more extensible tim.nordell
2016-03-04 23:30   ` [PATCH v2 8/8] ui-repolist: Support a trimmed view when several sections are present tim.nordell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1456520339-32708-2-git-send-email-tim.nordell@logicpd.com \
    --to=cgit@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).