nitweb/angular: add DocDown snippets page
authorAlexandre Terrasa <alexandre@moz-code.org>
Wed, 22 Jun 2016 01:20:45 +0000 (21:20 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Thu, 23 Jun 2016 14:25:02 +0000 (10:25 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

share/nitweb/index.html
share/nitweb/javascripts/docdown.js [new file with mode: 0644]
share/nitweb/javascripts/model.js
share/nitweb/javascripts/nitweb.js
share/nitweb/views/docdown.html [new file with mode: 0644]

index 337750b..c615d41 100644 (file)
        <body>
                <nav class='navbar navbar-default navbar-fixed-top'>
                        <div class='container-fluid'>
-                               <div class='col-xs-3 navbar-header'>
-                                       <a class='navbar-brand' ng-href='/'>Nitdoc</a>
+                               <div class='col-xs-3'>
+                                       <div class='navbar-header'>
+                                               <a class='navbar-brand' ng-href='/'>Nitdoc</a>
+                                       </div>
+                                       <ul class="nav navbar-nav">
+                                               <li><a href="/docdown?edit=true">DocDown</a></li>
+                                       </ul>
                                </div>
                                <div class='col-xs-7'>
                                        <form ng-controller='SearchCtrl as searchCtrl' >
@@ -64,5 +69,6 @@
                <script src='/javascripts/entities.js'></script>
                <script src='/javascripts/ui.js'></script>
                <script src='/javascripts/index.js'></script>
+               <script src='/javascripts/docdown.js'></script>
        </body>
 </html>
diff --git a/share/nitweb/javascripts/docdown.js b/share/nitweb/javascripts/docdown.js
new file mode 100644 (file)
index 0000000..365b8c9
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2016 Alexandre Terrasa <alexandre@moz-code.org>.
+ *
+ * Licensed 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.
+ */
+
+(function() {
+       angular
+               .module('docdown', ['model', 'ngSanitize'])
+
+               .controller('DocdownCtrl', ['$routeParams', '$sce', '$scope', '$location', 'DocDown', function($routeParams, $sce, $scope, $location, DocDown) {
+
+                       this.updateSnippet = function() {
+                               this.updateLink();
+                               this.updateHtml();
+                       }
+
+                       this.updateLink = function() {
+                               $scope.link = $location.protocol()+ '://' + $location.host() + ':' +
+                                       $location.port() + $location.path() + '?snippet=' +
+                                       encodeURIComponent(btoa($scope.markdown));
+                       }
+
+                       this.updateHtml = function() {
+                               DocDown.postMarkdown($scope.markdown,
+                                       function(data) {
+                                               $scope.html = $sce.trustAsHtml(data);
+                                       }, function(err) {
+                                               $scope.error = err;
+                                       });
+                       };
+
+                       this.editMode = function(isEdit) {
+                               $scope.edit = isEdit;
+                       }
+
+                       $scope.markdown = 'Type some markdown...';
+                       if($location.search().snippet) {
+                               $scope.markdown = atob($location.search().snippet);
+                       }
+                       $scope.edit = false;
+                       if($location.search().edit) {
+                               $scope.edit = Boolean($location.search().edit);
+                       }
+
+                       this.updateSnippet();
+               }])
+})();
index 8812a7a..3accab2 100644 (file)
                                },
                        }
                }])
+
+               .factory('DocDown', [ '$http', function($http) {
+                       return {
+                               postMarkdown: function(md, cb, cbErr) {
+                                       $http.post(apiUrl + '/docdown', md)
+                                               .success(cb)
+                                               .error(cbErr);
+                               }
+                       }
+               }])
 })();
index 99034a7..7fa1142 100644 (file)
@@ -15,7 +15,7 @@
  */
 
 (function() {
-       angular.module('nitweb', ['ngRoute', 'ngSanitize', 'angular-loading-bar', 'entities', 'index'])
+       angular.module('nitweb', ['ngRoute', 'ngSanitize', 'angular-loading-bar', 'entities', 'docdown', 'index'])
        .config(['cfpLoadingBarProvider', function(cfpLoadingBarProvider) {
                cfpLoadingBarProvider.includeSpinner = false;
        }])
                                controller: 'IndexCtrl',
                                controllerAs: 'indexCtrl'
                        })
+                       .when('/docdown', {
+                               templateUrl: 'views/docdown.html',
+                               controller: 'DocdownCtrl',
+                               controllerAs: 'docdownCtrl'
+                       })
                        .when('/doc/:id', {
                                templateUrl: 'views/doc.html',
                                controller: 'EntityCtrl',
diff --git a/share/nitweb/views/docdown.html b/share/nitweb/views/docdown.html
new file mode 100644 (file)
index 0000000..75fe6df
--- /dev/null
@@ -0,0 +1,33 @@
+<div class='container-fluid'>
+       <div class='page-header'>
+               <h2>Docdown snippets</h2>
+               <p class='text-muted'>Sharable documentation snippets.</p>
+               <div class="input-group">
+                       <span ng-if='edit' class="input-group-btn">
+                               <button class='btn btn-success' ng-click='docdownCtrl.editMode(false)'>
+                                       <span class='glyphicon glyphicon-link' /> View
+                               </button>
+                       </span>
+                       <span ng-if='!edit' class="input-group-btn">
+                               <button class='btn btn-success' ng-click='docdownCtrl.editMode(true)'>
+                                       <span class='glyphicon glyphicon-edit' /> Edit
+                               </button>
+                       </span>
+                       <input class='form-control' type='text' ng-model='link' />
+               </div>
+       </div>
+       <div class='row'>
+               <div ng-show='edit' class='col-xs-6'>
+                       <div class='card'>
+                               <textarea ng-model='markdown' ng-model-options='{ debounce: 100 }' ng-change='docdownCtrl.updateSnippet()' class='form-control' rows='20'></textarea>
+                       </div>
+               </div>
+               <div ng-class='edit ? "col-xs-6" : "col-xs-12"'>
+                       <div class='card'>
+                               <div class='card-body nitdoc'>
+                                       <div ng-bind-html='html' />
+                               </div>
+                       </div>
+               </div>
+       </div>
+</div>