{"id":1041,"date":"2010-07-03T16:58:10","date_gmt":"2010-07-03T20:58:10","guid":{"rendered":"http:\/\/www.dr-chuck.com\/csev-blog\/?p=1041"},"modified":"2011-12-17T12:33:47","modified_gmt":"2011-12-17T16:33:47","slug":"adding-a-new-feature-to-shiding-for-learning","status":"publish","type":"post","link":"https:\/\/www.dr-chuck.com\/csev-blog\/2010\/07\/adding-a-new-feature-to-shiding-for-learning\/","title":{"rendered":"Adding a New Feature to Shiding for Learning"},"content":{"rendered":"<p>In this exercise, we add a new feature to Shindig.   I may have jacked-in at the wrong place &#8211; but this will get you started.<\/p>\n<p>First we move into the feature directory:<\/p>\n<pre>\r\ncd features\/src\/main\/javascript\/features\r\n<\/pre>\n<p>Create a new directory named <b> learning<\/b> and put three files into it.<\/p>\n<p><b>learning_client.js<\/b><\/p>\n<pre>\r\ngadgets['learning'] = (function() {\r\n\r\n    return {\r\n       getContextLabel : function() {\r\n            return 'SI124';\r\n        },\r\n    \r\n        getContextName : function() {\r\n            return 'Social Computing';\r\n        },\r\n    \r\n        setOutcome : function(data) {\r\n            alert('setOutcome belongs here');\r\n        }\r\n    };\r\n\r\n})();\r\n<\/pre>\n<p>This creates our client code and defines three methods in the client.  For now they are simple stubs to keep life simple.<\/p>\n<p><b>taming.js<\/b><\/p>\n<pre>\r\nvar tamings___ = tamings___ || [];\r\ntamings___.push(function(imports) {\r\n  ___.grantRead(gadgets.learning, 'getContextLabel');\r\n  ___.grantRead(gadgets.learning, 'getContextName');\r\n  ___.grantRead(gadgets.learning, 'setOutcome');\r\n});\r\n<\/pre>\n<p>I am a little foggy on this file &#8211; it basically works with Caja to make sure that you are explicit as to what you want to really expose to JavaScript callers.  <\/p>\n<p><b>feature.xml<\/b><\/p>\n<pre>\r\n&lt;feature&gt;\r\n  &lt;name&gt;learning&lt;\/name&gt;\r\n  &lt;dependency&gt;globals&lt;\/dependency&gt;\r\n  &lt;gadget&gt;\r\n    &lt;script src=\"learning_client.js\"\/&gt;\r\n    &lt;script src=\"taming.js\"\/&gt;\r\n  &lt;\/gadget&gt;\r\n  &lt;container&gt;\r\n    &lt;script src=\"learning_client.js\"\/&gt;\r\n    &lt;script src=\"taming.js\"\/&gt;\r\n  &lt;\/container&gt;\r\n&lt;\/feature&gt;\r\n<\/pre>\n<p>This file names your feature and defines the source files that make it up.<\/p>\n<p>Then edit the file <b>features.txt<\/b> and add a line:<\/p>\n<pre>\r\nfeatures\/xmlutil\/feature.xml\r\nfeatures\/com.google.gadgets.analytics\/feature.xml\r\n<b>features\/learning\/feature.xml<\/b>\r\n<\/pre>\n<p>There is a way to do this using a script, but for now, lets just jack-in directly.<\/p>\n<p>At this point you need to rebuild Shindig.   And you might get syntax errors during the build which you need to fix.  Somehow the Javascript for features is compiled \/ processed at <b>mvn<\/b> time and put into a more run-time format.<\/p>\n<pre>\r\nmvn\r\n<\/pre>\n<p>once it compiles and installs, start Jetty again<\/p>\n<pre>\r\nmvn -Prun\r\n<\/pre>\n<p>And navigate to <a href=\"http:\/\/localhost:8080\/samplecontainer\/samplecontainer.html\" target=\"_new\">http:\/\/localhost:8080\/samplecontainer\/samplecontainer.html<\/a><\/p>\n<p>You should see the &#8220;Social Hello World&#8221; gadget.   Now lets edit this file:<\/p>\n<pre>\r\nvi .\/target\/work\/webapp\/samplecontainer\/examples\/SocialHelloWorld.xml\r\n<\/pre>\n<p>And add two lines:<\/p>\n<pre>\r\n   &lt;Require feature=\"osapi\"&gt;&lt;\/Require&gt;\r\n   <b>&lt;Require feature=\"learning\"&gt;&lt;\/Require&gt;<\/b>\r\n   &lt;Require feature=\"settitle\"\/&gt;&lt;\/Require&gt;\r\n\u2026\r\n\r\n   gadgets.window.setTitle('Social Hello World');\r\n   <b>alert(gadgets.learning.getContextLabel());<\/b>\r\n     var hellos = new Array('Hello World', 'Hallo Welt', 'Ciao a tutti',\r\n...\r\n<\/pre>\n<p>This requests that the container load the new <b>learning<\/b> feature and then we call the learning feature when the JavaScript starts up in the gadget and you should see the dialog box pop up once you save the <b>SampleHelloworld.xml<\/b> and do a refresh.<\/p>\n<p><a href=\"http:\/\/www.dr-chuck.com\/img\/2010\/shindig-dummies-02.png\" target=\"_new\"><img decoding=\"async\" src=\"http:\/\/www.dr-chuck.com\/img\/2010\/shindig-dummies-02.png\" width=\"500\" border=\"0\" align=\"right\"\/><\/a><br \/>\nUp next &#8211; talking to code inside the server&#8230;<\/p>\n<p><br clear=\"all\"\/><br \/>\n<a href=\"http:\/\/www.dr-chuck.com\/csev-blog\/2010\/07\/sending-data-to-a-server-side-service-with-shindig\/\">Next post in the series<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this exercise, we add a new feature to Shindig. I may have jacked-in at the wrong place &#8211; but this will get you started. First we move into the feature directory: cd features\/src\/main\/javascript\/features Create a new directory named learning and put three files into it. learning_client.js gadgets[&#8216;learning&#8217;] = (function() { return { getContextLabel : [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1041","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts\/1041","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/comments?post=1041"}],"version-history":[{"count":14,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts\/1041\/revisions"}],"predecessor-version":[{"id":2842,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts\/1041\/revisions\/2842"}],"wp:attachment":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/media?parent=1041"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/categories?post=1041"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/tags?post=1041"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}