Skip to content

Commit

Permalink
Generate Markdown languages list snippet for "README.md"
Browse files Browse the repository at this point in the history
Generate "de.agilantis.language_pack/target/info.md":
Table of languages with their file associations snippet for "README.md".
  • Loading branch information
howlger committed Apr 28, 2022
1 parent bb38a31 commit 58efb88
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 64 deletions.
16 changes: 16 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@
<param name="temp-dir"
expression="${project.build.directory}/generated_temp/@{extension}/"/>
</xslt>
<xslt style="${project.basedir}/../transform_to_info_md_snippet.xsl"
in="${project.build.directory}/generated_temp/@{extension}/package.json.xml"
out="${project.build.directory}/generated_temp/@{extension}/info_md_snippet.md">
<param name="extension" expression="@{extension}"/>
<param name="info-file" expression="${project.basedir}/../info.xml"/>
<param name="temp-dir"
expression="${project.build.directory}/generated_temp/@{extension}/"/>
</xslt>
</sequential>
</sequential>
</macrodef>
Expand Down Expand Up @@ -263,6 +271,14 @@
</filterchain>
</copy>

<!-- info.md -->
<concat destfile="${project.build.directory}/info.md" encoding="UTF-8">
<fileset dir="${project.build.directory}/generated_temp"
includes="*/info_md_snippet.md">
<contains text=" | "/>
</fileset>
</concat>

</sequential>
</target>
</configuration>
Expand Down
63 changes: 63 additions & 0 deletions transform_commons.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@
<xsl:with-param name="path" select="substring($path, 2)"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="substring($path, 1, 1) = '('">
<xsl:text>%28</xsl:text>
<xsl:call-template name="encode">
<xsl:with-param name="path" select="substring($path, 2)"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="substring($path, 1, 1) = ')'">
<xsl:text>%29</xsl:text>
<xsl:call-template name="encode">
<xsl:with-param name="path" select="substring($path, 2)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring($path, 1, 1)"/>
<xsl:call-template name="encode">
Expand Down Expand Up @@ -60,4 +72,55 @@
</xsl:choose>
</xsl:template>

<!-- info -->
<xsl:template name="info">
<xsl:param name="extension"/>
<xsl:param name="info-file"/>
<xsl:param name="temp-dir"/>
<xsl:variable name="languages">
<xsl:for-each select="o/o[@name='contributes']/a[@name='languages']/o">
<xsl:variable name="language-id" select="e[@name='id']/@string"/>
<xsl:variable name="grammars-count"
select="count(/o/o[@name='contributes']/a[@name='grammars']
/o/e[@name='language'][@string=$language-id])"/>
<xsl:if test=" not(document($info-file)/info/extension[@id=$extension]/language[@issues or @ignore])
and $grammars-count > 0
and a[@name='extensions' or @name='filenames' or @name='filenamePatterns']">
<xsl:variable name="original-name" select="a[@name='aliases']/v[1]/@string"/>
<xsl:variable name="name">
<xsl:choose>
<xsl:when test="document($info-file)/info/extension[@id = $extension]
/language[@name = $original-name][@better-name]">
<xsl:value-of select="document($info-file)/info/extension[@id = $extension]
/language[@name = $original-name]/@better-name"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$original-name"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="file-associations">
<xsl:for-each select="a[@name='extensions']/v">
<xsl:value-of select="concat(', *', @string)"/>
</xsl:for-each>
<xsl:for-each select="a[@name='filenames' or @name='filenamePatterns']/v">
<xsl:value-of select="concat(', ', @string)"/>
</xsl:for-each>
</xsl:variable>
<language name="{$name}" file-associations="{substring($file-associations, 3)}">
<xsl:if test="not(document(concat($temp-dir, e[@name='id']/@string, '_href.xml'))/href/@text = '')">
<xsl:attribute name="href">
<xsl:call-template name="encode">
<xsl:with-param name="path"
select="document(concat($temp-dir, e[@name='id']/@string, '_href.xml'))/href/text()"/>
</xsl:call-template>
</xsl:attribute>
</xsl:if>
</language>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:apply-templates select="exsl:node-set($languages)/language" mode="info-language"/>
</xsl:template>

</xsl:stylesheet>
90 changes: 26 additions & 64 deletions transform_to_info_html_snippet.xsl
Original file line number Diff line number Diff line change
@@ -1,77 +1,39 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common" exclude-result-prefixes="exsl">
<xsl:import href="transform_commons.xsl"/>
<xsl:output method="html" omit-xml-declaration="yes" indent="yes"/>

