Skip to content
This repository
Browse code

#tag_icons: added HtmlFragments.miniTagIcon()

  • Loading branch information...
commit 9240b942b0070830e7782fe632b44603d4d23b81 1 parent e37e7c0
Daisuke Morita authored
44  src/main/java/marubinotto/piggydb/ui/page/common/HtmlFragments.java
... ...
@@ -1,5 +1,7 @@
1 1
 package marubinotto.piggydb.ui.page.common;
2 2
 
  3
+import static marubinotto.util.web.WebUtils.escapeHtml;
  4
+
3 5
 import java.util.Map;
4 6
 
5 7
 import marubinotto.piggydb.model.Fragment;
@@ -181,29 +183,43 @@ public String tagIconClass(String tagName) {
181 183
     Assert.Arg.notNull(tagName, "tagName");
182 184
     String c = "tagIcon";
183 185
     if (tagName.startsWith("#")) {
184  
-      c = c + " tagIcon-" + WebUtils.escapeHtml(tagName.substring(1));
  186
+      c = c + " tagIcon-" + escapeHtml(tagName.substring(1));
185 187
     }
186 188
     return c;
187 189
   }
188 190
   
  191
+  private String _miniTagIcon(String iconClasses) {
  192
+    return XmlStringBuilder.create("span")
  193
+      .attribute("class", iconClasses)
  194
+      .text(" ")
  195
+      .toString();
  196
+  }
  197
+  
  198
+  public String miniTagIcon(Tag tag) {
  199
+    return _miniTagIcon(miniTagIconClass(tag));
  200
+  }
  201
+  
  202
+  public String miniTagIcon(String tagName, Boolean isTagFragment) {
  203
+    return _miniTagIcon(miniTagIconClass(tagName, isTagFragment));
  204
+  }
  205
+  
189 206
   public String miniTagIconClass(String tagName) {
190  
-    Assert.Arg.notNull(tagName, "tagName");
191  
-    String c = "miniTagIcon";
192  
-    if (tagName.startsWith("#")) {
193  
-      c = c + " miniTagIcon-" + WebUtils.escapeHtml(tagName.substring(1));
194  
-    }
195  
-    return c;
  207
+    return miniTagIconClass(tagName, null);
196 208
   }
197 209
   
198 210
   public String miniTagIconClass(Tag tag) {
199  
-    Assert.Arg.notNull(tag, "tag");
  211
+    return miniTagIconClass(tag.getName(), tag.isTagFragment());
  212
+  }
  213
+  
  214
+  public String miniTagIconClass(String tagName, Boolean isTagFragment) {
  215
+    Assert.Arg.notNull(tagName, "tagName");
200 216
     
201 217
     String c = "miniTagIcon";
202  
-    if (tag.getName().startsWith("#")) {
203  
-      c += " miniTagIcon-system miniTagIcon-" + WebUtils.escapeHtml(tag.getName().substring(1));
  218
+    if (tagName.startsWith("#")) {
  219
+      c += " miniTagIcon-system miniTagIcon-" + escapeHtml(tagName.substring(1));
204 220
     }
205  
-    else {
206  
-      c += " miniTagIcon-" + (tag.isTagFragment() ? "fragment" : "plain");
  221
+    else if (isTagFragment != null) {
  222
+      c += " miniTagIcon-" + (isTagFragment ? "fragment" : "plain");
207 223
     }
208 224
     return c;
209 225
   }
@@ -235,11 +251,11 @@ private String fragmentsViewSwitchButton(
235 251
       if (pageIndexName != null) {
236 252
         // Unless overwriting the page index, it will be restored by pageUrl.
237 253
         // When changing the view, the page index should be reset to 0.
238  
-        switchUrl = WebUtils.escapeHtml(
  254
+        switchUrl = escapeHtml(
239 255
           pageUrl.getPageUrl("fragmentsViewMode", mode, pageIndexName, 0));
240 256
       }
241 257
       else {
242  
-        switchUrl = WebUtils.escapeHtml(pageUrl.getPageUrl("fragmentsViewMode", mode));
  258
+        switchUrl = escapeHtml(pageUrl.getPageUrl("fragmentsViewMode", mode));
243 259
       }
244 260
       builder.attribute("onclick", "javascript:document.location.href='" + switchUrl + "';");
245 261
     }
4  src/main/webapp/macro/fragment-parts.vm
@@ -25,7 +25,7 @@
25 25
 #else
26 26
   #if ($fragment.isTag())
27 27
   	<a class="tag-fragment-caption" href="$resources.tagPath($fragment.tagId)">
28  
-  	#miniTagIcon($fragment.title)
  28
+    $utils.raw($html.miniTagIcon($fragment.title, true))
29 29
   	<span class="title">$fragment.title</span></a>
30 30
   #else
31 31
     $utils.raw($html.linkToFragment($fragment.id))
@@ -211,7 +211,7 @@
211 211
 #macro( fragmentTag $tag $fragment )
212 212
 
213 213
 <span class="tag">
214  
-  #miniTagIcon($tag.name)
  214
+  $utils.raw($html.miniTagIcon($tag))
215 215
   <a class="tag" href="$resources.tagPath($tag.id)">$tag.name</a>
216 216
   #if ($fragment.id && $fragment.canRemoveTag($tag, $user))
217 217
     <a href="#" onclick="piggydb.command.removeTag('$fragment.id', '$tag.name'); return false;">
4  src/main/webapp/macro/sidebar.vm
@@ -235,7 +235,7 @@
235 235
           $utils.raw($html.linkToFragment($entry.key.id))
236 236
           $entry.value
237 237
         #elseif ($entry.key.type == 2)
238  
-          #miniTagIcon($entry.value)
  238
+          $utils.raw($html.miniTagIcon($entry.value, null))
239 239
           <a class="tag" href="$resources.tagPath(${entry.key.id})">$entry.value</a>
240 240
         #elseif ($entry.key.type == 3)
241 241
 					$utils.raw($html.filterIconMini())
@@ -270,7 +270,7 @@
270 270
       #foreach ($tag in $tags)
271 271
       <li>
272 272
         <table class="nowrap-frame" border="0"><tr><td nowrap="nowrap">
273  
-          #miniTagIcon($tag.name)
  273
+          $utils.raw($html.miniTagIcon($tag.name, null))
274 274
           <a class="tag" href="$resources.tagPath(${tag.id})">$tag.name</a>
275 275
           × $tag.count
276 276
           
4  src/main/webapp/partial/preview-fragment.htm
@@ -8,14 +8,14 @@
8 8
       <div class="fragment-header">
9 9
         <span style="color: red;">#$messages.get("preview")</span>
10 10
     		#if ($fragment.isTag())
11  
-    			#miniTagIcon($fragment.title)
  11
+          $utils.raw($html.miniTagIcon($fragment.title, true))
12 12
     		#end
13 13
         <span class="title">$fragment.title &nbsp;</span>
14 14
         #if ($fragment.classification.size() > 0)
15 15
           <span class="tags bgcolor-base" style="margin-bottom: 5px;">
16 16
           #foreach ($tag in $fragment.classification.getTagIterator())
17 17
             <span class="tag">
18  
-              #miniTagIcon($tag.name)
  18
+              $utils.raw($html.miniTagIcon($tag))
19 19
               #if($tag.id)
20 20
                 <a class="tag" href="$resources.tagPath($tag.id)">$tag.name</a>
21 21
               #else

0 notes on commit 9240b94

Please sign in to comment.
Something went wrong with that request. Please try again.