Skip to content
Browse files

Added github ribbon to theme, and repo location sniffing

  • Loading branch information...
1 parent 9ccc45c commit 6dfa8bfa34fc39a2ed69ed1af5cb66d934a60672 @DamonOehlman committed Mar 29, 2012
View
10 assets/config/conf.py
@@ -68,9 +68,19 @@
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
+# -- Repository options used in the docstar templates --------------------------
+
+github_url = ''
+bitbucket_url = ''
# -- Options for HTML output ---------------------------------------------------
+# define the source options for the html
+html_context = {
+ 'github_url': github_url,
+ 'bitbucket_url': bitbucket_url
+}
+
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
View
7 assets/themes/mocha/layout.html
@@ -1,5 +1,8 @@
{% extends "basic/layout.html" %}
-{% block rootrellink %}
- :)
+{% block footer %}
+ {% if github_url %}
+ <a href="{{ github_url }}"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://a248.e.akamai.net/assets.github.com/img/30f550e0d38ceb6ef5b81500c64d970b7fb0f028/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6f72616e67655f6666373630302e706e67" alt="Fork me on GitHub"></a>
+ {% endif %}
+
{{ super() }}
{% endblock %}
View
7 docs/_theme/mocha/layout.html
@@ -1,5 +1,8 @@
{% extends "basic/layout.html" %}
-{% block rootrellink %}
- :)
+{% block footer %}
+ {% if github_url %}
+ <a href="{{ github_url }}"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://a248.e.akamai.net/assets.github.com/img/30f550e0d38ceb6ef5b81500c64d970b7fb0f028/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6f72616e67655f6666373630302e706e67" alt="Fork me on GitHub"></a>
+ {% endif %}
+
{{ super() }}
{% endblock %}
View
12 docs/conf.py
@@ -68,9 +68,19 @@
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
+# -- Repository options used in the docstar templates --------------------------
+
+github_url = 'https://github.com/DamonOehlman/docstar'
+bitbucket_url = 'https://github.com/DamonOehlman/docstar'
# -- Options for HTML output ---------------------------------------------------
+# define the source options for the html
+html_context = {
+ 'github_url': github_url,
+ 'bitbucket_url': bitbucket_url
+}
+
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'mocha'
@@ -149,4 +159,4 @@
#htmlhelp_basename = 'htmlhelp_base'
# Example configuration for intersphinx: refer to the Python standard library.
-intersphinx_mapping = {'http://docs.python.org/': None}
+intersphinx_mapping = {}
View
47 lib/actions/config.js
@@ -1,10 +1,29 @@
-var docstar = require('../docstar'),
- events = require('events'),
+var events = require('events'),
debug = require('debug')('docstar'),
pkginfo = require('pkginfo'),
path = require('path'),
util = require('util'),
- out = require('out');
+ out = require('out'),
+ _ = require('underscore'),
+ repoTypes = {
+ github: {
+ regex: /^git\:\/\/github.com\/(\w+)\/(.*)\.git$/,
+ replace: 'https://github.com/$1/$2'
+ }
+ };
+
+function _findRepositoryLocation(url) {
+ var data = {};
+
+ // iterate through the different repo type keys
+ for (var key in repoTypes) {
+ if (repoTypes[key].regex.test(url)) {
+ data.repourl = url.replace(repoTypes[key].regex, repoTypes[key].replace);
+ }
+ }
+
+ return data;
+}
function ConfigHelper() {
@@ -20,35 +39,39 @@ ConfigHelper.prototype.create = function(docstar, repl) {
return;
}
- repl.generator.copy(
+ docstar.scaffolder.copy(
'assets/config',
docstar.path,
function() {
// now call the update method
- helper.sync(docstar, scaffolder);
+ helper.sync(docstar, repl);
}
);
});
};
ConfigHelper.prototype.sync = function(docstar, repl) {
- var data = pkginfo.read(null, path.resolve('package.json'))['package'];
-
+ var data = pkginfo.read(null, path.resolve('package.json'))['package'],
+ repoData = {};
+
if (data) {
- docstar.tweakConfig({
+ // initialise the repo location
+ if (data.repository && data.repository.url) {
+ repoData = _findRepositoryLocation(data.repository.url);
+ }
+
+ docstar.tweakConfig(_.extend({
copyright: (new Date().getFullYear()) + ', ' + data.author,
project: data.name,
version: data.version
- });
+ }, repoData), repl.run.bind(repl, 'quit'));
}
-
- repl.run('quit');
};
module.exports = function(action) {
var repl = this;
- docstar.init(function(err, instance) {
+ require('../docstar').init(function(err, instance) {
if (err) {
out(err);
}
View
8 lib/actions/sync.js
@@ -14,7 +14,7 @@ function _sync(docstar, scaffolder, callback) {
});
}
- callback(err, data);
+ callback(err, data);
});
};
@@ -26,9 +26,9 @@ module.exports = function(opts, callback) {
scaffolder.out(err);
}
else {
- _sync(instance, scaffolder, function() {
-
- });
+ _sync(instance, scaffolder, function() {
+
+ });
}
});
};
View
15 lib/actions/theme.js
@@ -1,5 +1,4 @@
var async = require('async'),
- docstar = require('../docstar'),
events = require('events'),
debug = require('debug')('docstar'),
scaffolder = require('scaffolder'),
@@ -11,19 +10,19 @@ function ThemeHelper() {
};
-ThemeHelper.prototype.use = function(ds, cli, extraArgs) {
+ThemeHelper.prototype.use = function(docstar, cli, extraArgs) {
var theme = extraArgs[0],
helper = this;
if (! theme) {
docstar.error('No theme specified, could not install');
}
- debug('copying theme to : ' + path.join(ds.path, '_theme/' + theme));
+ debug('copying theme to : ' + path.join(docstar.path, '_theme/' + theme));
async.series([
- ds.scaffolder.copy.bind(ds.scaffolder, 'assets/themes/' + theme, path.join(ds.path, '_theme/' + theme)),
- ds.tweakConfig.bind(ds, { theme: theme })
+ docstar.scaffolder.copy.bind(docstar.scaffolder, 'assets/themes/' + theme, path.join(docstar.path, '_theme/' + theme)),
+ docstar.tweakConfig.bind(docstar, { theme: theme })
],
function(err) {
if (err) {
@@ -39,17 +38,17 @@ module.exports = function(input) {
extraArgs = (input || '').split(/\s/),
action = extraArgs[0] || 'use';
- docstar.init(function(err, instance) {
+ require('../docstar').init(function(err, docstar) {
if (err) {
- docstar.error(err);
+ throw err;
}
else {
// create the config helper
var helper = new ThemeHelper();
// if the config helper supports the action, then call it
if (typeof helper[action] == 'function') {
- helper[action].call(helper, instance, cli, extraArgs.slice(1));
+ helper[action].call(helper, docstar, cli, extraArgs.slice(1));
}
else {
out('Do not know how to \'theme ' + action + '\'');
View
14 lib/docstar.js
@@ -8,7 +8,8 @@ var fs = require('fs'),
copyright: /^(copyright).*/m,
project: /^(project).*/m,
theme: /^(html_theme).*/m,
- version: /^(version|release).*/mg
+ version: /^(version|release).*/mg,
+ repourl: /^(github_url|bitbucket_url).*/mg
},
unicodeSections = {
copyright: true,
@@ -20,17 +21,23 @@ function DocStar(docpath) {
debug('docpath set to ' + this.path);
};
+DocStar.prototype.error = function(err) {
+ out('!{red}: {0}', err);
+};
+
DocStar.prototype.getConfigPath = function() {
return path.join(this.path, SPHINX_CONFIG_FILE);
};
DocStar.prototype.readConfig = function(callback) {
+ debug('attempting to read configuration from: ' + this.getConfigPath());
fs.readFile(this.getConfigPath(), 'utf8', callback);
};
DocStar.prototype.tweakConfig = function(updates, callback) {
var docstar = this;
+ debug('attempting to tweak configuration, updates: ', updates);
this.readConfig(function(err, config) {
if (err) {
if (callback) {
@@ -60,6 +67,7 @@ DocStar.prototype.tweakConfig = function(updates, callback) {
DocStar.prototype.writeConfig = function(data, callback) {
var configPath = this.getConfigPath();
+ debug('attempting to write config update to: ' + configPath);
fs.writeFile(configPath, data, 'utf8', function(err) {
debug('updated config file: ' + configPath + (err ? ', err: ' + err : ''));
@@ -69,10 +77,6 @@ DocStar.prototype.writeConfig = function(data, callback) {
});
};
-exports.error = function(err) {
- out('!{red}: {0}', err);
-};
-
exports.init = function(callback) {
var pattern = '**/' + SPHINX_CONFIG_FILE;
View
3 package.json
@@ -23,7 +23,8 @@
"attachmate": "0.1.x",
"glob": "3.x.x",
"out": "*",
- "pkginfo": "0.2.x"
+ "pkginfo": "0.2.x",
+ "underscore": "1.3.x"
},
"devDependencies": {
},

0 comments on commit 6dfa8bf

Please sign in to comment.
Something went wrong with that request. Please try again.