diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-09 08:17:37 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-09 08:17:37 +0200 |
commit | 1b432288f041baef2ebe54c96a7a86f547b14c67 (patch) | |
tree | 8856ef41c7f38e135d84c8f5f3e4363c91459569 | |
parent | 2182baa2e9bf520943871c52340066cfdd28ba0b (diff) | |
parent | fa2f82d52f34b725483f0fd55be3cc9b04f7dc9b (diff) | |
download | gitbook-1b432288f041baef2ebe54c96a7a86f547b14c67.zip gitbook-1b432288f041baef2ebe54c96a7a86f547b14c67.tar.gz gitbook-1b432288f041baef2ebe54c96a7a86f547b14c67.tar.bz2 |
Merge branch 'optional-github' of https://github.com/mrpotes/gitbook into mrpotes-optional-github
-rw-r--r-- | bin/build.js | 19 | ||||
-rw-r--r-- | lib/generate/index.js | 8 | ||||
-rw-r--r-- | lib/generate/site/index.js | 4 | ||||
-rw-r--r-- | theme/assets/app.js | 21 | ||||
-rw-r--r-- | theme/javascript/app.js | 22 | ||||
-rw-r--r-- | theme/templates/includes/book/exercise.html | 2 | ||||
-rw-r--r-- | theme/templates/includes/book/header.html | 5 | ||||
-rw-r--r-- | theme/templates/includes/book/summary.html | 2 | ||||
-rw-r--r-- | theme/templates/page.html | 4 | ||||
-rw-r--r-- | theme/templates/site.html | 6 |
10 files changed, 57 insertions, 36 deletions
diff --git a/bin/build.js b/bin/build.js index 4f7429a..0384b77 100644 --- a/bin/build.js +++ b/bin/build.js @@ -24,16 +24,19 @@ var buildFunc = function(dir, options) { return null; }) .then(function(repoID) { + var title = options.title; var githubID = options.github || repoID; - if(!githubID) { - throw new Error('Needs a githubID (username/repo). Either set repo origin to a github repo or use the -g flag'); - } - - var parts = githubID.split('/', 2); - var user = parts[0], repo = parts[1]; + if (!title && !githubID) { + throw new Error('Needs either a title or a githubID (username/repo).\n'+ + ' If using github, either set repo origin to a github repo or use the -g flag.\n'+ + ' For title, use the -t flag.'); + } else if (!title) { + var parts = githubID.split('/', 2); + var user = parts[0], repo = parts[1]; - var title = options.title || utils.titleCase(repo); + title = utils.titleCase(repo); + } return generate.folder( _.extend(options.options || {}, { @@ -111,4 +114,4 @@ var buildFiles = function(dir, outputFile, options, masterOptions) { module.exports = { folder: buildFunc, files: buildFiles -};
\ No newline at end of file +}; diff --git a/lib/generate/index.js b/lib/generate/index.js index 53ae509..4804548 100644 --- a/lib/generate/index.js +++ b/lib/generate/index.js @@ -39,8 +39,8 @@ var generate = function(options) { theme: path.resolve(__dirname, '../../theme') }); - if (!options.github || !options.title || !options.input || !options.output) { - return Q.reject(new Error("Need options: github, title, input, output")); + if (!options.title || !options.input || !options.output) { + return Q.reject(new Error("Need options: title, input, output")); } if (!generators[options.generator]) { @@ -76,7 +76,7 @@ var generate = function(options) { // Generate sub-books .then(function(_langsSummary) { options.langsSummary = parse.langs(_langsSummary); - + // Generated a book for each valid entry return Q.all( _.map(options.langsSummary.list, function(entry) { @@ -84,7 +84,7 @@ var generate = function(options) { input: path.join(options.input, entry.path), output: path.join(options.output, entry.path) })); - }) + }) ); }) diff --git a/lib/generate/site/index.js b/lib/generate/site/index.js index fab2696..4bea547 100644 --- a/lib/generate/site/index.js +++ b/lib/generate/site/index.js @@ -49,7 +49,7 @@ Generator.prototype._writeTemplate = function(tpl, options, output) { title: that.options.title, description: that.options.description, - githubAuthor: that.options.github.split("/")[0], + githubAuthor: that.options.github ? that.options.github.split("/")[0] : "", githubId: that.options.github, githubHost: that.options.githubHost, @@ -153,4 +153,4 @@ Generator.prototype.finish = function() { .then(this.writeSearchIndex); }; -module.exports = Generator;
\ No newline at end of file +module.exports = Generator; diff --git a/theme/assets/app.js b/theme/assets/app.js index 3a10746..36eb935 100644 --- a/theme/assets/app.js +++ b/theme/assets/app.js @@ -21370,9 +21370,6 @@ require([ $(document).ready(function() { var $book = state.$book; - // Initialize storage - storage.setBaseKey(state.githubId); - // Init sidebar sidebar.init(); @@ -21382,12 +21379,17 @@ require([ // Init keyboard keyboard.init(); - // Star and watch count - $.getJSON("https://api.github.com/repos/"+state.githubId) - .done(function(repo) { - $book.find(".count-star span").text(repo.stargazers_count); - $book.find(".count-watch span").text(repo.subscribers_count); - }); + if (state.githubId) { + // Initialize storage + storage.setBaseKey(state.githubId); + + // Star and watch count + $.getJSON("https://api.github.com/repos/"+state.githubId) + .done(function(repo) { + $book.find(".count-star span").text(repo.stargazers_count); + $book.find(".count-watch span").text(repo.subscribers_count); + }); + } // Bind exercise exercise.init(); @@ -21402,5 +21404,6 @@ require([ $(".book-body").focus(); }); }); + define("app", function(){}); diff --git a/theme/javascript/app.js b/theme/javascript/app.js index 34247ca..392d45b 100644 --- a/theme/javascript/app.js +++ b/theme/javascript/app.js @@ -14,9 +14,6 @@ require([ $(document).ready(function() { var $book = state.$book; - // Initialize storage - storage.setBaseKey(state.githubId); - // Init sidebar sidebar.init(); @@ -26,12 +23,17 @@ require([ // Init keyboard keyboard.init(); - // Star and watch count - $.getJSON("https://api.github.com/repos/"+state.githubId) - .done(function(repo) { - $book.find(".count-star span").text(repo.stargazers_count); - $book.find(".count-watch span").text(repo.subscribers_count); - }); + if (state.githubId) { + // Initialize storage + storage.setBaseKey(state.githubId); + + // Star and watch count + $.getJSON("https://api.github.com/repos/"+state.githubId) + .done(function(repo) { + $book.find(".count-star span").text(repo.stargazers_count); + $book.find(".count-watch span").text(repo.subscribers_count); + }); + } // Bind exercise exercise.init(); @@ -45,4 +47,4 @@ require([ // Focus on content $(".book-body").focus(); }); -});
\ No newline at end of file +}); diff --git a/theme/templates/includes/book/exercise.html b/theme/templates/includes/book/exercise.html index 1acbe79..fbf8505 100644 --- a/theme/templates/includes/book/exercise.html +++ b/theme/templates/includes/book/exercise.html @@ -20,5 +20,7 @@ <div class="btn-group btn-group-justified"> <a href="#" class="btn btn-default action-submit">Submit</a> <a href="#" class="btn btn-default action-solution">Solution</a> + {% if githubId %} <a href="{{ githubHost }}{{ githubId }}/issues/new" target="_blank" class="btn btn-default">Have a Question?</a> + {% endif %} </div> diff --git a/theme/templates/includes/book/header.html b/theme/templates/includes/book/header.html index 7732b37..5662714 100644 --- a/theme/templates/includes/book/header.html +++ b/theme/templates/includes/book/header.html @@ -1,6 +1,8 @@ <div class="book-header"> <!-- Actions Left --> + {% if githubId %} <a href="{{ githubHost }}{{ githubId }}" target="_blank" class="btn pull-left"><i class="fa fa-github-alt"></i></a> + {% endif %} <a href="#" class="btn pull-left toggle-summary"><i class="fa fa-align-justify"></i></a> <a href="#" class="btn pull-left toggle-search"><i class="fa fa-search"></i></a> @@ -9,9 +11,10 @@ <a href="#" target="_blank" class="btn pull-right" data-sharing="facebook"><i class="fa fa-facebook"></i></a> <a href="#" target="_blank" class="btn pull-right" data-sharing="twitter"><i class="fa fa-twitter"></i></a> + {% if githubId %} <a href="{{ githubHost }}{{ githubId }}/stargazers" target="_blank" class="btn pull-right count-star"><i class="fa fa-star-o"></i> Star (<span>-</span>)</a> <a href="{{ githubHost }}{{ githubId }}/watchers" target="_blank" class="btn pull-right count-watch"><i class="fa fa-eye"></i> Watch (<span>-</span>)</a> - + {% endif %} <!-- Title --> <h1><a href="{{ basePath }}/" >{{ title }}</a></h1> diff --git a/theme/templates/includes/book/summary.html b/theme/templates/includes/book/summary.html index 485b2ef..cbed38c 100644 --- a/theme/templates/includes/book/summary.html +++ b/theme/templates/includes/book/summary.html @@ -3,6 +3,7 @@ <input type="text" placeholder="Search" class="form-control" /> </div> <ul class="summary"> + {% if githubId %} <li> <a href="{{ githubHost }}{{ githubAuthor }}" target="blank">About the author</a> </li> @@ -13,6 +14,7 @@ <a href="{{ githubHost }}{{ githubId }}/edit/master/{{ _input }}" target="blank">Edit and Contribute</a> </li> <li class="divider"></li> + {% endif %} <li data-level="0" data-path="index.html"> <a href="{{ basePath }}/"><i class="fa fa-check"></i> Introduction</a> </li> diff --git a/theme/templates/page.html b/theme/templates/page.html index b23c81e..6f5115f 100644 --- a/theme/templates/page.html +++ b/theme/templates/page.html @@ -12,7 +12,9 @@ {# Cover #} <section id="cover"> <h1>{{ title }}</h1> + {% if githubId %} <h2>By <a href="{{ githubHost }}{{ githubAuthor }}">@{{ githubAuthor }}</a></h2> + {% endif %} </section> {# Summary #} @@ -116,4 +118,4 @@ {% endif %} {% endblock %} -{% block javascript %}{% endblock %}
\ No newline at end of file +{% block javascript %}{% endblock %} diff --git a/theme/templates/site.html b/theme/templates/site.html index 2bc3408..6feb424 100644 --- a/theme/templates/site.html +++ b/theme/templates/site.html @@ -2,7 +2,11 @@ {% block title %}{{ progress.current.title }}{% parent %}{% endblock %} {% block content %} +{% if githubId %} <div class="book" data-github="{{ githubId }}" data-level="{{ progress.current.level }}" data-basepath="{{ basePath }}" data-revision="{{ revision }}"> +{% else %} +<div class="book" data-level="{{ progress.current.level }}" data-basepath="{{ basePath }}" data-revision="{{ revision }}"> +{% endif %} {% include "includes/book/header.html" %} {% include "includes/book/summary.html" %} <div class="book-body" tabindex="-1"> @@ -32,4 +36,4 @@ {% endif %} </div> </div> -{% endblock %}
\ No newline at end of file +{% endblock %} |