Module: Git2Epub
- Defined in:
- lib/git2epub.rb
Class Method Summary collapse
- .add_contents(epub, dir, git_url) ⇒ Object
- .git_clone(git_url) ⇒ Object
- .render(template_name, locals) ⇒ Object
- .run(git_url, epub_file = nil) ⇒ Object
- .template(name) ⇒ Object
Class Method Details
.add_contents(epub, dir, git_url) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/git2epub.rb', line 35 def add_contents(epub, dir, git_url) contents = Dir[File.join(dir, '**', '*')].select { |f| File.file?(f) && !File.binary?(f) } epub.sections << ['Index', render('index.haml', :git_url => git_url, :contents => contents, :dir => dir)] contents.each do |content| label = content.sub(File.join(dir, '/'), '') epub.sections << [label, render('section.haml', :label => label, :content => content)] puts "\e[35m#{label}\e[0m" end end |
.git_clone(git_url) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/git2epub.rb', line 27 def git_clone(git_url) dir = File.join(Dir.tmpdir, 'git2epub', File.basename(git_url)) FileUtils.rm_rf dir FileUtils.mkdir_p dir system 'git', 'clone', git_url, dir dir end |
.render(template_name, locals) ⇒ Object
47 48 49 |
# File 'lib/git2epub.rb', line 47 def render(template_name, locals) Tilt.new(template(template_name), :escape_html => true).render(self, locals) end |
.run(git_url, epub_file = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/git2epub.rb', line 11 def run(git_url, epub_file = nil) dir = git_clone(git_url) epub = EeePub::Easy.new do title git_url identifier git_url, :scheme => 'URL' uid git_url end add_contents(epub, dir, git_url) epub_file = File.basename(git_url) + '.epub' unless epub_file puts "\e[32m => #{epub_file}\e[0m" epub.save(epub_file) end |
.template(name) ⇒ Object
51 52 53 |
# File 'lib/git2epub.rb', line 51 def template(name) File.join(File.dirname(__FILE__), 'templates', name) end |