Skip to content

Commit

Permalink
updated for newer versions of scrivener.
Browse files Browse the repository at this point in the history
  • Loading branch information
akempler committed Feb 25, 2016
1 parent de11878 commit b25a4a8
Show file tree
Hide file tree
Showing 7 changed files with 260 additions and 227 deletions.
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
docboot
=======
# DocBoot

Command-line tool to convert Scrivener and Word exports to Twitter Bootstrap based website.
It creates a "paged" style experience.
A table of contents is automatically generated from all H1 tags and displayed in a sidebar.
It creates a "paged" style experience with a table of contents being generated
from all H1 and H2 tags and displayed in a sidebar.
You can then click on any of the contents items to automatically display the page.

USAGE:
> php scrivcl.php path\to\your\document.html path\to\target\directory\ doctype
## USAGE:
From within the docboot directory run the following command
> php scrivcl.php path\to\your\document.html path\to\target\directory\ doctype "documentTitle" "author"
Note the trailing slash on the target directory.
Make sure the target directory exists.

doctype can be either 'word' or 'scrivener'
doctype can be either 'word' or 'scrivener'.

Word:
Export your document as a html.
Note the trailing slash on the target directory. Also make sure to put quotes around your documentTitle and author.

Scrivener:

**Word:**
Export your document as a html from Word.

**Scrivener:**
Compile you Scrivener document using the Markdown -> HTML format.


68 changes: 46 additions & 22 deletions css/docboot.css
Original file line number Diff line number Diff line change
@@ -1,38 +1,62 @@
@CHARSET "UTF-8";

/*
body > .container-fluid {
padding: 0;
.page-header {
margin: 0 15px 30px 15px;
background-color: #e3e3e3;
}
.page-header h1 {
margin-top: .2em;
font-size: 2em;
}
.hero-unit {
background-color
}
*/

header {
padding: 20px 20px;
color: #fff;
background-color: #000;
padding: 0 0 1em 0;
text-align: left;
}

header h1 {
font-size: 6em;
font-weight: bold;
line-height: 1;
font-family: "Helvetica Neue", Helvetica, Arial, sans serif;
font-size: 2.5em;
font-weight: bold;
line-height: 1;
font-family: "Helvetica Neue", Helvetica, Arial, sans serif;
text-align: left;
}
header h2 {
font-weight: normal;
font-weight: bold;
}

.sidebar-nav {
padding: 1em 1em 1em 2em;
margin-bottom: 2em;
background-color: #f5f5f5;
border: 1px solid #e3e3e3;
border-radius: 4px;
box-shadow: inset 0 1px 1px rgba(0,0,0,.05);
}
p.large {
font-size: 2em;
color: #333;
line-height: 1.1;
font-size: 2em;
color: #333;
line-height: 1.1;
}

.row {
margin-top: 0;
}

.row-fluid {
margin-top: 2em;
.author {
font-size: 1em;
font-style: italic;
color: #999;
}

.nav-header {
font-weight: bold;
}
#scrivnav li {
padding: 0 0 .9em 0;
line-height: 1.1em;
text-indent: -1.1em;
}
#scrivnav li a {
padding: 0;
}
146 changes: 85 additions & 61 deletions js/scrivstrap.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,99 @@

$(document).ready(function(){

$('#scriv').css('display','none');
$('#scrivshow').css('display','none');

scrivNav();

$('#scrivnav > ul > li').click(function() {
// TODO use a jquery animation here to hide it and then show.
$('#scrivshow').html('');

var elementid = $(this).attr('id').split('-')[1];
var startElement = $('#'+elementid);
$(startElement).clone().appendTo('#scrivshow');

var content = scrivGetContent(startElement);

$('#scrivshow').css('display','block');
});

$('#samplelink').click(function(){

var url = $('#samplelink').attr("href");
var windowName = "Docboot Sample";
window.open(url, "_blank", "toolbar=no, location=no, directories=no, status=no, menubar=no");
return false;
});
scrivstrapConfig = {htags: $("H1, H2"), validTags: ["H1", "H2"]}

$('#scriv').css('display','none');
$('#scrivshow').css('display','none');

// Generate the navigation and get the default link to click
// so content is shown when the page is loaded.
var defaultLink = scrivNav();

$('#scrivnav > ul > li').click(function() {
$('#scrivshow').html('');

var title = $(this).text().replace(" - ", "").trim();
$('#article-title').html(title);

var elementid = $(this).attr('id').split('-')[1];
var startElement = $('#'+elementid);

var next = getNextIndex(elementid);

$(startElement).nextUntil(scrivstrapConfig.htags[next]).clone().appendTo('#scrivshow');

$('#scrivshow').css('display','block');
});

$(defaultLink).trigger("click");

});


