├── CHANGES.md ├── test ├── fixtures │ ├── book1 │ │ ├── test.md │ │ ├── README.md │ │ └── SUMMARY.md │ ├── book2 │ │ └── README.md │ ├── GITHUB_LINKS.md │ ├── README.md │ ├── MARKDOWN_LINKS.md │ ├── HR_PAGE.md │ ├── IMAGES.md │ ├── SUMMARY.md │ ├── SECTIONS.md │ ├── PAGE.md │ └── QUIZ_PAGE.md ├── sections.js ├── readme.js ├── generate.js ├── plugin.js ├── summary.js └── navigation.js ├── preview.png ├── .travis.yml ├── lib ├── utils │ ├── index.js │ ├── lang.js │ └── links.js ├── index.js ├── parse │ ├── index.js │ ├── langs.js │ ├── readme.js │ ├── progress.js │ ├── git.js │ ├── navigation.js │ ├── summary.js │ ├── lex.js │ └── renderer.js └── generate │ ├── json │ └── index.js │ ├── generator.js │ ├── fs.js │ ├── pdf │ └── index.js │ ├── site │ └── search_indexer.js │ ├── init.js │ ├── manifest.js │ ├── ebook │ └── index.js │ └── page │ └── index.js ├── theme ├── assets │ ├── images │ │ └── favicon.ico │ ├── fonts │ │ ├── opensans │ │ │ ├── 300.woff │ │ │ ├── 300i.woff │ │ │ ├── 400.woff │ │ │ ├── 400i.woff │ │ │ ├── 600.woff │ │ │ ├── 600i.woff │ │ │ ├── 700.woff │ │ │ └── 700i.woff │ │ ├── anonymouspro │ │ │ ├── 400.woff │ │ │ ├── 700.woff │ │ │ ├── 400i.woff │ │ │ └── 700i.woff │ │ ├── ebgaramond │ │ │ ├── 400.woff │ │ │ └── 400i.woff │ │ ├── merriweather │ │ │ ├── 250.woff │ │ │ ├── 400.woff │ │ │ ├── 700.woff │ │ │ ├── 900.woff │ │ │ ├── 250i.woff │ │ │ ├── 400i.woff │ │ │ ├── 700i.woff │ │ │ └── 900i.woff │ │ └── fontawesome │ │ │ ├── FontAwesome.otf │ │ │ ├── fontawesome-webfont.eot │ │ │ ├── fontawesome-webfont.ttf │ │ │ └── fontawesome-webfont.woff │ └── jsrepl │ │ ├── sandbox.html │ │ ├── langs │ │ └── javascript │ │ │ └── jsrepl_js.js │ │ └── engines │ │ └── javascript-default.js ├── javascript │ ├── core │ │ ├── events.js │ │ ├── loading.js │ │ ├── state.js │ │ ├── keyboard.js │ │ ├── sidebar.js │ │ ├── exercise.js │ │ ├── progress.js │ │ ├── quiz.js │ │ ├── search.js │ │ └── font-settings.js │ ├── utils │ │ ├── platform.js │ │ ├── appcache.js │ │ ├── storage.js │ │ ├── sharing.js │ │ ├── url.js │ │ └── execute.js │ ├── execute │ │ └── javascript.js │ └── gitbook.js ├── stylesheets │ ├── mixins.less │ ├── vendors │ │ ├── fontawesome │ │ │ ├── fixed-width.less │ │ │ ├── core.less │ │ │ ├── bordered-pulled.less │ │ │ ├── rotated-flipped.less │ │ │ ├── larger.less │ │ │ ├── list.less │ │ │ ├── stacked.less │ │ │ ├── path.less │ │ │ ├── mixins.less │ │ │ ├── spinning.less │ │ │ └── font-awesome.less │ │ └── bootstrap │ │ │ ├── breadcrumbs.less │ │ │ ├── component-animations.less │ │ │ ├── wells.less │ │ │ ├── thumbnails.less │ │ │ ├── utilities.less │ │ │ ├── close.less │ │ │ ├── jumbotron.less │ │ │ ├── media.less │ │ │ ├── pager.less │ │ │ ├── badges.less │ │ │ ├── labels.less │ │ │ ├── code.less │ │ │ ├── bootstrap.less │ │ │ ├── alerts.less │ │ │ ├── print.less │ │ │ ├── pagination.less │ │ │ ├── list-group.less │ │ │ ├── progress-bars.less │ │ │ ├── scaffolding.less │ │ │ ├── tooltip.less │ │ │ ├── input-groups.less │ │ │ ├── popovers.less │ │ │ ├── modals.less │ │ │ ├── buttons.less │ │ │ ├── panels.less │ │ │ └── carousel.less │ ├── main.less │ ├── book │ │ ├── languages.less │ │ ├── exercise.less │ │ ├── quiz.less │ │ ├── navigation.less │ │ ├── highlight │ │ │ ├── white.less │ │ │ ├── night.less │ │ │ └── sepia.less │ │ ├── header.less │ │ ├── progress.less │ │ ├── body.less │ │ └── font-settings.less │ ├── page │ │ └── highlight.less │ └── print.less └── templates │ ├── langs.html │ ├── includes │ └── book │ │ ├── progress.html │ │ ├── font-settings.html │ │ ├── exercise.html │ │ ├── quiz.html │ │ ├── header.html │ │ └── summary.html │ ├── layout.html │ └── site.html ├── bower.json ├── AUTHORS.md ├── .gitignore ├── bin ├── utils.js ├── build.js ├── server.js └── gitbook.js ├── package.json └── Gruntfile.js /CHANGES.md: -------------------------------------------------------------------------------- 1 | # Release notes 2 | 3 | -------------------------------------------------------------------------------- /test/fixtures/book1/test.md: -------------------------------------------------------------------------------- 1 | # Test 2 | -------------------------------------------------------------------------------- /test/fixtures/book2/README.md: -------------------------------------------------------------------------------- 1 | # This should fail 2 | -------------------------------------------------------------------------------- /test/fixtures/book1/README.md: -------------------------------------------------------------------------------- 1 | # This is a test 2 | 3 | -------------------------------------------------------------------------------- /test/fixtures/book1/SUMMARY.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | * [test](test.md) -------------------------------------------------------------------------------- /preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/preview.png -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.11" 4 | - "0.10" 5 | - "0.8" 6 | -------------------------------------------------------------------------------- /lib/utils/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | lang: require('./lang'), 3 | links: require('./links') 4 | }; 5 | -------------------------------------------------------------------------------- /test/fixtures/GITHUB_LINKS.md: -------------------------------------------------------------------------------- 1 | # Nice course 2 | 3 | Check out this source file [in C++](../src/something.cpp) 4 | -------------------------------------------------------------------------------- /theme/assets/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/images/favicon.ico -------------------------------------------------------------------------------- /test/fixtures/README.md: -------------------------------------------------------------------------------- 1 | # This is the title 2 | 3 | This is the book description. 4 | 5 | other content 6 | ... 7 | 8 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parse: require('./parse/'), 3 | generate: require('./generate/') 4 | }; 5 | 6 | -------------------------------------------------------------------------------- /theme/assets/fonts/opensans/300.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/fonts/opensans/300.woff -------------------------------------------------------------------------------- /theme/assets/fonts/opensans/300i.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/fonts/opensans/300i.woff -------------------------------------------------------------------------------- /theme/assets/fonts/opensans/400.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/fonts/opensans/400.woff -------------------------------------------------------------------------------- /theme/assets/fonts/opensans/400i.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/fonts/opensans/400i.woff -------------------------------------------------------------------------------- /theme/assets/fonts/opensans/600.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/fonts/opensans/600.woff -------------------------------------------------------------------------------- /theme/assets/fonts/opensans/600i.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/fonts/opensans/600i.woff -------------------------------------------------------------------------------- /theme/assets/fonts/opensans/700.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/fonts/opensans/700.woff -------------------------------------------------------------------------------- /theme/assets/fonts/opensans/700i.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/fonts/opensans/700i.woff -------------------------------------------------------------------------------- /theme/assets/fonts/anonymouspro/400.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/fonts/anonymouspro/400.woff -------------------------------------------------------------------------------- /theme/assets/fonts/anonymouspro/700.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/fonts/anonymouspro/700.woff -------------------------------------------------------------------------------- /theme/assets/fonts/ebgaramond/400.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/fonts/ebgaramond/400.woff -------------------------------------------------------------------------------- /theme/assets/fonts/ebgaramond/400i.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/fonts/ebgaramond/400i.woff -------------------------------------------------------------------------------- /theme/assets/fonts/merriweather/250.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/fonts/merriweather/250.woff -------------------------------------------------------------------------------- /theme/assets/fonts/merriweather/400.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/fonts/merriweather/400.woff -------------------------------------------------------------------------------- /theme/assets/fonts/merriweather/700.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/fonts/merriweather/700.woff -------------------------------------------------------------------------------- /theme/assets/fonts/merriweather/900.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/fonts/merriweather/900.woff -------------------------------------------------------------------------------- /theme/assets/fonts/anonymouspro/400i.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/fonts/anonymouspro/400i.woff -------------------------------------------------------------------------------- /theme/assets/fonts/anonymouspro/700i.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/fonts/anonymouspro/700i.woff -------------------------------------------------------------------------------- /theme/assets/fonts/merriweather/250i.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/fonts/merriweather/250i.woff -------------------------------------------------------------------------------- /theme/assets/fonts/merriweather/400i.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/fonts/merriweather/400i.woff -------------------------------------------------------------------------------- /theme/assets/fonts/merriweather/700i.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/fonts/merriweather/700i.woff -------------------------------------------------------------------------------- /theme/assets/fonts/merriweather/900i.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/fonts/merriweather/900i.woff -------------------------------------------------------------------------------- /theme/javascript/core/events.js: -------------------------------------------------------------------------------- 1 | define([ 2 | "jQuery" 3 | ], function($) { 4 | var events = $({}); 5 | 6 | return events; 7 | }); -------------------------------------------------------------------------------- /theme/assets/fonts/fontawesome/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/fonts/fontawesome/FontAwesome.otf -------------------------------------------------------------------------------- /theme/stylesheets/mixins.less: -------------------------------------------------------------------------------- 1 | .link-inherit { 2 | color: inherit; 3 | 4 | &:hover, &:focus { 5 | color: inherit; 6 | } 7 | } -------------------------------------------------------------------------------- /test/fixtures/MARKDOWN_LINKS.md: -------------------------------------------------------------------------------- 1 | # Nice course 2 | 3 | Check out this other chapter [Test](test.md) 4 | 5 | Check out this other chapter [Test](../before.md) 6 | -------------------------------------------------------------------------------- /theme/assets/fonts/fontawesome/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/fonts/fontawesome/fontawesome-webfont.eot -------------------------------------------------------------------------------- /theme/assets/fonts/fontawesome/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/fonts/fontawesome/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /theme/assets/fonts/fontawesome/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/diegowifi/gitbook/HEAD/theme/assets/fonts/fontawesome/fontawesome-webfont.woff -------------------------------------------------------------------------------- /theme/stylesheets/vendors/fontawesome/fixed-width.less: -------------------------------------------------------------------------------- 1 | // Fixed Width Icons 2 | // ------------------------- 3 | .@{fa-css-prefix}-fw { 4 | width: (18em / 14); 5 | text-align: center; 6 | } 7 | -------------------------------------------------------------------------------- /theme/javascript/utils/platform.js: -------------------------------------------------------------------------------- 1 | define([], function() { 2 | return { 3 | isMobile: /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) 4 | }; 5 | }); -------------------------------------------------------------------------------- /theme/assets/jsrepl/sandbox.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | jsREPL Sandbox 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/fixtures/HR_PAGE.md: -------------------------------------------------------------------------------- 1 | ## Wow such book 2 | 3 | Some nice content here 4 | 5 | --- 6 | 7 | A beautiful separator, but non an exercise or a quiz ! 8 | 9 | --- 10 | 11 | Some more beautiful text, because `this` book is awesome ... 12 | -------------------------------------------------------------------------------- /test/fixtures/IMAGES.md: -------------------------------------------------------------------------------- 1 | # Images Test 2 | 3 | This is a test for images path calculation. It supposed this fiel is in a syntax/ folder 4 | 5 | ### # 6 | 7 | [![Screen](./preview.png)](./preview.png) 8 | 9 | ### 2 10 | 11 | [![Screen](../preview2.png)](./preview2.png) 12 | 13 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "GitBook", 3 | "version": "1.0.0", 4 | "dependencies": { 5 | "jquery": "2.1.1", 6 | "lodash": "2.4.1", 7 | "requirejs": "2.1.11", 8 | "URIjs": "1.13.1", 9 | "mousetrap": "1.4.6", 10 | "lunr.js": "0.5.2" 11 | } 12 | } -------------------------------------------------------------------------------- /theme/javascript/execute/javascript.js: -------------------------------------------------------------------------------- 1 | define(function() { 2 | return { 3 | id: "javascript", 4 | assertCode: "function assert(condition, message) { \nif (!condition) { \n throw message || \"Assertion failed\"; \n } \n }\n", 5 | REPL: JSREPL, 6 | sep: ";\n", 7 | }; 8 | }); 9 | -------------------------------------------------------------------------------- /lib/parse/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | summary: require('./summary'), 3 | langs: require('./langs'), 4 | page: require('./page'), 5 | lex: require('./lex'), 6 | progress: require('./progress'), 7 | navigation: require('./navigation'), 8 | readme: require('./readme'), 9 | git: require('./git') 10 | }; 11 | -------------------------------------------------------------------------------- /test/fixtures/SUMMARY.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | * [Chapter 1](chapter-1/README.md) 4 | * [Article 1](chapter-1/ARTICLE1.md) 5 | * [Article 2](chapter-1/ARTICLE2.md) 6 | * [Chapter 2](chapter-2/README.md) 7 | * [Chapter 3](chapter-3/README.md) 8 | * [Chapter 4](chapter-4/README.md) 9 | * Unfinished article 10 | * Unfinished Chapter 11 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/fontawesome/core.less: -------------------------------------------------------------------------------- 1 | // Base Class Definition 2 | // ------------------------- 3 | 4 | .@{fa-css-prefix} { 5 | display: inline-block; 6 | font-family: FontAwesome; 7 | font-style: normal; 8 | font-weight: normal; 9 | line-height: 1; 10 | -webkit-font-smoothing: antialiased; 11 | -moz-osx-font-smoothing: grayscale; 12 | } 13 | -------------------------------------------------------------------------------- /lib/utils/lang.js: -------------------------------------------------------------------------------- 1 | var MAP = { 2 | 'py': 'python', 3 | 'js': 'javascript', 4 | 'rb': 'ruby', 5 | }; 6 | 7 | function normalize(lang) { 8 | if(!lang) { return null; } 9 | 10 | var lower = lang.toLowerCase(); 11 | return MAP[lower] || lower; 12 | } 13 | 14 | // Exports 15 | module.exports = { 16 | normalize: normalize, 17 | MAP: MAP 18 | }; 19 | -------------------------------------------------------------------------------- /AUTHORS.md: -------------------------------------------------------------------------------- 1 | Authors 2 | ======= 3 | 4 | Also see https://github.com/GitbookIO/gitbook/graphs/contributors. 5 | Names below are ordered by first contribution. 6 | 7 | Author 8 | ------ 9 | 10 | - Samy Pessé 11 | - Aaron O'Mullan 12 | 13 | 14 | Contributors 15 | ------------ 16 | 17 | - Nijiko Yonskai 18 | - Herman Starikov 19 | -------------------------------------------------------------------------------- /theme/javascript/core/loading.js: -------------------------------------------------------------------------------- 1 | define([ 2 | "jQuery" 3 | ], function($) { 4 | var showLoading = function(p) { 5 | var $book = $(".book"); 6 | 7 | $book.addClass("is-loading"); 8 | p.always(function() { 9 | $book.removeClass("is-loading"); 10 | }); 11 | 12 | return p; 13 | }; 14 | 15 | return { 16 | show: showLoading 17 | }; 18 | }); -------------------------------------------------------------------------------- /theme/javascript/utils/appcache.js: -------------------------------------------------------------------------------- 1 | define([], function() { 2 | var isAvailable = (typeof applicationCache !== "undefined"); 3 | 4 | var init = function() { 5 | if (!isAvailable) return; 6 | 7 | window.applicationCache.addEventListener('updateready', function() { 8 | window.location.reload(); 9 | }, false); 10 | }; 11 | 12 | return { 13 | init: init 14 | }; 15 | }); -------------------------------------------------------------------------------- /theme/stylesheets/vendors/fontawesome/bordered-pulled.less: -------------------------------------------------------------------------------- 1 | // Bordered & Pulled 2 | // ------------------------- 3 | 4 | .@{fa-css-prefix}-border { 5 | padding: .2em .25em .15em; 6 | border: solid .08em @fa-border-color; 7 | border-radius: .1em; 8 | } 9 | 10 | .pull-right { float: right; } 11 | .pull-left { float: left; } 12 | 13 | .@{fa-css-prefix} { 14 | &.pull-left { margin-right: .3em; } 15 | &.pull-right { margin-left: .3em; } 16 | } 17 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/fontawesome/rotated-flipped.less: -------------------------------------------------------------------------------- 1 | // Rotated & Flipped Icons 2 | // ------------------------- 3 | 4 | .@{fa-css-prefix}-rotate-90 { .fa-icon-rotate(90deg, 1); } 5 | .@{fa-css-prefix}-rotate-180 { .fa-icon-rotate(180deg, 2); } 6 | .@{fa-css-prefix}-rotate-270 { .fa-icon-rotate(270deg, 3); } 7 | 8 | .@{fa-css-prefix}-flip-horizontal { .fa-icon-flip(-1, 1, 0); } 9 | .@{fa-css-prefix}-flip-vertical { .fa-icon-flip(1, -1, 2); } 10 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/fontawesome/larger.less: -------------------------------------------------------------------------------- 1 | // Icon Sizes 2 | // ------------------------- 3 | 4 | /* makes the font 33% larger relative to the icon container */ 5 | .@{fa-css-prefix}-lg { 6 | font-size: (4em / 3); 7 | line-height: (3em / 4); 8 | vertical-align: -15%; 9 | } 10 | .@{fa-css-prefix}-2x { font-size: 2em; } 11 | .@{fa-css-prefix}-3x { font-size: 3em; } 12 | .@{fa-css-prefix}-4x { font-size: 4em; } 13 | .@{fa-css-prefix}-5x { font-size: 5em; } 14 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/fontawesome/list.less: -------------------------------------------------------------------------------- 1 | // List Icons 2 | // ------------------------- 3 | 4 | .@{fa-css-prefix}-ul { 5 | padding-left: 0; 6 | margin-left: @fa-li-width; 7 | list-style-type: none; 8 | > li { position: relative; } 9 | } 10 | .@{fa-css-prefix}-li { 11 | position: absolute; 12 | left: -@fa-li-width; 13 | width: @fa-li-width; 14 | top: (2em / 14); 15 | text-align: center; 16 | &.@{fa-css-prefix}-lg { 17 | left: -@fa-li-width + (4em / 14); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /theme/javascript/core/state.js: -------------------------------------------------------------------------------- 1 | define([ 2 | "jQuery" 3 | ], function() { 4 | var state = {}; 5 | 6 | state.update = function(dom) { 7 | var $book = $(dom.find(".book")); 8 | 9 | state.$book = $book; 10 | state.githubId = $book.data("github"); 11 | state.level = $book.data("level"); 12 | state.basePath = $book.data("basepath"); 13 | state.revision = $book.data("revision"); 14 | }; 15 | 16 | state.update($); 17 | 18 | return state; 19 | }); -------------------------------------------------------------------------------- /theme/templates/langs.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | 3 | {% block title %}{{ title }}{% endblock %} 4 | 5 | {% block content %} 6 |
7 |
8 |

Choose a language

9 | 10 |
    11 | {% for lang in langs %} 12 |
  • 13 | {{ lang.title }} 14 |
  • 15 | {% endfor %} 16 |
