Class: Publishr::Project
- Inherits:
-
Object
- Object
- Publishr::Project
- Defined in:
- lib/publishr/project.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, absolutepath, absoluteconverterspath = '', rails_resources_url = '') ⇒ Project
constructor
A new instance of Project.
- #make_images_local(kramdown) ⇒ Object
- #make_kindle ⇒ Object
- #make_pdf ⇒ Object
- #make_web ⇒ Object
Constructor Details
#initialize(name, absolutepath, absoluteconverterspath = '', rails_resources_url = '') ⇒ Project
Returns a new instance of Project.
21 22 23 24 25 26 27 28 |
# File 'lib/publishr/project.rb', line 21 def initialize(name,absolutepath,absoluteconverterspath='',rails_resources_url='') @name = name @inpath = absolutepath @converterspath = absoluteconverterspath @rails_resources_url = rails_resources_url @metadata = YAML::load(File.open(File.join(@inpath,'metadata.yml'), 'r').read) if File.exists? File.join(@inpath,'metadata.yml') end |
Class Method Details
.gempath ⇒ Object
30 31 32 |
# File 'lib/publishr/project.rb', line 30 def self.gempath File.('../../../', __FILE__) end |
Instance Method Details
#make_images_local(kramdown) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/publishr/project.rb', line 95 def make_images_local(kramdown) images = [] processed_lines = [] kramdown.split("\n").each do |line| match = /\!\[.*?\]\((.*?)\)/.match(line) images << match[1] if match processed_lines << line.gsub(/\!\[(.*?)\]\((.*?)\)/){ "![#{ $1 }](#{ File.basename($2) })" } end FileUtils.mkdir_p File.join(@inpath,'images') FileUtils.chdir File.join(@inpath,'images') output = ["The following files were downloaded into the image folder of your document:\n"] images.each do |image| FileUtils.rm_f File.join(@inpath,'images',File.basename(image)) output << `wget -nv #{image} 2>&1` end return processed_lines.join("\n"), output end |
#make_kindle ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/publishr/project.rb', line 34 def make_kindle outpath = File.join(@inpath,'epub') epub = EpubRenderer.new(@name,@inpath,outpath,@metadata, @rails_resources_url) epub.render binaryfile = File.join(@converterspath,'kindlegen') epubfile = File.join(@inpath,"#{ @name }.epub") lines = [] IO.popen("#{ binaryfile } -verbose #{ epubfile }") do |io| while (line = io.gets) do puts line lines << line end end lines.join('<br />') end |
#make_pdf ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/publishr/project.rb', line 50 def make_pdf pdf = LatexRenderer.new(@name,@inpath,@metadata) pdf.render outpath = File.join(@inpath,'latex') # pdflatex handles jpg files directly, so the following is commented out # binaryfile = File.join(@converterspath,'jpeg2ps 2>&1') # Dir[File.join(outpath,'*.jpg')].each do |infilepath| # outfilepath = File.join(outpath, File.basename(infilepath).gsub(/(.*).jpg/, '\1.eps')) # `#{ binaryfile } -r 0 -o #{ outfilepath } #{ infilepath }` # end Dir.chdir outpath Dir['*.eps'].each do |f| `perl /usr/bin/epstopdf #{ f }` jpg_to_delete = File.basename(f).gsub(/(.*).eps/, '\1.jpg') FileUtils.rm jpg_to_delete if File.exists? jpg_to_delete FileUtils.rm f end `makeindex preamble.idx` lines = [] IO.popen('pdflatex -interaction=nonstopmode preamble.tex 2>&1') do |io| while (line = io.gets) do puts line lines << line end end FileUtils.mv(File.join(outpath,'preamble.pdf'), File.join(@inpath,"#{ @name }.pdf")) if File.exists?(File.join(outpath,'preamble.pdf')) lines.join('<br />') end |
#make_web ⇒ Object
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/publishr/project.rb', line 84 def make_web Dir.chdir @inpath FileUtils.rm_rf 'out' site = Webgen::Website.new '.' site.init = site.render FileUtils.rm_rf '.sass-cache' FileUtils.rm_rf 'webgen.cache' end |