Author: scottbw
Date: Wed Jan 11 15:19:48 2012
New Revision: 1230086

URL: http://svn.apache.org/viewvc?rev=1230086&view=rev
Log:
Made the ItemDetail template more generic (WOOKIE-294), and replaced XSL 
processing with the token replacement method also used in the Browse template 
(see WOOKIE-297).

Added:
    incubator/wookie/trunk/widgets/templates/itemDetail/item_template.html
Removed:
    incubator/wookie/trunk/widgets/templates/itemDetail/content_footer.html
    incubator/wookie/trunk/widgets/templates/itemDetail/content_header.html
    incubator/wookie/trunk/widgets/templates/itemDetail/detail2html.xsl
    incubator/wookie/trunk/widgets/templates/itemDetail/lib/XSLTransform.js
Modified:
    
incubator/wookie/trunk/widgets/templates/itemDetail/default.widget.properties
    incubator/wookie/trunk/widgets/templates/itemDetail/index.html
    
incubator/wookie/trunk/widgets/templates/itemDetail/scripts/itemDetail_controller.js
    incubator/wookie/trunk/widgets/templates/itemDetail/style/screen.css.add
    incubator/wookie/trunk/widgets/templates/itemDetail/template_build.xml

Modified: 
incubator/wookie/trunk/widgets/templates/itemDetail/default.widget.properties
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/itemDetail/default.widget.properties?rev=1230086&r1=1230085&r2=1230086&view=diff
==============================================================================
--- 
incubator/wookie/trunk/widgets/templates/itemDetail/default.widget.properties 
(original)
+++ 
incubator/wookie/trunk/widgets/templates/itemDetail/default.widget.properties 
Wed Jan 11 15:19:48 2012
@@ -9,5 +9,29 @@ itemDetail.get.url="http://api.twitter.c
 # A value passed in the URL will take priority and set the widget preference 
value.
 itemDetail.default.itemId=129284508087357440
 
-# The XSL to transform the detail XML (from itemDetail.get.url) to HTML
-itemDetail.xsl.url="detail2html.xsl"
\ No newline at end of file
+
+#
+# The template string to use for the collection of items to browse. This is 
used to hold
+# the set of items to display.
+#
+# type: string
+#
+browse.collection.template = "<div>${ITEMS}</div>"
+
+#
+# The name of the XML element that represents a single item 
+# type: string
+#
+browse.item.name = "status"
+
+#
+# The names of the elements to map into the template placeholders. E.g. if it 
contains "title", then $TITLE in the template 
+# would be replaced by the content of the <title> element in the XML data
+#
+browse.item.elements = 
"name,screen_name,location,description,url,followers_count,listed_count,friends_count,statuses_count,text,profile_image_url,created_at,source"
+
+#
+# The names of the attributes to map into the template placeholders. E.g. if 
it contains "id", then $ID in the template 
+# would be replaced by the content of the id attribute of the item XML element 
in the XML data
+#
+browse.item.attributes = "id"
\ No newline at end of file

Modified: incubator/wookie/trunk/widgets/templates/itemDetail/index.html
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/itemDetail/index.html?rev=1230086&r1=1230085&r2=1230086&view=diff
==============================================================================
--- incubator/wookie/trunk/widgets/templates/itemDetail/index.html (original)
+++ incubator/wookie/trunk/widgets/templates/itemDetail/index.html Wed Jan 11 
15:19:48 2012
@@ -30,7 +30,6 @@
 
 
 <link rel="stylesheet" href="style/all.css" />
-<script type="text/javascript" src="lib/XSLTransform.js"></script>
 <script type="text/javascript" src="scripts/controller.js"></script>
 
 <title>${widget.name}</title>

Added: incubator/wookie/trunk/widgets/templates/itemDetail/item_template.html
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/itemDetail/item_template.html?rev=1230086&view=auto
==============================================================================
--- incubator/wookie/trunk/widgets/templates/itemDetail/item_template.html 
(added)
+++ incubator/wookie/trunk/widgets/templates/itemDetail/item_template.html Wed 
Jan 11 15:19:48 2012
@@ -0,0 +1,18 @@
+<div class='tweet'>
+<div class='overview'>
+  <div class='quote'>${TEXT}</div>
+</div>
+
+<div class='meta-data'>
+  <div class='clear'>${NAME} (${SCREEN_NAME}) from ${LOCATION} at 
${CREATED_AT} (using ${SOURCE} )
+    </div>
+    </div>
+    <div class='user clear'>
+      <h3>About ${NAME}</h3>
+      <div class='thumbnail'><img alt='Avatar for tweet author' 
src='${PROFILE_IMAGE_URL}'></div>
+      <p>${NAME} uses the screen name ${SCREEN_NAME}, and is based in 
${LOCATION}</p>
+      <p>They describe themselves as '${DESCRIPTION}' 
+         They provide more information about themselves at <a 
class='ui-link'>${URL}</a></p>
+      <p>They have ${FOLLOWERS_COUNT} followers, are listed in ${LISTED_COUNT} 
lists and follow ${FRIENDS_COUNT} people. They have tweeted ${STATUSES_COUNT} 
times.</p>
+</div>
+</div>
\ No newline at end of file

Modified: 
incubator/wookie/trunk/widgets/templates/itemDetail/scripts/itemDetail_controller.js
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/itemDetail/scripts/itemDetail_controller.js?rev=1230086&r1=1230085&r2=1230086&view=diff
==============================================================================
--- 
incubator/wookie/trunk/widgets/templates/itemDetail/scripts/itemDetail_controller.js
 (original)
+++ 
incubator/wookie/trunk/widgets/templates/itemDetail/scripts/itemDetail_controller.js
 Wed Jan 11 15:19:48 2012
@@ -41,10 +41,7 @@ var ${widget.shortname}_detail_controlle
        var itemId = Widget.preferences.getItem("itemId");
        var url = widget.proxify(${itemDetail.get.url});
         $('#detail').remove();
-        var html = $.XSLTransform({
-            xmlurl:url,
-            xslurl:${itemDetail.xsl.url}
-        });    
+        var html = ${widget.shortname}_detail_controller.transform(url);
         $('#content-primary').html(html).trigger("create");
     },
 
@@ -54,6 +51,60 @@ var ${widget.shortname}_detail_controlle
     get:function(name){
        if(name=(new 
RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)')).exec(location.search))
            return decodeURIComponent(name[1]);
+    },
+    
+    /**
+     * load XML data and transform it into HTML
+     */
+    transform:function(src){
+     var output = "";
+
+     $.ajax({
+      url: src,
+      dataType: "xml",
+      async: false,
+      success: function(xml){
+        output = ${widget.shortname}_detail_controller.transformXml(xml); 
+      }
+     });
+     
+     return output;
+    },
+
+    /**
+     * Transform data into HTML
+     */ 
+    transformXml:function(xml){
+        
+        var output = "";
+        var items = "";
+        
+        /**
+         * For each element that matches itemName, create a new ItemTemplate 
and
+         * replace placeholders in the template with values from the XML using 
the ItemElements 
+         * and ItemAttrobutes lists
+         */
+        $(xml).find(${browse.item.name}).each(
+           function(){
+             var item = "${browse.item.template}";
+             var elements = ${browse.item.elements}.split(",");
+             for (var i=0;i<elements.length;i++){
+                var element = elements[i]; 
+                var pattern = "\\$\{" + element.toUpperCase() +"\}";
+                item = item.replace(new RegExp(pattern,'g'), 
$(this).find(element).first().text());
+             }
+             var attributes = ${browse.item.attributes}.split(",");
+             for (var i=0;i<attributes.length;i++){
+                var attribute = attributes[i]; 
+                var pattern = '\\$\{'+attribute.toUpperCase()+'\}';
+                item = item.replace(new RegExp(pattern,'g'), 
$(this).attr(attribute));
+             }
+             items += item;
+           }
+        );
+        
+        output = ${browse.collection.template}.replace("${ITEMS}", items);
+        return output;
     }
 
 

Modified: 
incubator/wookie/trunk/widgets/templates/itemDetail/style/screen.css.add
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/itemDetail/style/screen.css.add?rev=1230086&r1=1230085&r2=1230086&view=diff
==============================================================================
--- incubator/wookie/trunk/widgets/templates/itemDetail/style/screen.css.add 
(original)
+++ incubator/wookie/trunk/widgets/templates/itemDetail/style/screen.css.add 
Wed Jan 11 15:19:48 2012
@@ -21,6 +21,8 @@
 
 .quote {
   font-style:italic;
+  font-weight: bold;
+  font-size: 120%;
 }
 
 .meta-data {

Modified: incubator/wookie/trunk/widgets/templates/itemDetail/template_build.xml
URL: 
http://svn.apache.org/viewvc/incubator/wookie/trunk/widgets/templates/itemDetail/template_build.xml?rev=1230086&r1=1230085&r2=1230086&view=diff
==============================================================================
--- incubator/wookie/trunk/widgets/templates/itemDetail/template_build.xml 
(original)
+++ incubator/wookie/trunk/widgets/templates/itemDetail/template_build.xml Wed 
Jan 11 15:19:48 2012
@@ -125,6 +125,30 @@
        
     <echoproperties 
destfile="${widget.build.dir}/${widget.shortname}.properties" prefix=""/>
   </target>
+       
+    <loadfile property="browse.item.template"
+             srcFile="item_template.html"
+             failonerror="false">
+      <filterchain>
+       <striplinebreaks/>
+      </filterchain>
+    </loadfile>
+
+    <loadfile property="browse.item.template"
+             srcFile="../common/item_template.html"
+             failonerror="false">
+      <filterchain>
+       <striplinebreaks/>
+      </filterchain>
+    </loadfile>
+    
+    <loadfile property="browse.item.template"
+              srcFile="${template.dir}/${template.name}/item_template.html"
+              failonerror="false">
+      <filterchain>
+       <striplinebreaks/>
+      </filterchain>
+    </loadfile>
 
   <target name="_generate_from_parent_templates">
     <echo message="+------------------------------------------"/>


Reply via email to