You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ca...@apache.org on 2020/04/17 23:36:33 UTC

[royale-asjs] branch develop updated: markdown-example: load from a royale docs md page from github

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 99fc0e3  markdown-example: load from a royale docs md page from github
99fc0e3 is described below

commit 99fc0e3771151880df2a22b7586f5cb95c377109
Author: Carlos Rovira <ca...@apache.org>
AuthorDate: Sat Apr 18 01:36:29 2020 +0200

    markdown-example: load from a royale docs md page from github
---
 .../src/main/royale/MainContent.mxml               |  29 ++++--
 .../src/main/royale/services/GitHubService.as      | 102 +++++++++++++++++++++
 2 files changed, 122 insertions(+), 9 deletions(-)

diff --git a/examples/jewel/royale-website/src/main/royale/MainContent.mxml b/examples/jewel/royale-website/src/main/royale/MainContent.mxml
index ac14c68..d715277 100644
--- a/examples/jewel/royale-website/src/main/royale/MainContent.mxml
+++ b/examples/jewel/royale-website/src/main/royale/MainContent.mxml
@@ -21,13 +21,16 @@ limitations under the License.
     xmlns:j="library://ns.apache.org/royale/jewel"
     xmlns:js="library://ns.apache.org/royale/basic"
     xmlns:html="library://ns.apache.org/royale/html"
-    xmlns:local="*"
-    >
+    initComplete="initComplete(event)">
 
     <fx:Script>
         <![CDATA[
             import org.apache.royale.events.Event;
+
+            import services.GitHubService;
             
+            private var service:GitHubService;
+
             public var md:markdownit;
 
             public function initComplete(event:Event):void
@@ -41,7 +44,8 @@ limitations under the License.
                     highlight: myHighlight
                 });
                 
-                lab.html = md.render('# Marked in browser\n\nRendered by **marked**. Syntax highlighting\n ```js \n var foo = function (bar) { \n return bar++; \n }; \n console.log(foo(5));\n ```');
+                service = new GitHubService();
+                service.addEventListener("dataReady", dataReadyHandler);
             }
 
             public function myHighlight(str:String, lang:String):String { 
@@ -52,16 +56,22 @@ limitations under the License.
                         // return hljs.highlight(lang, str).value;
                     } catch (error:Error) 
                     {
-
+                        trace(error);
                     }
                 }
 
                 return ''; // use external default escaping
             }
 
-            public function markDownComplete():void
+            public function loadGithubMarkDown():void
+            {
+                service.sourceCodeUrl = "https://raw.githubusercontent.com/apache/royale-docs/master/features/as3.md";
+                service.getContent();
+            }
+
+            public function dataReadyHandler(event:Event):void
             {
-                trace("finished!!");
+                placeholder.html = md.render(event.target.jsonToString);
             }
         ]]>
     </fx:Script>
@@ -70,8 +80,9 @@ limitations under the License.
         <js:ContainerDataBinding/>
     </j:beads>
 
-    <j:VContainer initComplete="initComplete(event)" width="400" height="400">
-        <j:Label localId="lab" multiline="true"/>
-    </j:VContainer>
+    <j:ScrollableSectionContent width="100%" height="100%" isSelected="true">
+        <j:Button text="Load MarkDown from Github" click="loadGithubMarkDown()"/>
+        <j:Label localId="placeholder" multiline="true"/>
+    </j:ScrollableSectionContent>
 
 </j:ApplicationResponsiveView>
diff --git a/examples/jewel/royale-website/src/main/royale/services/GitHubService.as b/examples/jewel/royale-website/src/main/royale/services/GitHubService.as
new file mode 100644
index 0000000..28c8340
--- /dev/null
+++ b/examples/jewel/royale-website/src/main/royale/services/GitHubService.as
@@ -0,0 +1,102 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package services
+{
+	import org.apache.royale.events.Event;
+	import org.apache.royale.events.EventDispatcher;
+	import org.apache.royale.net.HTTPConstants;
+	import org.apache.royale.net.HTTPService;
+	import org.apache.royale.utils.string.Base64;
+
+    [Event(name="dataReady", type="org.apache.royale.events.Event")]
+    /**
+     * GitHubService is in charge of getting the source code of some example
+     * so we can show the code in a TabBarContentPanel along with the working example
+     */
+	public class GitHubService extends EventDispatcher
+	{
+        /**
+         * constructor
+         */
+        public function GitHubService():void
+        {    
+            service = new HTTPService();
+            service.addEventListener(HTTPConstants.COMPLETE, completeHandler);
+        }
+
+        /**
+         * the service that performs the request to Github
+         */
+		private var service:HTTPService;
+
+        /**
+         * we dispatch an event once we have the source code from gihub
+         */
+        private function completeHandler(event:Event):void
+        {
+            dispatchEvent(new Event("dataReady"));
+        }
+
+        private var _sourceCodeUrl:String = null;
+        /**
+         * The source code url we want to retrieve
+         */
+        public function get sourceCodeUrl():String
+        {
+        	return _sourceCodeUrl;
+        }
+        public function set sourceCodeUrl(value:String):void
+        {
+            _sourceCodeUrl = value;
+            service.url = sourceCodeUrl;
+        }
+
+        /**
+         * 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 getContent():void
+        {
+        	service.send();
+        }
+	}
+}
\ No newline at end of file