17 |
18 |
19 | {% endblock %} 20 | 21 | {% block javascript %}{% endblock %} -------------------------------------------------------------------------------- /theme/templates/includes/book/progress.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 |
6 | {% for p in progress.chapters %} 7 | 8 | {% endfor %} 9 |
10 |
-------------------------------------------------------------------------------- /theme/stylesheets/vendors/fontawesome/stacked.less: -------------------------------------------------------------------------------- 1 | // Stacked Icons 2 | // ------------------------- 3 | 4 | .@{fa-css-prefix}-stack { 5 | position: relative; 6 | display: inline-block; 7 | width: 2em; 8 | height: 2em; 9 | line-height: 2em; 10 | vertical-align: middle; 11 | } 12 | .@{fa-css-prefix}-stack-1x, .@{fa-css-prefix}-stack-2x { 13 | position: absolute; 14 | left: 0; 15 | width: 100%; 16 | text-align: center; 17 | } 18 | .@{fa-css-prefix}-stack-1x { line-height: inherit; } 19 | .@{fa-css-prefix}-stack-2x { font-size: 2em; } 20 | .@{fa-css-prefix}-inverse { color: @fa-inverse; } 21 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/bootstrap/breadcrumbs.less: -------------------------------------------------------------------------------- 1 | // 2 | // Breadcrumbs 3 | // -------------------------------------------------- 4 | 5 | 6 | .breadcrumb { 7 | padding: 8px 15px; 8 | margin-bottom: @line-height-computed; 9 | list-style: none; 10 | background-color: @breadcrumb-bg; 11 | border-radius: @border-radius-base; 12 | > li { 13 | display: inline-block; 14 | &+li:before { 15 | content: "/\00a0"; // Unicode space added since inline-block means non-collapsing white-space 16 | padding: 0 5px; 17 | color: @breadcrumb-color; 18 | } 19 | } 20 | > .active { 21 | color: @breadcrumb-active-color; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/fontawesome/path.less: -------------------------------------------------------------------------------- 1 | /* FONT PATH 2 | * -------------------------- */ 3 | 4 | @font-face { 5 | font-family: 'FontAwesome'; 6 | src: url('@{fa-font-path}/fontawesome-webfont.eot'); 7 | src: url('@{fa-font-path}/fontawesome-webfont.eot') format('embedded-opentype'), 8 | url('@{fa-font-path}/fontawesome-webfont.woff') format('woff'), 9 | url('@{fa-font-path}/fontawesome-webfont.ttf') format('truetype'), 10 | url('@{fa-font-path}/fontawesome-webfont.svg') format('svg'); 11 | // src: url('@{fa-font-path}/FontAwesome.otf') format('opentype'); // used when developing fonts 12 | font-weight: normal; 13 | font-style: normal; 14 | } 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # Compiled binary addons (http://nodejs.org/api/addons.html) 20 | build/Release 21 | 22 | # Dependency directory 23 | # Deployed apps should consider commenting this line out: 24 | # see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git 25 | node_modules 26 | 27 | theme/javascript/vendors -------------------------------------------------------------------------------- /lib/parse/langs.js: -------------------------------------------------------------------------------- 1 | var _ = require("lodash") 2 | var parseSummary = require("./summary"); 3 | 4 | var parseLangs = function(content) { 5 | var summary = parseSummary(content); 6 | 7 | return { 8 | list: _.chain(summary.chapters) 9 | .filter(function(entry) { 10 | return entry.path != null; 11 | }) 12 | .map(function(entry) { 13 | return { 14 | title: entry.title, 15 | path: entry.path, 16 | lang: entry.path.replace("/", "") 17 | }; 18 | }) 19 | .value() 20 | } 21 | }; 22 | 23 | module.exports = parseLangs; -------------------------------------------------------------------------------- /theme/assets/jsrepl/langs/javascript/jsrepl_js.js: -------------------------------------------------------------------------------- 1 | (function(){self.JSREPLEngine=function(){function a(d,b,c,a,e,f){this.result=c;this.error=a;this.sandbox=e;this.inspect=this.sandbox.console.inspect;this.functionClass=this.sandbox.Function;this.sandbox.__eval=this.sandbox.eval;f()}a.prototype.Eval=function(d){var b;try{return b=this.sandbox.__eval(d),this.result(b===void 0?"":this.inspect(b))}catch(a){return this.error(a)}};a.prototype.RawEval=function(a){var b;try{return b=this.sandbox.__eval(a),this.result(b)}catch(c){return this.error(c)}};a.prototype.GetNextLineIndent= 2 | function(a){try{return new this.functionClass(a),false}catch(b){return/[\[\{\(]$/.test(a)?1:0}};return a}()}).call(this); 3 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/bootstrap/component-animations.less: -------------------------------------------------------------------------------- 1 | // 2 | // Component animations 3 | // -------------------------------------------------- 4 | 5 | // Heads up! 6 | // 7 | // We don't use the `.opacity()` mixin here since it causes a bug with text 8 | // fields in IE7-8. Source: https://github.com/twitter/bootstrap/pull/3552. 9 | 10 | .fade { 11 | opacity: 0; 12 | .transition(opacity .15s linear); 13 | &.in { 14 | opacity: 1; 15 | } 16 | } 17 | 18 | .collapse { 19 | display: none; 20 | &.in { 21 | display: block; 22 | } 23 | } 24 | .collapsing { 25 | position: relative; 26 | height: 0; 27 | overflow: hidden; 28 | .transition(height .35s ease); 29 | } 30 | -------------------------------------------------------------------------------- /test/sections.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var path = require('path'); 3 | var assert = require('assert'); 4 | 5 | var lex = require('../').parse.lex; 6 | 7 | 8 | var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/SECTIONS.md'), 'utf8'); 9 | var LEXED = lex(CONTENT); 10 | 11 | 12 | describe('Section parsing', function() { 13 | it('should correctly split sections', function() { 14 | assert.equal(LEXED.length, 3); 15 | }); 16 | 17 | it('should robustly detect exercises', function() { 18 | assert.equal(LEXED[0].type, 'normal'); 19 | assert.equal(LEXED[1].type, 'exercise'); 20 | assert.equal(LEXED[2].type, 'exercise'); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/bootstrap/wells.less: -------------------------------------------------------------------------------- 1 | // 2 | // Wells 3 | // -------------------------------------------------- 4 | 5 | 6 | // Base class 7 | .well { 8 | min-height: 20px; 9 | padding: 19px; 10 | margin-bottom: 20px; 11 | background-color: @well-bg; 12 | border: 1px solid darken(@well-bg, 7%); 13 | border-radius: @border-radius-base; 14 | .box-shadow(inset 0 1px 1px rgba(0,0,0,.05)); 15 | blockquote { 16 | border-color: #ddd; 17 | border-color: rgba(0,0,0,.15); 18 | } 19 | } 20 | 21 | // Sizes 22 | .well-lg { 23 | padding: 24px; 24 | border-radius: @border-radius-large; 25 | } 26 | .well-sm { 27 | padding: 9px; 28 | border-radius: @border-radius-small; 29 | } 30 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/bootstrap/thumbnails.less: -------------------------------------------------------------------------------- 1 | // 2 | // Thumbnails 3 | // -------------------------------------------------- 4 | 5 | 6 | // Mixin and adjust the regular image class 7 | .thumbnail { 8 | .img-thumbnail(); 9 | display: block; // Override the inline-block from `.img-thumbnail` 10 | 11 | > img { 12 | .img-responsive(); 13 | } 14 | } 15 | 16 | 17 | // Add a hover state for linked versions only 18 | a.thumbnail:hover, 19 | a.thumbnail:focus { 20 | border-color: @link-color; 21 | } 22 | 23 | // Images and captions 24 | .thumbnail > img { 25 | margin-left: auto; 26 | margin-right: auto; 27 | } 28 | .thumbnail .caption { 29 | padding: @thumbnail-caption-padding; 30 | color: @thumbnail-caption-color; 31 | } 32 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/bootstrap/utilities.less: -------------------------------------------------------------------------------- 1 | // 2 | // Utility classes 3 | // -------------------------------------------------- 4 | 5 | 6 | // Floats 7 | // ------------------------- 8 | 9 | .clearfix { 10 | .clearfix(); 11 | } 12 | .pull-right { 13 | float: right !important; 14 | } 15 | .pull-left { 16 | float: left !important; 17 | } 18 | 19 | 20 | // Toggling content 21 | // ------------------------- 22 | 23 | .hide { 24 | display: none !important; 25 | } 26 | .show { 27 | display: block !important; 28 | } 29 | .invisible { 30 | visibility: hidden; 31 | } 32 | .text-hide { 33 | .hide-text(); 34 | } 35 | 36 | 37 | // For Affix plugin 38 | // ------------------------- 39 | 40 | .affix { 41 | position: fixed; 42 | } 43 | -------------------------------------------------------------------------------- /lib/parse/readme.js: -------------------------------------------------------------------------------- 1 | var _ = require('lodash'); 2 | var marked = require('marked'); 3 | 4 | function extractFirstNode(nodes, nType) { 5 | return _.chain(nodes) 6 | .filter(function(node) { 7 | return node.type == nType; 8 | }) 9 | .pluck("text") 10 | .first() 11 | .value(); 12 | } 13 | 14 | 15 | function parseReadme(src) { 16 | var nodes, title, description; 17 | 18 | // Parse content 19 | nodes = marked.lexer(src); 20 | 21 | var title = extractFirstNode(nodes, "heading"); 22 | var description = extractFirstNode(nodes, "paragraph"); 23 | 24 | return { 25 | title: title, 26 | description: description 27 | }; 28 | } 29 | 30 | 31 | // Exports 32 | module.exports = parseReadme; 33 | -------------------------------------------------------------------------------- /lib/utils/links.js: -------------------------------------------------------------------------------- 1 | var url = require('url'); 2 | var path = require('path'); 3 | 4 | // Return true if the link is relative 5 | var isRelative = function(href) { 6 | var parsed = url.parse(href); 7 | 8 | return !parsed.protocol && parsed.path && parsed.path[0] != '/'; 9 | }; 10 | 11 | // Relative to absolute path 12 | // dir: directory parent of the file currently in rendering process 13 | // outdir: directory parent from the html output 14 | 15 | var toAbsolute = function(_href, dir, outdir) { 16 | // Absolute file in source 17 | _href = path.join(dir, _href); 18 | 19 | // make it relative to output 20 | _href = path.relative(outdir, _href); 21 | 22 | return _href; 23 | }; 24 | 25 | 26 | module.exports = { 27 | isRelative: isRelative, 28 | toAbsolute: toAbsolute 29 | }; -------------------------------------------------------------------------------- /theme/stylesheets/vendors/fontawesome/mixins.less: -------------------------------------------------------------------------------- 1 | // Mixins 2 | // -------------------------- 3 | 4 | .fa-icon-rotate(@degrees, @rotation) { 5 | filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=@rotation); 6 | -webkit-transform: rotate(@degrees); 7 | -moz-transform: rotate(@degrees); 8 | -ms-transform: rotate(@degrees); 9 | -o-transform: rotate(@degrees); 10 | transform: rotate(@degrees); 11 | } 12 | 13 | .fa-icon-flip(@horiz, @vert, @rotation) { 14 | filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=@rotation, mirror=1); 15 | -webkit-transform: scale(@horiz, @vert); 16 | -moz-transform: scale(@horiz, @vert); 17 | -ms-transform: scale(@horiz, @vert); 18 | -o-transform: scale(@horiz, @vert); 19 | transform: scale(@horiz, @vert); 20 | } 21 | -------------------------------------------------------------------------------- /test/readme.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var path = require('path'); 3 | var assert = require('assert'); 4 | 5 | var readme = require('../').parse.readme; 6 | 7 | 8 | var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/README.md'), 'utf8'); 9 | var LEXED = readme(CONTENT); 10 | 11 | describe('Readme parsing', function () { 12 | 13 | it('should contain a title', function() { 14 | assert(LEXED.title); 15 | }); 16 | 17 | it('should contain a description', function() { 18 | assert(LEXED.description); 19 | }); 20 | 21 | it('should extract the right title', function() { 22 | assert.equal(LEXED.title, "This is the title"); 23 | }); 24 | 25 | it('should extract the right description', function() { 26 | assert.equal(LEXED.description, "This is the book description."); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/bootstrap/close.less: -------------------------------------------------------------------------------- 1 | // 2 | // Close icons 3 | // -------------------------------------------------- 4 | 5 | 6 | .close { 7 | float: right; 8 | font-size: (@font-size-base * 1.5); 9 | font-weight: @close-font-weight; 10 | line-height: 1; 11 | color: @close-color; 12 | text-shadow: @close-text-shadow; 13 | .opacity(.2); 14 | 15 | &:hover, 16 | &:focus { 17 | color: @close-color; 18 | text-decoration: none; 19 | cursor: pointer; 20 | .opacity(.5); 21 | } 22 | 23 | // Additional properties for button version 24 | // iOS requires the button element instead of an anchor tag. 25 | // If you want the anchor version, it requires `href="#"`. 26 | button& { 27 | padding: 0; 28 | cursor: pointer; 29 | background: transparent; 30 | border: 0; 31 | -webkit-appearance: none; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /bin/utils.js: -------------------------------------------------------------------------------- 1 | var Q = require('q'); 2 | var _ = require('lodash'); 3 | 4 | var http = require('http'); 5 | var send = require('send'); 6 | 7 | var path = require('path'); 8 | var Gaze = require('gaze').Gaze; 9 | 10 | function watch(dir) { 11 | var d = Q.defer(); 12 | dir = path.resolve(dir); 13 | 14 | var gaze = new Gaze("**/*.md", { 15 | cwd: dir 16 | }); 17 | 18 | gaze.once("all", function(e, filepath) { 19 | gaze.close(); 20 | 21 | d.resolve(filepath); 22 | }); 23 | gaze.once("error", function(err) { 24 | gaze.close(); 25 | 26 | d.reject(err); 27 | }); 28 | 29 | return d.promise; 30 | } 31 | 32 | function logError(err) { 33 | console.log(err.stack || err.message || err); 34 | return Q.reject(err); 35 | }; 36 | 37 | 38 | // Exports 39 | module.exports = { 40 | watch: watch, 41 | logError: logError 42 | }; 43 | -------------------------------------------------------------------------------- /test/fixtures/SECTIONS.md: -------------------------------------------------------------------------------- 1 | # Title 2 | 3 | Some text 4 | 5 | --- 6 | 7 | ## NOT Exercise 8 | 9 | Simple subsection NOT exercise 10 | 11 | ``` 12 | x = 1 13 | ``` 14 | 15 | What is this 16 | 17 | ``` 18 | y = [1, 2, 3] 19 | ``` 20 | 21 | ``` 22 | z = {a: 1, b: 2} 23 | ``` 24 | 25 | --- 26 | 27 | ## Exercise 28 | 29 | Define a variable `x` equal to 10. 30 | 31 | ```js 32 | var x = 33 | ``` 34 | 35 | ```js 36 | var x = 10; 37 | ``` 38 | 39 | ```js 40 | assert(x == 10); 41 | ``` 42 | 43 | ```js 44 | // This is context code available everywhere 45 | // The user will be able to call magicFunc in his code 46 | function magicFunc() { 47 | return 3; 48 | } 49 | ``` 50 | 51 | --- 52 | 53 | ## Another exercise 54 | 55 | Bla bla bla ... This time with no `context` code. 56 | 57 | 58 | ```js 59 | var x = 60 | ``` 61 | 62 | ```js 63 | var x = 10; 64 | ``` 65 | 66 | ```js 67 | assert(x == 10); 68 | ``` 69 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/fontawesome/spinning.less: -------------------------------------------------------------------------------- 1 | // Spinning Icons 2 | // -------------------------- 3 | 4 | .@{fa-css-prefix}-spin { 5 | -webkit-animation: spin 2s infinite linear; 6 | -moz-animation: spin 2s infinite linear; 7 | -o-animation: spin 2s infinite linear; 8 | animation: spin 2s infinite linear; 9 | } 10 | 11 | @-moz-keyframes spin { 12 | 0% { -moz-transform: rotate(0deg); } 13 | 100% { -moz-transform: rotate(359deg); } 14 | } 15 | @-webkit-keyframes spin { 16 | 0% { -webkit-transform: rotate(0deg); } 17 | 100% { -webkit-transform: rotate(359deg); } 18 | } 19 | @-o-keyframes spin { 20 | 0% { -o-transform: rotate(0deg); } 21 | 100% { -o-transform: rotate(359deg); } 22 | } 23 | @-ms-keyframes spin { 24 | 0% { -ms-transform: rotate(0deg); } 25 | 100% { -ms-transform: rotate(359deg); } 26 | } 27 | @keyframes spin { 28 | 0% { transform: rotate(0deg); } 29 | 100% { transform: rotate(359deg); } 30 | } 31 | -------------------------------------------------------------------------------- /theme/stylesheets/main.less: -------------------------------------------------------------------------------- 1 | @import "vendors/bootstrap/bootstrap.less"; 2 | @import "vendors/fontawesome/font-awesome.less"; 3 | 4 | @import "mixins.less"; 5 | @import "variables.less"; 6 | @import "fonts.less"; 7 | 8 | @import "book/languages.less"; 9 | @import "book/header.less"; 10 | @import "book/summary.less"; 11 | @import "book/font-settings.less"; 12 | @import "book/body.less"; 13 | @import "book/exercise.less"; 14 | @import "book/quiz.less"; 15 | @import "book/markdown.less"; 16 | @import "book/progress.less"; 17 | @import "book/navigation.less"; 18 | 19 | * { 20 | -webkit-overflow-scrolling: touch; 21 | -webkit-tap-highlight-color: transparent; 22 | -webkit-text-size-adjust: none; 23 | -webkit-touch-callout: none; 24 | -webkit-font-smoothing: antialiased; 25 | } 26 | 27 | html, body { 28 | height: 100%; 29 | } 30 | 31 | body { 32 | text-rendering: optimizeLegibility; 33 | font-smoothing: antialiased; 34 | font-family: @font-family-base; 35 | } 36 | -------------------------------------------------------------------------------- /theme/javascript/utils/storage.js: -------------------------------------------------------------------------------- 1 | define(function(){ 2 | var baseKey = ""; 3 | 4 | /* 5 | * Simple module for storing data in the browser's local storage 6 | */ 7 | return { 8 | setBaseKey: function(key) { 9 | baseKey = key; 10 | }, 11 | set: function(key, value) { 12 | key = baseKey+":"+key; 13 | localStorage[key] = JSON.stringify(value); 14 | }, 15 | get: function(key, def) { 16 | key = baseKey+":"+key; 17 | if (localStorage[key] === undefined) return def; 18 | try { 19 | var v = JSON.parse(localStorage[key]); 20 | return v == null ? def : v;; 21 | } catch(err) { 22 | console.error(err); 23 | return localStorage[key] || def; 24 | } 25 | }, 26 | remove: function(key) { 27 | key = baseKey+":"+key; 28 | localStorage.removeItem(key); 29 | } 30 | }; 31 | }); -------------------------------------------------------------------------------- /theme/templates/includes/book/font-settings.html: -------------------------------------------------------------------------------- 1 | 23 | -------------------------------------------------------------------------------- /theme/javascript/core/keyboard.js: -------------------------------------------------------------------------------- 1 | define([ 2 | "jQuery", 3 | "Mousetrap", 4 | "core/navigation", 5 | "core/sidebar", 6 | "core/search" 7 | ], function($, Mousetrap, navigation, sidebar, search){ 8 | // Bind keyboard shortcuts 9 | var init = function() { 10 | // Next 11 | Mousetrap.bind(['right'], function(e) { 12 | navigation.goNext(); 13 | return false; 14 | }); 15 | 16 | // Prev 17 | Mousetrap.bind(['left'], function(e) { 18 | navigation.goPrev(); 19 | return false; 20 | }); 21 | 22 | // Toggle Summary 23 | Mousetrap.bind(['s'], function(e) { 24 | sidebar.toggle(); 25 | return false; 26 | }); 27 | 28 | // Toggle Search 29 | Mousetrap.bind(['f'], function(e) { 30 | search.toggle(); 31 | return false; 32 | }); 33 | }; 34 | 35 | return { 36 | init: init, 37 | search: search 38 | }; 39 | }); -------------------------------------------------------------------------------- /theme/javascript/utils/sharing.js: -------------------------------------------------------------------------------- 1 | define([ 2 | "jQuery" 3 | ], function($) { 4 | var url = location.href; 5 | var title = $("title").text(); 6 | 7 | var types = { 8 | "twitter": function($el) { 9 | window.open("http://twitter.com/home?status="+encodeURIComponent(title+" "+url)) 10 | }, 11 | "facebook": function($el) { 12 | window.open("http://www.facebook.com/sharer/sharer.php?s=100&p[url]="+encodeURIComponent(url)) 13 | }, 14 | "google-plus": function($el) { 15 | window.open("https://plus.google.com/share?url="+encodeURIComponent(url)) 16 | } 17 | }; 18 | 19 | 20 | // Bind all sharing button 21 | var init = function() { 22 | $(document).on("click", "a[data-sharing]", function(e) { 23 | if (e) e.preventDefault(); 24 | var type = $(this).data("sharing"); 25 | 26 | types[type]($(this)); 27 | }) 28 | }; 29 | 30 | return { 31 | init: init 32 | }; 33 | }); -------------------------------------------------------------------------------- /theme/stylesheets/vendors/bootstrap/jumbotron.less: -------------------------------------------------------------------------------- 1 | // 2 | // Jumbotron 3 | // -------------------------------------------------- 4 | 5 | 6 | .jumbotron { 7 | padding: @jumbotron-padding; 8 | margin-bottom: @jumbotron-padding; 9 | font-size: (@font-size-base * 1.5); 10 | font-weight: 200; 11 | line-height: (@line-height-base * 1.5); 12 | color: @jumbotron-color; 13 | background-color: @jumbotron-bg; 14 | 15 | h1 { 16 | line-height: 1; 17 | color: @jumbotron-heading-color; 18 | } 19 | p { 20 | line-height: 1.4; 21 | } 22 | 23 | .container & { 24 | border-radius: @border-radius-large; // Only round corners at higher resolutions if contained in a container 25 | } 26 | 27 | @media screen and (min-width: @screen-tablet) { 28 | padding-top: (@jumbotron-padding * 1.6); 29 | padding-bottom: (@jumbotron-padding * 1.6); 30 | 31 | .container & { 32 | padding-left: (@jumbotron-padding * 2); 33 | padding-right: (@jumbotron-padding * 2); 34 | } 35 | 36 | h1 { 37 | font-size: (@font-size-base * 4.5); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /test/fixtures/PAGE.md: -------------------------------------------------------------------------------- 1 | # Python basics 2 | 3 | Python is a nice language, you can add stuff. Bla bla bla. 4 | 5 | Lets jump into an exercise : 6 | 7 | --- 8 | 9 | It's dead simple, `c` must be the sum of `a` and `b` 10 | 11 | ```py 12 | a = 1 13 | b = 2 14 | ``` 15 | 16 | ```py 17 | a = 1 18 | b = 2 19 | c = a + b 20 | ``` 21 | 22 | ```py 23 | assert(c, 3) 24 | ``` 25 | 26 | --- 27 | 28 | Some more nice content .... 29 | 30 | [Cool stuff](http://gitbook.io) 31 | 32 | [Link to another Markdown file](./xyz/file.md) 33 | 34 | And look at this pretty picture: 35 | ![Pretty](../assets/my-pretty-picture.png "Pretty") 36 | 37 | Lets go for another exercise but this time with some context : 38 | 39 | --- 40 | 41 | Exercise with some context code : 42 | 43 | Using the `double` function provided, build a `quadruple` function 44 | 45 | ```py 46 | 47 | ``` 48 | 49 | ```py 50 | 51 | def quadruple(x): 52 | return double(double(x)) 53 | 54 | ``` 55 | 56 | ```py 57 | assert(quadruple(8), 32) 58 | ``` 59 | 60 | ```py 61 | 62 | def double(x): 63 | return x * 2 64 | 65 | ``` 66 | 67 | --- 68 | 69 | -------------------------------------------------------------------------------- /theme/templates/includes/book/exercise.html: -------------------------------------------------------------------------------- 1 |
2 |

Exercise

