Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
157 lines (130 loc) · 6.09 KB
/
Copy pathapp.js
File metadata and controls
157 lines (130 loc) · 6.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
DOCUMENTATION_FOLDER = '/learning-resources/';
angular.module('JuliusAkula',['ui.bootstrap', 'ui.router', 'ngClipboard', 'yaru22.md']).config(['ngClipProvider', '$stateProvider', '$urlRouterProvider', function(ngClipProvider, $stateProvider, $urlRouterProvider){
$urlRouterProvider.otherwise("/");
$stateProvider.state('index', {
url: "/",
templateUrl: 'src/views/homepage.tpl.html',
controller: function($scope){
$scope.btns = "btn btn-";
$scope.types = [
{
type: 'default',
message: 'Default Dialog'
},
{
type: 'danger',
message: 'Danger Dialog'
},
{
type: 'primary',
message: 'Primary Dialog'
},
{
type: 'success',
message: 'Success Dialog'
},
{
type: 'warning',
message: 'Warning Dialog'
},
{
type: 'info',
message: 'Info Dialog'
}];
}
});
ngClipProvider.setPath("node_modules/zeroclipboard/dist/ZeroClipboard.swf");
}]).controller('MarkdownRepeaterCtrl', function($scope, $http, $timeout, ReadmeService){
$scope.isCollapsed = false;
$scope.toggleCollapse = function(){
$scope.isCollapsed = !$scope.isCollapsed;
};
$scope.text = '';
$scope.$watch('text', function(newVal, oldVal){
if(oldVal == '' && newVal != ''){
// parse the text, get list of stuff to parse.
}
});
$scope.readREADME = function(filename){
$http({method: "GET", url: filename}).success(function(data, status, headers, config) {
$scope.text = data;
$scope.parseOrder();
});
};
$scope.FinalRender = '';
$scope.readyToFinalize = false;
$scope.FinalRenderData = {};
$scope.numLinks = 0;
$scope.FinalRenderData.numBulletPoints = 0;
$scope.FinalRenderData.numTotalRequests = 0; // know when to stop.
$scope.FinalRenderData.sentRequests = [];
$scope.parseOrder = function(){
// README.md, raw text is accessible via $scope.text. Search for `## Contents`. Each newline, if it begins with 1. ; is a "Section", and can be a "subsection" if it has two spaces and then `1.`
// current task print out only those lines
var begin = $scope.text.indexOf('## Contents');
contentsList = $scope.text.substr(begin);
arrayOfLines = contentsList.match(/[^\r\n]+/g); // would capture a blank newline http://stackoverflow.com/a/5035058/3100494
for(line in arrayOfLines){
var thisLine = arrayOfLines[line];
if(line==0){
$scope.text='';
}
var isBulletPoint = thisLine.indexOf('1.');
var hasLink = thisLine.indexOf('](');
if(isBulletPoint > -1){
// move to sentTopLevelRequests area a few lines down?
if(isBulletPoint == 0){
// Top level section, "Fundamentals, Developer tools"
}
else if(isBulletPoint == 2){
}
else{
// ... ?
}
$scope.numBulletPoints++;
if(isBulletPoint >= 0){
console.log(thisLine)
// Main section. Give it a big title, and list the links
// count of links counted after HTTP parse
// get link
if(hasLink > -1){
theLink = thisLine.substr(2);
theLink = theLink.substr(hasLink, thisLine.indexOf(")") - 2)
theLink = DOCUMENTATION_FOLDER + theLink.substring(0, theLink.length - 1);
console.log(theLink);
// increment amount of outgoing requests for top-level bullets, and send that outgoing request, to potentially recieve second-level bullets. When all the top-level are successfully returned, the contents of $scope.text will update to h, and trigger reading the second-level bullets.
$scope.FinalRenderData.numTotalRequests++;
$scope.FinalRenderData.sentRequests[$scope.numLinks] = { lineNo: $scope.FinalRenderData.numBulletPoints, url: theLink };
$scope.numLinks++;
}
//does not have link (only the "Future" section)
else{
}
}
$scope.text += thisLine+"\n";
}
// only add stuff to $scope.text if its in the bullet points parsed out of README.md
}
// goal is then parse out the parenthesis from `](` to the end `)`, that's the Link to parse out however many more links it may contain
// contained links are in the format
// * [link of material](www...) By [link to author/org](www...) #book/#article/#video
$timeout(function(){console.log($scope.FinalRenderData);}, 2000);
};
//$scope.$watch('FinalRenderData', function(newVal, oldVal){
// if(newVal!==0 && oldVal !== 0){
// // parse the text, get list of stuff to parse.
// if($scope.FinalRenderData.numTotalRequests == $scope.FinalRenderData.sentRequests.length){
// alert("Wooo!!");
// alert($scope.FinalRenderData.numTotalRequests);
// }
// }
//});
$scope.readREADME("README.md");
}).factory('ReadmeService', function($http){
return {
getReadme: function(url) {
return $http({method: "GET", url: url}).then(function(data, status, headers, config) {
return data; })
}
}
});