Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 75de7002c8
Fetching contributors…

Cannot retrieve contributors at this time

42 lines (38 sloc) 1.285 kb
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.new(:with_toc_data => true),
#:no_links => true,
:space_after_headers => 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
Jump to Line
Something went wrong with that request. Please try again.