3 |
4 |
5 | Correct! 6 |
7 | 8 |
9 | False! 10 |
11 | 12 |
13 | {% autoescape false %}{{ section.content }}{% endautoescape %} 14 |
15 |
{{ section.code.base }}
16 | 17 | 18 | 19 | {% if section.code.context %} 20 | 21 | {% endif %} 22 | 23 |
24 | Submit 25 | Solution 26 | {% if githubId %} 27 | Have a Question? 28 | {% endif %} 29 |
30 | -------------------------------------------------------------------------------- /theme/javascript/utils/url.js: -------------------------------------------------------------------------------- 1 | define([ 2 | "vendors/URIjs/src/URI" 3 | ], function(URI) { 4 | // Joins path segments. Preserves initial "/" and resolves ".." and "." 5 | // Does not support using ".." to go above/outside the root. 6 | // This means that join("foo", "../../bar") will not resolve to "../bar" 7 | function join(baseUrl, url) { 8 | var theUrl = new URI(url); 9 | if (theUrl.is("relative")) { 10 | theUrl = theUrl.absoluteTo(baseUrl); 11 | } 12 | return theUrl.toString(); 13 | } 14 | 15 | // A simple function to get the dirname of a path 16 | // Trailing slashes are ignored. Leading slash is preserved. 17 | function dirname(path) { 18 | return join(path, ".."); 19 | } 20 | 21 | // test if a path or url is absolute 22 | function isAbsolute(path) { 23 | if (!path) return false; 24 | 25 | return (path[0] == "/" || path.indexOf("http://") == 0 || path.indexOf("https://") == 0); 26 | } 27 | 28 | return { 29 | dirname: dirname, 30 | join: join, 31 | isAbsolute: isAbsolute 32 | }; 33 | }) -------------------------------------------------------------------------------- /theme/stylesheets/vendors/bootstrap/media.less: -------------------------------------------------------------------------------- 1 | // Media objects 2 | // Source: http://stubbornella.org/content/?p=497 3 | // -------------------------------------------------- 4 | 5 | 6 | // Common styles 7 | // ------------------------- 8 | 9 | // Clear the floats 10 | .media, 11 | .media-body { 12 | overflow: hidden; 13 | zoom: 1; 14 | } 15 | 16 | // Proper spacing between instances of .media 17 | .media, 18 | .media .media { 19 | margin-top: 15px; 20 | } 21 | .media:first-child { 22 | margin-top: 0; 23 | } 24 | 25 | // For images and videos, set to block 26 | .media-object { 27 | display: block; 28 | } 29 | 30 | // Reset margins on headings for tighter default spacing 31 | .media-heading { 32 | margin: 0 0 5px; 33 | } 34 | 35 | 36 | // Media image alignment 37 | // ------------------------- 38 | 39 | .media { 40 | > .pull-left { 41 | margin-right: 10px; 42 | } 43 | > .pull-right { 44 | margin-left: 10px; 45 | } 46 | } 47 | 48 | 49 | // Media list variation 50 | // ------------------------- 51 | 52 | // Undo default ul/ol styles 53 | .media-list { 54 | padding-left: 0; 55 | list-style: none; 56 | } 57 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/bootstrap/pager.less: -------------------------------------------------------------------------------- 1 | // 2 | // Pager pagination 3 | // -------------------------------------------------- 4 | 5 | 6 | .pager { 7 | padding-left: 0; 8 | margin: @line-height-computed 0; 9 | list-style: none; 10 | text-align: center; 11 | .clearfix(); 12 | li { 13 | display: inline; 14 | > a, 15 | > span { 16 | display: inline-block; 17 | padding: 5px 14px; 18 | background-color: @pagination-bg; 19 | border: 1px solid @pagination-border; 20 | border-radius: @pager-border-radius; 21 | } 22 | 23 | > a:hover, 24 | > a:focus { 25 | text-decoration: none; 26 | background-color: @pagination-hover-bg; 27 | } 28 | } 29 | 30 | .next { 31 | > a, 32 | > span { 33 | float: right; 34 | } 35 | } 36 | 37 | .previous { 38 | > a, 39 | > span { 40 | float: left; 41 | } 42 | } 43 | 44 | .disabled { 45 | > a, 46 | > a:hover, 47 | > a:focus, 48 | > span { 49 | color: @pager-disabled-color; 50 | background-color: @pagination-bg; 51 | cursor: not-allowed; 52 | } 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /theme/stylesheets/book/languages.less: -------------------------------------------------------------------------------- 1 | .book-langs-index { 2 | width: 100%; 3 | height: 100%; 4 | padding: 40px 0px; 5 | margin: 0px; 6 | overflow: auto; 7 | 8 | @media (max-width: 600px) { 9 | padding: 0px; 10 | } 11 | 12 | .inner { 13 | max-width: 600px; 14 | width: 100%; 15 | 16 | margin: 0px auto; 17 | padding: 30px; 18 | 19 | background: #fff; 20 | border-radius: 3px; 21 | 22 | h3 { 23 | margin: 0px; 24 | } 25 | 26 | .languages { 27 | list-style: none; 28 | padding: 20px 30px; 29 | margin-top: 20px; 30 | border-top: 1px solid #eee; 31 | 32 | .clearfix(); 33 | 34 | li { 35 | width: 50%; 36 | float: left; 37 | padding: 10px 5px; 38 | font-size: 16px; 39 | 40 | a { 41 | 42 | } 43 | 44 | @media (max-width: 600px) { 45 | width: 100%; 46 | max-width: 100%; 47 | } 48 | } 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /theme/stylesheets/book/exercise.less: -------------------------------------------------------------------------------- 1 | .book .book-body .page-wrapper .page-inner { 2 | section.exercise { 3 | padding: 0px; 4 | margin: 20px 0px; 5 | border: 3px solid #2f8cde; 6 | 7 | .header { 8 | padding: 5px 15px; 9 | 10 | color: #fff; 11 | background: #2f8cde; 12 | 13 | h2 { 14 | margin: 0px; 15 | font-size: 20px; 16 | } 17 | } 18 | 19 | .message { 20 | margin: 5px 15px; 21 | } 22 | 23 | .editor { 24 | min-height: 50px; 25 | font-size: 14px; 26 | border-top: 1px solid #ddd; 27 | border-bottom: 1px solid #ddd; 28 | } 29 | 30 | 31 | .alert { 32 | display: none; 33 | margin: 0px; 34 | margin-bottom: 10px; 35 | padding: 8px 15px; 36 | } 37 | 38 | &.return-error { 39 | .alert-danger { 40 | display: block; 41 | } 42 | } 43 | &.return-success { 44 | .alert-success { 45 | display: block; 46 | } 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /theme/stylesheets/vendors/bootstrap/badges.less: -------------------------------------------------------------------------------- 1 | // 2 | // Badges 3 | // -------------------------------------------------- 4 | 5 | 6 | // Base classes 7 | .badge { 8 | display: inline-block; 9 | min-width: 10px; 10 | padding: 3px 7px; 11 | font-size: @font-size-small; 12 | font-weight: @badge-font-weight; 13 | color: @badge-color; 14 | line-height: @badge-line-height; 15 | vertical-align: baseline; 16 | white-space: nowrap; 17 | text-align: center; 18 | background-color: @badge-bg; 19 | border-radius: @badge-border-radius; 20 | 21 | // Empty badges collapse automatically (not available in IE8) 22 | &:empty { 23 | display: none; 24 | } 25 | } 26 | 27 | // Hover state, but only for links 28 | a.badge { 29 | &:hover, 30 | &:focus { 31 | color: @badge-link-hover-color; 32 | text-decoration: none; 33 | cursor: pointer; 34 | } 35 | } 36 | 37 | // Quick fix for labels/badges in buttons 38 | .btn .badge { 39 | position: relative; 40 | top: -1px; 41 | } 42 | 43 | // Account for counters in navs 44 | a.list-group-item.active > .badge, 45 | .nav-pills > .active > a > .badge { 46 | color: @badge-active-color; 47 | background-color: @badge-active-bg; 48 | } 49 | .nav-pills > li > a > .badge { 50 | margin-left: 3px; 51 | } 52 | -------------------------------------------------------------------------------- /test/generate.js: -------------------------------------------------------------------------------- 1 | var _ = require('lodash'); 2 | var Q = require('q'); 3 | var path = require('path'); 4 | var tmp = require('tmp'); 5 | var assert = require('assert'); 6 | 7 | var generate = require("../lib/generate"); 8 | 9 | var generateTmpBook = function(path) { 10 | return ; 11 | }; 12 | 13 | 14 | var BOOKS = { 15 | "book1": true, 16 | "book2": false 17 | }; 18 | 19 | describe('Site Generation', function () { 20 | var ret = {}; 21 | 22 | beforeEach(function(done){ 23 | Q.all(_.map(BOOKS, function(state, bookName) { 24 | return Q.nfcall(tmp.dir) 25 | .then(function(_dir) { 26 | return generate.folder({ 27 | input: path.join(__dirname, "fixtures", bookName), 28 | output: _dir 29 | }); 30 | }) 31 | .then(function(_book) { 32 | ret[bookName] = _book; 33 | }, function(err) { 34 | // ignore errors here 35 | }); 36 | })) 37 | .fin(done); 38 | }); 39 | 40 | 41 | it('should generate the valid sites', function() { 42 | _.each(BOOKS, function(state, bookName) { 43 | assert((ret[bookName] != null) == state); 44 | }); 45 | }); 46 | }); 47 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/bootstrap/labels.less: -------------------------------------------------------------------------------- 1 | // 2 | // Labels 3 | // -------------------------------------------------- 4 | 5 | .label { 6 | display: inline; 7 | padding: .2em .6em .3em; 8 | font-size: 75%; 9 | font-weight: bold; 10 | line-height: 1; 11 | color: @label-color; 12 | text-align: center; 13 | white-space: nowrap; 14 | vertical-align: baseline; 15 | border-radius: .25em; 16 | 17 | // Add hover effects, but only for links 18 | &[href] { 19 | &:hover, 20 | &:focus { 21 | color: @label-link-hover-color; 22 | text-decoration: none; 23 | cursor: pointer; 24 | } 25 | } 26 | 27 | // Empty labels collapse automatically (not available in IE8) 28 | &:empty { 29 | display: none; 30 | } 31 | } 32 | 33 | // Colors 34 | // Contextual variations (linked labels get darker on :hover) 35 | 36 | .label-default { 37 | .label-variant(@label-default-bg); 38 | } 39 | 40 | .label-primary { 41 | .label-variant(@label-primary-bg); 42 | } 43 | 44 | .label-success { 45 | .label-variant(@label-success-bg); 46 | } 47 | 48 | .label-info { 49 | .label-variant(@label-info-bg); 50 | } 51 | 52 | .label-warning { 53 | .label-variant(@label-warning-bg); 54 | } 55 | 56 | .label-danger { 57 | .label-variant(@label-danger-bg); 58 | } 59 | -------------------------------------------------------------------------------- /lib/generate/json/index.js: -------------------------------------------------------------------------------- 1 | var util = require("util"); 2 | var path = require("path"); 3 | var Q = require("q"); 4 | 5 | var fs = require("../fs"); 6 | var parse = require("../../parse"); 7 | var BaseGenerator = require("../generator"); 8 | 9 | 10 | var Generator = function() { 11 | BaseGenerator.apply(this, arguments); 12 | }; 13 | util.inherits(Generator, BaseGenerator); 14 | 15 | Generator.prototype.transferFile = function(input) { 16 | // ignore 17 | }; 18 | 19 | Generator.prototype.convertFile = function(content, input) { 20 | var that = this; 21 | var json = { 22 | progress: parse.progress(this.options.navigation, input) 23 | }; 24 | 25 | return Q() 26 | .then(function() { 27 | return parse.page(content, { 28 | repo: that.options.githubId, 29 | dir: path.dirname(input) || '/' 30 | }); 31 | }) 32 | .then(function(sections) { 33 | json.sections = sections; 34 | }) 35 | .then(function() { 36 | return fs.writeFile( 37 | path.join(that.options.output, input.replace(".md", ".json")), 38 | JSON.stringify(json, null, 4) 39 | ); 40 | }); 41 | }; 42 | 43 | Generator.prototype.finish = function() { 44 | // ignore 45 | }; 46 | 47 | module.exports = Generator; -------------------------------------------------------------------------------- /test/fixtures/QUIZ_PAGE.md: -------------------------------------------------------------------------------- 1 | # Gitbook quiz 2 | 3 | Gitbook lets you write a quiz using GFM tables: 4 | 5 | --- 6 | 7 | Here's a quiz about Gitbook 8 | 9 | | | Good | Bad | 10 | | ---------------- | ---- | --- | 11 | | What is Gitbook? | (x) | ( ) | 12 | 13 | > Gitbook is good 14 | 15 | What does Gitbook support? 16 | - [x] Table-based questions with radio buttons 17 | - [x] Table-based questions with checkboxes 18 | - [ ] Telepathy 19 | - [x] List-based questions with checkboxes 20 | - [x] List-based questions with radio buttons 21 | - [ ] Moon-on-a-stick 22 | 23 | > Gitbook supports table and list based quiz questions using either radio buttons or checkboxes. 24 | > 25 | > Gitbook is not telepathic and does not give you the moon on a stick. 26 | 27 | --- 28 | 29 | Some more nice content .... 30 | 31 | [Cool stuff](http://gitbook.io) 32 | 33 | [Link to another Markdown file](./xyz/file.md) 34 | 35 | --- 36 | 37 | Quiz test 2: What does Gitbook support? 38 | - [x] Table-based questions with radio buttons 39 | - [x] Table-based questions with checkboxes 40 | - [ ] Telepathy 41 | - [x] List-based questions with checkboxes 42 | - [x] List-based questions with radio buttons 43 | - [ ] Moon-on-a-stick 44 | 45 | > Gitbook supports table and list based quiz questions using either radio buttons or checkboxes. 46 | 47 | --- 48 | 49 | -------------------------------------------------------------------------------- /theme/javascript/gitbook.js: -------------------------------------------------------------------------------- 1 | define([ 2 | "jQuery", 3 | "utils/storage", 4 | "utils/sharing", 5 | "utils/appcache", 6 | 7 | "core/events", 8 | "core/font-settings", 9 | "core/state", 10 | "core/keyboard", 11 | "core/navigation", 12 | "core/progress", 13 | "core/sidebar", 14 | "core/search" 15 | ], function($, storage, appCache, sharing, events, fontSettings, state, keyboard, navigation, progress, sidebar, search){ 16 | var start = function(config) { 17 | var $book; 18 | $book = state.$book; 19 | 20 | if (state.githubId) { 21 | // Initialize storage 22 | storage.setBaseKey(state.githubId); 23 | } 24 | 25 | // Init sidebar 26 | sidebar.init(); 27 | 28 | // Load search 29 | search.init(); 30 | 31 | // Init keyboard 32 | keyboard.init(); 33 | 34 | // Init appcache 35 | appCache.init(); 36 | 37 | // Bind sharing button 38 | sharing.init(); 39 | 40 | // Init navigation 41 | navigation.init(); 42 | 43 | //Init font settings 44 | fontSettings.init(config.fontSettings || {}); 45 | 46 | events.trigger("start", config); 47 | } 48 | 49 | return { 50 | start: start, 51 | events: events 52 | }; 53 | }); 54 | -------------------------------------------------------------------------------- /theme/stylesheets/book/quiz.less: -------------------------------------------------------------------------------- 1 | .book .book-body .page-wrapper .page-inner { 2 | section.quiz { 3 | padding: 0px; 4 | margin: 20px 0px; 5 | border: 3px solid #2f8cde; 6 | 7 | .header { 8 | padding: 5px 15px; 9 | 10 | color: #fff; 11 | background: #2f8cde; 12 | 13 | h2 { 14 | margin: 0px; 15 | font-size: 20px; 16 | } 17 | } 18 | 19 | .message { 20 | margin: 15px; 21 | } 22 | 23 | .question { 24 | .question-header { 25 | padding: 5px 15px; 26 | color: #fff; 27 | background: #2f8cde; 28 | } 29 | 30 | .question-inner { 31 | padding: 15px; 32 | .quiz-label { 33 | font-weight: normal; 34 | cursor: pointer; 35 | } 36 | } 37 | 38 | table { 39 | margin-bottom: 10px; 40 | width: 100%; 41 | } 42 | th, td { 43 | padding-right: 5px; 44 | } 45 | li { 46 | list-style-type: none; 47 | input { 48 | margin-right: 10px; 49 | } 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /lib/parse/progress.js: -------------------------------------------------------------------------------- 1 | var _ = require("lodash"); 2 | 3 | // Returns from a navigation and a current file, a snapshot of current detailed state 4 | var calculProgress = function(navigation, current) { 5 | var n = _.size(navigation); 6 | var percent = 0, prevPercent = 0, currentChapter = null; 7 | var done = true; 8 | 9 | var chapters = _.chain(navigation) 10 | .map(function(nav, path) { 11 | nav.path = path; 12 | return nav; 13 | }) 14 | .sortBy(function(nav) { 15 | return nav.level; 16 | }) 17 | .map(function(nav, i) { 18 | // Calcul percent 19 | nav.percent = (i * 100) / Math.max((n - 1), 1); 20 | 21 | // Is it done 22 | nav.done = done; 23 | if (nav.path == current) { 24 | currentChapter = nav; 25 | percent = nav.percent; 26 | done = false; 27 | } else if (done) { 28 | prevPercent = nav.percent; 29 | } 30 | 31 | return nav; 32 | }) 33 | .value(); 34 | 35 | return { 36 | // Previous percent 37 | prevPercent: prevPercent, 38 | 39 | // Current percent 40 | percent: percent, 41 | 42 | // List of chapter with progress 43 | chapters: chapters, 44 | 45 | // Current chapter 46 | current: currentChapter 47 | }; 48 | } 49 | 50 | module.exports = calculProgress; -------------------------------------------------------------------------------- /test/plugin.js: -------------------------------------------------------------------------------- 1 | var _ = require('lodash'); 2 | var path = require('path'); 3 | var assert = require('assert'); 4 | 5 | var Plugin = require('../').generate.Plugin; 6 | 7 | describe('Plugin validation', function () { 8 | var plugin = new Plugin("plugin", __dirname); 9 | 10 | it('should be valid', function() { 11 | assert(plugin.isValid()); 12 | }); 13 | }); 14 | 15 | describe('Plugin list of names', function () { 16 | var firstDefault = _.first(Plugin.defaults); 17 | 18 | it('should convert string to array', function() { 19 | var _name = "test"; 20 | assert(_.contains(Plugin.normalizeNames(_name), _name)); 21 | }); 22 | 23 | it('should contains default plugins', function() { 24 | assert(_.contains(Plugin.normalizeNames([]), firstDefault)); 25 | }); 26 | 27 | it('should remove name starting with -', function() { 28 | assert(!_.contains(Plugin.normalizeNames(["-"+firstDefault]), firstDefault)); 29 | }); 30 | }); 31 | 32 | describe('Plugin defaults loading', function () { 33 | var ret = true; 34 | 35 | beforeEach(function(done){ 36 | Plugin.fromList(Plugin.defaults, __dirname) 37 | .then(function(_r) { 38 | ret = _r; 39 | }, function(err) { 40 | ret = null; 41 | }) 42 | .fin(done); 43 | }); 44 | 45 | 46 | it('should load defaults addons', function() { 47 | assert(ret != null); 48 | }); 49 | }); 50 | -------------------------------------------------------------------------------- /theme/templates/includes/book/quiz.html: -------------------------------------------------------------------------------- 1 |
2 |

Quiz

3 |
4 | 5 |
6 | {% autoescape false %}{{ section.content }}{% endautoescape %} 7 |
8 | 9 | 10 | {% for quiz in section.quiz %} 11 |
12 |
Question {{ loop.index }} of {{ section.quiz.length }}
13 | 14 |
15 | 18 | 19 | 23 | 24 |
25 | {% autoescape false %}{{ quiz.base }}{% endautoescape %} 26 |
27 |
28 | 29 | 34 |
35 | {% endfor %} 36 | 37 |
38 | Submit 39 | Solution 40 | {% if githubId %} 41 | Have a Question? 42 | {% endif %} 43 |
44 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/bootstrap/code.less: -------------------------------------------------------------------------------- 1 | // 2 | // Code (inline and blocK) 3 | // -------------------------------------------------- 4 | 5 | 6 | // Inline and block code styles 7 | code, 8 | pre { 9 | font-family: @font-family-monospace; 10 | } 11 | 12 | // Inline code 13 | code { 14 | padding: 2px 4px; 15 | font-size: 90%; 16 | color: @code-color; 17 | background-color: @code-bg; 18 | white-space: nowrap; 19 | border-radius: @border-radius-base; 20 | } 21 | 22 | // Blocks of code 23 | pre { 24 | display: block; 25 | padding: ((@line-height-computed - 1) / 2); 26 | margin: 0 0 (@line-height-computed / 2); 27 | font-size: (@font-size-base - 1); // 14px to 13px 28 | line-height: @line-height-base; 29 | word-break: break-all; 30 | word-wrap: break-word; 31 | color: @pre-color; 32 | background-color: @pre-bg; 33 | border: 1px solid @pre-border-color; 34 | border-radius: @border-radius-base; 35 | 36 | // Make prettyprint styles more spaced out for readability 37 | &.prettyprint { 38 | margin-bottom: @line-height-computed; 39 | } 40 | 41 | // Account for some code outputs that place code tags in pre tags 42 | code { 43 | padding: 0; 44 | font-size: inherit; 45 | color: inherit; 46 | white-space: pre-wrap; 47 | background-color: transparent; 48 | border: 0; 49 | } 50 | } 51 | 52 | // Enable scrollable blocks of code 53 | .pre-scrollable { 54 | max-height: @pre-scrollable-max-height; 55 | overflow-y: scroll; 56 | } 57 | -------------------------------------------------------------------------------- /bin/build.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var Q = require('q'); 3 | var _ = require('lodash'); 4 | var fs = require('fs'); 5 | 6 | var utils = require('./utils'); 7 | var generate = require("../lib/generate"); 8 | var parse = require("../lib/parse"); 9 | var generators = require("../lib/generate").generators; 10 | 11 | var buildCommand = function(command) { 12 | return command 13 | .option('-o, --output ', 'Path to output directory, defaults to ./_book') 14 | .option('-f, --format ', 'Change generation format, defaults to site, availables are: '+_.keys(generators).join(", ")) 15 | .option('--config ', 'Configuration file to use, defualt to book.json') 16 | }; 17 | 18 | 19 | var makeBuildFunc = function(converter) { 20 | return function(dir, options) { 21 | dir = dir || process.cwd(); 22 | outputDir = options.output; 23 | 24 | console.log('Starting build ...'); 25 | return converter( 26 | _.extend({}, options || {}, { 27 | input: dir, 28 | output: outputDir, 29 | generator: options.format, 30 | configFile: options.config 31 | }) 32 | ) 33 | .then(function(output) { 34 | console.log("Successfuly built !"); 35 | return output; 36 | }, utils.logError); 37 | }; 38 | }; 39 | 40 | module.exports = { 41 | folder: makeBuildFunc(generate.folder), 42 | file: makeBuildFunc(generate.file), 43 | command: buildCommand 44 | }; 45 | -------------------------------------------------------------------------------- /theme/stylesheets/book/navigation.less: -------------------------------------------------------------------------------- 1 | .book .book-body { 2 | .navigation { 3 | position: absolute; 4 | top: 0px; 5 | bottom: 0px; 6 | margin: 0; 7 | max-width: 150px; 8 | min-width: 90px; 9 | 10 | display: flex; 11 | justify-content: center; 12 | align-content: center; 13 | flex-direction: column; 14 | 15 | font-size: 40px; 16 | color: rgba(0,0,0,0.5); 17 | 18 | text-align: center; 19 | 20 | .transition(all 350ms ease); 21 | 22 | &:hover { 23 | background-color: @body-pagination-background; 24 | text-decoration: none; 25 | } 26 | 27 | &.navigation-next { 28 | right: 0px; 29 | } 30 | &.navigation-prev { 31 | left: 0px; 32 | } 33 | } 34 | 35 | @media (max-width: @mobileMaxWidth) { 36 | .navigation { 37 | position: static; 38 | top: auto; 39 | max-width: 50%; 40 | width: 50%; 41 | display: inline-block; 42 | float: left; 43 | 44 | &.navigation-unique { 45 | max-width: 100%; 46 | width: 100%; 47 | } 48 | } 49 | } 50 | } 51 | .book.color-theme-1 .book-body { 52 | .navigation:hover{ 53 | background-color: @body-pagination-background-1; 54 | } 55 | } 56 | .book.color-theme-2 .book-body { 57 | .navigation:hover{ 58 | background-color: @body-pagination-background-2; 59 | } 60 | } -------------------------------------------------------------------------------- /lib/parse/git.js: -------------------------------------------------------------------------------- 1 | var Q = require('q'); 2 | var _ = require('lodash'); 3 | var cp = require('child_process'); 4 | var url = require('url'); 5 | 6 | // Get the remote of a given repo 7 | function gitURL(path) { 8 | var d = Q.defer(); 9 | 10 | cp.exec("git config --get remote.origin.url", { 11 | cwd: path, 12 | env: process.env, 13 | }, function(err, stdout, stderr) { 14 | if(err) { 15 | return d.reject(err); 16 | } 17 | 18 | return d.resolve(stdout); 19 | }); 20 | 21 | return d.promise 22 | .then(function(output) { 23 | return output.replace(/(\r\n|\n|\r)/gm, ""); 24 | }); 25 | } 26 | 27 | // Poorman's parsing 28 | // Parse a git URL to a github ID : username/reponame 29 | function githubID(_url) { 30 | // Remove .git if it's in _url 31 | var sliceEnd = _url.slice(-4) === '.git' ? -4 : _url.length; 32 | 33 | // Detect HTTPS repos 34 | var parsed = url.parse(_url); 35 | if(parsed.protocol === 'https:' && parsed.host === 'github.com') { 36 | return parsed.path.slice(1, sliceEnd); 37 | } 38 | 39 | // Detect SSH repos 40 | if(_url.indexOf('git@') === 0) { 41 | return _url.split(':', 2)[1].slice(0, sliceEnd); 42 | } 43 | 44 | // None found 45 | return null; 46 | } 47 | 48 | function titleCase(str) { 49 | return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); 50 | } 51 | 52 | module.exports = { 53 | url: gitURL, 54 | githubID: githubID, 55 | titleCase: titleCase 56 | }; 57 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/fontawesome/font-awesome.less: -------------------------------------------------------------------------------- 1 | /*! 2 | * Font Awesome 4.0.1 3 | * the iconic font designed for Bootstrap 4 | * ------------------------------------------------------------------------------ 5 | * The full suite of pictographic icons, examples, and documentation can be 6 | * found at http://fontawesome.io. Stay up to date on Twitter at 7 | * http://twitter.com/fontawesome. 8 | * 9 | * License 10 | * ------------------------------------------------------------------------------ 11 | * - The Font Awesome font is licensed under SIL OFL 1.1 - 12 | * http://scripts.sil.org/OFL 13 | * - Font Awesome CSS, LESS, and SASS files are licensed under MIT License - 14 | * http://opensource.org/licenses/mit-license.html 15 | * - Font Awesome documentation licensed under CC BY 3.0 - 16 | * http://creativecommons.org/licenses/by/3.0/ 17 | * - Attribution is no longer required in Font Awesome 3.0, but much appreciated: 18 | * "Font Awesome by Dave Gandy - http://fontawesome.io" 19 | * 20 | * Author - Dave Gandy 21 | * ------------------------------------------------------------------------------ 22 | * Email: dave@fontawesome.io 23 | * Twitter: http://twitter.com/davegandy 24 | * Work: Lead Product Designer @ Kyruus - http://kyruus.com 25 | */ 26 | 27 | @import "variables"; 28 | @import "mixins"; 29 | @import "path"; 30 | @import "core"; 31 | @import "larger"; 32 | @import "fixed-width"; 33 | @import "list"; 34 | @import "bordered-pulled"; 35 | @import "spinning"; 36 | @import "rotated-flipped"; 37 | @import "stacked"; 38 | @import "icons"; 39 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/bootstrap/bootstrap.less: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap v3.0.0 3 | * 4 | * Copyright 2013 Twitter, Inc 5 | * Licensed under the Apache License v2.0 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Designed and built with all the love in the world by @mdo and @fat. 9 | */ 10 | 11 | // Core variables and mixins 12 | @import "variables.less"; 13 | @import "mixins.less"; 14 | 15 | // Reset 16 | @import "normalize.less"; 17 | //@import "print.less"; 18 | 19 | // Core CSS 20 | @import "scaffolding.less"; 21 | @import "type.less"; 22 | @import "code.less"; 23 | @import "grid.less"; 24 | @import "tables.less"; 25 | @import "forms.less"; 26 | @import "buttons.less"; 27 | 28 | // Components 29 | @import "component-animations.less"; 30 | @import "glyphicons.less"; 31 | @import "dropdowns.less"; 32 | @import "button-groups.less"; 33 | @import "input-groups.less"; 34 | @import "navs.less"; 35 | @import "navbar.less"; 36 | @import "breadcrumbs.less"; 37 | @import "pagination.less"; 38 | @import "pager.less"; 39 | @import "labels.less"; 40 | @import "badges.less"; 41 | @import "jumbotron.less"; 42 | @import "thumbnails.less"; 43 | @import "alerts.less"; 44 | @import "progress-bars.less"; 45 | @import "media.less"; 46 | @import "list-group.less"; 47 | @import "panels.less"; 48 | @import "wells.less"; 49 | @import "close.less"; 50 | 51 | // Components w/ JavaScript 52 | @import "modals.less"; 53 | @import "tooltip.less"; 54 | @import "popovers.less"; 55 | @import "carousel.less"; 56 | 57 | // Utility classes 58 | @import "utilities.less"; 59 | @import "responsive-utilities.less"; 60 | -------------------------------------------------------------------------------- /lib/generate/generator.js: -------------------------------------------------------------------------------- 1 | var _ = require("lodash"); 2 | var path = require("path"); 3 | var Q = require("q"); 4 | var fs = require("./fs"); 5 | 6 | var Plugin = require("./plugin"); 7 | 8 | var BaseGenerator = function(options) { 9 | this.options = options; 10 | 11 | this.options.plugins = Plugin.normalizeNames(this.options.plugins); 12 | this.plugins = []; 13 | }; 14 | 15 | BaseGenerator.prototype.callHook = function(name, data) { 16 | return this.plugins.hook(name, this, data); 17 | }; 18 | 19 | BaseGenerator.prototype.loadPlugins = function() { 20 | var that = this; 21 | 22 | return Plugin.fromList(this.options.plugins, this.options.input) 23 | .then(function(_plugins) { 24 | that.plugins = _plugins; 25 | 26 | return that.callHook("init"); 27 | }); 28 | }; 29 | 30 | BaseGenerator.prototype.convertFile = function(content, input) { 31 | return Q.reject(new Error("Could not convert "+input)); 32 | }; 33 | 34 | BaseGenerator.prototype.transferFile = function(input) { 35 | return fs.copy( 36 | path.join(this.options.input, input), 37 | path.join(this.options.output, input) 38 | ); 39 | }; 40 | 41 | BaseGenerator.prototype.transferFolder = function(input) { 42 | return fs.mkdirp( 43 | path.join(this.options.output, input) 44 | ); 45 | }; 46 | 47 | BaseGenerator.prototype.langsIndex = function(langs) { 48 | return Q.reject(new Error("Langs index is not supported in this generator")); 49 | }; 50 | 51 | BaseGenerator.prototype.finish = function() { 52 | return Q.reject(new Error("Could not finish generation")); 53 | }; 54 | 55 | 56 | 57 | module.exports = BaseGenerator; -------------------------------------------------------------------------------- /theme/stylesheets/vendors/bootstrap/alerts.less: -------------------------------------------------------------------------------- 1 | // 2 | // Alerts 3 | // -------------------------------------------------- 4 | 5 | 6 | // Base styles 7 | // ------------------------- 8 | 9 | .alert { 10 | padding: @alert-padding; 11 | margin-bottom: @line-height-computed; 12 | border: 1px solid transparent; 13 | border-radius: @alert-border-radius; 14 | 15 | // Headings for larger alerts 16 | h4 { 17 | margin-top: 0; 18 | // Specified for the h4 to prevent conflicts of changing @headingsColor 19 | color: inherit; 20 | } 21 | // Provide class for links that match alerts 22 | .alert-link { 23 | font-weight: @alert-link-font-weight; 24 | } 25 | 26 | // Improve alignment and spacing of inner content 27 | > p, 28 | > ul { 29 | margin-bottom: 0; 30 | } 31 | > p + p { 32 | margin-top: 5px; 33 | } 34 | } 35 | 36 | // Dismissable alerts 37 | // 38 | // Expand the right padding and account for the close button's positioning. 39 | 40 | .alert-dismissable { 41 | padding-right: (@alert-padding + 20); 42 | 43 | // Adjust close link position 44 | .close { 45 | position: relative; 46 | top: -2px; 47 | right: -21px; 48 | color: inherit; 49 | } 50 | } 51 | 52 | // Alternate styles 53 | // 54 | // Generate contextual modifier classes for colorizing the alert. 55 | 56 | .alert-success { 57 | .alert-variant(@alert-success-bg; @alert-success-border; @alert-success-text); 58 | } 59 | .alert-info { 60 | .alert-variant(@alert-info-bg; @alert-info-border; @alert-info-text); 61 | } 62 | .alert-warning { 63 | .alert-variant(@alert-warning-bg; @alert-warning-border; @alert-warning-text); 64 | } 65 | .alert-danger { 66 | .alert-variant(@alert-danger-bg; @alert-danger-border; @alert-danger-text); 67 | } 68 | -------------------------------------------------------------------------------- /lib/generate/fs.js: -------------------------------------------------------------------------------- 1 | var Q = require("q"); 2 | var fs = require("fs"); 3 | var fsExtra = require("fs-extra"); 4 | var Ignore = require("fstream-ignore"); 5 | 6 | var getFiles = function(path) { 7 | var d = Q.defer(); 8 | 9 | // Our list of files 10 | var files = []; 11 | 12 | var ig = Ignore({ 13 | path: path, 14 | ignoreFiles: ['.ignore', '.gitignore', '.bookignore'] 15 | }); 16 | 17 | // Add extra rules to ignore common folders 18 | ig.addIgnoreRules([ 19 | '.git/', 20 | '.gitignore', 21 | '.DS_Store' 22 | ], '__custom_stuff'); 23 | 24 | // Push each file to our list 25 | ig.on('child', function (c) { 26 | files.push( 27 | c.path.substr(c.root.path.length + 1) + (c.props.Directory === true ? '/' : '') 28 | ); 29 | }); 30 | 31 | ig.on('end', function() { 32 | // Normalize paths on Windows 33 | if(process.platform === 'win32') { 34 | return d.resolve(files.map(function(file) { 35 | return file.replace(/\\/g, '/'); 36 | })); 37 | } 38 | 39 | // Simply return paths otherwise 40 | return d.resolve(files); 41 | }); 42 | 43 | ig.on('error', d.reject); 44 | 45 | return d.promise; 46 | }; 47 | 48 | module.exports = { 49 | list: getFiles, 50 | readFile: Q.denodeify(fs.readFile), 51 | writeFile: Q.denodeify(fs.writeFile), 52 | mkdirp: Q.denodeify(fsExtra.mkdirp), 53 | copy: Q.denodeify(fsExtra.copy), 54 | remove: Q.denodeify(fsExtra.remove), 55 | symlink: Q.denodeify(fsExtra.symlink), 56 | exists: function(path) { 57 | var d = Q.defer(); 58 | fs.exists(path, d.resolve); 59 | return d.promise; 60 | }, 61 | }; 62 | -------------------------------------------------------------------------------- /lib/generate/pdf/index.js: -------------------------------------------------------------------------------- 1 | var util = require("util"); 2 | var path = require("path"); 3 | var Q = require("q"); 4 | var _ = require("lodash"); 5 | var exec = require('child_process').exec; 6 | 7 | var fs = require("../fs"); 8 | var parse = require("../../parse"); 9 | var BaseGenerator = require("../page"); 10 | 11 | /* 12 | * This generator inherits from the single page generator 13 | * and convert the page output to pdf using gitbook-pdf 14 | */ 15 | var Generator = function() { 16 | BaseGenerator.apply(this, arguments); 17 | 18 | // Options for PDF generation 19 | this.options = _.defaults(this.options, { 20 | paperformat: "A4" 21 | }); 22 | }; 23 | util.inherits(Generator, BaseGenerator); 24 | 25 | Generator.prototype.finish = function() { 26 | var that = this; 27 | 28 | return BaseGenerator.prototype.finish.apply(this) 29 | .then(function() { 30 | var d = Q.defer(); 31 | 32 | var command = [ 33 | "gitbook-pdf", 34 | "generate", 35 | path.join(that.options.output, "index.html"), 36 | path.join(that.options.output, "index.pdf"), 37 | "--format="+that.options.paperformat 38 | ].join(" "); 39 | 40 | exec(command, function (error, stdout, stderr) { 41 | if (error) { 42 | if (error.code == 127) { 43 | error.message = "Need to install gitbook-pdf using: npm install gitbook-pdf -g"; 44 | } else { 45 | error.message = error.message + " "+stdout; 46 | } 47 | return d.reject(error); 48 | } 49 | d.resolve(); 50 | }); 51 | 52 | return d.promise; 53 | }); 54 | }; 55 | 56 | module.exports = Generator; 57 | -------------------------------------------------------------------------------- /lib/generate/site/search_indexer.js: -------------------------------------------------------------------------------- 1 | var Q = require("q"); 2 | var _ = require("lodash"); 3 | 4 | var lunr = require('lunr'); 5 | var marked = require('marked'); 6 | var textRenderer = require('marked-text-renderer'); 7 | 8 | 9 | function Indexer() { 10 | if(!(this instanceof Indexer)) { 11 | return new Indexer(); 12 | } 13 | 14 | _.bindAll(this); 15 | 16 | // Setup lunr index 17 | this.idx = lunr(function () { 18 | this.ref('url'); 19 | 20 | this.field('title', { boost: 10 }); 21 | this.field('body'); 22 | }); 23 | 24 | this.renderer = textRenderer(); 25 | } 26 | 27 | Indexer.prototype.text = function(nodes) { 28 | // Copy section 29 | var section = _.toArray(nodes); 30 | 31 | // marked's Render expects this, we don't use it yet 32 | section.links = {}; 33 | 34 | var options = _.extend({}, marked.defaults, { 35 | renderer: this.renderer 36 | }); 37 | 38 | return marked.parser(section, options); 39 | }; 40 | 41 | Indexer.prototype.addSection = function(path, section) { 42 | var url = [path, section.id].join('#'); 43 | 44 | var title = this.text( 45 | _.filter(section, {'type': 'heading'}) 46 | ); 47 | 48 | var body = this.text( 49 | _.omit(section, {'type': 'heading'}) 50 | ); 51 | 52 | // Add to lunr index 53 | this.idx.add({ 54 | url: url, 55 | title: title, 56 | body: body, 57 | }); 58 | }; 59 | 60 | Indexer.prototype.add = function(lexedPage, url) { 61 | var sections = lexedPage; 62 | 63 | _.map(sections, _.partial(this.addSection, url)); 64 | }; 65 | 66 | Indexer.prototype.dump = function() { 67 | return JSON.stringify(this.idx); 68 | }; 69 | 70 | // Exports 71 | module.exports = Indexer; 72 | -------------------------------------------------------------------------------- /theme/javascript/core/sidebar.js: -------------------------------------------------------------------------------- 1 | define([ 2 | "lodash", 3 | "utils/storage", 4 | "utils/platform", 5 | "core/state" 6 | ], function(_, storage, platform, state) { 7 | var $summary = state.$book.find(".book-summary"); 8 | 9 | // Toggle sidebar with or withour animation 10 | var toggleSidebar = function(_state, animation) { 11 | if (state != null && isOpen() == _state) return; 12 | if (animation == null) animation = true; 13 | 14 | state.$book.toggleClass("without-animation", !animation); 15 | state.$book.toggleClass("with-summary", _state); 16 | 17 | storage.set("sidebar", isOpen()); 18 | }; 19 | 20 | // Return true if sidebar is open 21 | var isOpen = function() { 22 | return state.$book.hasClass("with-summary"); 23 | }; 24 | 25 | // Prepare sidebar: state and toggle button 26 | var init = function() { 27 | // Toggle summary 28 | $(document).on("click", ".book-header .toggle-summary", function(e) { 29 | e.preventDefault(); 30 | toggleSidebar(); 31 | }); 32 | 33 | // Init last state if not mobile 34 | if (!platform.isMobile) { 35 | toggleSidebar(storage.get("sidebar", true), false); 36 | } 37 | }; 38 | 39 | // Filter summary with a list of path 40 | var filterSummary = function(paths) { 41 | $summary.find("li").each(function() { 42 | var path = $(this).data("path"); 43 | var st = paths == null || _.contains(paths, path); 44 | 45 | $(this).toggle(st); 46 | if (st) $(this).parents("li").show(); 47 | }); 48 | }; 49 | 50 | return { 51 | $el: $summary, 52 | init: init, 53 | toggle: toggleSidebar, 54 | filter: filterSummary 55 | } 56 | }); -------------------------------------------------------------------------------- /theme/stylesheets/page/highlight.less: -------------------------------------------------------------------------------- 1 | /* http://jmblog.github.io/color-themes-for-highlightjs */ 2 | 3 | /* Tomorrow Comment */ 4 | .hljs-comment, 5 | .hljs-title { 6 | color: #8e908c; 7 | } 8 | 9 | /* Tomorrow Red */ 10 | .hljs-variable, 11 | .hljs-attribute, 12 | .hljs-tag, 13 | .hljs-regexp, 14 | .ruby .hljs-constant, 15 | .xml .hljs-tag .hljs-title, 16 | .xml .hljs-pi, 17 | .xml .hljs-doctype, 18 | .html .hljs-doctype, 19 | .css .hljs-id, 20 | .css .hljs-class, 21 | .css .hljs-pseudo { 22 | color: #c82829; 23 | } 24 | 25 | /* Tomorrow Orange */ 26 | .hljs-number, 27 | .hljs-preprocessor, 28 | .hljs-pragma, 29 | .hljs-built_in, 30 | .hljs-literal, 31 | .hljs-params, 32 | .hljs-constant { 33 | color: #f5871f; 34 | } 35 | 36 | /* Tomorrow Yellow */ 37 | .ruby .hljs-class .hljs-title, 38 | .css .hljs-rules .hljs-attribute { 39 | color: #eab700; 40 | } 41 | 42 | /* Tomorrow Green */ 43 | .hljs-string, 44 | .hljs-value, 45 | .hljs-inheritance, 46 | .hljs-header, 47 | .ruby .hljs-symbol, 48 | .xml .hljs-cdata { 49 | color: #718c00; 50 | } 51 | 52 | /* Tomorrow Aqua */ 53 | .css .hljs-hexcolor { 54 | color: #3e999f; 55 | } 56 | 57 | /* Tomorrow Blue */ 58 | .hljs-function, 59 | .python .hljs-decorator, 60 | .python .hljs-title, 61 | .ruby .hljs-function .hljs-title, 62 | .ruby .hljs-title .hljs-keyword, 63 | .perl .hljs-sub, 64 | .javascript .hljs-title, 65 | .coffeescript .hljs-title { 66 | color: #4271ae; 67 | } 68 | 69 | /* Tomorrow Purple */ 70 | .hljs-keyword, 71 | .javascript .hljs-function { 72 | color: #8959a8; 73 | } 74 | 75 | .hljs { 76 | display: block; 77 | background: white; 78 | color: #4d4d4c; 79 | padding: 0.5em; 80 | } 81 | 82 | .coffeescript .javascript, 83 | .javascript .xml, 84 | .tex .hljs-formula, 85 | .xml .javascript, 86 | .xml .vbscript, 87 | .xml .css, 88 | .xml .hljs-cdata { 89 | opacity: 0.5; 90 | } 91 | -------------------------------------------------------------------------------- /theme/javascript/core/exercise.js: -------------------------------------------------------------------------------- 1 | define([ 2 | "jQuery", 3 | "utils/execute", 4 | "core/events", 5 | "core/state" 6 | ], function($, execute, events, state){ 7 | // Bind an exercise 8 | var prepareExercise = function($exercise) { 9 | var codeSolution = $exercise.find(".code-solution").text(); 10 | var codeValidation = $exercise.find(".code-validation").text(); 11 | var codeContext = $exercise.find(".code-context").text(); 12 | 13 | var editor = ace.edit($exercise.find(".editor").get(0)); 14 | editor.setTheme("ace/theme/tomorrow"); 15 | editor.getSession().setUseWorker(false); 16 | editor.getSession().setMode("ace/mode/javascript"); 17 | 18 | // Submit: test code 19 | $exercise.find(".action-submit").click(function(e) { 20 | e.preventDefault(); 21 | 22 | events.trigger("exercise.submit", {type: "code"}); 23 | 24 | execute("javascript", editor.getValue(), codeValidation, codeContext, function(err, result) { 25 | $exercise.toggleClass("return-error", err != null); 26 | $exercise.toggleClass("return-success", err == null); 27 | if (err) $exercise.find(".alert-danger").text(err.message || err); 28 | }); 29 | }); 30 | 31 | // Set solution 32 | $exercise.find(".action-solution").click(function(e) { 33 | e.preventDefault(); 34 | 35 | editor.setValue(codeSolution); 36 | editor.gotoLine(0); 37 | }); 38 | }; 39 | 40 | // Prepare all exercise 41 | var init = function() { 42 | state.$book.find("section.exercise").each(function() { 43 | prepareExercise($(this)); 44 | }); 45 | }; 46 | 47 | return { 48 | init: init, 49 | prepare: prepareExercise 50 | }; 51 | }); -------------------------------------------------------------------------------- /theme/stylesheets/book/highlight/white.less: -------------------------------------------------------------------------------- 1 | /* http://jmblog.github.com/color-themes-for-google-code-highlightjs */ 2 | 3 | /* Tomorrow Comment */ 4 | .hljs-comment, 5 | .hljs-title { 6 | color: #8e908c; 7 | } 8 | 9 | /* Tomorrow Red */ 10 | .hljs-variable, 11 | .hljs-attribute, 12 | .hljs-tag, 13 | .hljs-regexp, 14 | .ruby .hljs-constant, 15 | .xml .hljs-tag .hljs-title, 16 | .xml .hljs-pi, 17 | .xml .hljs-doctype, 18 | .html .hljs-doctype, 19 | .css .hljs-id, 20 | .css .hljs-class, 21 | .css .hljs-pseudo { 22 | color: #c82829; 23 | } 24 | 25 | /* Tomorrow Orange */ 26 | .hljs-number, 27 | .hljs-preprocessor, 28 | .hljs-pragma, 29 | .hljs-built_in, 30 | .hljs-literal, 31 | .hljs-params, 32 | .hljs-constant { 33 | color: #f5871f; 34 | } 35 | 36 | /* Tomorrow Yellow */ 37 | .ruby .hljs-class .hljs-title, 38 | .css .hljs-rules .hljs-attribute { 39 | color: #eab700; 40 | } 41 | 42 | /* Tomorrow Green */ 43 | .hljs-string, 44 | .hljs-value, 45 | .hljs-inheritance, 46 | .hljs-header, 47 | .ruby .hljs-symbol, 48 | .xml .hljs-cdata { 49 | color: #718c00; 50 | } 51 | 52 | /* Tomorrow Aqua */ 53 | .css .hljs-hexcolor { 54 | color: #3e999f; 55 | } 56 | 57 | /* Tomorrow Blue */ 58 | .hljs-function, 59 | .python .hljs-decorator, 60 | .python .hljs-title, 61 | .ruby .hljs-function .hljs-title, 62 | .ruby .hljs-title .hljs-keyword, 63 | .perl .hljs-sub, 64 | .javascript .hljs-title, 65 | .coffeescript .hljs-title { 66 | color: #4271ae; 67 | } 68 | 69 | /* Tomorrow Purple */ 70 | .hljs-keyword, 71 | .javascript .hljs-function { 72 | color: #8959a8; 73 | } 74 | 75 | .hljs { 76 | display: block; 77 | background: white; 78 | color: #4d4d4c; 79 | padding: 0.5em; 80 | } 81 | 82 | .coffeescript .javascript, 83 | .javascript .xml, 84 | .tex .hljs-formula, 85 | .xml .javascript, 86 | .xml .vbscript, 87 | .xml .css, 88 | .xml .hljs-cdata { 89 | opacity: 0.5; 90 | } -------------------------------------------------------------------------------- /test/summary.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var path = require('path'); 3 | var assert = require('assert'); 4 | 5 | var summary = require('../').parse.summary; 6 | 7 | 8 | var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/SUMMARY.md'), 'utf8'); 9 | var LEXED = summary(CONTENT); 10 | 11 | 12 | describe('Summary parsing', function () { 13 | 14 | it('should detect chapters', function() { 15 | assert.equal(LEXED.chapters.length, 5); 16 | }); 17 | 18 | it('should support articles', function() { 19 | assert.equal(LEXED.chapters[0].articles.length, 2); 20 | assert.equal(LEXED.chapters[1].articles.length, 0); 21 | assert.equal(LEXED.chapters[2].articles.length, 0); 22 | }); 23 | 24 | it('should detect paths and titles', function() { 25 | assert(LEXED.chapters[0].path); 26 | assert(LEXED.chapters[1].path); 27 | assert(LEXED.chapters[2].path); 28 | assert(LEXED.chapters[3].path); 29 | assert.equal(LEXED.chapters[4].path, null); 30 | 31 | assert(LEXED.chapters[0].title); 32 | assert(LEXED.chapters[1].title); 33 | assert(LEXED.chapters[2].title); 34 | assert(LEXED.chapters[3].title); 35 | assert(LEXED.chapters[4].title); 36 | }); 37 | 38 | it('should normalize paths from .md to .html', function() { 39 | assert.equal(LEXED.chapters[0].path,'chapter-1/README.md'); 40 | assert.equal(LEXED.chapters[1].path,'chapter-2/README.md'); 41 | assert.equal(LEXED.chapters[2].path,'chapter-3/README.md'); 42 | }); 43 | 44 | it('should detect levels correctly', function() { 45 | var c = LEXED.chapters; 46 | 47 | assert.equal(c[0].level, '1'); 48 | assert.equal(c[1].level, '2'); 49 | assert.equal(c[2].level, '3'); 50 | 51 | assert.equal(c[0].articles[0].level, '1.1'); 52 | assert.equal(c[0].articles[1].level, '1.2'); 53 | }); 54 | }); 55 | -------------------------------------------------------------------------------- /lib/parse/navigation.js: -------------------------------------------------------------------------------- 1 | var _ = require('lodash'); 2 | 3 | // Cleans up an article/chapter object 4 | // remove 'articles' attributes 5 | function clean(obj) { 6 | return obj && _.omit(obj, ['articles']); 7 | } 8 | 9 | function flattenChapters(chapters) { 10 | return _.reduce(chapters, function(accu, chapter) { 11 | return accu.concat([clean(chapter)].concat(chapter.articles)); 12 | }, []); 13 | } 14 | 15 | // Returns from a summary a map of 16 | /* 17 | { 18 | "file/path.md": { 19 | prev: ..., 20 | next: ..., 21 | }, 22 | ... 23 | } 24 | */ 25 | function navigation(summary, files) { 26 | // Support single files as well as list 27 | files = _.isArray(files) ? files : (_.isString(files) ? [files] : null); 28 | 29 | // Special README nav 30 | var README_NAV = { 31 | path: 'README.md', 32 | title: 'Introduction', 33 | level: '0', 34 | }; 35 | 36 | // List of all navNodes 37 | var navNodes = [README_NAV].concat(flattenChapters(summary.chapters)); 38 | var prevNodes = [null].concat(navNodes.slice(0, -1)); 39 | var nextNodes = navNodes.slice(1).concat([null]); 40 | 41 | // Mapping of prev/next for a give path 42 | var mapping = _.chain(_.zip(navNodes, prevNodes, nextNodes)) 43 | .map(function(nodes) { 44 | var current = nodes[0], prev = nodes[1], next = nodes[2]; 45 | 46 | // Skip if no path 47 | if(!current.path) return null; 48 | 49 | return [current.path, { 50 | title: current.title, 51 | prev: prev, 52 | next: next, 53 | level: current.level, 54 | }]; 55 | }) 56 | .filter() 57 | .object() 58 | .value(); 59 | 60 | // Filter for only files we want 61 | if(files) { 62 | return _.pick(mapping, files); 63 | } 64 | 65 | return mapping; 66 | } 67 | 68 | 69 | // Exports 70 | module.exports = navigation; 71 | -------------------------------------------------------------------------------- /theme/stylesheets/book/highlight/night.less: -------------------------------------------------------------------------------- 1 | /* Tomorrow Night Bright Theme */ 2 | /* Original theme - https://github.com/chriskempson/tomorrow-theme */ 3 | /* http://jmblog.github.com/color-themes-for-google-code-highlightjs */ 4 | 5 | /* Tomorrow Comment */ 6 | .hljs-comment, 7 | .hljs-title { 8 | color: #969896; 9 | } 10 | 11 | /* Tomorrow Red */ 12 | .hljs-variable, 13 | .hljs-attribute, 14 | .hljs-tag, 15 | .hljs-regexp, 16 | .ruby .hljs-constant, 17 | .xml .hljs-tag .hljs-title, 18 | .xml .hljs-pi, 19 | .xml .hljs-doctype, 20 | .html .hljs-doctype, 21 | .css .hljs-id, 22 | .css .hljs-class, 23 | .css .hljs-pseudo { 24 | color: #d54e53; 25 | } 26 | 27 | /* Tomorrow Orange */ 28 | .hljs-number, 29 | .hljs-preprocessor, 30 | .hljs-pragma, 31 | .hljs-built_in, 32 | .hljs-literal, 33 | .hljs-params, 34 | .hljs-constant { 35 | color: #e78c45; 36 | } 37 | 38 | /* Tomorrow Yellow */ 39 | .ruby .hljs-class .hljs-title, 40 | .css .hljs-rules .hljs-attribute { 41 | color: #e7c547; 42 | } 43 | 44 | /* Tomorrow Green */ 45 | .hljs-string, 46 | .hljs-value, 47 | .hljs-inheritance, 48 | .hljs-header, 49 | .ruby .hljs-symbol, 50 | .xml .hljs-cdata { 51 | color: #b9ca4a; 52 | } 53 | 54 | /* Tomorrow Aqua */ 55 | .css .hljs-hexcolor { 56 | color: #70c0b1; 57 | } 58 | 59 | /* Tomorrow Blue */ 60 | .hljs-function, 61 | .python .hljs-decorator, 62 | .python .hljs-title, 63 | .ruby .hljs-function .hljs-title, 64 | .ruby .hljs-title .hljs-keyword, 65 | .perl .hljs-sub, 66 | .javascript .hljs-title, 67 | .coffeescript .hljs-title { 68 | color: #7aa6da; 69 | } 70 | 71 | /* Tomorrow Purple */ 72 | .hljs-keyword, 73 | .javascript .hljs-function { 74 | color: #c397d8; 75 | } 76 | 77 | .hljs { 78 | display: block; 79 | background: black; 80 | color: #eaeaea; 81 | padding: 0.5em; 82 | } 83 | 84 | .coffeescript .javascript, 85 | .javascript .xml, 86 | .tex .hljs-formula, 87 | .xml .javascript, 88 | .xml .vbscript, 89 | .xml .css, 90 | .xml .hljs-cdata { 91 | opacity: 0.5; 92 | } -------------------------------------------------------------------------------- /lib/generate/init.js: -------------------------------------------------------------------------------- 1 | var Q = require('q'); 2 | var _ = require('lodash'); 3 | 4 | var path = require('path'); 5 | 6 | var fs = require('./fs'); 7 | var parse = require('../parse'); 8 | 9 | 10 | // Extract paths out of a summary 11 | function paths(summary) { 12 | return _.reduce(summary.chapters, function(accu, chapter) { 13 | return accu.concat( 14 | _.filter([chapter.path].concat(_.pluck(chapter.articles, 'path'))) 15 | ); 16 | }, []); 17 | } 18 | 19 | // Get the parent folders out of a group of files 20 | function folders(files) { 21 | return _.chain(files) 22 | .map(function(file) { 23 | return path.dirname(file); 24 | }) 25 | .uniq() 26 | .value(); 27 | } 28 | 29 | function initDir(dir) { 30 | return fs.readFile(path.join(dir, 'SUMMARY.md'), 'utf8') 31 | .then(function(src) { 32 | // Parse summary 33 | return parse.summary(src); 34 | }) 35 | .then(function(summary) { 36 | // Extract paths from summary 37 | return paths(summary); 38 | }) 39 | .then(function(paths) { 40 | // Convert to absolute paths 41 | return _.map(paths, function(file) { 42 | return path.resolve(file); 43 | }); 44 | }) 45 | .then(function(files) { 46 | // Create folders 47 | return Q.all(_.map(folders(files), function(folder) { 48 | return fs.mkdirp(folder); 49 | })) 50 | .then(_.constant(files)); 51 | }) 52 | .then(function(files) { 53 | // Create files that don't exist 54 | return Q.all(_.map(files, function(file) { 55 | return fs.exists(file) 56 | .then(function(exists) { 57 | if(exists) return; 58 | return fs.writeFile(file, ''); 59 | }); 60 | })); 61 | }) 62 | .fail(function(err) { 63 | console.error(err.stack); 64 | }); 65 | } 66 | 67 | 68 | // Exports 69 | module.exports = initDir; 70 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gitbook", 3 | "version": "0.4.2", 4 | "homepage": "http://www.gitbook.io/", 5 | "description": "Library and cmd utility to generate GitBooks", 6 | "main": "lib/index.js", 7 | "dependencies": { 8 | "q": "1.0.1", 9 | "lodash": "2.4.1", 10 | "marked": "0.3.2", 11 | "marked-text-renderer": "0.0.1", 12 | "lunr": "0.5.2", 13 | "swig": "1.3.2", 14 | "send": "0.2.0", 15 | "fstream-ignore": "0.0.7", 16 | "commander": "2.2.0", 17 | "fs-extra": "0.8.1", 18 | "highlight.js": "8.0.0", 19 | "tmp": "0.0.23", 20 | "semver": "2.2.1", 21 | "gaze": "~0.5.1", 22 | "resolve": "0.6.3", 23 | 24 | "gitbook-plugin": "0.0.2", 25 | "gitbook-plugin-mixpanel": "0.0.2", 26 | "gitbook-plugin-mathjax": "0.0.3" 27 | }, 28 | "devDependencies": { 29 | "mocha": "1.18.2", 30 | "grunt": "~0.4.2", 31 | "grunt-cli": "0.1.11", 32 | "grunt-contrib-less": "~0.5.0", 33 | "grunt-contrib-requirejs": "0.4.1", 34 | "grunt-bower-install-simple": "0.9.2" 35 | }, 36 | "scripts": { 37 | "test": "export TESTING=true; mocha --reporter list" 38 | }, 39 | "bin": { 40 | "gitbook": "./bin/gitbook.js" 41 | }, 42 | "repository": { 43 | "type": "git", 44 | "url": "https://github.com/GitbookIO/gitbook.git" 45 | }, 46 | "keywords": [ 47 | "git", 48 | "book", 49 | "gitbook" 50 | ], 51 | "author": "FriendCode ", 52 | "license": "Apache 2", 53 | "bugs": { 54 | "url": "https://github.com/GitbookIO/gitbook/issues" 55 | }, 56 | "contributors": [ 57 | { 58 | "name": "Aaron O'Mullan", 59 | "email": "aaron.omullan@gmail.com" 60 | }, 61 | { 62 | "name": "Samy Pessé", 63 | "email": "samypesse@gmail.com" 64 | } 65 | ] 66 | } 67 | -------------------------------------------------------------------------------- /lib/generate/manifest.js: -------------------------------------------------------------------------------- 1 | var _ = require('lodash'); 2 | var path = require('path'); 3 | var Q = require('q'); 4 | 5 | var fs = require("./fs"); 6 | 7 | var extsToIgnore = [".gz"] 8 | 9 | var Manifest = function() { 10 | this.revision = 0; 11 | this.clear(Date.now()); 12 | }; 13 | 14 | // Regenerate manifest 15 | Manifest.prototype.clear = function(revision) { 16 | if (revision) this.revision = revision; 17 | this.sections = { 18 | 'CACHE': {}, 19 | 'NETWORK': {}, 20 | 'FALLBACK': {} 21 | }; 22 | return Q(this); 23 | }; 24 | 25 | // Add a resource 26 | Manifest.prototype.add = function(category, resource, value) { 27 | if (_.isArray(resource)) { 28 | _.each(resource, function(subres) { 29 | this.add(category, subres, value); 30 | }, this); 31 | return; 32 | } 33 | this.sections[category][resource] = value; 34 | }; 35 | 36 | // Add a directory in cache 37 | Manifest.prototype.addFolder = function(folder, root, except) { 38 | var that = this; 39 | root = root || "/"; 40 | 41 | return fs.list(folder) 42 | .then(function(files) { 43 | _.each( 44 | // Ignore diretcories 45 | _.filter(files, function(file) { 46 | return file.substr(-1) != "/" && !_.contains(except, path.join(root, file)) && !_.contains(extsToIgnore, path.extname(file)); 47 | }), 48 | function(file) { 49 | that.add("CACHE", path.join(root, file)); 50 | } 51 | ); 52 | }) 53 | }; 54 | 55 | // Get manifest content 56 | Manifest.prototype.dump = function() { 57 | var lines = [ 58 | "CACHE MANIFEST", 59 | "# Revision "+this.revision 60 | ]; 61 | 62 | _.each(this.sections, function(content, section) { 63 | if (_.size(content) == 0) return; 64 | lines.push(""); 65 | lines.push(section+":"); 66 | lines = lines.concat(_.keys(content)); 67 | }, this); 68 | 69 | return Q(lines.join("\n")); 70 | }; 71 | 72 | module.exports = Manifest; 73 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/bootstrap/print.less: -------------------------------------------------------------------------------- 1 | // 2 | // Basic print styles 3 | // -------------------------------------------------- 4 | // Source: https://github.com/h5bp/html5-boilerplate/blob/master/css/main.css 5 | 6 | @media print { 7 | 8 | * { 9 | text-shadow: none !important; 10 | color: #000 !important; // Black prints faster: h5bp.com/s 11 | background: transparent !important; 12 | box-shadow: none !important; 13 | } 14 | 15 | a, 16 | a:visited { 17 | text-decoration: underline; 18 | } 19 | 20 | a[href]:after { 21 | content: " (" attr(href) ")"; 22 | } 23 | 24 | abbr[title]:after { 25 | content: " (" attr(title) ")"; 26 | } 27 | 28 | // Don't show links for images, or javascript/internal links 29 | .ir a:after, 30 | a[href^="javascript:"]:after, 31 | a[href^="#"]:after { 32 | content: ""; 33 | } 34 | 35 | pre, 36 | blockquote { 37 | border: 1px solid #999; 38 | page-break-inside: avoid; 39 | } 40 | 41 | thead { 42 | display: table-header-group; // h5bp.com/t 43 | } 44 | 45 | tr, 46 | img { 47 | page-break-inside: avoid; 48 | } 49 | 50 | img { 51 | max-width: 100% !important; 52 | } 53 | 54 | @page { 55 | margin: 2cm .5cm; 56 | } 57 | 58 | p, 59 | h2, 60 | h3 { 61 | orphans: 3; 62 | widows: 3; 63 | } 64 | 65 | h2, 66 | h3 { 67 | page-break-after: avoid; 68 | } 69 | 70 | // Bootstrap components 71 | .navbar { 72 | display: none; 73 | } 74 | .table { 75 | td, 76 | th { 77 | background-color: #fff !important; 78 | } 79 | } 80 | .btn, 81 | .dropup > .btn { 82 | > .caret { 83 | border-top-color: #000 !important; 84 | } 85 | } 86 | .label { 87 | border: 1px solid #000; 88 | } 89 | 90 | .table { 91 | border-collapse: collapse !important; 92 | } 93 | .table-bordered { 94 | th, 95 | td { 96 | border: 1px solid #ddd !important; 97 | } 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /theme/javascript/core/progress.js: -------------------------------------------------------------------------------- 1 | define([ 2 | "lodash", 3 | "jQuery", 4 | "utils/storage", 5 | "core/state" 6 | ], function(_, $, storage, state) { 7 | // Get current level 8 | var getCurrentLevel = function() { 9 | return state.level; 10 | }; 11 | 12 | // Return all levels 13 | var getLevels = function () { 14 | var levels = $(".book-summary li[data-level]"); 15 | 16 | return _.map(levels, function(level) { 17 | return $(level).data("level").toString(); 18 | }); 19 | }; 20 | 21 | // Return a map chapter -> number (timestamp) 22 | var getProgress = function () { 23 | // Current level 24 | var progress = storage.get("progress", {}); 25 | 26 | // Levels 27 | var levels = getLevels(); 28 | 29 | _.each(levels, function(level) { 30 | progress[level] = progress[level] || 0; 31 | }); 32 | 33 | return progress; 34 | }; 35 | 36 | // Change value of progress for a level 37 | var markProgress = function (level, state) { 38 | var progress = getProgress(); 39 | 40 | if (state == null) { 41 | state = true; 42 | } 43 | 44 | progress[level] = state 45 | ? Date.now() 46 | : 0; 47 | 48 | storage.set("progress", progress); 49 | }; 50 | 51 | // Show progress 52 | var showProgress = function () { 53 | var progress = getProgress(); 54 | var $summary = $(".book-summary"); 55 | 56 | _.each(progress, function (value, level) { 57 | $summary.find("li[data-level='"+level+"']").toggleClass("done", value > 0); 58 | }); 59 | 60 | // Mark current progress if we have not already 61 | if (!progress[getCurrentLevel()]) { 62 | markProgress(getCurrentLevel(), true); 63 | } 64 | }; 65 | 66 | return { 67 | 'current': getCurrentLevel, 68 | 'levels': getLevels, 69 | 'get': getProgress, 70 | 'mark': markProgress, 71 | 'show': showProgress 72 | }; 73 | }); -------------------------------------------------------------------------------- /theme/javascript/core/quiz.js: -------------------------------------------------------------------------------- 1 | define([ 2 | "jQuery", 3 | "utils/execute", 4 | "core/events", 5 | "core/state" 6 | ], function($, execute, events, state){ 7 | // Bind an exercise 8 | var prepareQuiz = function($quiz) { 9 | 10 | $quiz.find(".quiz-answers input").click(function(e) { 11 | e.preventDefault(); 12 | }); 13 | 14 | // Submit: test code 15 | $quiz.find(".action-submit").click(function(e) { 16 | e.preventDefault(); 17 | events.trigger("exercise.submit", {type: "quiz"}); 18 | $quiz.find("tr.alert-danger,li.alert-danger").removeClass("alert-danger"); 19 | $quiz.find(".alert-success,.alert-danger").addClass("hidden"); 20 | 21 | $quiz.find(".question").each(function(q) { 22 | var result = true; 23 | 24 | var $questions = $(this).find(".question-content").find("input[type=radio], input[type=checkbox]"); 25 | var $answers = $(this).find(".question-answers").find("input[type=radio], input[type=checkbox]"); 26 | 27 | $questions.each(function(i) { 28 | var correct = $(this).is(":checked") === $answers.slice(i).first().is(":checked"); 29 | result = result && correct; 30 | if (!correct) { 31 | $(this).closest("tr, li").addClass("alert-danger"); 32 | } 33 | }); 34 | $(this).find(result ? "div.alert-success" : "div.alert-danger").toggleClass("hidden"); 35 | }); 36 | 37 | }); 38 | 39 | $quiz.find(".action-solution").click(function(e) { 40 | e.preventDefault(); 41 | $quiz.find(".question-content, .question-answers").toggleClass("hidden"); 42 | }); 43 | }; 44 | 45 | // Prepare all exercise 46 | var init = function() { 47 | state.$book.find("section.quiz").each(function() { 48 | prepareQuiz($(this)); 49 | }); 50 | }; 51 | 52 | return { 53 | init: init, 54 | prepare: prepareQuiz 55 | }; 56 | }); -------------------------------------------------------------------------------- /theme/templates/includes/book/header.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | {% if options.links.home !== false and (options.links.home != null or githubId) %} 4 | 5 | {% endif %} 6 | 7 | 8 | 9 | 10 | 11 | {% include "./font-settings.html" %} 12 | 13 | 14 | 15 | {% if options.links.sharing.google !== false %} 16 | 17 | {% endif %} 18 | {% if options.links.sharing.facebook !== false %} 19 | 20 | {% endif %} 21 | {% if options.links.sharing.twitter !== false %} 22 | 23 | {% endif %} 24 | 25 | {% if githubId %} 26 | 27 | 28 | {% endif %} 29 | 30 | 31 |

32 | 33 | {{ title }} 34 |

35 |
36 | -------------------------------------------------------------------------------- /theme/stylesheets/book/highlight/sepia.less: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Orginal Style from ethanschoonover.com/solarized (c) Jeremy Hull 4 | 5 | */ 6 | 7 | .hljs { 8 | display: block; 9 | padding: 0.5em; 10 | background: #fdf6e3; 11 | color: #657b83; 12 | } 13 | 14 | .hljs-comment, 15 | .hljs-template_comment, 16 | .diff .hljs-header, 17 | .hljs-doctype, 18 | .hljs-pi, 19 | .lisp .hljs-string, 20 | .hljs-javadoc { 21 | color: #93a1a1; 22 | } 23 | 24 | /* Solarized Green */ 25 | .hljs-keyword, 26 | .hljs-winutils, 27 | .method, 28 | .hljs-addition, 29 | .css .hljs-tag, 30 | .hljs-request, 31 | .hljs-status, 32 | .nginx .hljs-title { 33 | color: #859900; 34 | } 35 | 36 | /* Solarized Cyan */ 37 | .hljs-number, 38 | .hljs-command, 39 | .hljs-string, 40 | .hljs-tag .hljs-value, 41 | .hljs-rules .hljs-value, 42 | .hljs-phpdoc, 43 | .tex .hljs-formula, 44 | .hljs-regexp, 45 | .hljs-hexcolor, 46 | .hljs-link_url { 47 | color: #2aa198; 48 | } 49 | 50 | /* Solarized Blue */ 51 | .hljs-title, 52 | .hljs-localvars, 53 | .hljs-chunk, 54 | .hljs-decorator, 55 | .hljs-built_in, 56 | .hljs-identifier, 57 | .vhdl .hljs-literal, 58 | .hljs-id, 59 | .css .hljs-function { 60 | color: #268bd2; 61 | } 62 | 63 | /* Solarized Yellow */ 64 | .hljs-attribute, 65 | .hljs-variable, 66 | .lisp .hljs-body, 67 | .smalltalk .hljs-number, 68 | .hljs-constant, 69 | .hljs-class .hljs-title, 70 | .hljs-parent, 71 | .haskell .hljs-type, 72 | .hljs-link_reference { 73 | color: #b58900; 74 | } 75 | 76 | /* Solarized Orange */ 77 | .hljs-preprocessor, 78 | .hljs-preprocessor .hljs-keyword, 79 | .hljs-pragma, 80 | .hljs-shebang, 81 | .hljs-symbol, 82 | .hljs-symbol .hljs-string, 83 | .diff .hljs-change, 84 | .hljs-special, 85 | .hljs-attr_selector, 86 | .hljs-subst, 87 | .hljs-cdata, 88 | .clojure .hljs-title, 89 | .css .hljs-pseudo, 90 | .hljs-header { 91 | color: #cb4b16; 92 | } 93 | 94 | /* Solarized Red */ 95 | .hljs-deletion, 96 | .hljs-important { 97 | color: #dc322f; 98 | } 99 | 100 | /* Solarized Violet */ 101 | .hljs-link_label { 102 | color: #6c71c4; 103 | } 104 | 105 | .tex .hljs-formula { 106 | background: #eee8d5; 107 | } -------------------------------------------------------------------------------- /theme/stylesheets/vendors/bootstrap/pagination.less: -------------------------------------------------------------------------------- 1 | // 2 | // Pagination (multiple pages) 3 | // -------------------------------------------------- 4 | .pagination { 5 | display: inline-block; 6 | padding-left: 0; 7 | margin: @line-height-computed 0; 8 | border-radius: @border-radius-base; 9 | 10 | > li { 11 | display: inline; // Remove list-style and block-level defaults 12 | > a, 13 | > span { 14 | position: relative; 15 | float: left; // Collapse white-space 16 | padding: @padding-base-vertical @padding-base-horizontal; 17 | line-height: @line-height-base; 18 | text-decoration: none; 19 | background-color: @pagination-bg; 20 | border: 1px solid @pagination-border; 21 | margin-left: -1px; 22 | } 23 | &:first-child { 24 | > a, 25 | > span { 26 | margin-left: 0; 27 | .border-left-radius(@border-radius-base); 28 | } 29 | } 30 | &:last-child { 31 | > a, 32 | > span { 33 | .border-right-radius(@border-radius-base); 34 | } 35 | } 36 | } 37 | 38 | > li > a, 39 | > li > span { 40 | &:hover, 41 | &:focus { 42 | background-color: @pagination-hover-bg; 43 | } 44 | } 45 | 46 | > .active > a, 47 | > .active > span { 48 | &, 49 | &:hover, 50 | &:focus { 51 | z-index: 2; 52 | color: @pagination-active-color; 53 | background-color: @pagination-active-bg; 54 | border-color: @pagination-active-bg; 55 | cursor: default; 56 | } 57 | } 58 | 59 | > .disabled { 60 | > span, 61 | > a, 62 | > a:hover, 63 | > a:focus { 64 | color: @pagination-disabled-color; 65 | background-color: @pagination-bg; 66 | border-color: @pagination-border; 67 | cursor: not-allowed; 68 | } 69 | } 70 | } 71 | 72 | // Sizing 73 | // -------------------------------------------------- 74 | 75 | // Large 76 | .pagination-lg { 77 | .pagination-size(@padding-large-vertical; @padding-large-horizontal; @font-size-large; @border-radius-large); 78 | } 79 | 80 | // Small 81 | .pagination-sm { 82 | .pagination-size(@padding-small-vertical; @padding-small-horizontal; @font-size-small; @border-radius-small); 83 | } 84 | -------------------------------------------------------------------------------- /lib/generate/ebook/index.js: -------------------------------------------------------------------------------- 1 | var util = require("util"); 2 | var path = require("path"); 3 | var Q = require("q"); 4 | var _ = require("lodash"); 5 | var exec = require('child_process').exec; 6 | 7 | var fs = require("fs"); 8 | var parse = require("../../parse"); 9 | var BaseGenerator = require("../page"); 10 | 11 | /* 12 | * This generator inherits from the single page generator 13 | * and convert the page output to ebook 14 | */ 15 | var Generator = function() { 16 | BaseGenerator.apply(this, arguments); 17 | 18 | // Options for eBook generation 19 | this.options = _.defaults(this.options, { 20 | extension: "epub" 21 | }); 22 | 23 | if (!this.options.cover && fs.existsSync(path.join(this.options.input, "cover.png"))) { 24 | this.options.cover = path.join(this.options.input, "cover.png") 25 | } 26 | }; 27 | util.inherits(Generator, BaseGenerator); 28 | 29 | Generator.prototype.finish = function() { 30 | var that = this; 31 | 32 | return BaseGenerator.prototype.finish.apply(this) 33 | .then(function() { 34 | var d = Q.defer(); 35 | 36 | var _options = { 37 | "--cover": that.options.cover 38 | }; 39 | 40 | var command = [ 41 | "ebook-convert", 42 | path.join(that.options.output, "index.html"), 43 | path.join(that.options.output, "index."+that.options.extension), 44 | _.chain(_options) 45 | .map(function(value, key) { 46 | if (value == null) return null; 47 | return key+"="+value; 48 | }) 49 | .compact() 50 | .value() 51 | .join(" ") 52 | ].join(" "); 53 | 54 | exec(command, function (error, stdout, stderr) { 55 | if (error) { 56 | if (error.code == 127) { 57 | error.message = "Need to install ebook-convert from Calibre"; 58 | } else { 59 | error.message = error.message + " "+stdout; 60 | } 61 | return d.reject(error); 62 | } 63 | d.resolve(); 64 | }); 65 | 66 | return d.promise; 67 | }); 68 | }; 69 | 70 | module.exports = Generator; 71 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/bootstrap/list-group.less: -------------------------------------------------------------------------------- 1 | // 2 | // List groups 3 | // -------------------------------------------------- 4 | 5 | // Base class 6 | // 7 | // Easily usable on
    ,
      , or
      . 8 | .list-group { 9 | // No need to set list-style: none; since .list-group-item is block level 10 | margin-bottom: 20px; 11 | padding-left: 0; // reset padding because ul and ol 12 | } 13 | 14 | // Individual list items 15 | // ------------------------- 16 | 17 | .list-group-item { 18 | position: relative; 19 | display: block; 20 | padding: 10px 15px; 21 | // Place the border on the list items and negative margin up for better styling 22 | margin-bottom: -1px; 23 | background-color: @list-group-bg; 24 | border: 1px solid @list-group-border; 25 | 26 | // Round the first and last items 27 | &:first-child { 28 | .border-top-radius(@list-group-border-radius); 29 | } 30 | &:last-child { 31 | margin-bottom: 0; 32 | .border-bottom-radius(@list-group-border-radius); 33 | } 34 | 35 | // Align badges within list items 36 | > .badge { 37 | float: right; 38 | } 39 | > .badge + .badge { 40 | margin-right: 5px; 41 | } 42 | 43 | // Linked list items 44 | a& { 45 | color: @list-group-link-color; 46 | 47 | .list-group-item-heading { 48 | color: @list-group-link-heading-color; 49 | } 50 | 51 | // Hover state 52 | &:hover, 53 | &:focus { 54 | text-decoration: none; 55 | background-color: @list-group-hover-bg; 56 | } 57 | } 58 | 59 | // Active class on item itself, not parent 60 | &.active, 61 | &.active:hover, 62 | &.active:focus { 63 | z-index: 2; // Place active items above their siblings for proper border styling 64 | color: @list-group-active-color; 65 | background-color: @list-group-active-bg; 66 | border-color: @list-group-active-border; 67 | 68 | // Force color to inherit for custom content 69 | .list-group-item-heading { 70 | color: inherit; 71 | } 72 | .list-group-item-text { 73 | color: lighten(@list-group-active-bg, 40%); 74 | } 75 | } 76 | } 77 | 78 | // Custom content options 79 | // ------------------------- 80 | 81 | .list-group-item-heading { 82 | margin-top: 0; 83 | margin-bottom: 5px; 84 | } 85 | .list-group-item-text { 86 | margin-bottom: 0; 87 | line-height: 1.3; 88 | } 89 | -------------------------------------------------------------------------------- /theme/templates/layout.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {% block head %} 5 | 6 | {% block title %} | {{ title }}{% endblock %} 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | {% if progress.current.next and progress.current.next.path %} 16 | 17 | {% endif %} 18 | {% if progress.current.prev and progress.current.prev.path %} 19 | 20 | {% endif %} 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | {% endblock %} 36 | 37 | 38 | {% block style %} 39 | 40 | {% endblock %} 41 | {% block content %}{% endblock %} 42 | {% block javascript %} 43 | 44 | 45 | 46 | 47 | {% endblock %} 48 | 49 | 50 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/bootstrap/progress-bars.less: -------------------------------------------------------------------------------- 1 | // 2 | // Progress bars 3 | // -------------------------------------------------- 4 | 5 | 6 | // Bar animations 7 | // ------------------------- 8 | 9 | // Webkit 10 | @-webkit-keyframes progress-bar-stripes { 11 | from { background-position: 40px 0; } 12 | to { background-position: 0 0; } 13 | } 14 | 15 | // Firefox 16 | @-moz-keyframes progress-bar-stripes { 17 | from { background-position: 40px 0; } 18 | to { background-position: 0 0; } 19 | } 20 | 21 | // Opera 22 | @-o-keyframes progress-bar-stripes { 23 | from { background-position: 0 0; } 24 | to { background-position: 40px 0; } 25 | } 26 | 27 | // Spec and IE10+ 28 | @keyframes progress-bar-stripes { 29 | from { background-position: 40px 0; } 30 | to { background-position: 0 0; } 31 | } 32 | 33 | 34 | 35 | // Bar itself 36 | // ------------------------- 37 | 38 | // Outer container 39 | .progress { 40 | overflow: hidden; 41 | height: @line-height-computed; 42 | margin-bottom: @line-height-computed; 43 | background-color: @progress-bg; 44 | border-radius: @border-radius-base; 45 | .box-shadow(inset 0 1px 2px rgba(0,0,0,.1)); 46 | } 47 | 48 | // Bar of progress 49 | .progress-bar { 50 | float: left; 51 | width: 0%; 52 | height: 100%; 53 | font-size: @font-size-small; 54 | color: @progress-bar-color; 55 | text-align: center; 56 | background-color: @progress-bar-bg; 57 | .box-shadow(inset 0 -1px 0 rgba(0,0,0,.15)); 58 | .transition(width .6s ease); 59 | } 60 | 61 | // Striped bars 62 | .progress-striped .progress-bar { 63 | #gradient > .striped(@progress-bar-bg); 64 | background-size: 40px 40px; 65 | } 66 | 67 | // Call animation for the active one 68 | .progress.active .progress-bar { 69 | -webkit-animation: progress-bar-stripes 2s linear infinite; 70 | -moz-animation: progress-bar-stripes 2s linear infinite; 71 | -ms-animation: progress-bar-stripes 2s linear infinite; 72 | -o-animation: progress-bar-stripes 2s linear infinite; 73 | animation: progress-bar-stripes 2s linear infinite; 74 | } 75 | 76 | 77 | 78 | // Variations 79 | // ------------------------- 80 | 81 | .progress-bar-success { 82 | .progress-bar-variant(@progress-bar-success-bg); 83 | } 84 | 85 | .progress-bar-info { 86 | .progress-bar-variant(@progress-bar-info-bg); 87 | } 88 | 89 | .progress-bar-warning { 90 | .progress-bar-variant(@progress-bar-warning-bg); 91 | } 92 | 93 | .progress-bar-danger { 94 | .progress-bar-variant(@progress-bar-danger-bg); 95 | } 96 | -------------------------------------------------------------------------------- /lib/generate/page/index.js: -------------------------------------------------------------------------------- 1 | var _ = require("lodash"); 2 | var util = require("util"); 3 | var path = require("path"); 4 | var Q = require("q"); 5 | var swig = require('swig'); 6 | var hljs = require('highlight.js'); 7 | 8 | var fs = require("../fs"); 9 | var parse = require("../../parse"); 10 | var BaseGenerator = require("../site"); 11 | 12 | // Swig filter: highlight coloration 13 | swig.setFilter('code', function(code, lang) { 14 | try { 15 | return hljs.highlight(lang, code).value; 16 | } catch(e) { 17 | return hljs.highlightAuto(code).value; 18 | } 19 | }); 20 | 21 | 22 | /* 23 | * This generator will generate a simple index.html which can be converted as a PDF 24 | */ 25 | var Generator = function() { 26 | BaseGenerator.apply(this, arguments); 27 | 28 | // List of pages content 29 | this.pages = {}; 30 | }; 31 | util.inherits(Generator, BaseGenerator); 32 | 33 | // Load all templates 34 | Generator.prototype.loadTemplates = function() { 35 | this.template = swig.compileFile( 36 | this.plugins.template("page") || path.resolve(this.options.theme, 'templates/page.html') 37 | ); 38 | }; 39 | 40 | Generator.prototype.convertFile = function(content, input) { 41 | var that = this; 42 | var json = { 43 | path: input, 44 | progress: parse.progress(this.options.navigation, input) 45 | }; 46 | 47 | return Q() 48 | .then(function() { 49 | return parse.page(content, { 50 | repo: that.options.githubId, 51 | dir: path.dirname(input) || '/', 52 | outdir: './', 53 | singleFile: true 54 | }); 55 | }) 56 | .then(function(sections) { 57 | json.content = sections; 58 | }) 59 | .then(function() { 60 | that.pages[input] = json; 61 | }); 62 | }; 63 | 64 | Generator.prototype.finish = function() { 65 | var that = this; 66 | var basePath = "."; 67 | var output = path.join(this.options.output, "index.html"); 68 | 69 | return Q() 70 | // Generate html 71 | .then(function(pages) { 72 | return that._writeTemplate(that.template, { 73 | pages: that.pages, 74 | 75 | basePath: basePath, 76 | staticBase: path.join(basePath, "gitbook"), 77 | }, output); 78 | }) 79 | 80 | // Copy assets 81 | .then(function() { 82 | return fs.copy( 83 | path.join(that.options.theme, "assets"), 84 | path.join(that.options.output, "gitbook") 85 | ); 86 | }); 87 | }; 88 | 89 | module.exports = Generator; -------------------------------------------------------------------------------- /bin/server.js: -------------------------------------------------------------------------------- 1 | var Q = require('q'); 2 | var _ = require('lodash'); 3 | 4 | var events = require('events'); 5 | var http = require('http'); 6 | var send = require('send'); 7 | var util = require('util'); 8 | var url = require('url'); 9 | 10 | var Server = function() { 11 | this.running = null; 12 | this.dir = null; 13 | this.port = 0; 14 | this.sockets = []; 15 | }; 16 | util.inherits(Server, events.EventEmitter); 17 | 18 | // Return true if the server is running 19 | Server.prototype.isRunning = function() { 20 | return this.running != null; 21 | }; 22 | 23 | // Stop the server 24 | Server.prototype.stop = function() { 25 | var that = this; 26 | if (!this.isRunning()) return Q(); 27 | 28 | var d = Q.defer(); 29 | this.running.close(function(err) { 30 | that.running = null; 31 | that.emit("state", false); 32 | 33 | if (err) d.reject(err); 34 | else d.resolve(); 35 | }); 36 | 37 | for (var i = 0; i < this.sockets.length; i++) { 38 | this.sockets[i].destroy(); 39 | } 40 | 41 | return d.promise; 42 | }; 43 | 44 | Server.prototype.start = function(dir, port) { 45 | var that = this, pre = Q(); 46 | port = port || 8004; 47 | 48 | if (that.isRunning()) pre = this.stop(); 49 | return pre 50 | .then(function() { 51 | var d = Q.defer(); 52 | 53 | that.running = http.createServer(function(req, res){ 54 | // Render error 55 | function error(err) { 56 | res.statusCode = err.status || 500; 57 | res.end(err.message); 58 | } 59 | 60 | // Redirect to directory's index.html 61 | function redirect() { 62 | res.statusCode = 301; 63 | res.setHeader('Location', req.url + '/'); 64 | res.end('Redirecting to ' + req.url + '/'); 65 | } 66 | 67 | // Send file 68 | send(req, url.parse(req.url).pathname) 69 | .root(dir) 70 | .on('error', error) 71 | .on('directory', redirect) 72 | .pipe(res); 73 | }); 74 | 75 | that.running.on('connection', function (socket) { 76 | that.sockets.push(socket); 77 | socket.setTimeout(4000); 78 | socket.on('close', function () { 79 | that.sockets.splice(that.sockets.indexOf(socket), 1); 80 | }); 81 | }); 82 | 83 | that.running.listen(port, function(err) { 84 | if (err) return d.reject(err); 85 | 86 | that.port = port; 87 | that.dir = dir; 88 | that.emit("state", true); 89 | d.resolve(); 90 | }); 91 | 92 | return d.promise; 93 | }); 94 | } 95 | 96 | module.exports = Server; 97 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/bootstrap/scaffolding.less: -------------------------------------------------------------------------------- 1 | // 2 | // Scaffolding 3 | // -------------------------------------------------- 4 | 5 | 6 | // Reset the box-sizing 7 | 8 | *, 9 | *:before, 10 | *:after { 11 | .box-sizing(border-box); 12 | } 13 | 14 | 15 | // Body reset 16 | 17 | html { 18 | font-size: 62.5%; 19 | -webkit-tap-highlight-color: rgba(0,0,0,0); 20 | } 21 | 22 | body { 23 | font-family: @font-family-base; 24 | font-size: @font-size-base; 25 | line-height: @line-height-base; 26 | color: @text-color; 27 | background-color: @body-bg; 28 | } 29 | 30 | // Reset fonts for relevant elements 31 | input, 32 | button, 33 | select, 34 | textarea { 35 | font-family: inherit; 36 | font-size: inherit; 37 | line-height: inherit; 38 | } 39 | 40 | // Reset unusual Firefox-on-Android default style. 41 | // 42 | // See https://github.com/necolas/normalize.css/issues/214 43 | 44 | button, 45 | input, 46 | select[multiple], 47 | textarea { 48 | background-image: none; 49 | } 50 | 51 | 52 | // Links 53 | 54 | a { 55 | color: @link-color; 56 | text-decoration: none; 57 | 58 | &:hover, 59 | &:focus { 60 | color: @link-hover-color; 61 | text-decoration: underline; 62 | } 63 | 64 | &:focus { 65 | .tab-focus(); 66 | } 67 | } 68 | 69 | 70 | // Images 71 | 72 | img { 73 | vertical-align: middle; 74 | } 75 | 76 | // Responsive images (ensure images don't scale beyond their parents) 77 | .img-responsive { 78 | .img-responsive(); 79 | } 80 | 81 | // Rounded corners 82 | .img-rounded { 83 | border-radius: @border-radius-large; 84 | } 85 | 86 | // Image thumbnails 87 | // 88 | // Heads up! This is mixin-ed into thumbnails.less for `.thumbnail`. 89 | .img-thumbnail { 90 | padding: @thumbnail-padding; 91 | line-height: @line-height-base; 92 | background-color: @thumbnail-bg; 93 | border: 1px solid @thumbnail-border; 94 | border-radius: @thumbnail-border-radius; 95 | .transition(all .2s ease-in-out); 96 | 97 | // Keep them at most 100% wide 98 | .img-responsive(inline-block); 99 | } 100 | 101 | // Perfect circle 102 | .img-circle { 103 | border-radius: 50%; // set radius in percents 104 | } 105 | 106 | 107 | // Horizontal rules 108 | 109 | hr { 110 | margin-top: @line-height-computed; 111 | margin-bottom: @line-height-computed; 112 | border: 0; 113 | border-top: 1px solid @hr-border; 114 | } 115 | 116 | 117 | // Only display content to screen readers 118 | // 119 | // See: http://a11yproject.com/posts/how-to-hide-content/ 120 | 121 | .sr-only { 122 | position: absolute; 123 | width: 1px; 124 | height: 1px; 125 | margin: -1px; 126 | padding: 0; 127 | overflow: hidden; 128 | clip: rect(0 0 0 0); 129 | border: 0; 130 | } 131 | -------------------------------------------------------------------------------- /theme/stylesheets/print.less: -------------------------------------------------------------------------------- 1 | @import "vendors/bootstrap/bootstrap.less"; 2 | @import "vendors/fontawesome/font-awesome.less"; 3 | 4 | @import "mixins.less"; 5 | @import "variables.less"; 6 | @import "fonts.less"; 7 | 8 | @import "page/highlight.less"; 9 | 10 | 11 | @font-size-base: 13px; 12 | 13 | 14 | * { 15 | -webkit-overflow-scrolling: touch; 16 | -webkit-tap-highlight-color: transparent; 17 | -webkit-text-size-adjust: none; 18 | -webkit-touch-callout: none; 19 | -webkit-font-smoothing: antialiased; 20 | } 21 | 22 | html, body { 23 | height: 100%; 24 | } 25 | 26 | body { 27 | text-rendering: optimizeLegibility; 28 | font-smoothing: antialiased; 29 | font-family: @font-family-base; 30 | } 31 | 32 | 33 | h1, h2, h3 { 34 | page-break-after: avoid; 35 | page-break-before: auto; 36 | } 37 | 38 | h1 { font-size: floor(@font-size-base * 2.15); } 39 | h2 { font-size: floor(@font-size-base * 1.70); } 40 | h3 { font-size: ceil(@font-size-base * 1.25); } 41 | h4 { font-size: ceil(@font-size-base * 1); } 42 | h5 { font-size: ceil(@font-size-base * 0.85); } 43 | h6 { font-size: ceil(@font-size-base * 0.65); } 44 | 45 | pre, blockquote { 46 | border: 1px solid #999; 47 | page-break-inside: avoid; 48 | } 49 | 50 | img { 51 | max-width: 100% !important; 52 | page-break-inside: avoid; 53 | } 54 | 55 | section { 56 | page-break-after: always; 57 | 58 | &#cover { 59 | padding: 3cm 0cm; 60 | text-align: center; 61 | 62 | h1 { 63 | font-size: 1.5cm; 64 | } 65 | } 66 | 67 | &#summary { 68 | margin: 1.5cm; 69 | 70 | h1 { 71 | text-align: center; 72 | } 73 | 74 | ol { 75 | list-style: none; 76 | padding: 0px; 77 | margin: 0px; 78 | margin-left: 1cm; 79 | } 80 | 81 | > ol { 82 | > li { 83 | } 84 | } 85 | } 86 | 87 | article { 88 | margin-bottom: 1.5cm; 89 | 90 | &.new-chapter { 91 | page-break-after: always; 92 | font-size: 0.6cm; 93 | text-align: center; 94 | padding: 3cm 0cm; 95 | 96 | h1 { 97 | font-size: floor(@font-size-base * 2.7); 98 | } 99 | } 100 | 101 | .exercise { 102 | margin: 1cm 0cm; 103 | padding: 0.4cm; 104 | page-break-inside: avoid; 105 | 106 | border: 3px solid #ddd; 107 | 108 | .exercise-header { 109 | margin-bottom: 0.4cm; 110 | padding-bottom: 0.2cm; 111 | border-bottom: 1px solid #ddd; 112 | } 113 | } 114 | } 115 | } -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function (grunt) { 2 | var path = require("path"); 3 | 4 | // Load NPM tasks 5 | grunt.loadNpmTasks('grunt-contrib-less'); 6 | grunt.loadNpmTasks('grunt-contrib-requirejs'); 7 | grunt.loadNpmTasks("grunt-bower-install-simple"); 8 | 9 | // Init GRUNT configuraton 10 | grunt.initConfig({ 11 | pkg: grunt.file.readJSON('package.json'), 12 | 'bower-install-simple': { 13 | options: { 14 | color: true, 15 | production: false, 16 | directory: "theme/javascript/vendors" 17 | } 18 | }, 19 | less: { 20 | development: { 21 | options: { 22 | compress: true, 23 | yuicompress: true, 24 | optimization: 2 25 | }, 26 | files: { 27 | "theme/assets/style.css": "theme/stylesheets/main.less", 28 | "theme/assets/print.css": "theme/stylesheets/print.less" 29 | } 30 | } 31 | }, 32 | requirejs: { 33 | compile: { 34 | options: { 35 | name: "gitbook", 36 | baseUrl: "theme/javascript/", 37 | out: "theme/assets/app.js", 38 | preserveLicenseComments: false, 39 | optimize: "uglify", //"uglify", 40 | include: ["requireLib"], 41 | paths: { 42 | "jQuery": 'vendors/jquery/dist/jquery', 43 | "lodash": 'vendors/lodash/dist/lodash', 44 | "requireLib": 'vendors/requirejs/require', 45 | "Mousetrap": 'vendors/mousetrap/mousetrap', 46 | "lunr": 'vendors/lunr.js/lunr', 47 | "URI": 'vendors/URIjs/src/URI' 48 | }, 49 | shim: { 50 | 'jQuery': { 51 | exports: '$' 52 | }, 53 | 'lodash': { 54 | exports: '_' 55 | }, 56 | 'Mousetrap': { 57 | exports: 'Mousetrap' 58 | }, 59 | 'lunr': { 60 | exports: 'lunr' 61 | } 62 | } 63 | } 64 | } 65 | } 66 | }); 67 | 68 | grunt.registerTask("bower-install", [ "bower-install-simple" ]); 69 | 70 | // Build 71 | grunt.registerTask('build', [ 72 | 'bower-install', 73 | 'less', 74 | 'requirejs' 75 | ]); 76 | 77 | grunt.registerTask('default', [ 78 | 'build' 79 | ]); 80 | }; -------------------------------------------------------------------------------- /theme/stylesheets/vendors/bootstrap/tooltip.less: -------------------------------------------------------------------------------- 1 | // 2 | // Tooltips 3 | // -------------------------------------------------- 4 | 5 | 6 | // Base class 7 | .tooltip { 8 | position: absolute; 9 | z-index: @zindex-tooltip; 10 | display: block; 11 | visibility: visible; 12 | font-size: @font-size-small; 13 | line-height: 1.4; 14 | .opacity(0); 15 | 16 | &.in { .opacity(.9); } 17 | &.top { margin-top: -3px; padding: 5px 0; } 18 | &.right { margin-left: 3px; padding: 0 5px; } 19 | &.bottom { margin-top: 3px; padding: 5px 0; } 20 | &.left { margin-left: -3px; padding: 0 5px; } 21 | } 22 | 23 | // Wrapper for the tooltip content 24 | .tooltip-inner { 25 | max-width: @tooltip-max-width; 26 | padding: 3px 8px; 27 | color: @tooltip-color; 28 | text-align: center; 29 | text-decoration: none; 30 | background-color: @tooltip-bg; 31 | border-radius: @border-radius-base; 32 | } 33 | 34 | // Arrows 35 | .tooltip-arrow { 36 | position: absolute; 37 | width: 0; 38 | height: 0; 39 | border-color: transparent; 40 | border-style: solid; 41 | } 42 | .tooltip { 43 | &.top .tooltip-arrow { 44 | bottom: 0; 45 | left: 50%; 46 | margin-left: -@tooltip-arrow-width; 47 | border-width: @tooltip-arrow-width @tooltip-arrow-width 0; 48 | border-top-color: @tooltip-arrow-color; 49 | } 50 | &.top-left .tooltip-arrow { 51 | bottom: 0; 52 | left: 5px; 53 | border-width: @tooltip-arrow-width @tooltip-arrow-width 0; 54 | border-top-color: @tooltip-arrow-color; 55 | } 56 | &.top-right .tooltip-arrow { 57 | bottom: 0; 58 | right: 5px; 59 | border-width: @tooltip-arrow-width @tooltip-arrow-width 0; 60 | border-top-color: @tooltip-arrow-color; 61 | } 62 | &.right .tooltip-arrow { 63 | top: 50%; 64 | left: 0; 65 | margin-top: -@tooltip-arrow-width; 66 | border-width: @tooltip-arrow-width @tooltip-arrow-width @tooltip-arrow-width 0; 67 | border-right-color: @tooltip-arrow-color; 68 | } 69 | &.left .tooltip-arrow { 70 | top: 50%; 71 | right: 0; 72 | margin-top: -@tooltip-arrow-width; 73 | border-width: @tooltip-arrow-width 0 @tooltip-arrow-width @tooltip-arrow-width; 74 | border-left-color: @tooltip-arrow-color; 75 | } 76 | &.bottom .tooltip-arrow { 77 | top: 0; 78 | left: 50%; 79 | margin-left: -@tooltip-arrow-width; 80 | border-width: 0 @tooltip-arrow-width @tooltip-arrow-width; 81 | border-bottom-color: @tooltip-arrow-color; 82 | } 83 | &.bottom-left .tooltip-arrow { 84 | top: 0; 85 | left: 5px; 86 | border-width: 0 @tooltip-arrow-width @tooltip-arrow-width; 87 | border-bottom-color: @tooltip-arrow-color; 88 | } 89 | &.bottom-right .tooltip-arrow { 90 | top: 0; 91 | right: 5px; 92 | border-width: 0 @tooltip-arrow-width @tooltip-arrow-width; 93 | border-bottom-color: @tooltip-arrow-color; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /test/navigation.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var path = require('path'); 3 | var assert = require('assert'); 4 | 5 | var summary = require('../').parse.summary; 6 | var navigation = require('../').parse.navigation; 7 | 8 | 9 | var CONTENT = fs.readFileSync(path.join(__dirname, './fixtures/SUMMARY.md'), 'utf8'); 10 | var LEXED = summary(CONTENT); 11 | 12 | 13 | describe('Summary navigation', function() { 14 | it('should provide next & prev entries for a file', function() { 15 | var nav = navigation(LEXED, [ 16 | 'README.md', 17 | 'chapter-1/README.md', 18 | 'chapter-1/ARTICLE1.md', 19 | 'chapter-1/ARTICLE2.md', 20 | 'chapter-2/README.md', 21 | ]); 22 | 23 | // Make sure it found the files we gave it 24 | assert(nav['README.md']); 25 | assert(nav['chapter-1/README.md']); 26 | assert(nav['chapter-1/ARTICLE1.md']); 27 | assert(nav['chapter-1/ARTICLE2.md']); 28 | assert(nav['chapter-2/README.md']); 29 | 30 | 31 | assert.equal(nav['README.md'].prev, null); 32 | assert.equal(nav['README.md'].next.path, 'chapter-1/README.md'); 33 | 34 | assert.equal(nav['chapter-1/README.md'].prev.path, 'README.md'); 35 | assert.equal(nav['chapter-1/README.md'].next.path, 'chapter-1/ARTICLE1.md'); 36 | 37 | assert.equal(nav['chapter-1/ARTICLE1.md'].prev.path, 'chapter-1/README.md'); 38 | assert.equal(nav['chapter-1/ARTICLE1.md'].next.path, 'chapter-1/ARTICLE2.md'); 39 | 40 | assert.equal(nav['chapter-1/ARTICLE2.md'].prev.path, 'chapter-1/ARTICLE1.md'); 41 | assert.equal(nav['chapter-1/ARTICLE2.md'].next.path, 'chapter-2/README.md'); 42 | 43 | assert.equal(nav['chapter-2/README.md'].prev.path, 'chapter-1/ARTICLE2.md'); 44 | assert.equal(nav['chapter-2/README.md'].next.path, 'chapter-3/README.md'); 45 | }); 46 | 47 | it('should give full tree, when not limited', function() { 48 | var nav = navigation(LEXED); 49 | 50 | assert(nav['README.md']); 51 | assert(nav['chapter-1/README.md']); 52 | assert(nav['chapter-1/ARTICLE1.md']); 53 | assert(nav['chapter-1/ARTICLE2.md']); 54 | assert(nav['chapter-2/README.md']); 55 | assert(nav['chapter-3/README.md']); 56 | }); 57 | 58 | it('should detect levels correctly', function() { 59 | var nav = navigation(LEXED); 60 | 61 | assert.equal(nav['README.md'].level, '0'); 62 | assert.equal(nav['chapter-1/README.md'].level, '1'); 63 | assert.equal(nav['chapter-1/ARTICLE1.md'].level, '1.1'); 64 | assert.equal(nav['chapter-1/ARTICLE2.md'].level, '1.2'); 65 | assert.equal(nav['chapter-2/README.md'].level, '2'); 66 | assert.equal(nav['chapter-3/README.md'].level, '3'); 67 | }); 68 | 69 | it('should not accept null paths', function() { 70 | var nav = navigation(LEXED); 71 | 72 | assert(!nav[null]); 73 | }); 74 | }); 75 | -------------------------------------------------------------------------------- /theme/javascript/core/search.js: -------------------------------------------------------------------------------- 1 | define([ 2 | "jQuery", 3 | "lodash", 4 | "lunr", 5 | "utils/storage", 6 | "core/state", 7 | "core/sidebar" 8 | ], function($, _, lunr, storage, state, sidebar) { 9 | var index = null; 10 | 11 | // Use a specific idnex 12 | var useIndex = function(data) { 13 | index = lunr.Index.load(data); 14 | }; 15 | 16 | // Load complete index 17 | var loadIndex = function() { 18 | $.getJSON(state.basePath+"/search_index.json") 19 | .then(useIndex); 20 | }; 21 | 22 | // Search for a term 23 | var search = function(q) { 24 | if (!index) return; 25 | var results = _.chain(index.search(q)) 26 | .map(function(result) { 27 | var parts = result.ref.split("#") 28 | return { 29 | path: parts[0], 30 | hash: parts[1] 31 | } 32 | }) 33 | .value(); 34 | 35 | return results; 36 | }; 37 | 38 | // Toggle search bar 39 | var toggleSearch = function(_state) { 40 | if (state != null && isSearchOpen() == _state) return; 41 | 42 | var $searchInput = $(".book-search input"); 43 | state.$book.toggleClass("with-search", _state); 44 | 45 | // If search bar is open: focus input 46 | if (isSearchOpen()) { 47 | sidebar.toggle(true); 48 | $searchInput.focus(); 49 | } else { 50 | $searchInput.blur(); 51 | $searchInput.val(""); 52 | sidebar.filter(null); 53 | } 54 | }; 55 | 56 | // Return true if search bar is open 57 | var isSearchOpen = function() { 58 | return state.$book.hasClass("with-search"); 59 | }; 60 | 61 | 62 | var init = function() { 63 | loadIndex(); 64 | 65 | // Toggle search 66 | $(document).on("click", ".book-header .toggle-search", function(e) { 67 | e.preventDefault(); 68 | toggleSearch(); 69 | }); 70 | }; 71 | 72 | var prepare = function() { 73 | var $searchInput = $(".book-search input"); 74 | 75 | $searchInput.keyup(function(e) { 76 | var key = (e.keyCode ? e.keyCode : e.which); 77 | var q = $(this).val(); 78 | 79 | if (key == 27) { 80 | e.preventDefault(); 81 | toggleSearch(false); 82 | return; 83 | } 84 | if (q.length == 0) { 85 | sidebar.filter(null); 86 | } else { 87 | var results = search(q); 88 | sidebar.filter( 89 | _.pluck(results, "path") 90 | ); 91 | } 92 | }); 93 | } 94 | 95 | return { 96 | init: init, 97 | search: search, 98 | toggle: toggleSearch, 99 | prepare: prepare 100 | }; 101 | }); -------------------------------------------------------------------------------- /theme/templates/site.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | 3 | {% block htmlTag %}manifest="{{ basePath }}/manifest.appcache"{% endblock %} 4 | {% block title %}{{ progress.current.title }}{% parent %}{% endblock %} 5 | {% block content %} 6 |
      7 | {% include "includes/book/header.html" %} 8 | {% include "includes/book/summary.html" %} 9 |
      10 |
      11 |
      12 | {% include "includes/book/progress.html" %} 13 | 14 |
      15 | {% for section in content %} 16 |
      17 | {% if section.type == "normal" %} 18 | {% autoescape false %}{{ section.content }}{% endautoescape %} 19 | {% elif section.type == "exercise" %} 20 | {% include "./includes/book/exercise.html" with {section: section} %} 21 | {% elif section.type == "quiz" %} 22 | {% include "./includes/book/quiz.html" with {section: section} %} 23 | {% endif %} 24 |
      25 | {% endfor %} 26 |
      27 |
      28 |
      29 | 30 | {% if progress.current.prev and progress.current.prev.path %} 31 | 32 | {% endif %} 33 | {% if progress.current.next and progress.current.next.path %} 34 | 35 | {% endif %} 36 |
      37 |
      38 | {% endblock %} 39 | 40 | {% block javascript %} 41 | {% parent %} 42 | {% for resource in plugins.resources.js %} 43 | {% if resource.url %} 44 | 45 | {% else %} 46 | 47 | {% endif %} 48 | {% endfor %} 49 | 55 | {% endblock %} 56 | 57 | {% block style %} 58 | {% parent %} 59 | {% for resource in plugins.resources.css %} 60 | {% if resource.url %} 61 | 62 | {% else %} 63 | 64 | {% endif %} 65 | {% endfor %} 66 | {% endblock %} 67 | -------------------------------------------------------------------------------- /theme/stylesheets/book/header.less: -------------------------------------------------------------------------------- 1 | .book { 2 | .book-header { 3 | font-family: @font-family-sans; 4 | 5 | position: absolute; 6 | overflow: visible; 7 | top: 0px; 8 | right: 0px; 9 | left: 0px; 10 | height: @header-height; 11 | z-index: 2; 12 | 13 | font-size: 0.85em; 14 | color: @header-color; 15 | background: @header-background; 16 | box-shadow: 0 1px 2px hsla(200,10%,80%,0.6); 17 | 18 | .btn { 19 | display: block; 20 | height: @header-height; 21 | padding: 0px 15px; 22 | border-bottom: none; 23 | color: @header-button-color; 24 | text-transform: uppercase; 25 | line-height: @header-height; 26 | .box-shadow(none) !important; 27 | position:relative; 28 | 29 | &:hover { 30 | position: relative; 31 | text-decoration: none; 32 | color: @header-button-hover-color; 33 | background: @header-button-hover-background; 34 | } 35 | } 36 | 37 | h1 { 38 | margin: 0px; 39 | font-size: 20px; 40 | text-align: center; 41 | line-height: @header-height; 42 | 43 | padding-left: 200px; 44 | padding-right: 200px; 45 | .transition(margin-left 0.5s ease); 46 | 47 | a, a:hover { 48 | color: inherit; 49 | text-decoration: none; 50 | } 51 | 52 | @media (max-width: 800px) { 53 | display: none; 54 | } 55 | 56 | i { 57 | display: none; 58 | } 59 | } 60 | } 61 | 62 | &.is-loading { 63 | .book-header h1 { 64 | i { 65 | display: inline-block; 66 | } 67 | a { 68 | display: none; 69 | } 70 | } 71 | } 72 | &.with-summary { 73 | .book-header h1 { 74 | margin-left: 250px; 75 | } 76 | } 77 | &.without-animation { 78 | .book-header h1 { 79 | .transition(none) !important; 80 | } 81 | } 82 | &.color-theme-1{ 83 | .book-header{ 84 | color: @header-color-1; 85 | background: @header-background-1; 86 | .btn { 87 | color: @header-button-color-1; 88 | &:hover { 89 | color: @header-button-hover-color-1; 90 | background: @header-button-hover-background-1; 91 | } 92 | } 93 | } 94 | } 95 | &.color-theme-2{ 96 | .book-header{ 97 | color: @header-color-2; 98 | background: @header-background-2; 99 | .btn { 100 | color: @header-button-color-2; 101 | &:hover { 102 | color: @header-button-hover-color-2; 103 | background: @header-button-hover-background-2; 104 | } 105 | } 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /theme/templates/includes/book/summary.html: -------------------------------------------------------------------------------- 1 |
      2 | 5 |
        6 | {% if options.links.about !== false && (options.links.about != null || githubId) %} 7 |
      • 8 | About the author 9 |
      • 10 | {% endif %} 11 | 12 | {% if options.links.issues !== false && (options.links.issues != null || githubId) %} 13 |
      • 14 | Questions and Issues 15 |
      • 16 | {% endif %} 17 | 18 | {% if options.links.contribute !== false && (options.links.contribute != null || githubId) %} 19 |
      • 20 | Edit and Contribute 21 |
      • 22 | {% endif %} 23 | 24 | {% if options.links.contribute || options.links.issues || options.links.about %} 25 |
      • 26 | {% endif %} 27 | 28 |
      • 29 | Introduction 30 |
      • 31 | {% for item in summary.chapters %} 32 |
      • 33 | {% if item.path %} 34 | 35 | {{ item.level }}. {{ item.title }} 36 | 37 | {% else %} 38 | {{ item.level }}. {{ item.title }} 39 | {% endif %} 40 | {% if item.articles.length > 0 %} 41 | 54 | {% endif %} 55 |
      • 56 | {% endfor %} 57 | 58 | {% if options.links.gitbook !== false %} 59 |
      • 60 |
      • 61 | Generated using GitBook 62 |
      • 63 | {% endif %} 64 |
      65 |
      66 | -------------------------------------------------------------------------------- /bin/gitbook.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | 3 | var Q = require('q'); 4 | var _ = require('lodash'); 5 | var path = require('path'); 6 | var prog = require('commander'); 7 | 8 | var pkg = require('../package.json'); 9 | var generators = require("../lib/generate").generators; 10 | var initDir = require("../lib/generate/init"); 11 | var fs = require('../lib/generate/fs'); 12 | 13 | var utils = require('./utils'); 14 | var build = require('./build'); 15 | var Server = require('./server'); 16 | 17 | // General options 18 | prog 19 | .version(pkg.version); 20 | 21 | build.command(prog.command('build [source_dir]')) 22 | .description('Build a gitbook from a directory') 23 | .action(build.folder); 24 | 25 | build.command(prog.command('serve [source_dir]')) 26 | .description('Build then serve a gitbook from a directory') 27 | .option('-p, --port ', 'Port for server to listen on', 4000) 28 | .option('--no-watch', 'Disable restart with file watching') 29 | .action(function(dir, options) { 30 | var server = new Server(); 31 | 32 | var generate = function() { 33 | if (server.isRunning()) console.log("Stopping server"); 34 | 35 | server.stop() 36 | .then(function() { 37 | return build.folder(dir, options); 38 | }) 39 | .then(function(_options) { 40 | console.log(); 41 | console.log('Starting server ...'); 42 | return server.start(_options.output, options.port) 43 | .then(function() { 44 | console.log('Serving book on http://localhost:'+options.port); 45 | 46 | if (!options.watch) return; 47 | return utils.watch(_options.input) 48 | .then(function(filepath) { 49 | console.log("Restart after change in files"); 50 | console.log(''); 51 | return generate(); 52 | }) 53 | }) 54 | }) 55 | .fail(utils.logError); 56 | }; 57 | 58 | console.log('Press CTRL+C to quit ...'); 59 | console.log('') 60 | generate(); 61 | }); 62 | 63 | build.command(prog.command('pdf [source_dir]')) 64 | .description('Build a gitbook as a PDF') 65 | .option('-pf, --paperformat ', 'PDF paper format (default is A4): "5in*7.5in", "10cm*20cm", "A4", "Letter"') 66 | .action(function(dir, options) { 67 | build.file(dir, _.extend(options, { 68 | extension: "pdf", 69 | format: "pdf" 70 | })); 71 | }); 72 | 73 | build.command(prog.command('ebook [source_dir]')) 74 | .description('Build a gitbook as a eBook') 75 | .option('-c, --cover ', 'Cover image, default is cover.png if exists') 76 | .action(function(dir, options) { 77 | var ext = options.output ? path.extname(options.output) : "epub"; 78 | 79 | build.file(dir, _.extend(options, { 80 | extension: ext, 81 | format: "ebook" 82 | })); 83 | }); 84 | 85 | prog 86 | .command('init [source_dir]') 87 | .description('Create files and folders based on contents of SUMMARY.md') 88 | .action(function(dir) { 89 | dir = dir || process.cwd(); 90 | return initDir(dir); 91 | }); 92 | 93 | // Parse and fallback to help if no args 94 | if(_.isEmpty(prog.parse(process.argv).args) && process.argv.length === 2) { 95 | prog.help(); 96 | } 97 | -------------------------------------------------------------------------------- /theme/javascript/utils/execute.js: -------------------------------------------------------------------------------- 1 | define([ 2 | "execute/javascript" 3 | ], function(javascript) { 4 | var LANGUAGES = { 5 | "javascript": javascript 6 | }; 7 | 8 | 9 | var evalJS = function(lang, code, callback) { 10 | var ready = false; 11 | var finished = false; 12 | 13 | var finish = function() { 14 | if(finished) { 15 | return console.error('Already finished'); 16 | } 17 | finished = true; 18 | return callback.apply(null, arguments); 19 | }; 20 | 21 | var repl; 22 | 23 | // Handles all our events 24 | var eventHandler = function(data, eventType) { 25 | console.log([eventType, data]); 26 | switch(eventType) { 27 | case 'progress': 28 | // Update UI loading bar 29 | break; 30 | case 'timeout': 31 | finish(new Error(data)); 32 | break; 33 | case 'result': 34 | finish(null, { 35 | value: data, 36 | type: 'result' 37 | }); 38 | break; 39 | case 'error': 40 | if(ready) { 41 | return finish(null, { 42 | value: data, 43 | type: 'error' 44 | }); 45 | } 46 | return finish(new Error(data)); 47 | break 48 | case 'ready': 49 | // We're good to get results and stuff back now 50 | ready = true; 51 | // Eval our code now that the runtime is ready 52 | repl.eval(code); 53 | break; 54 | default: 55 | console.log('Unhandled event =', eventType, 'data =', data); 56 | } 57 | }; 58 | 59 | repl = new lang.REPL({ 60 | input: eventHandler, 61 | output: eventHandler, 62 | result: eventHandler, 63 | error: eventHandler, 64 | progress: eventHandler, 65 | timeout: { 66 | time: 30000, 67 | callback: eventHandler 68 | } 69 | }); 70 | 71 | repl.loadLanguage(lang.id, eventHandler); 72 | }; 73 | 74 | var execute = function(lang, solution, validation, context, callback) { 75 | // Language data 76 | var langd = LANGUAGES[lang]; 77 | 78 | // Check language is supported 79 | if (!langd) return callback(new Error("Language '"+lang+"' not available for execution")); 80 | 81 | // Validate with validation code 82 | var code = [ 83 | context, 84 | solution, 85 | langd.assertCode, 86 | validation, 87 | ].join(langd.sep); 88 | evalJS(langd, code, function(err, res) { 89 | if(err) return callback(err); 90 | 91 | if (res.type == "error") callback(new Error(res.value)); 92 | else callback(null, res.value); 93 | }); 94 | }; 95 | 96 | return execute; 97 | }); 98 | -------------------------------------------------------------------------------- /theme/stylesheets/book/progress.less: -------------------------------------------------------------------------------- 1 | /* Chrome, Safari, Opera */ 2 | @-webkit-keyframes animate-loading { 3 | from {width: 0%;} 4 | to {} 5 | } 6 | 7 | /* Standard syntax */ 8 | @keyframes animate-loading { 9 | from {width: 0%;} 10 | to {} 11 | } 12 | 13 | .book .book-body { 14 | .book-progress { 15 | height: @progress-height; 16 | width: 100%; 17 | position: relative; 18 | background: #fff; 19 | margin-bottom: 10px; 20 | 21 | .bar { 22 | height: @bar-height; 23 | position: @bar-position; 24 | right: @bar-right; 25 | left: @bar-left; 26 | top: @bar-top; 27 | 28 | background: @bar-background; 29 | border-radius: 5px; 30 | overflow: hidden; 31 | 32 | .inner { 33 | height: 100%; 34 | width: 0%; 35 | 36 | background: @bar-progress-background; 37 | -webkit-animation: animate-loading 1s; /* Chrome, Safari, Opera */ 38 | animation: animate-loading 1s; 39 | 40 | .in-inner { 41 | height: 100%; 42 | width: 50%; 43 | } 44 | } 45 | } 46 | 47 | .chapters { 48 | display: @chapter-display; 49 | 50 | position: absolute; 51 | right: 20px + @chapter-size; 52 | left: 20px; 53 | top: 7px; 54 | 55 | .chapter { 56 | position: absolute; 57 | width: @chapter-size; 58 | height: @chapter-size; 59 | border-radius: @chapter-size; 60 | 61 | background: @bar-background; 62 | box-shadow: 0px 0px 1px #bbb; 63 | 64 | &.new-chapter { 65 | 66 | } 67 | 68 | &.done { 69 | background: @bar-progress-background; 70 | box-shadow: none; 71 | } 72 | 73 | @media (max-width: 800px) { 74 | display: none; 75 | 76 | &.new-chapter { 77 | display: block; 78 | } 79 | } 80 | } 81 | } 82 | } 83 | } 84 | .book.color-theme-1 .book-body { 85 | .book-progress { 86 | .bar { 87 | background: @bar-background-1; 88 | .inner { 89 | background: @bar-progress-background-1; 90 | } 91 | } 92 | } 93 | .chapters .chapter{ 94 | background: @bar-background-1; 95 | &.done{ 96 | background: @bar-progress-background-1; 97 | } 98 | } 99 | } 100 | .book.color-theme-2 .book-body { 101 | .book-progress { 102 | .bar { 103 | background: @bar-background-2; 104 | .inner { 105 | background: @bar-progress-background-2; 106 | } 107 | } 108 | } 109 | .chapters .chapter{ 110 | background: @bar-background-2; 111 | &.done{ 112 | background: @bar-progress-background-2; 113 | } 114 | } 115 | } -------------------------------------------------------------------------------- /lib/parse/summary.js: -------------------------------------------------------------------------------- 1 | var _ = require('lodash'); 2 | var marked = require('marked'); 3 | 4 | 5 | // Utility function for splitting a list into groups 6 | function splitBy(list, starter, ender) { 7 | var starts = 0; 8 | var ends = 0; 9 | var group = []; 10 | 11 | // Groups 12 | return _.reduce(list, function(groups, value) { 13 | // Ignore start and end delimiters in resulted groups 14 | if(starter(value)) { 15 | starts++; 16 | } else if(ender(value)) { 17 | ends++; 18 | } 19 | 20 | // Add current value to group 21 | group.push(value); 22 | 23 | // We've got a matching 24 | if(starts === ends && starts !== 0) { 25 | // Add group to end groups 26 | // (remove starter and ender token) 27 | groups.push(group.slice(1, -1)); 28 | 29 | // Reset group 30 | group = []; 31 | } 32 | 33 | return groups; 34 | }, []); 35 | } 36 | 37 | function listSplit(nodes, start_type, end_type) { 38 | return splitBy(nodes, function(el) { 39 | return el.type === start_type; 40 | }, function(el) { 41 | return el.type === end_type; 42 | }); 43 | } 44 | 45 | // Get the biggest list 46 | // out of a list of marked nodes 47 | function filterList(nodes) { 48 | return _.chain(nodes) 49 | .toArray() 50 | .rest(function(el) { 51 | // Get everything after list_start 52 | return el.type !== 'list_start'; 53 | }) 54 | .reverse() 55 | .rest(function(el) { 56 | // Get everything after list_end (remember we're reversed) 57 | return el.type !== 'list_end'; 58 | }) 59 | .reverse() 60 | .value().slice(1, -1); 61 | } 62 | 63 | // Parses an Article or Chapter title 64 | // supports extracting links 65 | function parseTitle(src, nums) { 66 | // Check if it's a link 67 | var matches = marked.InlineLexer.rules.link.exec(src); 68 | 69 | var level = nums.join('.'); 70 | 71 | // Not a link, return plain text 72 | if(!matches) { 73 | return { 74 | title: src, 75 | level: level, 76 | path: null, 77 | }; 78 | } 79 | 80 | return { 81 | title: matches[1], 82 | level: level, 83 | 84 | // Replace .md references with .html 85 | path: matches[2].replace(/\\/g, '/'), 86 | }; 87 | } 88 | 89 | function parseArticle(chapterNum, nodes, idx) { 90 | return parseTitle(_.first(nodes).text, [chapterNum, idx+1]); 91 | } 92 | 93 | function parseChapter(nodes, idx) { 94 | return _.extend(parseTitle(_.first(nodes).text, [idx+1]), { 95 | articles: _.map(listSplit(filterList(nodes), 'list_item_start', 'list_item_end'), parseArticle.bind(null, idx+1)) 96 | }); 97 | } 98 | 99 | function parseSummary(src) { 100 | var nodes = marked.lexer(src); 101 | 102 | // Get out list of chapters 103 | var chapterList = filterList(nodes); 104 | 105 | // Split out chapter sections 106 | var chapters = _.chain(listSplit(chapterList, 'list_item_start', 'list_item_end')) 107 | .map(parseChapter) 108 | .value(); 109 | 110 | return { 111 | chapters: chapters 112 | }; 113 | } 114 | 115 | 116 | // Exports 117 | module.exports = parseSummary; 118 | -------------------------------------------------------------------------------- /theme/stylesheets/book/body.less: -------------------------------------------------------------------------------- 1 | .book { 2 | position: relative; 3 | width: 100%; 4 | height: 100%; 5 | 6 | .book-body { 7 | position: absolute; 8 | top: @header-height; 9 | right: 0px; 10 | left: 0px; 11 | bottom: 0px; 12 | 13 | color: @page-color; 14 | background: @body-background; 15 | .transition(left 0.5s ease); 16 | 17 | .body-inner { 18 | position: absolute; 19 | top: 0px; 20 | right: 0px; 21 | left: 0px; 22 | bottom: 0px; 23 | overflow-y: auto; 24 | } 25 | 26 | .page-wrapper { 27 | position: relative; 28 | outline: none; 29 | 30 | .page-inner { 31 | max-width: 800px; 32 | margin: 0px auto; 33 | 34 | section { 35 | margin: 0px 0px; 36 | padding: 5px 15px; 37 | 38 | background: @page-background; 39 | border-radius: 2px; 40 | line-height: 1.5em; 41 | } 42 | 43 | .btn-group { 44 | .btn { 45 | border-radius: 0px; 46 | background: #eee; 47 | border: 0px; 48 | } 49 | } 50 | } 51 | } 52 | 53 | @media (max-width: @mobileMaxWidth) { 54 | overflow-y: auto; 55 | 56 | .body-inner { 57 | position: static; 58 | padding-bottom: 20px; 59 | min-height: calc(~"100% - 57px") 60 | } 61 | } 62 | &.font-size-0{ 63 | font-size:@s-font-size; 64 | } 65 | &.font-size-1{ 66 | font-size:@m-font-size; 67 | } 68 | &.font-size-2{ 69 | font-size:@l-font-size; 70 | } 71 | &.font-size-3{ 72 | font-size:@xl-font-size; 73 | } 74 | &.font-size-4{ 75 | font-size:@xxl-font-size; 76 | } 77 | 78 | &.font-family-0{ 79 | font-family: @font-family-serif; 80 | } 81 | &.font-family-1{ 82 | font-family: @font-family-sans; 83 | } 84 | } 85 | 86 | &.with-summary { 87 | @media (min-width: 800px) { 88 | .book-body { 89 | left: 250px; 90 | } 91 | } 92 | } 93 | 94 | &.without-animation { 95 | .book-body { 96 | .transition(none) !important; 97 | } 98 | } 99 | &.color-theme-1{ 100 | .book-body { 101 | color: @page-color-1; 102 | background: @body-background-1; 103 | .page-wrapper { 104 | .page-inner { 105 | section{ 106 | background: @page-background-1; 107 | } 108 | } 109 | } 110 | } 111 | } 112 | &.color-theme-2{ 113 | .book-body { 114 | color: @page-color-2; 115 | background: @body-background-2; 116 | .page-wrapper { 117 | .page-inner { 118 | section{ 119 | background: @page-background-2; 120 | } 121 | } 122 | } 123 | } 124 | } 125 | } -------------------------------------------------------------------------------- /lib/parse/lex.js: -------------------------------------------------------------------------------- 1 | var _ = require('lodash'); 2 | var marked = require('marked'); 3 | 4 | // Split a page up into sections (lesson, exercises, ...) 5 | function splitSections(nodes) { 6 | var section = []; 7 | 8 | return _.reduce(nodes, function(sections, el) { 9 | if(el.type === 'hr') { 10 | sections.push(section); 11 | section = []; 12 | } else { 13 | section.push(el); 14 | } 15 | 16 | return sections; 17 | }, []).concat([section]); // Add remaining nodes 18 | } 19 | 20 | function isQuizNode(node) { 21 | return (/^[(\[][ x][)\]]/).test(node.text || node); 22 | } 23 | 24 | function isExercise(nodes) { 25 | var codeType = { type: 'code' }; 26 | 27 | // Number of code nodes in section 28 | var len = _.filter(nodes, codeType).length; 29 | 30 | return ( 31 | // Got 3 or 4 code blocks 32 | (len === 3 || len === 4) && 33 | // Ensure all nodes are at the end 34 | _.all(_.last(nodes, len), codeType) 35 | ); 36 | } 37 | 38 | function isQuiz(nodes) { 39 | if (nodes.length < 3) { 40 | return false; 41 | } 42 | 43 | // Support having a first paragraph block 44 | // before our series of questions 45 | var quizNodes = nodes.slice(nodes[0].type === 'paragraph' ? 1 : 0); 46 | 47 | // No questions 48 | if (!_.some(quizNodes, { type: 'blockquote_start' })) { 49 | return false; 50 | } 51 | 52 | // Check if section has list of questions 53 | // or table of questions 54 | var listIdx = _.findIndex(quizNodes, { type: 'list_item_start' }); 55 | var tableIdx = _.findIndex(quizNodes, { type: 'table' }); 56 | 57 | if( 58 | // List of questions 59 | listIdx !== -1 && isQuizNode(quizNodes[listIdx + 1]) || 60 | 61 | // Table of questions 62 | ( 63 | tableIdx !== -1 && 64 | _.every(quizNodes[tableIdx].cells[0].slice(1), isQuizNode) 65 | ) 66 | ) { 67 | return true; 68 | } 69 | 70 | return false; 71 | } 72 | 73 | // What is the type of this section 74 | function sectionType(nodes, idx) { 75 | if(isExercise(nodes)) { 76 | return 'exercise'; 77 | } else if(isQuiz(nodes)) { 78 | return 'quiz'; 79 | } 80 | 81 | return 'normal'; 82 | } 83 | 84 | // Generate a uniqueId to identify this section in our code 85 | function sectionId(section, idx) { 86 | return _.uniqueId('gitbook_'); 87 | } 88 | 89 | function lexPage(src) { 90 | // Lex file 91 | var nodes = marked.lexer(src); 92 | 93 | return _.chain(splitSections(nodes)) 94 | .map(function(section, idx) { 95 | // Detect section type 96 | section.type = sectionType(section, idx); 97 | return section; 98 | }) 99 | .map(function(section, idx) { 100 | // Give each section an ID 101 | section.id = sectionId(section, idx); 102 | return section; 103 | 104 | }) 105 | .filter(function(section) { 106 | return !_.isEmpty(section); 107 | }) 108 | .reduce(function(sections, section) { 109 | var last = _.last(sections); 110 | 111 | // Merge normal sections together 112 | if(last && last.type === section.type && last.type === 'normal') { 113 | last.push.apply(last, [{'type': 'hr'}].concat(section)); 114 | } else { 115 | // Add to list of sections 116 | sections.push(section); 117 | } 118 | 119 | return sections; 120 | }, []) 121 | .value(); 122 | } 123 | 124 | // Exports 125 | module.exports = lexPage; 126 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/bootstrap/input-groups.less: -------------------------------------------------------------------------------- 1 | // 2 | // Input groups 3 | // -------------------------------------------------- 4 | 5 | // Base styles 6 | // ------------------------- 7 | .input-group { 8 | position: relative; // For dropdowns 9 | display: table; 10 | border-collapse: separate; // prevent input groups from inheriting border styles from table cells when placed within a table 11 | 12 | // Undo padding and float of grid classes 13 | &.col { 14 | float: none; 15 | padding-left: 0; 16 | padding-right: 0; 17 | } 18 | 19 | .form-control { 20 | width: 100%; 21 | margin-bottom: 0; 22 | } 23 | } 24 | 25 | // Sizing options 26 | // 27 | // Remix the default form control sizing classes into new ones for easier 28 | // manipulation. 29 | 30 | .input-group-lg > .form-control, 31 | .input-group-lg > .input-group-addon, 32 | .input-group-lg > .input-group-btn > .btn { .input-lg(); } 33 | .input-group-sm > .form-control, 34 | .input-group-sm > .input-group-addon, 35 | .input-group-sm > .input-group-btn > .btn { .input-sm(); } 36 | 37 | 38 | // Display as table-cell 39 | // ------------------------- 40 | .input-group-addon, 41 | .input-group-btn, 42 | .input-group .form-control { 43 | display: table-cell; 44 | 45 | &:not(:first-child):not(:last-child) { 46 | border-radius: 0; 47 | } 48 | } 49 | // Addon and addon wrapper for buttons 50 | .input-group-addon, 51 | .input-group-btn { 52 | width: 1%; 53 | white-space: nowrap; 54 | vertical-align: middle; // Match the inputs 55 | } 56 | 57 | // Text input groups 58 | // ------------------------- 59 | .input-group-addon { 60 | padding: @padding-base-vertical @padding-base-horizontal; 61 | font-size: @font-size-base; 62 | font-weight: normal; 63 | line-height: 1; 64 | text-align: center; 65 | background-color: @input-group-addon-bg; 66 | border: 1px solid @input-group-addon-border-color; 67 | border-radius: @border-radius-base; 68 | 69 | // Sizing 70 | &.input-sm { 71 | padding: @padding-small-vertical @padding-small-horizontal; 72 | font-size: @font-size-small; 73 | border-radius: @border-radius-small; 74 | } 75 | &.input-lg { 76 | padding: @padding-large-vertical @padding-large-horizontal; 77 | font-size: @font-size-large; 78 | border-radius: @border-radius-large; 79 | } 80 | 81 | // Nuke default margins from checkboxes and radios to vertically center within. 82 | input[type="radio"], 83 | input[type="checkbox"] { 84 | margin-top: 0; 85 | } 86 | } 87 | 88 | // Reset rounded corners 89 | .input-group .form-control:first-child, 90 | .input-group-addon:first-child, 91 | .input-group-btn:first-child > .btn, 92 | .input-group-btn:first-child > .dropdown-toggle, 93 | .input-group-btn:last-child > .btn:not(:last-child):not(.dropdown-toggle) { 94 | .border-right-radius(0); 95 | } 96 | .input-group-addon:first-child { 97 | border-right: 0; 98 | } 99 | .input-group .form-control:last-child, 100 | .input-group-addon:last-child, 101 | .input-group-btn:last-child > .btn, 102 | .input-group-btn:last-child > .dropdown-toggle, 103 | .input-group-btn:first-child > .btn:not(:first-child) { 104 | .border-left-radius(0); 105 | } 106 | .input-group-addon:last-child { 107 | border-left: 0; 108 | } 109 | 110 | // Button input groups 111 | // ------------------------- 112 | .input-group-btn { 113 | position: relative; 114 | white-space: nowrap; 115 | } 116 | .input-group-btn > .btn { 117 | position: relative; 118 | // Jankily prevent input button groups from wrapping 119 | + .btn { 120 | margin-left: -4px; 121 | } 122 | // Bring the "active" button to the front 123 | &:hover, 124 | &:active { 125 | z-index: 2; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/bootstrap/popovers.less: -------------------------------------------------------------------------------- 1 | // 2 | // Popovers 3 | // -------------------------------------------------- 4 | 5 | 6 | .popover { 7 | position: absolute; 8 | top: 0; 9 | left: 0; 10 | z-index: @zindex-popover; 11 | display: none; 12 | max-width: @popover-max-width; 13 | padding: 1px; 14 | text-align: left; // Reset given new insertion method 15 | background-color: @popover-bg; 16 | background-clip: padding-box; 17 | border: 1px solid @popover-fallback-border-color; 18 | border: 1px solid @popover-border-color; 19 | border-radius: @border-radius-large; 20 | .box-shadow(0 5px 10px rgba(0,0,0,.2)); 21 | 22 | // Overrides for proper insertion 23 | white-space: normal; 24 | 25 | // Offset the popover to account for the popover arrow 26 | &.top { margin-top: -10px; } 27 | &.right { margin-left: 10px; } 28 | &.bottom { margin-top: 10px; } 29 | &.left { margin-left: -10px; } 30 | } 31 | 32 | .popover-title { 33 | margin: 0; // reset heading margin 34 | padding: 8px 14px; 35 | font-size: @font-size-base; 36 | font-weight: normal; 37 | line-height: 18px; 38 | background-color: @popover-title-bg; 39 | border-bottom: 1px solid darken(@popover-title-bg, 5%); 40 | border-radius: 5px 5px 0 0; 41 | } 42 | 43 | .popover-content { 44 | padding: 9px 14px; 45 | } 46 | 47 | // Arrows 48 | // 49 | // .arrow is outer, .arrow:after is inner 50 | 51 | .popover .arrow { 52 | &, 53 | &:after { 54 | position: absolute; 55 | display: block; 56 | width: 0; 57 | height: 0; 58 | border-color: transparent; 59 | border-style: solid; 60 | } 61 | } 62 | .popover .arrow { 63 | border-width: @popover-arrow-outer-width; 64 | } 65 | .popover .arrow:after { 66 | border-width: @popover-arrow-width; 67 | content: ""; 68 | } 69 | 70 | .popover { 71 | &.top .arrow { 72 | left: 50%; 73 | margin-left: -@popover-arrow-outer-width; 74 | border-bottom-width: 0; 75 | border-top-color: @popover-arrow-outer-fallback-color; // IE8 fallback 76 | border-top-color: @popover-arrow-outer-color; 77 | bottom: -@popover-arrow-outer-width; 78 | &:after { 79 | content: " "; 80 | bottom: 1px; 81 | margin-left: -@popover-arrow-width; 82 | border-bottom-width: 0; 83 | border-top-color: @popover-arrow-color; 84 | } 85 | } 86 | &.right .arrow { 87 | top: 50%; 88 | left: -@popover-arrow-outer-width; 89 | margin-top: -@popover-arrow-outer-width; 90 | border-left-width: 0; 91 | border-right-color: @popover-arrow-outer-fallback-color; // IE8 fallback 92 | border-right-color: @popover-arrow-outer-color; 93 | &:after { 94 | content: " "; 95 | left: 1px; 96 | bottom: -@popover-arrow-width; 97 | border-left-width: 0; 98 | border-right-color: @popover-arrow-color; 99 | } 100 | } 101 | &.bottom .arrow { 102 | left: 50%; 103 | margin-left: -@popover-arrow-outer-width; 104 | border-top-width: 0; 105 | border-bottom-color: @popover-arrow-outer-fallback-color; // IE8 fallback 106 | border-bottom-color: @popover-arrow-outer-color; 107 | top: -@popover-arrow-outer-width; 108 | &:after { 109 | content: " "; 110 | top: 1px; 111 | margin-left: -@popover-arrow-width; 112 | border-top-width: 0; 113 | border-bottom-color: @popover-arrow-color; 114 | } 115 | } 116 | 117 | &.left .arrow { 118 | top: 50%; 119 | right: -@popover-arrow-outer-width; 120 | margin-top: -@popover-arrow-outer-width; 121 | border-right-width: 0; 122 | border-left-color: @popover-arrow-outer-fallback-color; // IE8 fallback 123 | border-left-color: @popover-arrow-outer-color; 124 | &:after { 125 | content: " "; 126 | right: 1px; 127 | border-right-width: 0; 128 | border-left-color: @popover-arrow-color; 129 | bottom: -@popover-arrow-width; 130 | } 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/bootstrap/modals.less: -------------------------------------------------------------------------------- 1 | // 2 | // Modals 3 | // -------------------------------------------------- 4 | 5 | // .modal-open - body class for killing the scroll 6 | // .modal - container to scroll within 7 | // .modal-dialog - positioning shell for the actual modal 8 | // .modal-content - actual modal w/ bg and corners and shit 9 | 10 | // Kill the scroll on the body 11 | .modal-open { 12 | overflow: hidden; 13 | 14 | 15 | // Account for hiding of scrollbar 16 | body&, 17 | .navbar-fixed-top, 18 | .navbar-fixed-bottom { 19 | margin-right: 15px 20 | } 21 | } 22 | 23 | // Container that the modal scrolls within 24 | .modal { 25 | display: none; 26 | overflow: auto; 27 | overflow-y: scroll; 28 | position: fixed; 29 | top: 0; 30 | right: 0; 31 | bottom: 0; 32 | left: 0; 33 | z-index: @zindex-modal-background; 34 | 35 | // When fading in the modal, animate it to slide down 36 | &.fade .modal-dialog { 37 | .translate(0, -25%); 38 | .transition-transform(~"0.3s ease-out"); 39 | } 40 | &.in .modal-dialog { .translate(0, 0)} 41 | } 42 | 43 | // Shell div to position the modal with bottom padding 44 | .modal-dialog { 45 | margin-left: auto; 46 | margin-right: auto; 47 | width: auto; 48 | padding: 10px; 49 | z-index: (@zindex-modal-background + 10); 50 | } 51 | 52 | // Actual modal 53 | .modal-content { 54 | position: relative; 55 | background-color: @modal-content-bg; 56 | border: 1px solid @modal-content-fallback-border-color; //old browsers fallback (ie8 etc) 57 | border: 1px solid @modal-content-border-color; 58 | border-radius: @border-radius-large; 59 | .box-shadow(0 3px 9px rgba(0,0,0,.5)); 60 | background-clip: padding-box; 61 | // Remove focus outline from opened modal 62 | outline: none; 63 | } 64 | 65 | // Modal background 66 | .modal-backdrop { 67 | position: fixed; 68 | top: 0; 69 | right: 0; 70 | bottom: 0; 71 | left: 0; 72 | z-index: (@zindex-modal-background - 10); 73 | background-color: @modal-backdrop-bg; 74 | // Fade for backdrop 75 | &.fade { .opacity(0); } 76 | &.in { .opacity(.5); } 77 | } 78 | 79 | // Modal header 80 | // Top section of the modal w/ title and dismiss 81 | .modal-header { 82 | padding: @modal-title-padding; 83 | border-bottom: 1px solid @modal-header-border-color; 84 | min-height: (@modal-title-padding + @modal-title-line-height); 85 | } 86 | // Close icon 87 | .modal-header .close { 88 | margin-top: -2px; 89 | } 90 | 91 | // Title text within header 92 | .modal-title { 93 | margin: 0; 94 | line-height: @modal-title-line-height; 95 | } 96 | 97 | // Modal body 98 | // Where all modal content resides (sibling of .modal-header and .modal-footer) 99 | .modal-body { 100 | position: relative; 101 | padding: @modal-inner-padding; 102 | } 103 | 104 | // Footer (for actions) 105 | .modal-footer { 106 | margin-top: 15px; 107 | padding: (@modal-inner-padding - 1) @modal-inner-padding @modal-inner-padding; 108 | text-align: right; // right align buttons 109 | border-top: 1px solid @modal-footer-border-color; 110 | .clearfix(); // clear it in case folks use .pull-* classes on buttons 111 | 112 | // Properly space out buttons 113 | .btn + .btn { 114 | margin-left: 5px; 115 | margin-bottom: 0; // account for input[type="submit"] which gets the bottom margin like all other inputs 116 | } 117 | // but override that for button groups 118 | .btn-group .btn + .btn { 119 | margin-left: -1px; 120 | } 121 | // and override it for block buttons as well 122 | .btn-block + .btn-block { 123 | margin-left: 0; 124 | } 125 | } 126 | 127 | // Scale up the modal 128 | @media screen and (min-width: @screen-tablet) { 129 | 130 | .modal-dialog { 131 | left: 50%; 132 | right: auto; 133 | width: 600px; 134 | padding-top: 30px; 135 | padding-bottom: 30px; 136 | } 137 | .modal-content { 138 | .box-shadow(0 5px 15px rgba(0,0,0,.5)); 139 | } 140 | 141 | } 142 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/bootstrap/buttons.less: -------------------------------------------------------------------------------- 1 | // 2 | // Buttons 3 | // -------------------------------------------------- 4 | 5 | 6 | // Base styles 7 | // -------------------------------------------------- 8 | 9 | // Core styles 10 | .btn { 11 | display: inline-block; 12 | padding: @padding-base-vertical @padding-base-horizontal; 13 | margin-bottom: 0; // For input.btn 14 | font-size: @font-size-base; 15 | font-weight: @btn-font-weight; 16 | line-height: @line-height-base; 17 | text-align: center; 18 | vertical-align: middle; 19 | cursor: pointer; 20 | border: 1px solid transparent; 21 | border-radius: @border-radius-base; 22 | white-space: nowrap; 23 | .user-select(none); 24 | 25 | &:focus { 26 | .tab-focus(); 27 | } 28 | 29 | &:hover, 30 | &:focus { 31 | color: @btn-default-color; 32 | text-decoration: none; 33 | } 34 | 35 | &:active, 36 | &.active { 37 | outline: 0; 38 | background-image: none; 39 | .box-shadow(inset 0 3px 5px rgba(0,0,0,.125)); 40 | } 41 | 42 | &.disabled, 43 | &[disabled], 44 | fieldset[disabled] & { 45 | cursor: not-allowed; 46 | pointer-events: none; // Future-proof disabling of clicks 47 | .opacity(.65); 48 | .box-shadow(none); 49 | } 50 | 51 | } 52 | 53 | 54 | // Alternate buttons 55 | // -------------------------------------------------- 56 | 57 | .btn-default { 58 | .button-variant(@btn-default-color; @btn-default-bg; @btn-default-border); 59 | } 60 | .btn-primary { 61 | .button-variant(@btn-primary-color; @btn-primary-bg; @btn-primary-border); 62 | } 63 | // Warning appears as orange 64 | .btn-warning { 65 | .button-variant(@btn-warning-color; @btn-warning-bg; @btn-warning-border); 66 | } 67 | // Danger and error appear as red 68 | .btn-danger { 69 | .button-variant(@btn-danger-color; @btn-danger-bg; @btn-danger-border); 70 | } 71 | // Success appears as green 72 | .btn-success { 73 | .button-variant(@btn-success-color; @btn-success-bg; @btn-success-border); 74 | } 75 | // Info appears as blue-green 76 | .btn-info { 77 | .button-variant(@btn-info-color; @btn-info-bg; @btn-info-border); 78 | } 79 | 80 | 81 | // Link buttons 82 | // ------------------------- 83 | 84 | // Make a button look and behave like a link 85 | .btn-link { 86 | color: @link-color; 87 | font-weight: normal; 88 | cursor: pointer; 89 | border-radius: 0; 90 | 91 | &, 92 | &:active, 93 | &[disabled], 94 | fieldset[disabled] & { 95 | background-color: transparent; 96 | .box-shadow(none); 97 | } 98 | &, 99 | &:hover, 100 | &:focus, 101 | &:active { 102 | border-color: transparent; 103 | } 104 | &:hover, 105 | &:focus { 106 | color: @link-hover-color; 107 | text-decoration: underline; 108 | background-color: transparent; 109 | } 110 | &[disabled], 111 | fieldset[disabled] & { 112 | &:hover, 113 | &:focus { 114 | color: @btn-link-disabled-color; 115 | text-decoration: none; 116 | } 117 | } 118 | } 119 | 120 | 121 | // Button Sizes 122 | // -------------------------------------------------- 123 | 124 | .btn-lg { 125 | // line-height: ensure even-numbered height of button next to large input 126 | .button-size(@padding-large-vertical; @padding-large-horizontal; @font-size-large; @line-height-large; @border-radius-large); 127 | } 128 | .btn-sm, 129 | .btn-xs { 130 | // line-height: ensure proper height of button next to small input 131 | .button-size(@padding-small-vertical; @padding-small-horizontal; @font-size-small; @line-height-small; @border-radius-small); 132 | } 133 | .btn-xs { 134 | padding: 1px 5px; 135 | } 136 | 137 | 138 | // Block button 139 | // -------------------------------------------------- 140 | 141 | .btn-block { 142 | display: block; 143 | width: 100%; 144 | padding-left: 0; 145 | padding-right: 0; 146 | } 147 | 148 | // Vertically space out multiple block buttons 149 | .btn-block + .btn-block { 150 | margin-top: 5px; 151 | } 152 | 153 | // Specificity overrides 154 | input[type="submit"], 155 | input[type="reset"], 156 | input[type="button"] { 157 | &.btn-block { 158 | width: 100%; 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/bootstrap/panels.less: -------------------------------------------------------------------------------- 1 | // 2 | // Panels 3 | // -------------------------------------------------- 4 | 5 | 6 | // Base class 7 | .panel { 8 | margin-bottom: @line-height-computed; 9 | background-color: @panel-bg; 10 | border: 1px solid transparent; 11 | border-radius: @panel-border-radius; 12 | .box-shadow(0 1px 1px rgba(0,0,0,.05)); 13 | } 14 | 15 | // Panel contents 16 | .panel-body { 17 | padding: 15px; 18 | .clearfix(); 19 | } 20 | 21 | 22 | // List groups in panels 23 | // 24 | // By default, space out list group content from panel headings to account for 25 | // any kind of custom content between the two. 26 | 27 | .panel { 28 | > .list-group { 29 | margin-bottom: 0; 30 | 31 | .list-group-item { 32 | border-width: 1px 0; 33 | 34 | // Remove border radius for top one 35 | &:first-child { 36 | .border-top-radius(0); 37 | } 38 | // But keep it for the last one 39 | &:last-child { 40 | border-bottom: 0; 41 | } 42 | } 43 | } 44 | } 45 | // Collapse space between when there's no additional content. 46 | .panel-heading + .list-group { 47 | .list-group-item:first-child { 48 | border-top-width: 0; 49 | } 50 | } 51 | 52 | 53 | // Tables in panels 54 | // 55 | // Place a non-bordered `.table` within a panel (not within a `.panel-body`) and 56 | // watch it go full width. 57 | 58 | .panel { 59 | > .table { 60 | margin-bottom: 0; 61 | } 62 | > .panel-body + .table { 63 | border-top: 1px solid @table-border-color; 64 | } 65 | } 66 | 67 | 68 | // Optional heading 69 | .panel-heading { 70 | padding: 10px 15px; 71 | border-bottom: 1px solid transparent; 72 | .border-top-radius(@panel-border-radius - 1); 73 | } 74 | 75 | // Within heading, strip any `h*` tag of it's default margins for spacing. 76 | .panel-title { 77 | margin-top: 0; 78 | margin-bottom: 0; 79 | font-size: ceil((@font-size-base * 1.125)); 80 | > a { 81 | color: inherit; 82 | } 83 | } 84 | 85 | // Optional footer (stays gray in every modifier class) 86 | .panel-footer { 87 | padding: 10px 15px; 88 | background-color: @panel-footer-bg; 89 | border-top: 1px solid @panel-inner-border; 90 | .border-bottom-radius(@panel-border-radius - 1); 91 | } 92 | 93 | 94 | // Collapsable panels (aka, accordion) 95 | // 96 | // Wrap a series of panels in `.panel-group` to turn them into an accordion with 97 | // the help of our collapse JavaScript plugin. 98 | 99 | .panel-group { 100 | // Tighten up margin so it's only between panels 101 | .panel { 102 | margin-bottom: 0; 103 | border-radius: @panel-border-radius; 104 | overflow: hidden; // crop contents when collapsed 105 | + .panel { 106 | margin-top: 5px; 107 | } 108 | } 109 | 110 | .panel-heading { 111 | border-bottom: 0; 112 | + .panel-collapse .panel-body { 113 | border-top: 1px solid @panel-inner-border; 114 | } 115 | } 116 | .panel-footer { 117 | border-top: 0; 118 | + .panel-collapse .panel-body { 119 | border-bottom: 1px solid @panel-inner-border; 120 | } 121 | } 122 | 123 | // New subcomponent for wrapping collapsable content for proper animations 124 | .panel-collapse { 125 | 126 | } 127 | } 128 | 129 | 130 | // Contextual variations 131 | .panel-default { 132 | .panel-variant(@panel-default-border; @panel-default-text; @panel-default-heading-bg; @panel-default-border); 133 | } 134 | .panel-primary { 135 | .panel-variant(@panel-primary-border; @panel-primary-text; @panel-primary-heading-bg; @panel-primary-border); 136 | } 137 | .panel-success { 138 | .panel-variant(@panel-success-border; @panel-success-text; @panel-success-heading-bg; @panel-success-border); 139 | } 140 | .panel-warning { 141 | .panel-variant(@panel-warning-border; @panel-warning-text; @panel-warning-heading-bg; @panel-warning-border); 142 | } 143 | .panel-danger { 144 | .panel-variant(@panel-danger-border; @panel-danger-text; @panel-danger-heading-bg; @panel-danger-border); 145 | } 146 | .panel-info { 147 | .panel-variant(@panel-info-border; @panel-info-text; @panel-info-heading-bg; @panel-info-border); 148 | } 149 | -------------------------------------------------------------------------------- /theme/stylesheets/book/font-settings.less: -------------------------------------------------------------------------------- 1 | .book-header{ 2 | #font-settings-wrapper{ 3 | position:relative; 4 | .dropdown-menu{ 5 | background-color:@header-background; 6 | border-color:@sidebar-divider-color; 7 | padding: 0px; 8 | 9 | .dropdown-caret{ 10 | position: absolute; 11 | top: 14px; 12 | left: -8px; 13 | width: 10px; 14 | height: 18px; 15 | float: left; 16 | overflow: hidden; 17 | .caret-outer{ 18 | position: absolute; 19 | border-bottom: 9px solid transparent; 20 | border-top: 9px solid transparent; 21 | border-right: 9px solid rgba(0,0,0,0.1); 22 | height: auto; 23 | left: 0; 24 | top: 0; 25 | width: auto; 26 | display: inline-block; 27 | margin-left: -1px; 28 | } 29 | .caret-inner{ 30 | position: absolute; 31 | display: inline-block; 32 | margin-left: -1px; 33 | top: 0; 34 | left: 1px; 35 | border-bottom: 9px solid transparent; 36 | border-top: 9px solid transparent; 37 | border-right: 9px solid @header-background; 38 | } 39 | } 40 | button{ 41 | border: 0; 42 | background-color:transparent; 43 | color:@header-button-color; 44 | &:hover{ 45 | color:@header-button-hover-color; 46 | background-color:@header-button-hover-background; 47 | } 48 | } 49 | #enlarge-font-size{ 50 | width: 50%; 51 | font-size:1.4em; 52 | } 53 | #reduce-font-size{ 54 | width: 50.5%; 55 | font-size:1em; 56 | } 57 | .btn-group-xs{ 58 | .btn{ 59 | width: 33.7%; 60 | padding: initial; 61 | } 62 | } 63 | .list-group{ 64 | margin: 0px 0; 65 | 66 | .list-group-item{ 67 | cursor:pointer; 68 | background-color:transparent; 69 | border-color: @sidebar-divider-color; 70 | border-width: 1px 0 !important; 71 | 72 | &:hover{ 73 | color:@header-button-hover-color; 74 | background-color:@header-button-hover-background !important; 75 | } 76 | &.active{ 77 | color:@header-button-hover-color; 78 | background-color:@header-button-hover-background !important; 79 | } 80 | } 81 | } 82 | &.open{ 83 | display:block; 84 | } 85 | } 86 | } 87 | } 88 | 89 | /* 90 | * Theme 1 91 | */ 92 | 93 | .color-theme-1{ 94 | #font-settings-wrapper{ 95 | .dropdown-menu{ 96 | background-color:@sidebar-background-1; 97 | border-color:@sidebar-divider-color-1; 98 | .dropdown-caret .caret-inner{ 99 | border-right: 9px solid @sidebar-background-1; 100 | } 101 | button{ 102 | color:@header-button-color-1; 103 | &:hover{ 104 | color:@header-button-hover-color-1; 105 | background-color:@header-button-hover-background-1; 106 | } 107 | } 108 | .list-group{ 109 | .list-group-item{ 110 | border-color:@sidebar-divider-color-1; 111 | &:hover{ 112 | color:@header-button-hover-color-1; 113 | background-color:@header-button-hover-background-1 !important; 114 | } 115 | &.active{ 116 | color:@header-button-hover-color-1; 117 | background-color:@header-button-hover-background-1 !important; 118 | } 119 | } 120 | } 121 | } 122 | } 123 | } 124 | 125 | /* 126 | * Theme 2 127 | */ 128 | 129 | .color-theme-2{ 130 | #font-settings-wrapper{ 131 | .dropdown-menu{ 132 | background-color:@sidebar-background-2; 133 | border-color:@sidebar-divider-color-2; 134 | .dropdown-caret .caret-inner{ 135 | border-right: 9px solid @sidebar-background-2; 136 | } 137 | button{ 138 | color:@header-button-color-2; 139 | &:hover{ 140 | color:@header-button-hover-color-2; 141 | background-color:@header-button-hover-background-2; 142 | } 143 | } 144 | .list-group{ 145 | .list-group-item{ 146 | border-color:@sidebar-divider-color-2; 147 | &:hover{ 148 | color:@header-button-hover-color-2; 149 | background-color:@header-button-hover-background-2 !important; 150 | } 151 | &.active{ 152 | color:@header-button-hover-color-2; 153 | background-color:@header-button-hover-background-2 !important; 154 | } 155 | } 156 | } 157 | } 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /theme/javascript/core/font-settings.js: -------------------------------------------------------------------------------- 1 | define([ 2 | "jQuery", 3 | "utils/storage" 4 | ], function($, storage) { 5 | var fontState; 6 | 7 | var THEMES = { 8 | "white": 0, 9 | "sepia": 1, 10 | "night": 2 11 | }; 12 | 13 | var FAMILY = { 14 | "serif": 0, 15 | "sans": 1 16 | }; 17 | 18 | var togglePopover = function(e) { 19 | var $dropdown = $("#font-settings-wrapper .dropdown-menu"); 20 | 21 | $dropdown.toggleClass("open"); 22 | e.stopPropagation(); 23 | e.preventDefault(); 24 | }; 25 | 26 | var closePopover = function(e) { 27 | var $dropdown = $("#font-settings-wrapper .dropdown-menu"); 28 | 29 | $dropdown.removeClass("open"); 30 | }; 31 | 32 | var enlargeFontSize = function(e){ 33 | var $bookBody = $(".book-body"); 34 | 35 | if (fontState.size < 4){ 36 | $bookBody.toggleClass("font-size-"+fontState.size, false); 37 | fontState.size++; 38 | 39 | $bookBody.toggleClass("font-size-"+fontState.size, true); 40 | fontState.save(); 41 | } 42 | }; 43 | 44 | var reduceFontSize = function(e){ 45 | var $bookBody = $(".book-body"); 46 | 47 | if (fontState.size > 0){ 48 | $bookBody.toggleClass("font-size-"+fontState.size); 49 | fontState.size--; 50 | 51 | $bookBody.toggleClass("font-size-"+fontState.size); 52 | fontState.save(); 53 | } 54 | }; 55 | 56 | var changeFontFamily = function(){ 57 | var $bookBody = $(".book-body"); 58 | var index = $(this).data("font"); 59 | 60 | $bookBody.toggleClass("font-family-"+fontState.family); 61 | $(".font-settings .font-family-list li:nth-child("+(fontState.family+1)+")") 62 | .removeClass("active"); 63 | 64 | fontState.family = index; 65 | $bookBody.toggleClass("font-family-"+fontState.family); 66 | $(this).addClass("active"); 67 | fontState.save(); 68 | }; 69 | 70 | var changeColorTheme = function(){ 71 | var $book = $(".book"); 72 | var index = $(this).data("theme"); 73 | 74 | if (fontState.theme !== 0) 75 | $book.removeClass("color-theme-"+fontState.theme); 76 | 77 | fontState.theme = index; 78 | if (fontState.theme !== 0) 79 | $book.addClass("color-theme-"+fontState.theme); 80 | 81 | fontState.save(); 82 | }; 83 | 84 | var init = function(config) { 85 | var $toggle, $bookBody, $dropdown, $book; 86 | 87 | //Find DOM elements. 88 | $book = $(".book"); 89 | $toggle = $(".book-header .toggle-font-settings"); 90 | $dropdown = $("#font-settings-wrapper .dropdown-menu"); 91 | $bookBody = $(".book-body"); 92 | 93 | // Instantiate font state object 94 | fontState = storage.get("fontState", { 95 | size: config.size || 1, 96 | family: FAMILY[config.family || "serif"], 97 | theme: THEMES[config.theme || "white"] 98 | }); 99 | fontState.save = function(){ 100 | storage.set("fontState",fontState); 101 | }; 102 | 103 | $bookBody.addClass("font-size-"+fontState.size); 104 | $bookBody.addClass("font-family-"+fontState.family); 105 | 106 | $(".font-settings .font-family-list li:nth-child("+(fontState.family+1)+")").addClass("active"); 107 | 108 | if(fontState.theme !== 0) 109 | $book.addClass("color-theme-"+fontState.theme); 110 | 111 | //Add event listeners 112 | $(document).on('click', "#enlarge-font-size", enlargeFontSize); 113 | $(document).on('click', "#reduce-font-size", reduceFontSize); 114 | 115 | $(document).on('click', "#font-settings-wrapper .font-family-list li", changeFontFamily); 116 | $(document).on('click', "#font-settings-wrapper .color-theme-list button", changeColorTheme); 117 | 118 | $(document).on('click', ".book-header .toggle-font-settings", togglePopover); 119 | $(document).on('click', "#font-settings-wrapper .dropdown-menu", function(e){ e.stopPropagation(); }); 120 | $(document).on("click", closePopover); 121 | }; 122 | 123 | return { 124 | init: init 125 | } 126 | }); -------------------------------------------------------------------------------- /theme/assets/jsrepl/engines/javascript-default.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright Joyent, Inc. and other Node contributors. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a 6 | copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to permit 10 | persons to whom the Software is furnished to do so, subject to the 11 | following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 19 | NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 20 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 21 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 22 | USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | Original at: https://github.com/joyent/node/blob/master/lib/util.js 25 | */ 26 | (function(){function o(c){return c instanceof Array||Array.isArray(c)||c&&c!==Object.prototype&&o(c.__proto__)}function p(c){return c instanceof RegExp||typeof c==="function"&&c.constructor.name==="RegExp"&&c.compile&&c.test&&c.exec&&(""+c).match(/^\/.*\/[gim]{0,3}$/)}var q=80,l=function(c,h,b,f){function m(a,c){switch(typeof a){case "undefined":return d("undefined","undefined");case "string":var b="'"+JSON.stringify(a).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return d(b,"string"); 27 | case "number":return d(""+a,"number");case "boolean":return d(""+a,"boolean")}if(a===null)return d("null","null");var f=Object.keys(a),i=h?Object.getOwnPropertyNames(a):f;if(typeof a==="function"&&i.length===0)return p(a)?d(""+a,"regexp"):d("[Function"+(a.name?": "+a.name:"")+"]","special");if(a instanceof Date&&i.length===0)return d(a.toUTCString(),"date");var j,l;o(a)?(l="Array",b=["[","]"]):(l="Object",b=["{","}"]);typeof a==="function"?(j=a.name?": "+a.name:"",j=p(a)?" "+a:" [Function"+j+"]"): 28 | j="";a instanceof Date&&(j=" "+a.toUTCString());if(i.length===0)return b[0]+j+b[1];if(c<0)return p(a)?d(""+a,"regexp"):d("[Object]","special");k.push(a);i=i.map(function(b){var e,g;a.__lookupGetter__&&(a.__lookupGetter__(b)?g=a.__lookupSetter__(b)?d("[Getter/Setter]","special"):d("[Getter]","special"):a.__lookupSetter__(b)&&(g=d("[Setter]","special")));f.indexOf(b)<0&&(e="["+b+"]");g||(k.indexOf(a[b])<0?(g=c===null?m(a[b]):m(a[b],c-1),g.indexOf("\n")>-1&&(g=o(a)?g.split("\n").map(function(a){return" "+ 29 | a}).join("\n").substr(2):"\n"+g.split("\n").map(function(a){return" "+a}).join("\n"))):g=d("[Circular]","special"));if(typeof e==="undefined"){if(l==="Array"&&b.match(/^\d+$/))return g;e=JSON.stringify(""+b);e.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(e=e.substr(1,e.length-2),e=d(e,"name")):(e=e.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),e=d(e,"string"))}return e+": "+g});k.pop();var n=0;return i=i.reduce(function(a,b){n++;b.indexOf("\n")>=0&&n++;return a+b.length+1},0)>q?b[0]+ 30 | (j===""?"":j+"\n ")+" "+i.join(",\n ")+" "+b[1]:b[0]+j+" "+i.join(", ")+" "+b[1]}var k=[],d=function(a,b){var c={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},d={special:"cyan",number:"blue","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"}[b];return d?"\u001b["+c[d][0]+"m"+a+"\u001b["+c[d][1]+"m":a};f||(d=function(a){return a}); 31 | return m(c,typeof b==="undefined"?2:b)},r=/%[sdj%]/g,s=function(c){if(typeof c!=="string"){for(var h=[],b=0;b=m)return c;switch(c){case "%s":return String(f[b++]);case "%d":return Number(f[b++]);case "%j":return JSON.stringify(f[b++]);case "%%":return"%";default:return c}}),k=f[b];b'; 85 | return out; 86 | }; 87 | 88 | GitBookRenderer.prototype.image = function(href, title, text) { 89 | // Our "fixed" href 90 | var _href = href; 91 | 92 | // Parsed version of the url 93 | var parsed = url.parse(href); 94 | 95 | // Options 96 | var o = this._extra_options; 97 | 98 | // Relative image, rewrite it depending output 99 | if(links.isRelative(href) && o && o.dir && o.outdir) { 100 | // o.dir: directory parent of the file currently in rendering process 101 | // o.outdir: directory parent from the html output 102 | 103 | _href = links.toAbsolute(_href, o.dir, o.outdir); 104 | } 105 | 106 | return GitBookRenderer.super_.prototype.image.call(this, _href, title, text); 107 | }; 108 | 109 | GitBookRenderer.prototype.tablerow = function(content) { 110 | this.quizRowId += 1; 111 | return GitBookRenderer.super_.prototype.tablerow(content); 112 | }; 113 | 114 | var fieldRegex = /^([(\[])([ x])[\])]/; 115 | GitBookRenderer.prototype._createCheckboxAndRadios = function(text) { 116 | var match = fieldRegex.exec(text); 117 | if (!match) { 118 | return text; 119 | } 120 | var quizIdentifier = 'quiz-row-' + this.id + '-' + this.quizRowId + '-' + this.quizIndex++; 121 | var field = "" : "'/>"; 124 | var splittedText = text.split(fieldRegex); 125 | var length = splittedText.length; 126 | var label = ''; 127 | return text.replace(fieldRegex, field).replace(splittedText[length - 1], label); 128 | } 129 | 130 | GitBookRenderer.prototype.tablecell = function(content, flags) { 131 | return GitBookRenderer.super_.prototype.tablecell(this._createCheckboxAndRadios(content), flags); 132 | }; 133 | 134 | GitBookRenderer.prototype.listitem = function(text) { 135 | return GitBookRenderer.super_.prototype.listitem(this._createCheckboxAndRadios(text)); 136 | }; 137 | 138 | // Exports 139 | module.exports = GitBookRenderer; 140 | -------------------------------------------------------------------------------- /theme/stylesheets/vendors/bootstrap/carousel.less: -------------------------------------------------------------------------------- 1 | // 2 | // Carousel 3 | // -------------------------------------------------- 4 | 5 | 6 | // Wrapper for the slide container and indicators 7 | .carousel { 8 | position: relative; 9 | } 10 | 11 | .carousel-inner { 12 | position: relative; 13 | overflow: hidden; 14 | width: 100%; 15 | 16 | > .item { 17 | display: none; 18 | position: relative; 19 | .transition(.6s ease-in-out left); 20 | 21 | // Account for jankitude on images 22 | > img, 23 | > a > img { 24 | .img-responsive(); 25 | line-height: 1; 26 | } 27 | } 28 | 29 | > .active, 30 | > .next, 31 | > .prev { display: block; } 32 | 33 | > .active { 34 | left: 0; 35 | } 36 | 37 | > .next, 38 | > .prev { 39 | position: absolute; 40 | top: 0; 41 | width: 100%; 42 | } 43 | 44 | > .next { 45 | left: 100%; 46 | } 47 | > .prev { 48 | left: -100%; 49 | } 50 | > .next.left, 51 | > .prev.right { 52 | left: 0; 53 | } 54 | 55 | > .active.left { 56 | left: -100%; 57 | } 58 | > .active.right { 59 | left: 100%; 60 | } 61 | 62 | } 63 | 64 | // Left/right controls for nav 65 | // --------------------------- 66 | 67 | .carousel-control { 68 | position: absolute; 69 | top: 0; 70 | left: 0; 71 | bottom: 0; 72 | width: @carousel-control-width; 73 | .opacity(@carousel-control-opacity); 74 | font-size: @carousel-control-font-size; 75 | color: @carousel-control-color; 76 | text-align: center; 77 | text-shadow: @carousel-text-shadow; 78 | // We can't have this transition here because webkit cancels the carousel 79 | // animation if you trip this while in the middle of another animation. 80 | 81 | // Set gradients for backgrounds 82 | &.left { 83 | #gradient > .horizontal(@start-color: rgba(0,0,0,.5); @end-color: rgba(0,0,0,.0001)); 84 | } 85 | &.right { 86 | left: auto; 87 | right: 0; 88 | #gradient > .horizontal(@start-color: rgba(0,0,0,.0001); @end-color: rgba(0,0,0,.5)); 89 | } 90 | 91 | // Hover/focus state 92 | &:hover, 93 | &:focus { 94 | color: @carousel-control-color; 95 | text-decoration: none; 96 | .opacity(.9); 97 | } 98 | 99 | // Toggles 100 | .icon-prev, 101 | .icon-next, 102 | .glyphicon-chevron-left, 103 | .glyphicon-chevron-right { 104 | position: absolute; 105 | top: 50%; 106 | left: 50%; 107 | z-index: 5; 108 | display: inline-block; 109 | } 110 | .icon-prev, 111 | .icon-next { 112 | width: 20px; 113 | height: 20px; 114 | margin-top: -10px; 115 | margin-left: -10px; 116 | font-family: serif; 117 | } 118 | 119 | .icon-prev { 120 | &:before { 121 | content: '\2039';// SINGLE LEFT-POINTING ANGLE QUOTATION MARK (U+2039) 122 | } 123 | } 124 | .icon-next { 125 | &:before { 126 | content: '\203a';// SINGLE RIGHT-POINTING ANGLE QUOTATION MARK (U+203A) 127 | } 128 | } 129 | } 130 | 131 | // Optional indicator pips 132 | // 133 | // Add an unordered list with the following class and add a list item for each 134 | // slide your carousel holds. 135 | 136 | .carousel-indicators { 137 | position: absolute; 138 | bottom: 10px; 139 | left: 50%; 140 | z-index: 15; 141 | width: 60%; 142 | margin-left: -30%; 143 | padding-left: 0; 144 | list-style: none; 145 | text-align: center; 146 | 147 | li { 148 | display: inline-block; 149 | width: 10px; 150 | height: 10px; 151 | margin: 1px; 152 | text-indent: -999px; 153 | border: 1px solid @carousel-indicator-border-color; 154 | border-radius: 10px; 155 | cursor: pointer; 156 | } 157 | .active { 158 | margin: 0; 159 | width: 12px; 160 | height: 12px; 161 | background-color: @carousel-indicator-active-bg; 162 | } 163 | } 164 | 165 | // Optional captions 166 | // ----------------------------- 167 | // Hidden by default for smaller viewports 168 | .carousel-caption { 169 | position: absolute; 170 | left: 15%; 171 | right: 15%; 172 | bottom: 20px; 173 | z-index: 10; 174 | padding-top: 20px; 175 | padding-bottom: 20px; 176 | color: @carousel-caption-color; 177 | text-align: center; 178 | text-shadow: @carousel-text-shadow; 179 | & .btn { 180 | text-shadow: none; // No shadow for button elements in carousel-caption 181 | } 182 | } 183 | 184 | 185 | // Scale up controls for tablets and up 186 | @media screen and (min-width: @screen-tablet) { 187 | 188 | // Scale up the controls a smidge 189 | .carousel-control .icon-prev, 190 | .carousel-control .icon-next { 191 | width: 30px; 192 | height: 30px; 193 | margin-top: -15px; 194 | margin-left: -15px; 195 | font-size: 30px; 196 | } 197 | 198 | // Show and left align the captions 199 | .carousel-caption { 200 | left: 20%; 201 | right: 20%; 202 | padding-bottom: 30px; 203 | } 204 | 205 | // Move up the indicators 206 | .carousel-indicators { 207 | bottom: 20px; 208 | } 209 | } 210 | --------------------------------------------------------------------------------