Last active
December 30, 2015 08:59
-
-
Save yannis/7806288 to your computer and use it in GitHub Desktop.
Generate a PDF of the ember.js guides with the Gimli gem from a local clone of https://github.com/emberjs/website
After http://blog.alistairrobinson.com/reading-the-emberjs-guides-on-your-kindle-using-gimli-for-pdf-conversion/
This file contains hidden or 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
require "gimli" | |
require "yaml" | |
ROOT_PATH = "~/Documents/ember_guides/" | |
TABLE_OF_CONTENT_PATH = ROOT_PATH+"website/data/guides.yml" | |
GUIDE_FILES_PATH = ROOT_PATH+"website/source/guides/" | |
def concatenated_path | |
yaml_table_of_content = YAML.load_file TABLE_OF_CONTENT_PATH | |
concatenated_paths = [] | |
yaml_table_of_content.each do |k,v| | |
unless k == "Views" # there is an error when generating this folder, ignoring this for now | |
v.each do |k1,v1| | |
path = k1["url"] | |
unless path.match /.html/ | |
pathsplit = path.split "/" | |
path += "/index" if pathsplit.size == 1 | |
path = GUIDE_FILES_PATH+path | |
unless File.exist? path+".md" | |
path = path+"/index" | |
p "file #{path} doe not exist" unless File.exist? path+".md" | |
end | |
concatenated_paths << path+".md" | |
end | |
end | |
end | |
end | |
return concatenated_paths.join(" ") | |
end | |
def remove_js_bin | |
file_name = "#{ROOT_PATH}ember_guides_combined.md" | |
text = File.read(file_name) | |
text.gsub! /### Live Preview/, "" | |
text.gsub! /<a class="jsbin-embed".+/, "" | |
File.open(file_name, "w") do |file| | |
file.puts text | |
end | |
end | |
system "mkdir #{ROOT_PATH}" | |
system "cd #{ROOT_PATH}" | |
system "git clone https://github.com/emberjs/website.git #{ROOT_PATH}website" | |
system "cat #{concatenated_path} > #{ROOT_PATH}ember_guides_combined.md" | |
remove_js_bin | |
system "gimli -file #{ROOT_PATH}ember_guides_combined.md > #{ROOT_PATH}ember_guides_combined.pdf" | |
system "open ember_guides_combined.pdf" | |
system "rm -fdr #{ROOT_PATH}" | |
p "done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment