Skip to content

Commit

Permalink
Merge pull request #767 from olivergondza/wbr_layout
Browse files Browse the repository at this point in the history
[FIXED JENKINS-17030] Enable word breaking for job names.
  • Loading branch information
jglick committed May 21, 2013
2 parents c3ee622 + 0426377 commit e31b750
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 8 deletions.
16 changes: 16 additions & 0 deletions core/src/main/java/hudson/Functions.java
Expand Up @@ -1716,4 +1716,20 @@ public static String humanReadableByteSize(long size){
DecimalFormat format = new DecimalFormat("#0.00");
return format.format(number) + " " + measure;
}

/**
* Get a string that can be safely broken to several lines when necessary.
*
* This implementation inserts <wbr> tags into string. It allows browsers
* to wrap line before any sequence of punctuation characters or anywhere
* in the middle of prolonged sequences of word characters.
*
* @since 1.516
*/
public static String breakableString(final String plain) {

return plain.replaceAll("(\\p{Punct}+\\w)", "<wbr>$1")
.replaceAll("(\\w{10})(?=\\w{3})", "$1<wbr>")
;
}
}
Expand Up @@ -27,7 +27,7 @@ THE SOFTWARE.
<l:layout title="${it.name}">
<st:include page="sidepanel.jelly" />
<l:main-panel>
<h1>${%Project} ${it.displayName}</h1>
<h1>${%Project} <l:breakable value="${it.displayName}"/></h1>
<j:if test="${it.name!=it.displayName}">
${%Project name}: ${it.fullName}
</j:if>
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/hudson/model/Job/index.jelly
Expand Up @@ -27,7 +27,7 @@ THE SOFTWARE.
<l:layout title="${it.displayName}">
<st:include page="sidepanel.jelly" />
<l:main-panel>
<h1>${it.pronoun} ${it.displayName}</h1>
<h1>${it.pronoun} <l:breakable value="${it.displayName}"/></h1>
<j:if test="${(it.name!=it.displayName) and (it.class.name!='hudson.matrix.MatrixConfiguration')}">
${%Project name}: ${it.fullName}
</j:if>
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/resources/hudson/views/JobColumn/column.jelly
Expand Up @@ -25,6 +25,6 @@ THE SOFTWARE.
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<td style="${indenter.getCss(job)}">
<a href="${jobBaseUrl}${job.shortUrl}" class='model-link inside'> ${h.getRelativeDisplayNameFrom(job,currentView.owner.itemGroup)}</a>
<a href="${jobBaseUrl}${job.shortUrl}" class='model-link inside'> <l:breakable value="${h.getRelativeDisplayNameFrom(job,currentView.owner.itemGroup)}"/></a>
</td>
</j:jelly>
</j:jelly>
2 changes: 1 addition & 1 deletion core/src/main/resources/lib/hudson/buildListTable.jelly
Expand Up @@ -53,7 +53,7 @@ THE SOFTWARE.
</a>
</td>
<td>
<a href="${jobBaseUrl}${b.parent.url}" class="model-link">${b.parent.fullDisplayName}</a>
<a href="${jobBaseUrl}${b.parent.url}" class="model-link"><l:breakable value="${b.parent.fullDisplayName}"/></a>
<st:nbsp/>
<a href="${jobBaseUrl}${b.url}" class="model-link inside">${b.displayName}</a>
</td>
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/lib/hudson/executors.jelly
Expand Up @@ -79,7 +79,7 @@ THE SOFTWARE.
</j:invokeStatic>
<j:choose>
<j:when test="${h.hasPermission(exeparent,exeparent.READ)}">
<a href="${rootURL}/${exeparent.url}">${exeparent.fullDisplayName}</a>&#160;<a href="${rootURL}/${exe.url}" class="model-link inside">#${exe.number}</a>
<a href="${rootURL}/${exeparent.url}"><l:breakable value="${exeparent.fullDisplayName}"/></a>&#160;<a href="${rootURL}/${exe.url}" class="model-link inside">#${exe.number}</a>
<t:buildProgressBar build="${exe}" executor="${executor}"/>
</j:when>
<j:otherwise>
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/lib/hudson/jobLink.jelly
Expand Up @@ -32,5 +32,5 @@ THE SOFTWARE.
</st:documentation>

<img src="${imagesURL}/16x16/${job.buildStatusUrl}" alt="${job.iconColor.description}" height="16" width="16"/>
<a href="${h.getRelativeLinkTo(job)}" class="model-link">${job.fullDisplayName}</a>
<a href="${h.getRelativeLinkTo(job)}" class="model-link"><l:breakable value="${job.fullDisplayName}"/></a>
</j:jelly>
2 changes: 1 addition & 1 deletion core/src/main/resources/lib/hudson/queue.jelly
Expand Up @@ -63,7 +63,7 @@ THE SOFTWARE.
<j:choose>
<j:when test="${h.hasPermission(item.task,item.task.READ)}">
<a href="${rootURL}/${item.task.url}" class="model-link inside tl-tr" tooltip="${item.why}${h.escape(item.params)}&lt;br&gt;${%WaitingFor(item.inQueueForString)}">
${item.task.fullDisplayName}
<l:breakable value="${item.task.fullDisplayName}"/>
</a>
<!-- XXX include estimated number as in BuildHistoryWidget/entries.jelly if possible -->
<j:if test="${stuck}">
Expand Down
34 changes: 34 additions & 0 deletions core/src/main/resources/lib/layout/breakable.jelly
@@ -0,0 +1,34 @@
<!--
The MIT License
Copyright (c) 2013 Red Hat, Inc.
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.
-->

<?jelly escape-by-default='false'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler">
<st:documentation>
Send escaped value to output decorated to be safely broken into lines when necessary
<st:attribute name="value" use="required">
Unescaped value to output
</st:attribute>
</st:documentation>
${h.breakableString(h.escape(value))}
</j:jelly>
7 changes: 7 additions & 0 deletions core/src/test/java/hudson/FunctionsTest.java
Expand Up @@ -264,4 +264,11 @@ public void testHumanReadableFileSize(){
}
}

@Test
public void testBreakableString() {

assertEquals("Hello world!", Functions.breakableString("Hello world!"));
assertEquals("H<wbr>,e<wbr>.l<wbr>/l<wbr>:o<wbr>-w<wbr>_o<wbr>=+|d", Functions.breakableString("H,e.l/l:o-w_o=+|d"));
assertEquals("ALongStrin<wbr>gThatCanNo<wbr>tBeBrokenB<wbr>yDefault", Functions.breakableString("ALongStringThatCanNotBeBrokenByDefault"));
}
}

0 comments on commit e31b750

Please sign in to comment.