/**
* Get the content to display.
* @param startId string - the element id to start retrieving content at.
*/
// var scrivGetContent = function(startId) {
var scrivGetContent = function(element) {

// loop through each element starting at startId.
var curElement = element.next();

if( ! $(curElement).is("h1") ) {
$(curElement).clone().appendTo('#scrivshow');
scrivGetContent($(curElement));
}

}
function getNextIndex(id) {
var next = 0;

scrivstrapConfig.htags.each(function(index) {
if($(this).attr('id') == id) {
next = index + 1;
}
});
return next;
}


/**
* Generate navigation based on headings.
*
* todo keep track of the index.
* if it is bigger than add another ul li.
* if less then end them.
*/
var scrivNav = function() {

var nav = $('#scrivnav');

$('h1').each(function(index) {

var listItem = document.createElement('li');
listItem.setAttribute('id', 'nav-'+$(this).attr('id'));
listItem.innerHTML = '<a href="#">'+$(this).text()+'</a>';

$('#scrivnav > ul').append(listItem);
});
}

/**
* Create elements
*/
var scrivElement = function(title) {

// link.setAttribute('href', 'mypage.htm');


var defaultId = "";
// heading tags with these ids will be excluded from the nav.
var exclude = ["page-heading", "article-title"];

var x = 1;
scrivstrapConfig.htags.each(function(index) {
var tagname = $(this).prop("tagName");

// if the tag is in the array of tags.
if (jQuery.inArray(tagname, scrivstrapConfig.validTags) != -1) {

// if the tag is NOT in the exclude array add it to the nav.
if (jQuery.inArray($(this).attr('id'), exclude) == -1) {

var listItem = document.createElement('li');
listItem.setAttribute('id', 'nav-'+$(this).attr('id'));

var indent = "";
if(tagname == "H2") {
indent = "&nbsp; - ";
}

// If the next element is an h tag in the tags array,
// then don't make a link because there is no content to display.
var nextElement = $(this).next();
var nextTag = nextElement.prop("tagName");
if (jQuery.inArray(nextTag, scrivstrapConfig.validTags) != -1) {
listItem.innerHTML = indent + $(this).text();
} else {
listItem.innerHTML = '<a href="#">' + indent + $(this).text()+'</a>';
}

$('#scrivnav > ul').append(listItem);

if(x == 1){
defaultId = '#nav-'+$(this).attr('id');
}
x++;
}
};
});

// The element id to use as the default content to display.
return defaultId;
}
11 changes: 7 additions & 4 deletions scrivcl.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
require_once('scrivmsg.class.php');
require_once('scrivprocess.class.php');

// getopt only works in php 5.3+
//$args = getopt("f:d:t");

$filetype = $argv[3]; // 'word' or 'scrivener'

$ScrivProcess = new ScrivProcess($filetype);

$docName = $argv[4];
$author = $argv[5];
$ScrivProcess->doc_title = $docName;
$ScrivProcess->doc_author = $author;

$convertpath = $argv[2];
// TODO make the directory if it does not exist?
$ScrivProcess->set_converted_path($convertpath);
Expand All @@ -33,7 +36,7 @@
// Copy the scrivstrap.js file to the converted directory.
$file = './js/scrivstrap.js';
$oldumask = umask(0);
mkdir($convertpath.'/js', 0777); // or even 01777 so you get the sticky bit set
mkdir($convertpath.'/js', 0777);
umask($oldumask);

if (!copy($file, $convertpath.'/js/scrivstrap.js')) {
Expand All @@ -43,7 +46,7 @@
// Copy the docboot.css file to the converted directory.
$file = './css/docboot.css';
$oldumask = umask(0);
mkdir($convertpath.'/css', 0777); // or even 01777 so you get the sticky bit set
mkdir($convertpath.'/css', 0777);
umask($oldumask);

if (!copy($file, $convertpath.'/css/docboot.css')) {
Expand Down
Loading

0 comments on commit b25a4a8

Please sign in to comment.