mirror of
https://github.com/ethauvin/kobalt-doc.git
synced 2025-04-25 03:57:11 -07:00
Automated table of contents.
This commit is contained in:
parent
dbc8dab834
commit
38150edf33
4 changed files with 100 additions and 66 deletions
|
@ -75,7 +75,7 @@
|
|||
|
||||
<div class="col-md-9">
|
||||
|
||||
<h2 id="downloading">Downloading and installing Kobalt</h3>
|
||||
<h2 class="section" id="downloading">Downloading and installing Kobalt</h3>
|
||||
|
||||
<p>
|
||||
<a href="https://github.com/cbeust/kobalt/releases/latest">Download the zip file</a> then unzip it in a location we'll call <code>KOBALT_HOME</code>:
|
||||
|
@ -116,9 +116,9 @@ If your project follows a regular build structure (e.g. Maven's hierarchy), this
|
|||
|
||||
As of this writing, Kobalt supports Java and Kotlin projects.
|
||||
|
||||
<h2 id="structure">Structure of a build file</h2>
|
||||
<h2 class="section" id="structure">Structure of a build file</h2>
|
||||
|
||||
<h3 id="general-concepts">General concepts</h3>
|
||||
<h3 class="section" indent=".." id="general-concepts">General concepts</h3>
|
||||
|
||||
<p>
|
||||
The build file is typically called <code>Built.kt</code> and it is a valid Kotlin file. Typically, it contains imports, the declaration of one or more projects and the declaration of additional configurations (e.g. packaging, publishing, etc...). Since it's a Kotlin file, it can also contain any class or function you need:
|
||||
|
@ -145,7 +145,7 @@ Here are a few noteworthy details about this small build file:
|
|||
<li>The functions <code>kotlinProject</code> and <code>homeDir</code> are supplied by Kobalt and are sometimes referred to as "directives"
|
||||
</ul>
|
||||
|
||||
<h3 id="directives">Directives</h3>
|
||||
<h3 class="section" indent=".." id="directives">Directives</h3>
|
||||
|
||||
<p>
|
||||
Now that we have declared a project, we can use it to configure additional steps of our build, such as the assembling it (creating jar and other files:
|
||||
|
@ -192,7 +192,7 @@ Our jar file is now declared to be a "fat jar" (which means it will include all
|
|||
The zip directive follows a similar structure, although here we are specifying which file we want to include. For more details on the <code>packaging</code> plug-in, please see its documentation.
|
||||
</p>
|
||||
|
||||
<h3>Dependencies</h3>
|
||||
<h3 class="section" indent=".." id="dependencies">Dependencies</h3>
|
||||
|
||||
<p>
|
||||
You can declare compile and test dependencies as follows:
|
||||
|
@ -209,7 +209,7 @@ dependenciesTest {
|
|||
}
|
||||
</pre>
|
||||
|
||||
<h2 id="maven-repos">Maven repos</h2>
|
||||
<h2 class="section" id="maven-repos">Maven repos</h2>
|
||||
|
||||
<p>
|
||||
Kobalt already knows the location of the most popular Maven repos (Maven Central, JCenter, JBoss) but you can add repos with the <code>repos()</code> directive:
|
||||
|
@ -219,7 +219,7 @@ Kobalt already knows the location of the most popular Maven repos (Maven Central
|
|||
val repos = repos("https://dl.bintray.com/cbeust/maven/")
|
||||
</pre>
|
||||
|
||||
<h2 id="using-plug-ins">Using plug-ins</h2>
|
||||
<h2 class="section" id="using-plug-ins">Using plug-ins</h2>
|
||||
|
||||
<p>
|
||||
Kobalt comes with a few preconfigured plug-ins but you will want to include external ones as well, which can be downloaded either from a Maven repository (Sonatype, JCenter, ...) or from a local file.
|
||||
|
@ -276,7 +276,7 @@ $ ./kobaltw --tasks
|
|||
|
||||
Notice the new <code>"coverage"</code> task, provided by the plug-in <code>kobalt-example-plugin</code> that we just included. With the simple action of declaring the plug-in, it is now fully loaded and available right away. Of course, such plug-ins can allow or require additional configuration with their own directives. Please read the plug-in developer documentation for more details.
|
||||
|
||||
<h2 id="multiple-projects">Multiple projects</h2>
|
||||
<h2 class="section" id="multiple-projects">Multiple projects</h2>
|
||||
|
||||
<p>
|
||||
You can specify more than one project in a build file, simply by declaring them:
|
||||
|
@ -309,7 +309,7 @@ You can also run tasks for a specific project only as follows:
|
|||
|
||||
This will run the <code>assemble</code> task only for the <code>p2</code>, instead of running it for all projects.
|
||||
|
||||
<h2 id="command-line">Command line</h2>
|
||||
<h2 class="section" id="command-line">Command line</h2>
|
||||
|
||||
<p>
|
||||
Here are the options that you can pass to <code>./kobaltw</code>:
|
||||
|
@ -385,7 +385,7 @@ New versions found:
|
|||
</table>
|
||||
|
||||
|
||||
<h2 id="publishing">Publishing</h2>
|
||||
<h2 class="section" id="publishing">Publishing</h2>
|
||||
|
||||
<p>
|
||||
Kobalt supports JCenter natively so you can upload your project and make it available on JCenter very easily.
|
||||
|
@ -427,11 +427,11 @@ Now, all you need to do is to upload your package:
|
|||
./kobaltw uploadJcenter
|
||||
</pre>
|
||||
|
||||
<h2 id="writing-a-plug-in">Writing a plug-in</h2>
|
||||
<h2 class="section" id="writing-a-plug-in">Writing a plug-in</h2>
|
||||
|
||||
A good starting point to write a plug-in is the <a href="https://github.com/cbeust/kobalt-line-count">kobalt-line-count project</a>, which shows a minimalistic plug-in.
|
||||
|
||||
<h3 id="building">Building</h3>
|
||||
<h3 class="section" indent=".." id="building">Building</h3>
|
||||
|
||||
You only need to do two things to build a Kobalt plug-in:
|
||||
|
||||
|
@ -455,7 +455,7 @@ val p = packaging(examplePlugin) {
|
|||
}
|
||||
</pre>
|
||||
|
||||
<h3 id="implementing">Implementing</h3>
|
||||
<h3 class="section" indent=".." id="implementing">Implementing</h3>
|
||||
|
||||
A plug-in typically has three components:
|
||||
|
||||
|
@ -465,7 +465,7 @@ A plug-in typically has three components:
|
|||
<li>Specifying directives (functions that will be used from the build file).
|
||||
</ul>
|
||||
|
||||
<h3 id="base-plugin">BasePlugin</h3>
|
||||
<h3 class="section" indent=".." id="base-plugin">BasePlugin</h3>
|
||||
|
||||
<p>
|
||||
The main class of your plugin extends <code>BasePlugin</code> and implements its <code>apply()</code> method and <code>name</code> variable:
|
||||
|
@ -481,7 +481,7 @@ public class ExamplePlugin : BasePlugin() {
|
|||
}
|
||||
</pre>
|
||||
|
||||
<h3 id="plugin-tasks">Plugin tasks</h3>
|
||||
<h3 class="section" indent=".." id="plugin-tasks">Plugin tasks</h3>
|
||||
|
||||
<p>
|
||||
Next, you can declare tasks with the <code>@Task</code> annotation:
|
||||
|
@ -503,7 +503,7 @@ public fun coverage(project: Project): TaskResult {
|
|||
<li><code>runAfter</code> and <code>runBefore</code> let you specify the dependencies of your task. In this example plug-in, we want to calculate the coverage of the project so it makes sense to run after the <code>"compile"</code> task.
|
||||
</ul>
|
||||
|
||||
<h3 id="plugin-directives">Directives</h3>
|
||||
<h3 class="section" indent=".." id="plugin-directives">Directives</h3>
|
||||
|
||||
<p>
|
||||
Finally, you need to define functions that can be used from the build file (directives). You are encouraged to use the <a href="https://confluence.jetbrains.com/display/Kotlin/Type-safe+Groovy-style+builders">Kotlin DSL approach</a> to expose these functions so that the build file syntax can remain consistent. Typically, these functions will update data that your tasks can then use to do their job.
|
||||
|
@ -557,7 +557,7 @@ val p = kotlinProject {
|
|||
}
|
||||
</pre>
|
||||
|
||||
<h2 id="sources">Sources and license</h2>
|
||||
<h2 class="section" id="sources">Sources and license</h2>
|
||||
|
||||
<p>
|
||||
Kobalt is <a href="https://github.com/cbeust/kobalt/blob/master/LICENSE.txt">licensed under Apache 2.0</a> and is <a href="http://github.com/cbeust/kobalt">currently hosted on github.</a>
|
||||
|
@ -583,41 +583,19 @@ If you are interested in discussing Kobalt related topics with other fellow user
|
|||
</div>
|
||||
|
||||
|
||||
<!-- Table of contents -->
|
||||
<div class="col-md-3">
|
||||
<ul class="nav">
|
||||
<li><a href="#downloading">Downloading and installing</a>
|
||||
<li><a href="#structure">Structure of a build file</a>
|
||||
<ul>
|
||||
<li><a href="#general-concepts">General concepts</a>
|
||||
<li><a href="#directives">Directives</a>
|
||||
<li><a href="#dependencies">Dependencies</a>
|
||||
</ul>
|
||||
<li><a href="#maven-repos">Maven repos</a>
|
||||
<li><a href="#using-plug-ins">Using plug-ins</a>
|
||||
<li><a href="#publishing">Publishing</a>
|
||||
<li><a href="#multiple-projects">Multiple projects</a>
|
||||
<li><a href="#command-line">Command line arguments</a>
|
||||
<li><a href="#writing-a-plug-in">Writing a plug-in</a>
|
||||
<ul>
|
||||
<li><a href="#building">Building</a>
|
||||
<li><a href="#implemeting">Implementing</a>
|
||||
<li><a href="#base-plugin"><code>BasePlugin</code></a>
|
||||
<li><a href="#plugin-tasks">Plugin tasks</a>
|
||||
<li><a href="#plugin-directives">Directives
|
||||
</ul>
|
||||
<li><a href="#sources">Sources</a>
|
||||
<li><a href="#discuss">Discuss Kobalt</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div> <!-- /container -->
|
||||
<!-- Table of contents -->
|
||||
<div class="col-md-3" id="table-of-contents">
|
||||
</div>
|
||||
</div> <!-- /container -->
|
||||
|
||||
<!-- Bootstrap core JavaScript
|
||||
================================================== -->
|
||||
<!-- Placed at the end of the document so the pages load faster -->
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
|
||||
<script src="../bootstrap/dist/js/bootstrap.min.js"></script>
|
||||
<script src="../bootstrap/dist/js/bootstrap.min.js"></script>
|
||||
<script src="../js/toc.js"></script>
|
||||
<script>generateToc();</script>
|
||||
|
||||
<!--
|
||||
<script src="../bootstrap/dist/js/docs.min.js"></script>
|
||||
-->
|
||||
|
|
|
@ -69,9 +69,7 @@
|
|||
<!-- Main content -->
|
||||
<div class="col-md-9">
|
||||
|
||||
<h2 id="overview">Overview</h2>
|
||||
|
||||
<p>
|
||||
<h2 class="section" id="overview">Overview</h2>
|
||||
Kobalt is a build system heavily inspired from Gradle and entirely written in Kotlin. It's focused on offering an intuitive DSL and plug-in architecture, fast builds and build file auto completion from your favorite IDE.
|
||||
</p>
|
||||
|
||||
|
@ -106,7 +104,7 @@ val j = jcenter(jcommander) {
|
|||
}
|
||||
</pre>
|
||||
|
||||
<h2 id="design-goals">Design goals</h2>
|
||||
<h2 class="section" id="design-goals">Design goals</h2>
|
||||
|
||||
<ul>
|
||||
<li>Completely written in Kotlin: core, plug-ins and build files.
|
||||
|
@ -119,7 +117,7 @@ val j = jcenter(jcommander) {
|
|||
<li>An agnostic build tool. Kobalt can be used to build Kotlin and Java projects today but it's capable to build anything: any language (JVM or not) or platform (Android, Spring, ...).
|
||||
</ul>
|
||||
|
||||
<h2 id="why-kobalt">Why Kobalt?</h2>
|
||||
<h2 class="section" id="why-kobalt">Why Kobalt?</h2>
|
||||
|
||||
<p>
|
||||
As of this writing (October 2015), Kobalt is in alpha and changing a lot so I am mostly interested in getting the attention of developers who are curious about:
|
||||
|
@ -139,7 +137,7 @@ Kobalt is complete enough to build three of my personal projects (<a href="https
|
|||
|
||||
With this disclaimer, why did I decide to write Kobalt?
|
||||
|
||||
<h3>1. Scratching an itch</h3>
|
||||
<h3 class="section" indent="..">1. Scratching an itch</h3>
|
||||
|
||||
<p>
|
||||
I give a lot of credit to Gradle for having open a brand new avenue in build tools but despite all its power and flexibility and the fact that I've used Gradle for more than five years, I've never really felt comfortable or fluent with it. Even today, I regularly find myself spending a lot of time on StackOverflow whenever I need to do something a bit out of the ordinary with my Gradle builds.
|
||||
|
@ -154,19 +152,19 @@ I suspect a part of it is due to Groovy which, even though it started gaining so
|
|||
<li>Building is slow and hard to diagnose because of Gradle's mixed Java/Groovy code base.
|
||||
</ul>
|
||||
|
||||
<h3>2. An experiment</h3>
|
||||
<h3 class="section" indent="..">2. An experiment</h3>
|
||||
|
||||
<p>
|
||||
I wanted to see for myself if my discomfort with Gradle was justified or if, by trying to write a build tool myself, I would end up with a very similar tool with similar strengths and weaknesses. I still haven't made up my mind about this but I will certainly by the time Kobalt reaches 1.0.
|
||||
</p>
|
||||
|
||||
<h3>3. A proof of concept</h3>
|
||||
<h3 class="section" indent="..">3. A proof of concept</h3>
|
||||
|
||||
<p>
|
||||
I have been a fervent believer that there is nothing that dynamically typed languages can do today that statically typed languages can't. Groovy's meta model and features have enabled a lot of clever tricks (DSL and others) for Gradle builds and I was really curious if I could put money where my mouth is by creating a similar project with Kotlin. This experiment is still ongoing but by now, I'm pretty convinced that the answer is a resounding "yes".
|
||||
</p>
|
||||
|
||||
<h3>4. An excuse to write Kotlin</h3>
|
||||
<h3 class="section" indent="..">4. An excuse to write Kotlin</h3>
|
||||
|
||||
<p>
|
||||
Just a personal thing. After toying with the language for almost four years now, I wanted to take my efforts to the next level and push the language to the limit. So far, the language has held all its promises and then some.
|
||||
|
@ -202,24 +200,20 @@ Is your curiosity piqued? Are you interested in writing some cool Kotlin code an
|
|||
<p>
|
||||
</p>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Table of contents -->
|
||||
<div class="col-md-3">
|
||||
<ul class="nav">
|
||||
<li><a href="#overview">Overview</a>
|
||||
<li><a href="#design-goals">Design goals</a>
|
||||
<li><a href="#why-kobalt">Why Kobalt?</a>
|
||||
<li><a href="#path">The path to 1.0</a>
|
||||
</ul>
|
||||
<div class="col-md-3" id="table-of-contents">
|
||||
</div>
|
||||
|
||||
<!-- Bootstrap core JavaScript
|
||||
================================================== -->
|
||||
<!-- Placed at the end of the document so the pages load faster -->
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
|
||||
<script src="../bootstrap/dist/js/bootstrap.min.js"></script>
|
||||
<script src="../bootstrap/dist/js/bootstrap.min.js"></script>
|
||||
<script src="../js/toc.js"></script>
|
||||
<script>generateToc();</script>
|
||||
|
||||
<!--
|
||||
<script src="../../assets/js/docs.min.js"></script>
|
||||
-->
|
||||
|
|
62
js/toc.js
Normal file
62
js/toc.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
function countersToHeading(counters) {
|
||||
var result = "";
|
||||
for (var i = 0; i < counters.length; i++) {
|
||||
if (i > 0) result = result + ".";
|
||||
result = result + counters[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function indentSection(count) {
|
||||
var result = "";
|
||||
for (var i = 0; i < count; i++) {
|
||||
result += " ";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function rewriteSection(section, counters) {
|
||||
var result = "";
|
||||
result = result + countersToHeading(counters) + " - " + section.innerHTML;
|
||||
return result;
|
||||
}
|
||||
|
||||
function generateToc() {
|
||||
var sections = document.getElementsByClassName("section");
|
||||
|
||||
var toc = '';//<ul class="nav">\n';
|
||||
var counters = new Array();
|
||||
var currentLevel = 0;
|
||||
for (i = 0; i < sections.length; i++) {
|
||||
var section = sections[i];
|
||||
var nameNode = section.attributes["name"];
|
||||
var name = nameNode ? nameNode.nodeValue : i;
|
||||
var indentNode = section.attributes["indent"];
|
||||
var indent = indentNode ? indentNode.nodeValue : ".";
|
||||
var currentCounter = 0;
|
||||
var ind = indent.length;
|
||||
if (ind > currentLevel) {
|
||||
if (ind == 1) {
|
||||
toc += '<ul class="nav">\n';
|
||||
} else {
|
||||
toc += '<ul>\n';
|
||||
}
|
||||
} else if (ind < currentLevel) {
|
||||
toc += '</ul>\n';
|
||||
}
|
||||
toc += '<li><a href="#' + section.id + '">' + section.innerHTML + '</a></li>\n';
|
||||
currentLevel = ind;
|
||||
}
|
||||
toc += "</ul>\n";
|
||||
console.log(toc);
|
||||
|
||||
var tocId = "table-of-contents";
|
||||
var tocTag = document.getElementById(tocId);
|
||||
|
||||
if (tocTag) {
|
||||
tocTag.innerHTML = toc;
|
||||
} else {
|
||||
alert("Couldn't find an id " + tocId);
|
||||
}
|
||||
|
||||
}
|
|
@ -256,7 +256,7 @@ And that's it! You can now iterate on your plug-in and upload it with additional
|
|||
================================================== -->
|
||||
<!-- Placed at the end of the document so the pages load faster -->
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
|
||||
<script src="../bootstrap/dist/js/bootstrap.min.js"></script>
|
||||
<script src="../bootstrap/dist/js/bootstrap.min.js"></script>
|
||||
<!--
|
||||
<script src="../bootstrap/dist/js/docs.min.js"></script>
|
||||
-->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue