Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Sep 3, 2014
1 parent 751b266 commit 2db33b9
Show file tree
Hide file tree
Showing 52 changed files with 4,673 additions and 8,880 deletions.
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ branches:
- master
env:
global:
- secure: "B1vanjI2TMf+YnmbcF5HWAMNnmT+CFr2EB1CCIcyoWqs2RIBvgiDH0gDR46iUDdfPRSt3Eokaru1fY8ptZDRnrt3oKokWp4ZrRO0x7uUGbkGfdmHHxnOlUA1m9rVhaOBCWl5opfaA8ncWcXwdWZGg7HWpS7EfTNr2dIr7lAC2mU="
- secure: "a9Qx7y7dIWXEdppdmPW5g6CJQpUWUmd3sKWcJPKMfcg+xVHEBhPl9PCt/2jGK1sxstTDiwrVaV1NKpG4qD03UVot2zX28o1mM7JY6rDAl709rvKveegDeC9vo+U/BWid3lq/Impl37X0YYGY+spEcptI6bnvWxa6d7MGPCx3L2c="
- GH_OWNER: GoogleCloudPlatform
- GH_PROJECT_NAME: gcloud-node
script:
- npm run lint
- npm run test
after_success:
- git submodule add -b gh-pages https://${GH_OAUTH_TOKEN}@github.com/${GH_OWNER}/${GH_PROJECT_NAME} site > /dev/null 2>&1
- cd site
- git submodule add -b master https://${GH_OAUTH_TOKEN}@github.com/${GH_OWNER}/${GH_PROJECT_NAME} master > /dev/null 2>&1
- cd master
- npm install
- npm run docs
- git submodule add -b gh-pages https://${GH_OAUTH_TOKEN}@github.com/${GH_OWNER}/${GH_PROJECT_NAME} ghpages > /dev/null 2>&1
- cd ghpages
- if git checkout gh-pages; then git checkout -b gh-pages; fi
- git rm -r .
- cp -R ../docs/* .
- cp ../docs/.* .
- git add -f .
- git config user.email "sawchuk@gmail.com"
- git config user.name "stephenplusplus"
Expand Down
124 changes: 124 additions & 0 deletions docs/components/docs/docs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<header class="page-header fixed" role="banner">
<h1 class="logo">
<a href="/gcloud-node" title="Home">
<img src="img/logo.svg" alt="Google Cloud Platform" />
<span class="gcloud">gcloud</span>
</a>
</h1>
</header><!-- end of .page-header -->

<article class="main lang-page" role="main">
<section class="content">
<h1 class="page-title">Node.js</h1>

<article>
<h1>{{module[0].toUpperCase() + module.substr(1)}}</h1>
<p>
First, install <code>gcloud</code> with npm and require it into your project:
</p>
<div hljs>$ npm install --save gcloud</div>
<div hljs>var gcloud = require('gcloud');</div>

<article ng-if="isActiveDoc('datastore')">
<p>
The <code>gcloud.datastore</code> object gives you some convenience methods, as well as exposes a <code>Dataset</code> function. This will allow you to create a <code>Dataset</code>, which is the object from which you will interact with the Google Cloud Datastore.
</p>
<div hljs>
var datastore = gcloud.datastore;
var dataset = new datastore.Dataset();</div>
<p ng-if="!isActiveUrl('/docs/datastore/dataset')">
See <a href="/#/docs/datastore/dataset">the Dataset documentation</a> for examples of how to query the datastore, save entities, run a transaction, and others.
</p>
</article>

<article ng-if="isActiveDoc('storage')">
<p>
The <code>gcloud.storage</code> object contains a <code>Bucket</code> object, which is how you will interact with your Google Cloud Storage bucket.
</p>
<div hljs>
var storage = gcloud.storage;
var bucket = new storage.Bucket({
bucketName: 'MyBucket'
});</div>
<p>
See examples below for more on how to upload a file, read from your bucket's files, create signed URLs, and more.
</p>
</article>
</article>

<article ng-repeat="method in methods" id="{{method.name}}">
<h2 ng-if="method.name[0].toUpperCase() === method.name[0]">
{{method.name}}
</h2>
<h3 ng-if="method.name[0].toUpperCase() !== method.name[0]">
{{method.name}}
</h3>
<p ng-if="method.description" ng-bind-html="method.description"></p>
<h4 ng-show="method.params">Parameters</h4>
<table class="table" ng-show="method.params">
<tbody>
<tr ng-repeat="param in method.params">
<th scope="row">{{param.name}}</th>
<td ng-bind-html="param.types"></td>
<td ng-bind-html="param.description"></td>
</tr>
</tbody>
</table>
<h4 ng-show="method.returns">Returns</h4>
<p ng-show="method.returns" ng-bind-html="method.returns"></p>
<h4 ng-show="method.example">Example</h4>
<div ng-repeat-end
ng-show="method.example"
hljs source="method.example" language="js"></div>
<hr ng-if="$index < methods.length - 1">
</article>
</section><!-- end of .content -->

<nav class="side-nav">
<ul class="page-sections">
<li ng-repeat="page in pages">
<a
ng-class="{ current: isActiveUrl(page.url) }"
ng-href="{{page.url}}">
{{page.title}}
</a>
<ul class="sub-sections" ng-if="page.pages">
<li ng-repeat="innerPage in page.pages">
<a
ng-class="{ current: isActiveUrl(page.url + innerPage.url) }"
ng-href="{{page.url + innerPage.url}}">
{{innerPage.title}}
</a>
</li>
</ul>
</li>
</ul>

<ul class="external-links">
<li>
<a href="https://github.com/GoogleCloudPlatform/gcloud-node" title="gcloud-node on Github">
<img src="img/icon-link-github.svg" alt="GitHub icon" />
GitHub
</a>
</li>
<li>
<a href="https://github.com/GoogleCloudPlatform/gcloud-node/issues" title="gcloud-node issues on Github">
<img src="img/icon-link-github.svg" alt="GitHub icon" />
Issues
</a>
</li>
<li>
<a href="http://stackoverflow.com/questions/tagged/gcloud-node" title="gcloud-node on StackOverflow">
<img src="img/icon-link-stackoverflow.svg" alt="StackOverflow icon" />
StackOverflow
</a>
</li>
<li>
<a href="http://npmjs.org/package/gcloud" title="gcloud-node on npm">
<img src="img/icon-link-package-manager.svg" alt="npm icon" />
npm
</a>
</li>
</ul>
</nav><!-- end of .side-nav -->
</article>
175 changes: 175 additions & 0 deletions docs/components/docs/docs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
angular
.module('gcloud.docs', ['ngRoute', 'hljs'])
.config(function($routeProvider) {
'use strict';

function filterDocJson($sce) {
// Transform JSON response to remove extraneous objects, such as copyright
// notices & use strict directives.
function formatHtml(str) {
return str
.replace(/\s+/g, ' ')
.replace(/<br *\/*>/g, ' ')
.replace(/`([^`]*)`/g, '<code>$1</code>');
}
function detectLinks(str) {
var regex = {
withCode: /{@linkcode <a href="([^\"]*)">([^<]*)<\/a>/g,
withTitle: /\[([^\]]*)]{@link <a href="([^}]*)}">[^}]*}<\/a>/g,
withoutTitle: /{@link <a href="([^}]*)}">[^}]*}<\/a>/g
};
var a = document.createElement('a');
return str
.replace(regex.withTitle, function(match, title, link) {
a.href = link;
a.innerText = title;
return a.outerHTML;
})
.replace(regex.withoutTitle, function(match, link) {
a.href = link;
a.innerText = link.replace(/^http\s*:\/\//, '');
return a.outerHTML;
})
.replace(regex.withCode, function(match, link, text) {
a.href = link;
a.innerText = text;
return '<code>' + a.outerHTML + '</code>';
});
}
function detectModules(str) {
var regex = {
see: /{*module:([^}]*)}*/g
};
var a = document.createElement('a');
return str.replace(regex.see, function(match, module) {
a.href = '/gcloud-node/#/docs/' + module;
a.innerText = module;
return a.outerHTML;
});
}
function reduceModules(acc, type, index, types) {
var CUSTOM_TYPES = ['query', 'dataset'];
if (CUSTOM_TYPES.indexOf(type.toLowerCase()) > -1) {
if (types[index - 1]) {
type = types[index - 1] + '/' + type;
delete types[index - 1];
}
}
acc.push(detectModules(type));
return acc;
}
return function(data) {
return data.data
.filter(function(obj) {
return obj.isPrivate === false && obj.ignore === false;
})
.map(function(obj) {
return {
data: obj,
name: obj.ctx.name,
description: $sce.trustAsHtml(
formatHtml(detectLinks(detectModules(obj.description.full)))),
params: obj.tags.filter(function(tag) {
return tag.type === 'param';
})
.map(function(tag) {
tag.description = $sce.trustAsHtml(
formatHtml(tag.description.replace(/^- /, '')));
tag.types = $sce.trustAsHtml(tag.types.reduceRight(
reduceModules, []).join(', '));
return tag;
}),
returns: obj.tags.filter(function(tag) {
return tag.type === 'return';
})
.map(function(tag) {
return $sce.trustAsHtml(
tag.types.reduceRight(reduceModules, [])[0])
})[0],
example: obj.tags.filter(function(tag) {
return tag.type === 'example'
})
.map(function(tag) {
return tag.string;
})[0]
};
})
.sort(function(a, b) {
return a.name > b.name;
});
};
}

$routeProvider
.when('/docs', {
controller: 'DocsCtrl',
templateUrl: '/gcloud-node/components/docs/docs.html',
resolve: {
methods: function($http, $sce) {
return $http.get('/gcloud-node/json/index.json')
.then(filterDocJson($sce));
}
}
})
.when('/docs/:module', {
controller: 'DocsCtrl',
templateUrl: '/gcloud-node/components/docs/docs.html',
resolve: {
methods: function($http, $route, $sce) {
var module = $route.current.params.module;
return $http.get('/gcloud-node/json/' + module + '/index.json')
.then(filterDocJson($sce));
}
}
})
.when('/docs/:module/:class', {
controller: 'DocsCtrl',
templateUrl: '/gcloud-node/components/docs/docs.html',
resolve: {
methods: function($q, $http, $route, $sce) {
var module = $route.current.params.module;
var cl = $route.current.params.class;
return $http.get('/gcloud-node/json/' + module + '/' + cl + '.json')
.then(filterDocJson($sce));
}
}
});
})
.controller('DocsCtrl', function($location, $scope, $routeParams, methods) {
'use strict';

$scope.isActiveUrl = function(url) {
return url.replace(/^\/gcloud-node\/#/, '') === $location.path();
};

$scope.isActiveDoc = function(doc) {
return doc.toLowerCase() === $routeParams.module;
};

$scope.methods = methods;
$scope.module = $routeParams.module;
$scope.pages = [
{
title: 'gcloud',
url: '/gcloud-node/#/docs'
},
{
title: 'Datastore',
url: '/gcloud-node/#/docs/datastore',
pages: [
{
title: 'Dataset',
url: '/dataset'
},
{
title: 'Query',
url: '/query'
}
]
},
{
title: 'Storage',
url: '/gcloud-node/#/docs/storage'
}
];
});
Loading

0 comments on commit 2db33b9

Please sign in to comment.