Skip to content

Commit

Permalink
#1 start
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed May 19, 2024
1 parent 6558de1 commit 2b461ec
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 9 deletions.
5 changes: 5 additions & 0 deletions tests/simple.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
<fb dob="2024-05-18T22:22:22Z" factbase_version="0.0.0">
<f>
<time>2024-05-18T22:22:22.8492Z</time>
<award>15</award>
<payee>yegor256</payee>
<reason>for being a good boy</reason>
<href>https://github.com/yegor256/judges/issues/111</href>
</f>
<f>
<time>2024-05-15T22:22:22.8492Z</time>
<award>-25</award>
<payee>yegor256</payee>
<reason>for being a bad boy</reason>
<href>https://github.com/yegor256/judges/issues/111</href>
</f>
<f>
<time>2024-04-18T22:22:22.8492Z</time>
<award>30</award>
<payee>linus</payee>
<reason>for a new release</reason>
Expand Down
82 changes: 73 additions & 9 deletions xsl/awards.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,22 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:z="https://www.zerocracy.com" version="2.0">
<xsl:function name="z:award">
<xsl:param name="a"/>
<xsl:if test="$a &gt; 0">
<xsl:text>+</xsl:text>
</xsl:if>
<xsl:value-of select="$a"/>
</xsl:function>
<xsl:template match="/" mode="awards">
<table id="awards">
<table id="awards" border="1">
<colgroup>
<col/>
<col style="width: 2.5em;"/>
<col style="width: 2em;"/>
<col/>
<col/>
<col/>
</colgroup>
<thead>
Expand All @@ -38,12 +48,15 @@ SOFTWARE.
<th>
<xsl:text></xsl:text>
</th>
<th>
<th colspan="2">
<xsl:text>Programmer</xsl:text>
</th>
<th>
<xsl:text>Score</xsl:text>
</th>
<th>
<xsl:text></xsl:text>
</th>
</tr>
</thead>
<xsl:apply-templates select="/fb" mode="awards"/>
Expand All @@ -68,7 +81,7 @@ SOFTWARE.
<td class="avatar">
<img src="https://github.com/{$name}.png" width="64" height="64"/>
</td>
<td>
<td colspan="2">
<a>
<xsl:attribute name="href">
<xsl:text>https://github.com/</xsl:text>
Expand All @@ -79,13 +92,64 @@ SOFTWARE.
</a>
</td>
<td class="right">
<xsl:variable name="sum" select="sum(/fb/f[payee=$name and award]/award)"/>
<xsl:if test="$sum &gt; 0">
<xsl:text>+</xsl:text>
</xsl:if>
<xsl:value-of select="$sum"/>
<xsl:value-of select="z:award(sum(/fb/f[payee=$name and award]/award))"/>
</td>
<td>
<xsl:text></xsl:text>
</td>
</tr>
<xsl:for-each select="/fb/f[payee=$name and award]">
<tr>
<xsl:attribute name="programmer">
<xsl:value-of select="$name"/>
</xsl:attribute>
<td>
<xsl:text></xsl:text>
</td>
<td>
<xsl:text></xsl:text>
</td>
<td>
<xsl:text></xsl:text>
</td>
<td>
<xsl:value-of select="reason"/>
</td>
<td class="right">
<xsl:choose>
<xsl:when test="href">
<a>
<xsl:attribute name="href">
<xsl:value-of select="href"/>
</xsl:attribute>
<xsl:value-of select="z:award(award)"/>
</a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="z:award(award)"/>
</xsl:otherwise>
</xsl:choose>
</td>
<td>
<xsl:variable name="age" select="number((current-dateTime() - xs:dateTime(time)) div xs:dayTimeDuration('P1D'))"/>
<xsl:choose>
<xsl:when test="$age &lt; 1">
<xsl:text>today</xsl:text>
</xsl:when>
<xsl:when test="$age &lt; 7">
<xsl:text>this week</xsl:text>
</xsl:when>
<xsl:when test="$age &lt; 99">
<xsl:value-of select="floor($age)"/>
<xsl:text>d ago</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>earlier</xsl:text>
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</xsl:for-each>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:copy>
Expand Down

0 comments on commit 2b461ec

Please sign in to comment.