[yelp/41-settings-revamp] Make help list use XSLT
- From: Shaun McCance <shaunm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [yelp/41-settings-revamp] Make help list use XSLT
- Date: Sat, 24 Jul 2021 15:00:55 +0000 (UTC)
commit 248359857ed254e61c4aa6e49ece183042b918c6
Author: Shaun McCance <shaunm gnome org>
Date: Sat Jul 24 11:00:27 2021 -0400
Make help list use XSLT
Makefile.am | 1 +
configure.ac | 6 +-
data/xslt/info2html.xsl.in | 1 +
data/xslt/links2html.xsl.in | 97 ++++++++++++++++++++
data/xslt/man2html.xsl.in | 1 +
libyelp/yelp-help-list.c | 217 +++++++++++++-------------------------------
6 files changed, 170 insertions(+), 153 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 4551da42..51d9e74c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -691,6 +691,7 @@ xsldir = $(pkgdatadir)/xslt
xsl_DATA = \
data/xslt/db2html.xsl \
data/xslt/info2html.xsl \
+ data/xslt/links2html.xsl \
data/xslt/mal2html.xsl \
data/xslt/man2html.xsl \
data/xslt/yelp-common.xsl
diff --git a/configure.ac b/configure.ac
index 89244242..d9b3211b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -35,7 +35,7 @@ PKG_CHECK_MODULES(YELP,
libexslt >= 0.8.1
sqlite3
webkit2gtk-4.0 >= 2.19.2
- yelp-xsl >= 3.27.1
+ yelp-xsl >= 40.0
])
AC_SUBST([YELP_CFLAGS])
AC_SUBST([YELP_LIBS])
@@ -136,6 +136,9 @@ XSL_ICONS="`$PKG_CONFIG --variable=xsltdir yelp-xsl`/common/icons.xsl"
AC_SUBST(XSL_ICONS)
XSL_HTML="`$PKG_CONFIG --variable=xsltdir yelp-xsl`/common/html.xsl"
AC_SUBST(XSL_HTML)
+XSL_TMPL="`$PKG_CONFIG --variable=xsltdir yelp-xsl`/common/tmpl.xsl"
+AC_SUBST(XSL_TMPL)
+
XSL_JSDIR="`$PKG_CONFIG --variable=jsdir yelp-xsl`"
AC_SUBST(XSL_JSDIR)
@@ -159,6 +162,7 @@ docs/libyelp/version.xml
data/dtd/catalog
data/xslt/db2html.xsl
data/xslt/info2html.xsl
+data/xslt/links2html.xsl
data/xslt/mal2html.xsl
data/xslt/man2html.xsl
data/xslt/yelp-common.xsl
diff --git a/data/xslt/info2html.xsl.in b/data/xslt/info2html.xsl.in
index 34c1caa7..bb84ba60 100644
--- a/data/xslt/info2html.xsl.in
+++ b/data/xslt/info2html.xsl.in
@@ -10,6 +10,7 @@
<xsl:import href="@XSL_ICONS@"/>
<xsl:import href="@XSL_HTML@"/>
<xsl:import href="@XSL_GETTEXT@"/>
+<xsl:import href="@XSL_TMPL@"/>
<xsl:include href="yelp-common.xsl"/>
<xsl:template name="linktrails">
diff --git a/data/xslt/links2html.xsl.in b/data/xslt/links2html.xsl.in
new file mode 100644
index 00000000..e5b8c1d2
--- /dev/null
+++ b/data/xslt/links2html.xsl.in
@@ -0,0 +1,97 @@
+<?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- -->
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:yelp="http://www.gnome.org/yelp/ns"
+ xmlns="http://www.w3.org/1999/xhtml"
+ extension-element-prefixes="yelp"
+ version="1.0">
+
+<xsl:import href="@XSL_COLOR@"/>
+<xsl:import href="@XSL_ICONS@"/>
+<xsl:import href="@XSL_HTML@"/>
+<xsl:import href="@XSL_GETTEXT@"/>
+<xsl:import href="@XSL_TMPL@"/>
+<xsl:include href="yelp-common.xsl"/>
+
+<!-- copied from mal2html-page.xsl, not ideal -->
+<!-- We need this in the CSS, but the text templates can't xsl:call-template -->
+<xsl:variable name="_color.link_button_hover">
+ <xsl:call-template name="color.blend">
+ <xsl:with-param name="bg" select="$color.blue"/>
+ <xsl:with-param name="fg" select="$color.bg"/>
+ <xsl:with-param name="mix" select="0.1"/>
+ </xsl:call-template>
+</xsl:variable>
+
+<xsl:template match="/">
+ <xsl:for-each select="links">
+ <xsl:call-template name="html.output"/>
+ </xsl:for-each>
+</xsl:template>
+
+<xsl:template mode="html.title.mode" match="links">
+ <xsl:value-of select="title"/>
+</xsl:template>
+
+<xsl:template mode="html.css.mode" match="links">
+ <xsl:param name="direction">
+ <xsl:call-template name="l10n.direction"/>
+ </xsl:param>
+ <xsl:param name="left">
+ <xsl:call-template name="l10n.align.start">
+ <xsl:with-param name="direction" select="$direction"/>
+ </xsl:call-template>
+ </xsl:param>
+ <xsl:param name="right">
+ <xsl:call-template name="l10n.align.end">
+ <xsl:with-param name="direction" select="$direction"/>
+ </xsl:call-template>
+ </xsl:param>
+ <xsl:call-template name="tmpl.file">
+ <xsl:with-param name="file" select="'css/mallard.css.tmpl'"/>
+ <xsl:with-param name="node" select="."/>
+ <xsl:with-param name="direction" select="$direction"/>
+ <xsl:with-param name="left" select="$left"/>
+ <xsl:with-param name="right" select="$right"/>
+ </xsl:call-template>
+ <xsl:text>
+.ex-yelp-panel-icon {
+ display: flex;
+}
+ </xsl:text>
+</xsl:template>
+
+<xsl:template mode="html.body.mode" match="links">
+ <div class="hgroup pagewide">
+ <h1><span class="title"><xsl:value-of select="title"/></span></h1>
+ </div>
+ <div class="region">
+ <div class="contents pagewide">
+ <div class="links-divs">
+ <xsl:for-each select="link">
+ <div class="linkdiv">
+ <a class="linkdiv" href="{@href}" title="{title}">
+ <span style="display:flex;">
+ <span class="thumb" style="min-width:48px;padding-right:10px;">
+ <xsl:if test="thumb/@src != ''">
+ <img src="{thumb/@src}" width="48" height="48"/>
+ </xsl:if>
+ </span>
+ <span>
+ <span class="title">
+ <xsl:value-of select="title"/>
+ </span>
+ <span class="desc">
+ <xsl:value-of select="desc"/>
+ </span>
+ </span>
+ </span>
+ </a>
+ </div>
+ </xsl:for-each>
+ </div>
+ </div>
+ </div>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/data/xslt/man2html.xsl.in b/data/xslt/man2html.xsl.in
index cae7a3c7..676ce3eb 100644
--- a/data/xslt/man2html.xsl.in
+++ b/data/xslt/man2html.xsl.in
@@ -10,6 +10,7 @@
<xsl:import href="@XSL_ICONS@"/>
<xsl:import href="@XSL_HTML@"/>
<xsl:import href="@XSL_GETTEXT@"/>
+<xsl:import href="@XSL_TMPL@"/>
<xsl:include href="yelp-common.xsl"/>
<xsl:param name="html.basename" select="'//index'"/>
diff --git a/libyelp/yelp-help-list.c b/libyelp/yelp-help-list.c
index 7c21ab1f..9860d713 100644
--- a/libyelp/yelp-help-list.c
+++ b/libyelp/yelp-help-list.c
@@ -33,6 +33,9 @@
#include "yelp-help-list.h"
#include "yelp-settings.h"
+#include "yelp-transform.h"
+
+#define STYLESHEET DATADIR"/yelp/xslt/links2html.xsl"
typedef struct _HelpListEntry HelpListEntry;
@@ -96,6 +99,9 @@ struct _YelpHelpListPrivate {
GHashTable *entries;
GList *all_entries;
GSList *pending;
+ xmlDocPtr entriesdoc;
+
+ YelpTransform *transform;
xmlXPathCompExprPtr get_docbook_title;
xmlXPathCompExprPtr get_mallard_title;
@@ -154,6 +160,11 @@ yelp_help_list_finalize (GObject *object)
g_hash_table_destroy (priv->entries);
g_mutex_clear (&priv->mutex);
+ if (priv->entriesdoc) {
+ xmlFreeDoc (priv->entriesdoc);
+ priv->entriesdoc = NULL;
+ }
+
if (priv->get_docbook_title)
xmlXPathFreeCompExpr (priv->get_docbook_title);
if (priv->get_mallard_title)
@@ -161,6 +172,8 @@ yelp_help_list_finalize (GObject *object)
if (priv->get_mallard_desc)
xmlXPathFreeCompExpr (priv->get_mallard_desc);
+ g_clear_object (&priv->transform);
+
G_OBJECT_CLASS (yelp_help_list_parent_class)->finalize (object);
}
@@ -389,7 +402,12 @@ help_list_think (YelpHelpList *list)
else if (entry->type == YELP_URI_DOCUMENT_TYPE_DOCBOOK)
help_list_process_docbook (list, entry);
- tmp = g_strconcat (entryid, ".desktop", NULL);
+ if (g_str_equal (entryid, "gnome-terminal")) {
+ tmp = g_strconcat ("org.gnome.Terminal", ".desktop", NULL);
+ }
+ else {
+ tmp = g_strconcat (entryid, ".desktop", NULL);
+ }
app = g_desktop_app_info_new (tmp);
g_free (tmp);
@@ -407,9 +425,7 @@ help_list_think (YelpHelpList *list)
if (app != NULL) {
GIcon *icon = g_app_info_get_icon ((GAppInfo *) app);
if (icon != NULL) {
- GtkIconInfo *info = gtk_icon_theme_lookup_by_gicon (theme,
- icon, 22,
- GTK_ICON_LOOKUP_NO_SVG);
+ GtkIconInfo *info = gtk_icon_theme_lookup_by_gicon (theme, icon, 48, 0);
if (info != NULL) {
const gchar *iconfile = gtk_icon_info_get_filename (info);
if (iconfile)
@@ -435,167 +451,64 @@ help_list_think (YelpHelpList *list)
g_object_unref (list);
}
+
+static void
+transform_chunk_ready (YelpTransform *transform,
+ gchar *chunk_id,
+ YelpHelpList *list)
+{
+ gchar *content;
+ content = yelp_transform_take_chunk (transform, chunk_id);
+ yelp_document_give_contents (YELP_DOCUMENT (list),
+ chunk_id,
+ content,
+ "application/xhtml+xml");
+ yelp_document_signal (YELP_DOCUMENT (list),
+ chunk_id,
+ YELP_DOCUMENT_SIGNAL_CONTENTS,
+ NULL);
+}
+
+
/* This function expects to be called inside a locked mutex */
static void
help_list_handle_page (YelpHelpList *list,
const gchar *page_id)
{
- gchar **colors, *tmp;
- GList *cur;
YelpHelpListPrivate *priv = yelp_help_list_get_instance_private (list);
- GtkTextDirection direction = gtk_widget_get_default_direction ();
- GString *string = g_string_new
- ("<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><style type='text/css'>\n"
- "html { height: 100%; }\n"
- "body { margin: 0; padding: 0; max-width: 100%;");
- colors = yelp_settings_get_colors (yelp_settings_get_default ());
-
- tmp = g_markup_printf_escaped (" background-color: %s; color: %s;"
- " direction: %s; }\n",
- colors[YELP_SETTINGS_COLOR_BASE],
- colors[YELP_SETTINGS_COLOR_TEXT],
- (direction == GTK_TEXT_DIR_RTL) ? "rtl" : "ltr");
- g_string_append (string, tmp);
- g_free (tmp);
-
- g_string_append (string,
- "div.body { margin: 0 12px 0 12px; padding: 0;"
- " max-width: 60em; min-height: 20em; }\n"
- "div.header { max-width: 100%; width: 100%;"
- " padding: 0; margin: 0 0 1em 0; }\n"
- "div.footer { max-width: 60em; }\n"
- "div.sect { margin-top: 1.72em; }\n"
- "div.trails { margin: 0; padding: 0.2em 12px 0 12px;");
-
- tmp = g_markup_printf_escaped (" background-color: %s;"
- " border-bottom: solid 1px %s; }\n",
- colors[YELP_SETTINGS_COLOR_GRAY_BASE],
- colors[YELP_SETTINGS_COLOR_GRAY_BORDER]);
- g_string_append (string, tmp);
- g_free (tmp);
-
- g_string_append (string,
- "div.trail { margin: 0 1em 0.2em 1em; padding: 0; text-indent: -1em;");
-
- tmp = g_markup_printf_escaped (" color: %s; }\n",
- colors[YELP_SETTINGS_COLOR_TEXT_LIGHT]);
- g_string_append (string, tmp);
- g_free (tmp);
-
- g_string_append (string,
- "a.trail { white-space: nowrap; }\n"
- "div.hgroup { margin: 0 0 0.5em 0;");
-
- tmp = g_markup_printf_escaped (" color: %s;"
- " border-bottom: solid 1px %s; }\n",
- colors[YELP_SETTINGS_COLOR_TEXT_LIGHT],
- colors[YELP_SETTINGS_COLOR_GRAY_BORDER]);
- g_string_append (string, tmp);
- g_free (tmp);
-
- tmp = g_markup_printf_escaped ("div.title { margin: 0 0 0.2em 0; font-weight: bold; color: %s; }\n"
- "div.desc { margin: 0 0 0.2em 0; }\n"
- "div.linkdiv div.inner { padding-%s: 30px; min-height: 24px;"
- " background-position: top %s; background-repeat: no-repeat;"
- " -webkit-background-size: 22px 22px; }\n"
- "div.linkdiv div.title {font-size: 1em; color: inherit; }\n"
- "div.linkdiv div.desc { color: %s; }\n"
- "div.linkdiv { margin: 0; padding: 0.5em; }\n"
- "a:hover div.linkdiv {"
- " text-decoration: none;"
- " outline: solid 1px %s;"
- " background: -webkit-gradient(linear, left top, left 80,"
- " from(%s), to(%s)); }\n",
- colors[YELP_SETTINGS_COLOR_TEXT_LIGHT],
- ((direction == GTK_TEXT_DIR_RTL) ? "right" : "left"),
- ((direction == GTK_TEXT_DIR_RTL) ? "right" : "left"),
- colors[YELP_SETTINGS_COLOR_TEXT_LIGHT],
- colors[YELP_SETTINGS_COLOR_BLUE_BASE],
- colors[YELP_SETTINGS_COLOR_BLUE_BASE],
- colors[YELP_SETTINGS_COLOR_BASE]);
- g_string_append (string, tmp);
- g_free (tmp);
-
- g_string_append (string,
- "h1, h2, h3, h4, h5, h6, h7 { margin: 0; padding: 0; font-weight: bold; }\n"
- "h1 { font-size: 1.44em; }\n"
- "h2 { font-size: 1.2em; }"
- "h3.title, h4.title, h5.title, h6.title, h7.title { font-size: 1.2em; }"
- "h3, h4, h5, h6, h7 { font-size: 1em; }"
- "p { line-height: 1.72em; }"
- "div, pre, p { margin: 1em 0 0 0; padding: 0; }"
- "div:first-child, pre:first-child, p:first-child { margin-top: 0; }"
- "div.inner, div.contents, pre.contents { margin-top: 0; }"
- "p img { vertical-align: middle; }"
- "a {"
- " text-decoration: none;");
-
- tmp = g_markup_printf_escaped (" color: %s; } a:visited { color: %s; }",
- colors[YELP_SETTINGS_COLOR_LINK],
- colors[YELP_SETTINGS_COLOR_LINK_VISITED]);
- g_string_append (string, tmp);
- g_free (tmp);
-
- g_string_append (string,
- "a:hover { text-decoration: underline; }\n"
- "a img { border: none; }\n"
- "</style>\n");
-
- tmp = g_markup_printf_escaped ("<title>%s</title>",
- _("All Help Documents"));
- g_string_append (string, tmp);
- g_free (tmp);
-
- g_string_append (string,
- "</head><body>"
- "<div class='header'></div>"
- "<div class='body'><div class='hgroup'>");
- tmp = g_markup_printf_escaped ("<h1>%s</h1></div>\n",
- _("All Help Documents"));
- g_string_append (string, tmp);
- g_free (tmp);
+ xmlNodePtr rootnode;
+ GList *entrycur;
+ gchar **params = NULL;
+
+ priv->entriesdoc = xmlNewDoc (BAD_CAST "1.0");
+ rootnode = xmlNewDocNode (priv->entriesdoc, NULL, BAD_CAST "links", NULL);
+ xmlDocSetRootElement (priv->entriesdoc, rootnode);
+ xmlNewTextChild (rootnode, NULL, BAD_CAST "title", BAD_CAST _("All Help Documents"));
priv->all_entries = g_list_sort (priv->all_entries,
(GCompareFunc) help_list_entry_cmp);
- for (cur = priv->all_entries; cur != NULL; cur = cur->next) {
- HelpListEntry *entry = (HelpListEntry *) cur->data;
- gchar *title = entry->title ? entry->title : (strchr (entry->id, ':') + 1);
- const gchar *desc = entry->desc ? entry->desc : "";
+ for (entrycur = priv->all_entries; entrycur != NULL; entrycur = entrycur->next) {
+ xmlNodePtr linknode, curnode;
+ HelpListEntry *entry = (HelpListEntry *) entrycur->data;
+ linknode = xmlNewChild (rootnode, NULL, BAD_CAST "link", NULL);
+ xmlSetProp (linknode, BAD_CAST "href", BAD_CAST entry->id);
+ xmlNewTextChild (linknode, NULL, BAD_CAST "title", BAD_CAST entry->title);
+ xmlNewTextChild (linknode, NULL, BAD_CAST "desc", BAD_CAST entry->desc);
+ curnode = xmlNewChild (linknode, NULL, BAD_CAST "thumb", NULL);
+ xmlSetProp (curnode, BAD_CAST "src", BAD_CAST entry->icon);
+ }
- tmp = g_markup_printf_escaped ("<a href='%s'><div class='linkdiv'>",
- entry->id);
- g_string_append (string, tmp);
- g_free (tmp);
+ params = yelp_settings_get_all_params (yelp_settings_get_default (), 0, NULL);
+ priv->transform = yelp_transform_new (STYLESHEET);
- if (entry->icon) {
- tmp = g_markup_printf_escaped ("<div class='inner' style='background-image: url(%s);'>",
- entry->icon);
- g_string_append (string, tmp);
- g_free (tmp);
- }
- else
- g_string_append (string, "<div class='inner'>");
-
- tmp = g_markup_printf_escaped ("<div class='title'>%s</div>"
- "<div class='desc'>%s</div>"
- "</div></div></a>",
- title, desc);
- g_string_append (string, tmp);
- g_free (tmp);
- }
+ g_signal_connect (priv->transform, "chunk-ready",
+ (GCallback) transform_chunk_ready,
+ list);
- g_string_append (string,
- "</div>"
- "<div class='footer'></div>"
- "</body></html>");
+ yelp_transform_start (priv->transform, priv->entriesdoc, NULL,
+ (const gchar * const *) params);
- yelp_document_give_contents (YELP_DOCUMENT (list), page_id,
- string->str,
- "application/xhtml+xml");
- g_strfreev (colors);
- g_string_free (string, FALSE);
- yelp_document_signal (YELP_DOCUMENT (list), page_id,
- YELP_DOCUMENT_SIGNAL_CONTENTS, NULL);
+ g_strfreev (params);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]