Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c5381c6

Browse files
author
Tariq Islam
committedJul 8, 2014
Merge pull request #90 from tripit/dev
Version 1.0
2 parents 0a8c73a + 60d1dbd commit c5381c6

15 files changed

+644
-304
lines changed
 

‎CHANGELOG.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Changelog
2+
3+
## Version 1.0
4+
5+
*July 2, 2014*
6+
7+
[View Issues](https://github.com/tripit/slate/issues?milestone=1&state=closed)
8+
9+
**Features:**
10+
11+
- Responsive designs for phones and tablets
12+
- Started tagging versions
13+
14+
**Fixes:**
15+
16+
- Fixed 'unrecognized expression' error
17+
- Fixed #undefined hash bug
18+
- Fixed bug where the current language tab would be unselected
19+
- Fixed bug where tocify wouldn't highlight the current section while searching
20+
- Fixed bug where ids of header tags would have special characters that caused problems
21+
- Updated layout so that pages with disabled search wouldn't load search.js
22+
- Cleaned up Javascript

‎README.md

+18-12
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ Slate
33

44
[![Build Status](https://travis-ci.org/tripit/slate.svg?branch=master)](https://travis-ci.org/tripit/slate) [![Dependency Status](https://gemnasium.com/tripit/slate.png)](https://gemnasium.com/tripit/slate)
55

6-
Slate helps you create beautiful single-page API documentation. Think of it as an intelligent, modern documentation template for your API.
6+
Slate helps you create beautiful API documentation. Think of it as an intelligent, responsive documentation template for your API.
77

8-
<img src="https://dl.dropboxusercontent.com/u/95847291/github%20images/slate/slate_screenshot.png" width=700 alt="Screenshot of Example Documentation created with Slate">
8+
<img src="https://dl.dropboxusercontent.com/u/95847291/github%20images/slate/slate_screenshot_new.png" width=700 alt="Screenshot of Example Documentation created with Slate">
99

1010
*The example above was created with Slate. Check it out at [tripit.github.io/slate](http://tripit.github.io/slate).*
1111

1212
Features
1313
------------
1414

15-
* **Clean, intuitive design** — with Slate, the description of your API is on the left side of your documentation, and all the code examples are on the right side. Inspired by [Stripe's](https://stripe.com/docs/api) and [Paypal's](https://developer.paypal.com/webapps/developer/docs/api/) API docs. In addition to the design you see on screen, Slate comes with a print stylesheet, so your docs look great on paper.
15+
* **Clean, intuitive design** — with Slate, the description of your API is on the left side of your documentation, and all the code examples are on the right side. Inspired by [Stripe's](https://stripe.com/docs/api) and [Paypal's](https://developer.paypal.com/webapps/developer/docs/api/) API docs. Slate is responsive, so it looks great on tablets, phones, and even print.
1616

17-
* **Everything on a single page** — gone are the days where your users had to search through a million pages to find what they wanted. Slate puts the entire documentation on a single page. We haven't sacrificed linkability, though. As you scroll, your browser's hash will update to the nearest header, so it's insanely easy to link to a particular point in the documentation.
17+
* **Everything on a single page** — gone are the days where your users had to search through a million pages to find what they wanted. Slate puts the entire documentation on a single page. We haven't sacrificed linkability, though. As you scroll, your browser's hash will update to the nearest header, so linking to a particular point in the documentation is still natural and easy.
1818

1919
* **Slate is just Markdown** — when you write docs with Slate, you're just writing Markdown, which makes it simple to edit and understand. Everything is written in Markdown — even the code samples are just Markdown code blocks!
2020

@@ -55,6 +55,8 @@ Now that Slate is all set up your machine, you'll probably want to learn more ab
5555
Examples of Slate in the Wild
5656
---------------------------------
5757

58+
* [Travis-CI's API docs](http://docs.travis-ci.com/api/)
59+
* [Mozilla's localForage docs](http://mozilla.github.io/localForage/)
5860
* [Orchestrate.io API docs](https://docs.orchestrate.io/)
5961
* [ChaiOne Gameplan API docs](http://chaione.github.io/gameplanb2b/#introduction)
6062
* [Drcaban's Build a Quine tutorial](http://drcabana.github.io/build-a-quine/#introduction)
@@ -69,18 +71,22 @@ Need Help? Found a bug?
6971
Just [submit a issue](https://github.com/tripit/slate/issues) to the Slate Github if you need any help. And, of course, feel free to submit pull requests with bug fixes or changes.
7072

7173

74+
Contributors
75+
--------------------
76+
77+
Slate was built by [Robert Lord](http://lord.io) while at [TripIt](http://tripit.com).
78+
79+
Thanks to the following people who have submitted major pull requests:
80+
81+
- [@chrissrogers](https://github.com/chrissrogers)
82+
- [@bootstraponline](https://github.com/bootstraponline)
83+
84+
Also, thanks to [Sauce Labs](http://saucelabs.com) for helping sponsor the project.
85+
7286
Special Thanks
7387
--------------------
7488
- [Middleman](https://github.com/middleman/middleman)
7589
- [jquery.tocify.js](https://github.com/gfranko/jquery.tocify.js)
7690
- [middleman-syntax](https://github.com/middleman/middleman-syntax)
7791
- [middleman-gh-pages](https://github.com/neo/middleman-gh-pages)
7892
- [Font Awesome](http://fortawesome.github.io/Font-Awesome/)
79-
80-
Contributors
81-
--------------------
82-
83-
Thanks to the following people who have submitted pull requests:
84-
85-
- [@chrissrogers](https://github.com/chrissrogers)
86-
- [@bootstraponline](https://github.com/bootstraponline)

‎config.rb

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require './lib/redcarpet_header_fix'
2+
13
set :css_dir, 'stylesheets'
24

35
set :js_dir, 'javascripts'
@@ -34,3 +36,4 @@
3436
# Or use a different image path
3537
# set :http_prefix, "/Content/images/"
3638
end
39+

‎lib/redcarpet_header_fix.rb

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module RedcarpetHeaderFix
2+
def header(text, level, id)
3+
clean_id = id.gsub(/[\.]/, '-').gsub(/[^a-zA-Z0-9\-_]/, '')
4+
"<h#{level} id='#{clean_id}'>#{text}</h1>"
5+
end
6+
end
7+
8+
require 'middleman-core/renderers/redcarpet'
9+
Middleman::Renderers::MiddlemanRedcarpetHTML.send :include, RedcarpetHeaderFix

‎source/images/navbar.png

2.72 KB
Loading

‎source/javascripts/all_nosearch.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//= require_tree ./lib
2+
//= require_tree ./app
3+
//= stub ./app/search.js
4+
//= stub ./lib/lunr.js

‎source/javascripts/app/lang.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ under the License.
2121

2222
function activateLanguage(language) {
2323
if (!language) return;
24+
if (language === "") return;
2425

25-
$("#lang-selector a").removeClass('active');
26-
$("#lang-selector a[data-language-name='" + language + "']").addClass('active');
26+
$(".lang-selector a").removeClass('active');
27+
$(".lang-selector a[data-language-name='" + language + "']").addClass('active');
2728
for (var i=0; i < languages.length; i++) {
2829
$(".highlight." + languages[i]).hide();
2930
}
@@ -41,6 +42,9 @@ under the License.
4142
hash = hash.replace(/^#+/, '');
4243
}
4344
history.pushState({}, '', '?' + language + '#' + hash);
45+
46+
// save language as next default
47+
localStorage.setItem("language", language);
4448
}
4549

4650
function setupLanguages(l) {
@@ -53,7 +57,6 @@ under the License.
5357
// the language is in the URL, so use that language!
5458
activateLanguage(location.search.substr(1));
5559

56-
// set this language as the default for next time, if the URL has no language
5760
localStorage.setItem("language", location.search.substr(1));
5861
} else if ((defaultLanguage !== null) && (jQuery.inArray(defaultLanguage, languages) != -1)) {
5962
// the language was the last selected one saved in localstorage, so use that language!
@@ -66,7 +69,7 @@ under the License.
6669

6770
// if we click on a language tab, activate that language
6871
$(function() {
69-
$("#lang-selector a").on("click", function() {
72+
$(".lang-selector a").on("click", function() {
7073
var language = $(this).data("language-name");
7174
pushURL(language);
7275
activateLanguage(language);

‎source/javascripts/app/search.js

+21-79
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
(function (global) {
22

33
var $global = $(global);
4-
var content, darkBox, searchInfo;
4+
var content, darkBox, searchResults;
55
var highlightOpts = { element: 'span', className: 'search-highlight' };
66

7-
var index = new lunr.Index;
7+
var index = new lunr.Index();
88

99
index.ref('id');
1010
index.field('title', { boost: 10 });
@@ -14,15 +14,10 @@
1414
$(populate);
1515
$(bind);
1616

17-
function populate () {
18-
$('h1').each(function () {
17+
function populate() {
18+
$('h1, h2').each(function() {
1919
var title = $(this);
20-
var body = title.nextUntil('h1');
21-
var wrapper = $('<section id="section-' + title.prop('id') + '"></section>');
22-
23-
title.after(wrapper.append(body));
24-
wrapper.prepend(title);
25-
20+
var body = title.nextUntil('h1, h2');
2621
index.add({
2722
id: title.prop('id'),
2823
title: title.text(),
@@ -31,99 +26,46 @@
3126
});
3227
}
3328

34-
function bind () {
29+
function bind() {
3530
content = $('.content');
3631
darkBox = $('.dark-box');
37-
searchInfo = $('.search-info');
38-
39-
$('#input-search')
40-
.on('keyup', search)
41-
.on('focus', active)
42-
.on('blur', inactive);
43-
}
44-
45-
function refToHeader (itemRef) {
46-
return $('.tocify-item[data-unique=' + itemRef + ']').closest('.tocify-header');
47-
}
32+
searchResults = $('.search-results');
4833

49-
function sortDescending (obj2, obj1) {
50-
var s1 = parseInt(obj1.id.replace(/[^\d]/g, ''), 10);
51-
var s2 = parseInt(obj2.id.replace(/[^\d]/g, ''), 10);
52-
return s1 === s2 ? 0 : s1 < s2 ? -1 : 1;
34+
$('#input-search').on('keyup', search);
5335
}
5436

55-
function resetHeaderLocations () {
56-
var headers = $(".tocify-header").sort(sortDescending);
57-
$.each(headers, function (index, item) {
58-
$(item).insertBefore($("#toc ul:first-child"));
59-
});
60-
}
61-
62-
function search (event) {
63-
var sections = $('section, #toc .tocify-header');
64-
65-
searchInfo.hide();
37+
function search(event) {
6638
unhighlight();
39+
searchResults.addClass('visible');
6740

6841
// ESC clears the field
6942
if (event.keyCode === 27) this.value = '';
7043

7144
if (this.value) {
72-
sections.hide();
73-
// results are sorted by score in descending order
74-
var results = index.search(this.value);
45+
var results = index.search(this.value).filter(function(r) {
46+
return r.score > 0.0001;
47+
});
7548

7649
if (results.length) {
77-
resetHeaderLocations();
78-
var lastRef;
79-
$.each(results, function (index, item) {
80-
if (item.score <= 0.0001) return; // remove low-score results
81-
var itemRef = item.ref;
82-
$('#section-' + itemRef).show();
83-
// headers must be repositioned in the DOM
84-
var closestHeader = refToHeader(itemRef);
85-
if (lastRef) {
86-
refToHeader(lastRef).insertBefore(closestHeader);
87-
}
88-
closestHeader.show();
89-
lastRef = itemRef;
50+
searchResults.empty();
51+
$.each(results, function (index, result) {
52+
searchResults.append("<li><a href='#" + result.ref + "'>" + $('#'+result.ref).text() + "</a></li>");
9053
});
91-
92-
// position first element. it wasn't positioned above if len > 1
93-
if (results.length > 1) {
94-
var firstRef = results[0].ref;
95-
var secondRef = results[1].ref
96-
refToHeader(firstRef).insertBefore(refToHeader(secondRef));
97-
}
98-
9954
highlight.call(this);
10055
} else {
101-
sections.show();
102-
searchInfo.text('No Results Found for "' + this.value + '"').show();
56+
searchResults.html('<li>No Results Found for "' + this.value + '"</li>');
10357
}
10458
} else {
105-
sections.show();
59+
unhighlight();
60+
searchResults.removeClass('visible');
10661
}
107-
108-
// HACK trigger tocify height recalculation
109-
$global.triggerHandler('scroll.tocify');
110-
$global.triggerHandler('resize');
111-
}
112-
113-
function active () {
114-
search.call(this, {});
115-
}
116-
117-
function inactive () {
118-
unhighlight();
119-
searchInfo.hide();
12062
}
12163

122-
function highlight () {
64+
function highlight() {
12365
if (this.value) content.highlight(this.value, highlightOpts);
12466
}
12567

126-
function unhighlight () {
68+
function unhighlight() {
12769
content.unhighlight(highlightOpts);
12870
}
12971

‎source/javascripts/app/toc.js

+20-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
(function (global) {
22

3-
var toc;
3+
var closeToc = function() {
4+
$(".tocify-wrapper").removeClass('open');
5+
$("#nav-button").removeClass('open');
6+
};
47

5-
global.toc = toc;
6-
7-
$(toc);
8-
$(animate);
9-
10-
function toc () {
11-
toc = $("#toc").tocify({
8+
var makeToc = function() {
9+
global.toc = $("#toc").tocify({
1210
selectors: 'h1, h2',
1311
extendPage: false,
1412
theme: 'none',
@@ -17,13 +15,22 @@
1715
hideEffectSpeed: 180,
1816
ignoreSelector: '.toc-ignore',
1917
highlightOffset: 60,
20-
scrollTo: -2,
18+
scrollTo: -1,
2119
scrollHistory: true,
2220
hashGenerator: function (text, element) {
2321
return element.prop('id');
2422
}
2523
}).data('toc-tocify');
26-
}
24+
25+
$("#nav-button").click(function() {
26+
$(".tocify-wrapper").toggleClass('open');
27+
$("#nav-button").toggleClass('open');
28+
return false;
29+
});
30+
31+
$(".page-wrapper").click(closeToc);
32+
$(".tocify-item").click(closeToc);
33+
};
2734

2835
// Hack to make already open sections to start opened,
2936
// instead of displaying an ugly animation
@@ -33,5 +40,8 @@
3340
}, 50);
3441
}
3542

43+
$(makeToc);
44+
$(animate);
45+
3646
})(window);
3747

There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Please sign in to comment.