This is an automated email from the ASF dual-hosted git repository.

carlosrovira pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new a40ce33  some fixes to Jewel example load code
a40ce33 is described below

commit a40ce33fb31a0482608d51c7528b821f054bfaed
Author: Carlos Rovira <[email protected]>
AuthorDate: Sun Sep 23 23:45:42 2018 +0200

    some fixes to Jewel example load code
---
 examples/royale/JewelExample/pom.xml               |  2 +-
 .../src/main/royale/AlertPlayGround.mxml           | 14 ++++---
 .../src/main/royale/services/GitHubService.as      | 46 ++++++++++++++++------
 3 files changed, 43 insertions(+), 19 deletions(-)

diff --git a/examples/royale/JewelExample/pom.xml 
b/examples/royale/JewelExample/pom.xml
index 17e1621..3a6da6e 100644
--- a/examples/royale/JewelExample/pom.xml
+++ b/examples/royale/JewelExample/pom.xml
@@ -44,7 +44,7 @@
           <targets>SWF,JSRoyale</targets>
           <debug>false</debug>
           
<htmlTemplate>${basedir}/target/javascript/bin/js-debug/jewel-example-index-template.html</htmlTemplate>
-          <additionalCompilerOptions>-source-map=true 
-js-dynamic-access-unknown-members=true</additionalCompilerOptions>
+          
<additionalCompilerOptions>-source-map=true;-js-dynamic-access-unknown-members=true</additionalCompilerOptions>
         </configuration>
       </plugin>
     </plugins>
diff --git a/examples/royale/JewelExample/src/main/royale/AlertPlayGround.mxml 
b/examples/royale/JewelExample/src/main/royale/AlertPlayGround.mxml
index 915e8eb..482bd5e 100644
--- a/examples/royale/JewelExample/src/main/royale/AlertPlayGround.mxml
+++ b/examples/royale/JewelExample/src/main/royale/AlertPlayGround.mxml
@@ -85,11 +85,15 @@ limitations under the License.
             import org.apache.royale.collections.ArrayList;
             import vos.TabBarButtonVO;
             import utils.HighlightCode;
-            
+
             private function changeHandler(event:Event):void
             {
                 var item:TabBarButtonVO = (event.target as 
TabBar).selectedItem as TabBarButtonVO;
                 tabcontent.showContent(item.href);
+                if(sourceCodeTab.isActive && sourceCodeMXMLText.text == "")
+                {
+                    service.getContent();
+                }
             }
 
             private var _tabBarNavigation:ArrayList = new ArrayList([
@@ -104,18 +108,18 @@ limitations under the License.
 
                        public function dataReadyHandler(event:Event):void
                        {
-                sourceCodeTextHolder.text = event.target.data;
+                sourceCodeMXMLText.text = event.target.sourceCode;
                 
                 COMPILE::JS
                 {
                     var highlightCode:HighlightCode = new HighlightCode();
-                    highlightCode.highlightBlock(sourceCodeTextHolder.element);
+                    highlightCode.highlightBlock(sourceCodeMXMLText.element);
                 }
                        }
                ]]>
        </fx:Script>
 
-    <services:GitHubService 
+    <services:GitHubService id="service"
             
sourceCodeUrl="https://api.github.com/repos/apache/royale-asjs/contents/examples/royale/JewelExample/src/main/royale/AlertPlayGround.mxml";
             dataReady="dataReadyHandler(event)"/>
 
@@ -153,7 +157,7 @@ limitations under the License.
 
         <j:SectionContent id="sourceCodeTab">
             <html:Pre>
-                <html:Code id="sourceCodeTextHolder" className="xml 
codeExample"/>
+                <html:Code id="sourceCodeMXMLText" className="xml 
codeExample"/>
             </html:Pre>
         </j:SectionContent>
 
diff --git 
a/examples/royale/JewelExample/src/main/royale/services/GitHubService.as 
b/examples/royale/JewelExample/src/main/royale/services/GitHubService.as
index 666cf36..6737596 100644
--- a/examples/royale/JewelExample/src/main/royale/services/GitHubService.as
+++ b/examples/royale/JewelExample/src/main/royale/services/GitHubService.as
@@ -22,6 +22,8 @@ package services
        import org.apache.royale.net.HTTPHeader;
        import org.apache.royale.events.EventDispatcher;
        import org.apache.royale.events.Event;
+    import org.apache.royale.utils.string.Base64;
+    import org.apache.royale.net.HTTPConstants;
 
     [Event(name="dataReady", type="org.apache.royale.events.Event")]
     /**
@@ -34,13 +36,9 @@ package services
          * constructor
          */
         public function GitHubService():void
-        {
-            // this header makes gihub serve the raw code instead of base64 
encoded data
-            var header:HTTPHeader = new HTTPHeader('accept', 
'application/vnd.github.VERSION.raw');
-            
+        {    
             service = new HTTPService();
-                       service.headers.push(header);
-                       service.addEventListener("complete", completeHandler);
+            service.addEventListener(HTTPConstants.COMPLETE, completeHandler);
         }
 
         /**
@@ -56,7 +54,6 @@ package services
             dispatchEvent(new Event("dataReady"));
         }
 
-        //example = 
"https://api.github.com/repos/apache/royale-asjs/contents/examples/royale/JewelExample/src/main/royale/AlertPlayGround.mxml";;
         private var _sourceCodeUrl:String = null;
         /**
          * The source code url we want to retrieve
@@ -67,17 +64,40 @@ package services
         }
         public function set sourceCodeUrl(value:String):void
         {
-               _sourceCodeUrl = value;
+            _sourceCodeUrl = value;
             service.url = sourceCodeUrl;
-            service.send();
         }
 
         /**
-         * data holds the resulting text code to show
+         * json return the retrieved GitHub JSON Object
+         */
+        public function get json():Object
+        {
+            return service.json;
+        }
+
+        /**
+         * jsonToString return the retrieved GitHub JSON Object as String
+         */
+        public function get jsonToString():String
+        {
+            return service.data;
+        }
+
+        /**
+         * decode and return the base 64 content (real source code)
+         */
+        public function get sourceCode():String
+        {
+            return Base64.decode(service.json.content);
+        }
+        
+        /**
+         * trigger the HTTPService to retrieve the GitHub data
          */
-        public function get data():String
+        public function getContent():void
         {
-               return service.data;
+               service.send();
         }
        }
-}
+}
\ No newline at end of file

Reply via email to