Created
May 10, 2012 14:40
-
-
Save xpathr/2653493 to your computer and use it in GitHub Desktop.
Blueprint CSS: Adjust-Span Utility by wjnielsen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8"?> | |
| <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> | |
| <!-- | |
| Name: Blueprint CSS: Adjust-Span Utility; | |
| Version: 1.0; | |
| Author: Will Nielsen; | |
| Date: 2010-09-10; | |
| Description: Adjusting span-# mathematically in a string used for the class attribute of a tag | |
| Dependency:http://blueprintcss.org/ | |
| All source code included in this file is, unless otherwise specified, | |
| released under the MIT licence as follows: | |
| ***** begin license block ***** | |
| Copyright 2010 Will Nielsen | |
| Permission is hereby granted, free of charge, to any person obtaining a copy | |
| of this software and associated documentation files (the "Software"), to deal | |
| in the Software without restriction, including without limitation the rights | |
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| copies of the Software, and to permit persons to whom the Software is | |
| furnished to do so, subject to the following conditions: | |
| The above copyright notice and this permission notice shall be included in | |
| all copies or substantial portions of the Software. | |
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| 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. | |
| ***** end license block ***** | |
| --> | |
| <xsl:template name="adjust-class-span"> | |
| <xsl:param name="operator" select="'-'"/> | |
| <xsl:param name="span-int" select="1"/> | |
| <xsl:param name="class"/> | |
| <xsl:variable name="part-1" select="substring-before(normalize-space($class), 'span-')"/> | |
| <xsl:variable name="part-2"> | |
| <xsl:choose> | |
| <!-- When there are more characters after the span-x bit --> | |
| <xsl:when test="string-length(substring-after(substring-after(normalize-space($class), 'span-'), ' ')) > 0"> | |
| <xsl:value-of select="substring-after(substring-after(normalize-space($class), 'span-'), ' ')"/> | |
| </xsl:when> | |
| </xsl:choose> | |
| </xsl:variable> | |
| <xsl:variable name="span-val"> | |
| <xsl:choose> | |
| <!-- When there are more characters after the span-x bit --> | |
| <xsl:when test="string-length(substring-after(substring-after(normalize-space($class), 'span-'), ' ')) > 0"> | |
| <xsl:value-of select="substring-before(substring-after(normalize-space($class), 'span-'), ' ')"/> | |
| </xsl:when> | |
| <!-- otherwise part-2 is the span value --> | |
| <xsl:otherwise> | |
| <xsl:value-of select="substring-after(normalize-space($class), 'span-')"/> | |
| </xsl:otherwise> | |
| </xsl:choose> | |
| </xsl:variable> | |
| <xsl:variable name="new-span-val"> | |
| <xsl:choose> | |
| <!-- Subtraction --> | |
| <xsl:when test="$operator = '-'"> | |
| <xsl:value-of | |
| select="number($span-val - $span-int)" | |
| /> | |
| </xsl:when> | |
| <!-- Addition --> | |
| <xsl:when test="$operator = '+'"> | |
| <xsl:value-of | |
| select="number($span-val + $span-int)" | |
| /> | |
| </xsl:when> | |
| <!-- Multiplication --> | |
| <xsl:when test="$operator = '*' or $operator = 'x'"> | |
| <xsl:value-of | |
| select="number($span-val * $span-int)" | |
| /> | |
| </xsl:when> | |
| <!-- Division --> | |
| <xsl:when test="$operator = '/'"> | |
| <xsl:value-of | |
| select="number($span-val div $span-int)" | |
| /> | |
| </xsl:when> | |
| </xsl:choose> | |
| </xsl:variable> | |
| <!-- RETURN STRING --> | |
| <xsl:value-of | |
| select="normalize-space(concat(normalize-space($part-1), ' span-', normalize-space($new-span-val), ' ', normalize-space($part-2)))"/> | |
| </xsl:template> | |
| </xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment