Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added export for Padrino Book PDF.

  • Loading branch information...
commit 84fe27804c849c932ae4a9f96dea975fae7df16e 1 parent f3121cc
@DAddYE DAddYE authored
View
1  Gemfile
@@ -14,6 +14,7 @@ gem 'diff-lcs', :require => 'diff/lcs'
gem 'disqus'
gem 'yui-compressor', :require => 'yui/compressor'
gem 'rdoc'
+gem 'pdfkit'
# Test requirements
gem 'rspec', :group => "test"
View
7 README.rdoc
@@ -12,6 +12,7 @@ The Padrino website is a simplified CMS with the following features:
* Beautiful admin interface for managing all content
* MongoDB + MongoMapper + Padrino powered
* {Disqus comments}[http://disqus.com] Integration
+* PDF integration through {PDFKit}[https://github.com/jdpace/PDFKit]
== Installation
@@ -22,6 +23,12 @@ In order for this project to run on your server, you need the following dependen
You need to download mongo from here: http://www.mongodb.org/display/DOCS/Downloads
and install following: http://www.mongodb.org/display/DOCS/Quickstart
+=== WKHTMLTOPDF
+
+HTML+CSS to PDF using wkhtmltopdf used to generate the pocket pdf guide.
+
+https://github.com/jdpace/PDFKit/wiki/Installing-WKHTMLTOPDF
+
=== Pygmentize
Go here http://pygments.org/download/ and install it.
View
16 app/controllers/guides.rb
@@ -19,4 +19,20 @@
not_found unless @guide
render 'guides/show'
end
+
+ get :book, :provides => :pdf do
+ content_type :pdf
+ @guides = Guide.all(:order => "position")
+ html = render 'guides/book', :layout => false
+ html.gsub!(/href="/, "href=\"http://www.padrinorb.com")
+ kit = PDFKit.new(html, "footer-right" => "Page [page] of [toPage]",
+ "header-right" => "Padrino Framework v.#{Padrino.version} Book",
+ "disable-internal-links" => false,
+ "disable-external-links" => false)
+
+ %w(reset text highlighter padrino).each do |style|
+ kit.stylesheets << Padrino.root("public", "stylesheets", "#{style}.css")
+ end
+ kit.to_pdf
+ end
end
View
11 app/views/guides/book.haml
@@ -0,0 +1,11 @@
+!!!
+%html{ :xmlns=>"http://www.w3.org/1999/xhtml" }
+ %head
+ %title="Padrino Framework v.#{Padrino.version} - Book"
+ %body
+ .logo{:style => "text-align:center;margin-top:400px"}=image_tag(Padrino.root("public/images/padrino.jpg"))
+ .guide{:style => "page-break-before:always"}
+ -@guides.each do |guide|
+ -next if guide.title =~ /blog tutorial/i
+ %h1=guide.title
+ .content~guide.body_html
View
2  app/views/guides/index.haml
@@ -13,4 +13,4 @@
.pagination=paginate(@guides, :guides, :search)
.grid_4.omega.margin-top=partial "guides/sidebar"
-.clear
+.clear
Please sign in to comment.
Something went wrong with that request. Please try again.