Skip to content

Commit 3405698

Browse files
author
Michael Sharer
committed
Initial Commit of Redux for Dash v3.4.0
0 parents  commit 3405698

14 files changed

+460
-0
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_Store
2+
node_modules
3+
Contents/Resources
4+
src/docs
5+
*.docset
6+
*.tgz

Contents/Info.plist

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleIdentifier</key>
6+
<string>Facebook</string>
7+
<key>CFBundleName</key>
8+
<string>Redux</string>
9+
<key>DocSetPlatformFamily</key>
10+
<string>Redux</string>
11+
<key>DashDocSetFamily</key>
12+
<string>dashtoc</string>
13+
<key>isDashDocset</key>
14+
<true/>
15+
<key>isJavaScriptEnabled</key>
16+
<true/>
17+
<key>dashIndexFilePath</key>
18+
<string>redux/index.html</string>
19+
</dict>
20+
</plist>

README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# [Redux](https://github.com/reactjs/redux/) documentation for [Dash](http://kapeli.com/dash)
2+
3+
## Installation in Dash
4+
5+
**To install the Redux documentation in Dash, go to:**
6+
7+
Preferences >> Downloads >> User Contributed
8+
9+
This repo is used to generate those docs. You don't need to touch it unless you want to contribute to it.
10+
11+
To update the docset, please read the instructions [here](https://github.com/Kapeli/Dash-User-Contributions#contribute-a-new-docset) (more specifically, "Set up your directory structure"). To generate the docset for your Dash-User-Contributions pull request, you'd use this repo.
12+
13+
**Note**: If you do wish to update the docset, please notify me by [opening an issue](https://github.com/epitaphmike/redux/issues/new). I'd like to double check everything before you send it off to the Dash repo.
14+
15+
## Docset Manual Build Instructions
16+
17+
Prerequisites: wget, node and sqlite3. For OS X:
18+
19+
brew install wget node sqlite3
20+
21+
Clone this repo, `cd` into it and do:
22+
23+
npm install
24+
chmod 777 build.sh
25+
./build.sh
26+
27+
The script will:
28+
29+
- Fetch the newest released Redux documentation from https://github.com/reactjs/redux/.
30+
- Parse the doc site into a new SQLite database for Dash. The list of files are hardcoded. Please check `src/index.js` for more detail.
31+
- Bundle up the result in a Redux.docset.
32+
- GZip for Dash contribution
33+
34+
Test the output by loading the Redux.docset (importing it into Dash).

build.sh

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# clean up previous remains, if any
2+
rm -rf Contents/Resources
3+
rm -rf Redux.docset
4+
mkdir -p Contents/Resources/Documents
5+
6+
# create a fresh sqlite db
7+
cd Contents/Resources
8+
sqlite3 docSet.dsidx 'CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT)'
9+
sqlite3 docSet.dsidx 'CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path)'
10+
11+
# fetch the whole doc site
12+
cd Documents
13+
wget -m -p -E -k -np http://redux.js.org/
14+
15+
# change folder name to just redux
16+
mv redux.js.org ./redux
17+
cd ../../../
18+
19+
# create data file from base index page
20+
node src/createSectionJSON.js
21+
22+
# change the documentation markup layout a bit to fit dash's small window
23+
node src/modifyDocsHTML.js
24+
25+
# read the previously fetched doc site and parse it into sqlite
26+
node src/index.js
27+
28+
# bundle up!
29+
mkdir Redux.docset
30+
cp -r Contents Redux.docset
31+
cp src/icon* Redux.docset
32+
33+
# Create gzip bundle for Dash Contribution
34+
tar --exclude='.DS_Store' -cvzf Redux.tgz Redux.docset

package.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "redux",
3+
"version": "3.4.0",
4+
"description": "Redux Documentation Source for Dash (http://kapeli.com/dash)",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/epitaphmike/redux-dash"
8+
},
9+
"main": "src/index.js",
10+
"dependencies": {
11+
"cheerio": "^0.19.0",
12+
"lodash.flatten": "^3.0.2",
13+
"sequelize": "^3.0.0",
14+
"sqlite3": "^3.0.9"
15+
},
16+
"keywords": [
17+
"Redux",
18+
"React",
19+
"Reactjs",
20+
"Facebook",
21+
"javascript",
22+
"iOS",
23+
"android"
24+
],
25+
"devDependencies": {},
26+
"scripts": {
27+
"test": "echo \"Error: no test specified\" && exit 1"
28+
},
29+
"author": "Michael Sharer <[email protected]> (http://29degre.es)",
30+
"license": "ISC",
31+
"bugs": {
32+
"url": "https://github.com/epitaphmike/redux-dash/issues"
33+
},
34+
"homepage": "https://github.com/epitaphmike/redux-dash"
35+
}

src/config.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var config = {
2+
"name" : "redux",
3+
"properName" : "Redux",
4+
"index" : "index.html",
5+
6+
"sectionClass" : "chapter",
7+
"headerTag" : "h1",
8+
"defaultPageType" : "Guides",
9+
"defaultPageTOC" : "Section",
10+
"pageHeader" : ".page-inner section h1",
11+
"pageSubHeaders" : [".page-inner section h2"],
12+
"ignoreSection" : {
13+
"sectionsArray" : []
14+
},
15+
"ignorePage" : {
16+
"pagesArray" : []
17+
}
18+
}
19+
20+
module.exports = config;

