Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Begin fixing the internal anchors and nav for the site

  • Loading branch information...
commit ff0906c7ae6acbca0a75cb4511d4b6746f2358a6 1 parent 30ed935
@mde mde authored
View
57 site/app/controllers/main.js
@@ -19,7 +19,16 @@
var fs = require('fs')
, path = require('path')
, md = require('marked')
- , hljs = require('highlight.js');
+ , hljs = require('highlight.js')
+ , TOC = function (parent, text) {
+ this.parent = parent;
+ this.text = text;
+ this.name = null;
+ this.children = [];
+ if (parent) {
+ parent.children.push(this);
+ };
+ };
var BRANCH = 'v0.12'
, URL_PREFIX = 'https://raw.github.com/geddy/geddy/' +
@@ -142,16 +151,44 @@ var Main = function () {
this.tutorial = function (req, resp, params) {
var self = this;
- fetch('tutorial.md', function (data) {
- var content = md(data)
- , lines = data.split('\n')
- , sections = [];
- for (var i in lines) {
- if (lines[i].indexOf('### ') == 0) {
- sections.push(geddy.string.trim(lines[i].replace("###", '')));
+ fetch('tutorial.md', function (d) {
+ var content
+ , lines = d.split('\n')
+ , sections = []
+ , data = []
+ , currentLength = 0
+ , currentObj = new TOC()
+ , topObj = currentObj;
+
+ lines.forEach(function (line) {
+ var s, t, n, match, pat = /^#+/;;
+ if ((match = pat.exec(line))) {
+ t = geddy.string.trim(line.replace(pat, ''));
+ n = t.toLowerCase().replace(/ /g, '_');
+ // If more pound signs, we're descending into children
+ if (match[0].length > currentLength) {
+ s = new TOC(currentObj, t);
+ }
+ // Fewer pound signs, we're going up to next sibling of parent
+ else if (match[0].length < currentLength) {
+ s = new TOC(currentObj.parent.parent, t);
+ }
+ // Same number, next child
+ else {
+ s = new TOC(currentObj.parent, t);
+ }
+ currentObj = s;
+ n = s.parent.name ? s.parent.name + '_' + n : n;
+ s.name = n;
+ data.push('<a name="' + n + '"></a>');
+ currentLength = match[0].length;
}
- }
- self.respond({sections: sections, content: content}, {
+
+ data.push(line);
+ });
+ content = md(data.join('\n'));
+
+ self.respond({sections: topObj, content: content}, {
format: 'html'
, template: 'app/views/main/tutorial'
});
View
2  site/app/views/main/guide.html.jade
@@ -12,7 +12,7 @@
ul
each sub in doc.subs
li
- a(href="#"+ encodeURIComponent(doc.name+sub))=sub
+ a(href="#"+ encodeURIComponent(geddy.string.capitalize(doc.name)+sub))=sub
.span6.docs
each doc in docs
h3(id=doc.name)=geddy.string.capitalize(doc.name)
View
5 site/app/views/main/tutorial.html.jade
@@ -3,9 +3,6 @@
h2 Quick start tutorial
.row.content
.span4.toc
- ul
- each section in sections
- li
- a(href="#"+ encodeURIComponent(section))=section
+ != toc(sections)
.span8.docs
!=content
View
20 site/public/js/site.js
@@ -11,7 +11,6 @@ app.docs = new (function() {
this.init = function() {
this.$toc = $('.toc');
this.$content = $('content .span8');
- this.giveSubIDs();
this.registerScroll();
this.registerMenu();
};
@@ -61,25 +60,6 @@ app.docs = new (function() {
});
};
- // make internal anchor links work for sub menu items
- this.giveSubIDs = function() {
- $('.content .docs').find('h3, h4').each(function (i, el) {
- var $el = $(el);
- console.log($el);
- if (el.nodeName == "H3") {
- section = $el.attr('id');
- if (!section) {
- section = $el.text()
- $el.attr('id', section);
- }
- }
- else {
- console.log($el.text());
- $el.attr('id', encodeURIComponent(section + $el.text()));
- }
- });
- };
-
})();
// wait for document to load
View
2  tutorial.md
@@ -3,7 +3,7 @@
In this tutorial we'll learn how to use Geddy by creating a simple To-Do
Manager applciation.
-#### In this tutorial we'll cover:
+In this tutorial we'll cover:
- Creating a Geddy application
- Learning how to use the Geddy executable
Please sign in to comment.
Something went wrong with that request. Please try again.