<!-- parameters -->
<xsl:param name="extension"/>
<xsl:param name="info-file"/>
<xsl:param name="temp-dir"/>

<!-- process specified extension -->
<!-- table of languages with their file associations -->
<xsl:template match="/">

<!-- languages -->
<xsl:variable name="languages">
<xsl:for-each select="o/o[@name='contributes']/a[@name='languages']/o">
<xsl:variable name="language-id" select="e[@name='id']/@string"/>
<xsl:variable name="grammars-count"
select="count(/o/o[@name='contributes']/a[@name='grammars']
/o/e[@name='language'][@string=$language-id])"/>
<xsl:if test=" not(document($info-file)/info/extension[@id=$extension]/language[@issues or @ignore])
and $grammars-count > 0
and a[@name='extensions' or @name='filenames' or @name='filenamePatterns']">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:if test="exsl:node-set($languages)/o">
<table>
<xsl:for-each select="exsl:node-set($languages)/o">
<tr>

<!-- language -->
<xsl:variable name="original-name" select="a[@name='aliases']/v[1]/@string"/>
<xsl:variable name="name">
<xsl:choose>
<xsl:when test="document($info-file)/info/extension[@id = $extension]
/language[@name = $original-name][@better-name]">
<xsl:value-of select="document($info-file)/info/extension[@id = $extension]
/language[@name = $original-name]/@better-name"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$original-name"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<td>
<xsl:choose>
<xsl:when test="not(document(concat($temp-dir, e[@name='id']/@string, '_href.xml'))
/href/@text = '')">
<a href="{document(concat($temp-dir, e[@name='id']/@string, '_href.xml'))/href/text()}">
<xsl:value-of select="$name"/>
</a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$name"/>
</xsl:otherwise>
</xsl:choose>
</td>

<!-- file associations -->
<xsl:variable name="file-names">
<xsl:for-each select="a[@name='extensions']/v">
<xsl:value-of select="concat(', *', @string)"/>
</xsl:for-each>
<xsl:for-each select="a[@name='filenames' or @name='filenamePatterns']/v">
<xsl:value-of select="concat(', ', @string)"/>
</xsl:for-each>
</xsl:variable>
<td><xsl:value-of select="substring($file-names, 3)"/></td>

</tr>
</xsl:for-each>
</table>
</xsl:if>
<table>
<xsl:call-template name="info">
<xsl:with-param name="extension" select="$extension"/>
<xsl:with-param name="info-file" select="$info-file"/>
<xsl:with-param name="temp-dir" select="$temp-dir"/>
</xsl:call-template>
</table>
</xsl:template>
<xsl:template match="language" mode="info-language">
<tr>
<td>
<xsl:choose>
<xsl:when test="@href">
<a href="{@href}">
<xsl:value-of select="@name"/>
</a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@name"/>
</xsl:otherwise>
</xsl:choose>
</td>
<td><xsl:value-of select="@file-associations"/></td>
</tr>
</xsl:template>

</xsl:stylesheet>
40 changes: 40 additions & 0 deletions transform_to_info_md_snippet.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common" exclude-result-prefixes="exsl">
<xsl:import href="transform_commons.xsl"/>
<xsl:output method="text"/>

<!-- parameters -->
<xsl:param name="extension"/>
<xsl:param name="info-file"/>
<xsl:param name="temp-dir"/>

<!-- table of languages with their file associations -->
<xsl:template match="/">
<table>
<xsl:call-template name="info">
<xsl:with-param name="extension" select="$extension"/>
<xsl:with-param name="info-file" select="$info-file"/>
<xsl:with-param name="temp-dir" select="$temp-dir"/>
</xsl:call-template>
</table>
</xsl:template>
<xsl:template match="language" mode="info-language">
<xsl:text>| </xsl:text>
<xsl:choose>
<xsl:when test="@href">
<xsl:text>[</xsl:text>
<xsl:value-of select="@name"/>
<xsl:text>](</xsl:text>
<xsl:value-of select="@href"/>
<xsl:text>)</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@name"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text> | </xsl:text>
<xsl:value-of select="@file-associations"/>
<xsl:text> |&#xa;</xsl:text>
</xsl:template>

</xsl:stylesheet>

0 comments on commit 58efb88

Please sign in to comment.