src/createSectionJSON.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
var cheerio = require('cheerio');
2+
var fs = require('fs');
3+
var config = require('./config');
4+
5+
// get base file to itterate over
6+
var basePath = __dirname + '/../Contents/Resources/Documents/' + config.name + '/' + config.index;
7+
var baseSrc = fs.readFileSync(basePath, 'utf8');
8+
var $ = cheerio.load(baseSrc);
9+
var pageNamesArray = [];
10+
var $section = $('nav ul.summary li.' + config.sectionClass);
11+
var path = __dirname + '/../src/indexedFiles.js';
12+
13+
$section.each(function(i, elem){
14+
15+
// TODO: create a better config pointer
16+
//var $sectionHeader = $(this).children(config.headerTag).text();
17+
var $sectionHeader = $(this).children('a').text();
18+
var $sectionLink = $(this).children('ul.articles').children('li').children('a');
19+
20+
$sectionLink.each(function(i, elem){
21+
var page = {};
22+
var excludeArray = $(this).text();
23+
24+
if(config.ignoreSection.sectionsArray.indexOf($sectionHeader) !== -1) {
25+
return;
26+
}
27+
28+
// $(this).attr('href') returns ie.(guides-containers.html#content)
29+
// substring removes last 13 characters '.html' from href.
30+
var sectionType = $(this).attr('href').split('/')[1];
31+
page.name = $(this).attr('href').substring(0, $(this).attr('href').length - 5);
32+
33+
if(config.ignorePage.pagesArray.indexOf(excludeArray) !== -1) {
34+
return;
35+
}
36+
37+
// set the Dash types based on the doc headers.
38+
switch (sectionType) {
39+
case 'recipes':
40+
page.type = 'Sample';
41+
page.toc = 'Property';
42+
break;
43+
case 'api':
44+
page.type = 'Function';
45+
page.toc = 'Method';
46+
break;
47+
default:
48+
page.type = config.defaultPageType;
49+
page.toc = config.defaultPageTOC;
50+
};
51+
pageNamesArray.push(page);
52+
});
53+
});
54+
55+
fs.writeFile(path, 'var indexedFiles = ' + JSON.stringify(pageNamesArray, null, 4) + ';\n\nmodule.exports = indexedFiles;', 'utf8');

src/getData.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
var cheerio = require('cheerio');
2+
var fs = require('fs');
3+
var flatten = require('lodash.flatten');
4+
var config = require('./config');
5+
var indexedFiles = require('./indexedFiles');
6+
7+
// this assumes build.sh has been run, and the docs fetched into
8+
// Contents/Resources/Documents/redux
9+
function getData() {
10+
var res = indexedFiles.map(function(array) {
11+
var path = __dirname + '/../Contents/Resources/Documents/' + config.name + '/' + array.name + '.html';
12+
var src = fs.readFileSync(path, 'utf-8');
13+
var $ = cheerio.load(src);
14+
15+
var $headers = $(config.pageHeader).first();
16+
17+
var names = [];
18+
19+
$headers.each(function(index, elem) {
20+
21+
var name = $($(elem).contents()).text();
22+
23+
names.push(name.trim());
24+
});
25+
26+
var url = config.name + '/' + array.name + '.html';
27+
28+
var res = names.map(function(n, i) {
29+
return {
30+
name: n,
31+
type: array.type,
32+
path: url,
33+
};
34+
});
35+
36+
return res;
37+
});
38+
39+
return flatten(res);
40+
}
41+
42+
module.exports = getData;

src/icon.png

1.57 KB
Loading

src/[email protected]

2.27 KB
Loading

src/icon_64px.png

3.66 KB
Loading

src/index.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
var getData = require('./getData');
2+
var Sequelize = require('sequelize');
3+
4+
// to see the relevant doc pages we crawl, check indexedFiles.js
5+
6+
// db ops
7+
var sequelize = new Sequelize('database', null, null, {
8+
dialect: 'sqlite',
9+
storage: __dirname + '/../Contents/Resources/docSet.dsidx',
10+
});
11+
12+
var searchIndex = sequelize.define(
13+
'searchIndex',
14+
{
15+
id: {type: Sequelize.INTEGER, autoIncrement: true, primaryKey: true},
16+
name: {type: Sequelize.STRING},
17+
type: {type: Sequelize.STRING},
18+
path: {type: Sequelize.STRING},
19+
},
20+
{
21+
freezeTableName: true,
22+
timestamps: false,
23+
}
24+
);
25+
26+
searchIndex.sync().then(function() {
27+
var data = getData();
28+
data.forEach(function(header) {
29+
var si = searchIndex.build({
30+
name: header.name,
31+
type: header.type,
32+
path: header.path
33+
});
34+
si.save();
35+
});
36+
});

0 commit comments

Comments
 (0)