Permalink
Browse files

much nicer looking output now

  • Loading branch information...
1 parent cba8859 commit 9da55b89721bef0d465bba44c1c1f43a4e1cc2b6 @schacon schacon committed Jan 20, 2011
Showing with 346 additions and 37 deletions.
  1. +3 −1 TODO.txt
  2. +28 −13 lib/git-scribe.rb
  3. +23 −19 site/default/index.html
  4. +281 −0 site/default/master.css
  5. +11 −4 site/default/page.html
View
4 TODO.txt
@@ -1,15 +1,17 @@
To-Do List
=============
-* multi-page site
* custom site layouts
* auto-links to pdf/epub/mobi in site
* custom/alternate themes (stylesheets)
* cover page for site (author, about, etc)
* book cover (w/template)
* github pages publishing
* checking for proper tools
+* book search
* math formula
+* generate different languages from branches/tags (site, epub, mobi)
+* docbook import / direct from docbook
* workflow
- review / copy editing
View
41 lib/git-scribe.rb
@@ -132,7 +132,7 @@ def do_site
section.children.each do |item|
if item.name == 'dt' # section
c += 1
- sections[c] ||= {}
+ sections[c] ||= {'number' => c}
link = item.css('a').first
sections[c]['title'] = title = link.text
sections[c]['href'] = href = link['href']
@@ -145,7 +145,7 @@ def do_site
end
if item.name == 'dd' # subsection
item.css('dt').each do |sub|
- link = item.css('a').first
+ link = sub.css('a').first
data = {}
data['title'] = title = link.text
data['href'] = href = link['href']
@@ -157,23 +157,35 @@ def do_site
puts
end
+ pp sections
+
book_title = html.css('head > title').text
- content = html.css('div.section').first.to_html
- header = html.css('div.navheader').to_html
- footer = html.css('div.navfooter').to_html
+ content = html.css('body > div')[1]
+ content.css('.toc').first.remove
+ content = content.inner_html
+
+ puts content
+ sections.each do |s|
+ content.gsub!(s['href'], s['link'])
+ end
template_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'site', 'default'))
+
+ # copy the template files in
+ files = Dir.glob(template_dir + '/*')
+ FileUtils.cp_r files, '.'
+
Liquid::Template.file_system = Liquid::LocalFileSystem.new(template_dir)
index_template = Liquid::Template.parse(File.read(File.join(template_dir, 'index.html')))
page_template = Liquid::Template.parse(File.read(File.join(template_dir, 'page.html')))
# write the index page
+ main_data = {
+ 'book_title' => book_title,
+ 'sections' => sections
+ }
File.open('index.html', 'w+') do |f|
- data = {
- 'title' => book_title,
- 'sections' => sections
- }
- f.puts index_template.render( data )
+ f.puts index_template.render( main_data )
end
# write the title page
@@ -186,6 +198,7 @@ def do_site
'next' => sections[1],
'content' => content
}
+ data.merge!(main_data)
f.puts page_template.render( data )
end
@@ -194,11 +207,12 @@ def do_site
if i > 0 # skip title page
source = File.read(section['href'])
- puts source
-
html = Nokogiri::HTML.parse(source, nil, 'utf-8')
- content = html.css('div.section').first.to_html
+ content = html.css('body > div')[1].to_html
+ sections.each do |s|
+ content.gsub!(s['href'], s['link'])
+ end
File.open(section['link'], 'w+') do |f|
next_section = nil
@@ -213,6 +227,7 @@ def do_site
'next' => next_section,
'content' => content
}
+ data.merge!(main_data)
f.puts page_template.render( data )
end
#File.unlink(section['href'])
View
42 site/default/index.html
@@ -2,28 +2,32 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <link rel="stylesheet" href="stylesheets/handbookish.css" type="text/css" />
- <title>{{title}}</title>
+ <link rel="stylesheet" href="master.css" type="text/css" />
+ <title>{{book_title}}</title>
</head>
<body>
- <h1>{{title}}</h1>
- <hr/>
- <div>
- {{toc}}
- </div>
- <div>
- {% for section in sections %}
- <li>
+ <div class="content">
+ <h1>{{book_title}}</h1>
+ <hr/>
+ <div>
+ {{toc}}
+ </div>
+ <div id="toc">
+ <ul>
+ {% for section in sections %}
+ <li>
<h2><a href="{{ section.link }}">{{section.title}}</a></h2>
- {% if section.sub %}
- <ul>
- {% for sub in section.sub %}
- <li><a href="{{ sub.link }}">{{ sub.title }}</a></li>
- {% endfor %}
- </ul>
- {% endif %}
- </li>
- {% endfor %}
+ {% if section.sub %}
+ <ul>
+ {% for sub in section.sub %}
+ <li><a href="{{ sub.link }}">{{ sub.title }}</a></li>
+ {% endfor %}
+ </ul>
+ {% endif %}
+ </li>
+ {% endfor %}
+ </ul>
+ </div>
</div>
<hr/>
<a href="book.mobi">Mobi</a>
View
281 site/default/master.css
@@ -0,0 +1,281 @@
+/* BEG */
+/* ---------------------------------------------------------------------------
+ Bare AsciiDoc styles
+ Ryan Tomayko <r@tomayko.com>
+--------------------------------------------------------------------------- */
+
+body {
+ font-family:"Helvetica Neue", Helvetica, Arial, sans-serif;
+ font-size: 1.2em;
+ line-height:150%;
+ margin-left: 10%;
+ margin-right: 10%;
+ min-width: 790px;
+ color:#222;
+ background: #eee;
+}
+
+.tip {
+ background: #eee;
+ padding: 0 10px;
+}
+.warning {
+ background: #fcc;
+ padding: 0 10px;
+}
+.important {
+ background: #ccf;
+ padding: 0 10px;
+}
+.caution {
+ background: #ffc;
+ padding: 0 10px;
+}
+.content {
+ background: #fff;
+ padding: 20px;
+}
+
+a {
+ color: #336;
+}
+
+a:visited {
+ color: #447;
+}
+
+.nav {
+ color: #777;
+}
+.nav a {
+ color: #555;
+}
+
+#toc a {
+ text-decoration: none;
+ color: #444;
+}
+#toc > ul {
+ list-style: none;
+ padding-left: 0;
+}
+#toc > ul ul {
+ list-style: none;
+}
+
+hr { border: none; border-bottom: 1px solid #ccc; }
+
+em {
+ font-style:italic;
+}
+
+strong {
+ font-weight:bold;
+ color:#000;
+}
+
+tt {
+ font-family:consolas, 'lucida console', 'bitstream vera sans mono',
+ 'courier new', monospace;
+ color:#000;
+}
+
+p, ul, ol, dl {
+ margin:10px 0
+}
+
+dl {
+ margin-left:40px
+}
+
+dt {
+ font-weight:normal;
+ color:#000;
+}
+
+h1, h2, h3, h4, h5 {
+ font-family:'lucida grande',georgia,verdana,helvetica,arial,sans-serif;
+ font-weight:normal;
+ color:#000;
+}
+
+h1 {
+ font-size:30px;
+ line-height:1.428;
+ margin:20px 0;
+}
+
+h2 {
+ font-size:23px;
+ line-height:1.36363636; /* repeating, of course */
+ margin:20px 0;
+}
+
+h2 + .sectionbody {}
+
+h3 {
+ font-size:18px;
+ line-height:1.1;
+ margin:30px 0 10px 0;
+}
+
+h4 {
+ font-size:13px;
+ font-weight:bold;
+ line-height:1.538;
+}
+
+h5 {
+ font-size:13px;
+ font-style:italic;
+ line-height:1.538;
+}
+
+pre {
+ font-size:larger;
+}
+
+#header {
+ text-align:center;
+ margin-bottom:30px;
+}
+
+#header h1 { margin-bottom:0 }
+
+
+.title, .sidebar-title {
+ font-weight:normal;
+ margin-bottom:0;
+}
+
+.admonitionblock .title {
+ font-weight:bold;
+}
+
+.admonitionblock {
+ margin:30px 0px;
+ color:#555;
+}
+
+.admonitionblock td.icon {
+ width:30px;
+ padding-right:20px;
+ padding-left:20px;
+ text-transform:uppercase;
+ font-weight:bold;
+ color:#888;
+}
+
+.listingblock .content {
+ border:1px solid silver;
+ background:#eee;
+ padding:5px;
+}
+
+.listingblock .content pre {
+ margin:0;
+}
+
+.literalblock .content {
+ margin-left:40px;
+}
+
+.verseblock .content {
+ white-space:pre
+}
+
+.sidebarblock .sidebar-content {
+ border:1px solid silver;
+ background:#FFFFEE;
+ padding:0 10px;
+ color:#222;
+ font-size:smaller;
+ line-height:1.5;
+}
+
+.sidebar-title {
+ margin:10px 0;
+ font-weight:bold;
+ color:#442;
+}
+
+.quoteblock-content {
+ font-style:italic;
+ color:#444;
+ margin-left:40px;
+}
+
+.quoteblock-content .attribution {
+ font-style:normal;
+ text-align:right;
+ color:#000;
+}
+
+.exampleblock-content *:first-child { margin-top:0 }
+.exampleblock-content {
+ border-left:2px solid silver;
+ padding-left:8px;
+}
+
+#footer {
+ font-size:11px;
+ margin-top:40px;
+ border-top:1px solid silver;
+ color:#555;
+}
+
+#author {
+ color:#000;
+ text-transform:uppercase
+}
+
+/* vim: set ft=css ts=4 sw=4 noexpandtab: */
+
+/* END @import url(bare.css); */
+
+/* ---------------------------------------------------------------------------
+ FreeBSD AsciiDoc Theme
+ Ryan Tomayko <r@tomayko.com>
+
+ Based on The FreeBSD Handbook and various other FreeBSD documenration.
+--------------------------------------------------------------------------- */
+
+tt { color:#007A00 }
+pre tt { color:#000 }
+
+dt { color:#000 }
+
+h1, h2, h3, h4, h5 {
+ font-family:'lucida grande',helvetica,verdana,sans-serif;
+ color:#900;
+ font-weight:bold;
+}
+
+#header {
+ text-align:left;
+}
+#header h1 { margin-bottom:40px }
+
+h1 {
+ font-size:36px;
+ line-height:1;
+ margin:40px 0;
+}
+
+h2 {
+ font-size:28px;
+ line-height:1;
+ margin:30px 0 20px 0;
+}
+
+.sectionbody {
+ margin-left:30px;
+}
+
+pre {
+ background:#000;
+ color:#fff;
+ padding: 15px;
+}
+
+/* vim: set ft=css ts=4 sw=4 noexpandtab: */
View
15 site/default/page.html
@@ -2,11 +2,12 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <link rel="stylesheet" href="stylesheets/handbookish.css" type="text/css" />
- <title>Page {{title}}</title>
+ <link rel="stylesheet" href="master.css" type="text/css" />
+ <title>{{title}}</title>
</head>
<body>
+ <div class="nav" id="navheader">
<table width="100%">
<tr><td width="33%" align="left">
{% if prev %}
@@ -16,6 +17,7 @@
</td><td width="33%" align="center">
{% if prev %}
<a href="{{home.link}}">Home</a><br/>
+ <strong>{{ book_title }}</strong>
{% endif %}
</td><td width="33%" align="right">
{% if next %}
@@ -24,13 +26,17 @@
{% endif %}
</td></tr>
</table>
+ </div>
<hr/>
- {{content}}
+ <div class="content">
+ {{content}}
+ </div>
<hr/>
+ <div class="nav" id="navfooter">
<table width="100%">
<tr><td width="33%" align="left">
{% if prev %}
@@ -40,6 +46,7 @@
</td><td width="33%" align="center">
{% if prev %}
<a href="{{home.link}}">Home</a><br/>
+ {{ book_title }}
{% endif %}
</td><td width="33%" align="right">
{% if next %}
@@ -48,6 +55,6 @@
{% endif %}
</td></tr>
</table>
-
+ </div>
</body>
</html>

0 comments on commit 9da55b8

Please sign in to comment.