forked from sinatra/sinatra-book
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zachary Scott
committed
Sep 7, 2012
1 parent
304dcbc
commit fcc74b3
Showing
7 changed files
with
78 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
source 'http://rubygems.org' | ||
|
||
gem 'thor', '~> 0.14' | ||
gem 'maruku', '~> 0.6' | ||
gem 'pdfkit' | ||
gem 'rake' | ||
gem 'redcarpet', '~> 2.0' | ||
gem 'sinatra' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require File.join(File.dirname(__FILE__), "book.rb") | ||
|
||
namespace :book do | ||
desc "build the book into pdf" | ||
task :build do | ||
include Book | ||
build(true) | ||
#File.open("#{OUTPUT_DIR}/sinatra-book.html", "w") { |f| f.write(doc) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require File.join(File.dirname(__FILE__), "book.rb") | ||
require 'erb' | ||
require 'sinatra' | ||
include Book | ||
|
||
get('/'){ erb build } | ||
|
||
get('/book.css') { send_file "#{ASSETS_DIR}/book.css", :type => 'text/css' } | ||
|
||
get('/logo.png') { send_file "#{ASSETS_DIR}/images/logo.png", :type => :png } | ||
|
||
__END__ | ||
@@layout | ||
<html> | ||
<head> | ||
<title>Sinatra Book</title> | ||
<link rel="stylesheet" type="text/css" href="/book.css" /> | ||
</head> | ||
<body> | ||
<p><img src="/logo.png" /></p> | ||
<%= yield %> | ||
</body> | ||
</html> |
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'pdfkit' | ||
require 'redcarpet' | ||
|
||
module Book | ||
ASSETS_DIR = File.join(File.dirname(__FILE__), "assets") | ||
BOOK_DIR = File.join(File.dirname(__FILE__), "book") | ||
OUTPUT_DIR = File.join(File.dirname(__FILE__), "output") | ||
|
||
def build(pdf=false) | ||
renderer = Redcarpet::Markdown.new(Redcarpet::Render::HTML, | ||
#:no_links => true, | ||
:space_after_headers => true, | ||
:with_toc_data => true, | ||
:fenced_code_blocks => true) | ||
toc_renderer = Redcarpet::Markdown.new(Redcarpet::Render::HTML_TOC) | ||
doc = toc_renderer.render(complete_markdown(true)) | ||
doc << renderer.render(complete_markdown) | ||
if pdf | ||
kit = PDFKit.new(doc, :page_size=>'Letter') | ||
kit.stylesheets << "#{ASSETS_DIR}/book.css" | ||
pdf = kit.to_pdf | ||
mkdir_p OUTPUT_DIR | ||
file = kit.to_file("#{OUTPUT_DIR}/sinatra-book.pdf") | ||
end | ||
return doc | ||
end | ||
|
||
private | ||
def complete_markdown(toc=false) | ||
s = [] | ||
File.new("book-order.txt").each_line do |line| | ||
line.strip! | ||
next if line =~ /^#/ # Skip comments | ||
next if line =~ /^$/ # Skip blank lines | ||
File.open(File.join(BOOK_DIR, line)) do |f| | ||
s << f.read | ||
end | ||
end | ||
return s.join("\n\n* * *\n\n") | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.