Add lib-string.ftl for functions and macros for string manipulation. Add two methods, one for camelcasing and one for uncamelcasing.
This commit is contained in:
parent
bb7444cf4c
commit
bb984ccaea
3 changed files with 26 additions and 1 deletions
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
<#-- Template for browsing individuals in class groups for menupages -->
|
<#-- Template for browsing individuals in class groups for menupages -->
|
||||||
|
|
||||||
|
<#import "lib-string.ftl" as str>
|
||||||
|
|
||||||
<section id="browse-by" role="region">
|
<section id="browse-by" role="region">
|
||||||
<nav role="navigation">
|
<nav role="navigation">
|
||||||
<ul id="browse-classes">
|
<ul id="browse-classes">
|
||||||
|
@ -11,7 +13,7 @@
|
||||||
to degrade gracefully in absence of JavaScript. Something
|
to degrade gracefully in absence of JavaScript. Something
|
||||||
similar to what Brian had setup with widget-browse.ftl
|
similar to what Brian had setup with widget-browse.ftl
|
||||||
------------------------------------------------------------->
|
------------------------------------------------------------->
|
||||||
<#assign vClassCamel = vClass.name?capitalize?replace(" ", "")?uncap_first />
|
<#assign vClassCamel = str.camelCase(vClass.name) />
|
||||||
<#-- Only display vClasses with individuals -->
|
<#-- Only display vClasses with individuals -->
|
||||||
<#if (vClass.entityCount > 0)>
|
<#if (vClass.entityCount > 0)>
|
||||||
<li id="${vClassCamel}"><a href="#${vClassCamel}" title="Browse all individuals in this class" data-uri="${vClass.URI}">${vClass.name} <span class="count-classes">(${vClass.entityCount})</span></a></li>
|
<li id="${vClassCamel}"><a href="#${vClassCamel}" title="Browse all individuals in this class" data-uri="${vClass.URI}">${vClass.name} <span class="count-classes">(${vClass.entityCount})</span></a></li>
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
<#-- FreeMarker samples -->
|
<#-- FreeMarker samples -->
|
||||||
|
|
||||||
<#import "lib-datetime.ftl" as dt>
|
<#import "lib-datetime.ftl" as dt>
|
||||||
|
<#import "lib-string.ftl" as str>
|
||||||
|
|
||||||
<h2>${title}</h2>
|
<h2>${title}</h2>
|
||||||
|
|
||||||
|
@ -113,6 +114,11 @@ ${r"${two}"}: ${two}<br />
|
||||||
${r"${numbers[1]}"}: ${numbers[1]}<br />
|
${r"${numbers[1]}"}: ${numbers[1]}<br />
|
||||||
${r"${numbers2[1]}"}: ${numbers2[1]}<br />
|
${r"${numbers2[1]}"}: ${numbers2[1]}<br />
|
||||||
|
|
||||||
|
<h3>Uncamelcasing</h3>
|
||||||
|
<#assign s1 = "FreemarkerTest">
|
||||||
|
${s1} => ${str.unCamelCase(s1)}<br />
|
||||||
|
<#assign s2 = "Freemarker">
|
||||||
|
${s2} => ${str.unCamelCase(s2)}<br />
|
||||||
|
|
||||||
<@dump var="now" />
|
<@dump var="now" />
|
||||||
<@dump var="urls" />
|
<@dump var="urls" />
|
||||||
|
|
17
webapp/web/templates/freemarker/lib/lib-string.ftl
Normal file
17
webapp/web/templates/freemarker/lib/lib-string.ftl
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||||
|
|
||||||
|
<#-- Macros and functions for string manipulation -->
|
||||||
|
|
||||||
|
<#function camelCase str>
|
||||||
|
<#return str?capitalize?replace(" ", "")?uncap_first>
|
||||||
|
</#function>
|
||||||
|
|
||||||
|
<#function unCamelCase str>
|
||||||
|
<#local str = str?replace("([a-z])([A-Z])", "$1 $2", "r")>
|
||||||
|
<#local words = str?split(" ")>
|
||||||
|
<#local out = "">
|
||||||
|
<#list words as word>
|
||||||
|
<#local out = out + " " + word?uncap_first>
|
||||||
|
</#list>
|
||||||
|
<#return out?trim>
|
||||||
|
</#function>
|
Loading…
Add table
Add a link
Reference in a new issue