git2epub 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
 - data/Gemfile +3 -1
 - data/Gemfile.lock +6 -2
 - data/VERSION +1 -1
 - data/lib/git2epub.rb +33 -67
 - data/lib/templates/index.haml +15 -0
 - data/lib/templates/section.haml +13 -0
 - metadata +5 -3
 
    
        data/.gitignore
    CHANGED
    
    
    
        data/Gemfile
    CHANGED
    
    
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/VERSION
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            0. 
     | 
| 
      
 1 
     | 
    
         
            +
            0.2.0
         
     | 
    
        data/lib/git2epub.rb
    CHANGED
    
    | 
         @@ -1,87 +1,53 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'bundler/setup'
         
     | 
| 
       2 
2 
     | 
    
         
             
            Bundler.require :default
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            require 'cgi'
         
     | 
| 
       5 
     | 
    
         
            -
            require 'mime/types'
         
     | 
| 
       6 
4 
     | 
    
         
             
            require 'tmpdir'
         
     | 
| 
       7 
5 
     | 
    
         
             
            require 'fileutils'
         
     | 
| 
       8 
6 
     | 
    
         | 
| 
       9 
7 
     | 
    
         
             
            module Git2Epub
         
     | 
| 
      
 8 
     | 
    
         
            +
              class << self
         
     | 
| 
      
 9 
     | 
    
         
            +
                def run(git_url, epub_file = nil)
         
     | 
| 
      
 10 
     | 
    
         
            +
                  dir = git_clone(git_url)
         
     | 
| 
       10 
11 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
      
 12 
     | 
    
         
            +
                  epub = EeePub::Easy.new do
         
     | 
| 
      
 13 
     | 
    
         
            +
                    title       git_url
         
     | 
| 
      
 14 
     | 
    
         
            +
                    identifier  git_url, :scheme => 'URL'
         
     | 
| 
      
 15 
     | 
    
         
            +
                    uid         git_url
         
     | 
| 
      
 16 
     | 
    
         
            +
                  end
         
     | 
| 
       13 
17 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                  title       git_url
         
     | 
| 
       16 
     | 
    
         
            -
                  creator     `whoami`
         
     | 
| 
       17 
     | 
    
         
            -
                  identifier  git_url, :scheme => 'URL'
         
     | 
| 
       18 
     | 
    
         
            -
                  uid         git_url
         
     | 
| 
       19 
     | 
    
         
            -
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
                  add_contents(epub, dir, git_url)
         
     | 
| 
       20 
19 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
      
 20 
     | 
    
         
            +
                  epub_file = File.basename(git_url) + '.epub' unless epub_file
         
     | 
| 
      
 21 
     | 
    
         
            +
                  puts "\e[32m => #{epub_file}\e[0m"
         
     | 
| 
      
 22 
     | 
    
         
            +
                  epub.save(epub_file)
         
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
       22 
24 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
                 
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
      
 25 
     | 
    
         
            +
                def git_clone(git_url)
         
     | 
| 
      
 26 
     | 
    
         
            +
                  dir = File.join(Dir.tmpdir, 'git2epub', File.basename(git_url))
         
     | 
| 
      
 27 
     | 
    
         
            +
                  FileUtils.rm_rf dir
         
     | 
| 
      
 28 
     | 
    
         
            +
                  FileUtils.mkdir_p dir
         
     | 
| 
      
 29 
     | 
    
         
            +
                  system 'git', 'clone', git_url, dir
         
     | 
| 
      
 30 
     | 
    
         
            +
                  dir
         
     | 
| 
      
 31 
     | 
    
         
            +
                end
         
     | 
| 
       27 
32 
     | 
    
         | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
                FileUtils.rm_rf dir
         
     | 
| 
       31 
     | 
    
         
            -
                FileUtils.mkdir_p dir
         
     | 
| 
       32 
     | 
    
         
            -
                system 'git', 'clone', git_url, dir
         
     | 
| 
       33 
     | 
    
         
            -
                dir
         
     | 
| 
       34 
     | 
    
         
            -
              end
         
     | 
| 
      
 33 
     | 
    
         
            +
                def add_contents(epub, dir, git_url)
         
     | 
| 
      
 34 
     | 
    
         
            +
                  contents = Dir[File.join(dir, '**', '*')].select { |f| File.file?(f) && !File.binary?(f) }
         
     | 
| 
       35 
35 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
                contents = Dir[File.join(dir, '**', '*')].
         
     | 
| 
       38 
     | 
    
         
            -
                    select { |f| File.file?(f) && MIME::Types.of(f).first.ascii? rescue false }
         
     | 
| 
      
 36 
     | 
    
         
            +
                  epub.sections << ['Index', render('index.haml', :git_url => git_url, :contents => contents, :dir => dir)]
         
     | 
| 
       39 
37 
     | 
    
         | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
      
 38 
     | 
    
         
            +
                  contents.each do |content|
         
     | 
| 
      
 39 
     | 
    
         
            +
                    label = content.sub(File.join(dir, '/'), '')
         
     | 
| 
      
 40 
     | 
    
         
            +
                    epub.sections << [label, render('section.haml', :label => label, :content => content)]
         
     | 
| 
      
 41 
     | 
    
         
            +
                    puts "\e[35m#{label}\e[0m"
         
     | 
| 
      
 42 
     | 
    
         
            +
                  end
         
     | 
| 
       44 
43 
     | 
    
         
             
                end
         
     | 
| 
       45 
44 
     | 
    
         | 
| 
       46 
     | 
    
         
            -
                 
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
         
     | 
| 
       50 
     | 
    
         
            -
              <head>
         
     | 
| 
       51 
     | 
    
         
            -
                <title>#{git_url}</title>
         
     | 
| 
       52 
     | 
    
         
            -
              </head>
         
     | 
| 
       53 
     | 
    
         
            -
              <body>
         
     | 
| 
       54 
     | 
    
         
            -
                <h1>#{git_url}</h1>
         
     | 
| 
       55 
     | 
    
         
            -
                <ul>
         
     | 
| 
       56 
     | 
    
         
            -
                  #{lis.join("\n")}
         
     | 
| 
       57 
     | 
    
         
            -
                </ul>
         
     | 
| 
       58 
     | 
    
         
            -
              </body>
         
     | 
| 
       59 
     | 
    
         
            -
            </html>
         
     | 
| 
       60 
     | 
    
         
            -
                HTML
         
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
                contents.each do |content|
         
     | 
| 
       63 
     | 
    
         
            -
                  label = content.sub(File.join(dir, '/'), '')
         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
                  puts "\e[35m#{label}\e[0m"
         
     | 
| 
      
 45 
     | 
    
         
            +
                def render(template_name, locals)
         
     | 
| 
      
 46 
     | 
    
         
            +
                  Tilt.new(template(template_name), :escape_html => true).render(self, locals)
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
       66 
48 
     | 
    
         | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
         
     | 
| 
       70 
     | 
    
         
            -
            <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
         
     | 
| 
       71 
     | 
    
         
            -
              <head>
         
     | 
| 
       72 
     | 
    
         
            -
                <title>#{label}</title>
         
     | 
| 
       73 
     | 
    
         
            -
                <style>
         
     | 
| 
       74 
     | 
    
         
            -
                  body {font-size: 76%;}
         
     | 
| 
       75 
     | 
    
         
            -
                </style>
         
     | 
| 
       76 
     | 
    
         
            -
              </head>
         
     | 
| 
       77 
     | 
    
         
            -
              <body>
         
     | 
| 
       78 
     | 
    
         
            -
                <h1>#{label}</h1>
         
     | 
| 
       79 
     | 
    
         
            -
                <pre><code>
         
     | 
| 
       80 
     | 
    
         
            -
            #{CGI.escapeHTML(File.read(content))}
         
     | 
| 
       81 
     | 
    
         
            -
                </code></pre>
         
     | 
| 
       82 
     | 
    
         
            -
              </body>
         
     | 
| 
       83 
     | 
    
         
            -
            </html>
         
     | 
| 
       84 
     | 
    
         
            -
                  HTML
         
     | 
| 
      
 49 
     | 
    
         
            +
                def template(name)
         
     | 
| 
      
 50 
     | 
    
         
            +
                  File.join(File.dirname(__FILE__), 'templates', name)
         
     | 
| 
       85 
51 
     | 
    
         
             
                end
         
     | 
| 
       86 
52 
     | 
    
         
             
              end
         
     | 
| 
       87 
53 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,15 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            !!!
         
     | 
| 
      
 2 
     | 
    
         
            +
            %html
         
     | 
| 
      
 3 
     | 
    
         
            +
              %head
         
     | 
| 
      
 4 
     | 
    
         
            +
                %title= git_url
         
     | 
| 
      
 5 
     | 
    
         
            +
                %style{:type => 'text/css'}
         
     | 
| 
      
 6 
     | 
    
         
            +
                  :css
         
     | 
| 
      
 7 
     | 
    
         
            +
                    h1 {font-size: 120%; color: #666; margin: 4px 0;}
         
     | 
| 
      
 8 
     | 
    
         
            +
                    ul {font-size: 80%;}
         
     | 
| 
      
 9 
     | 
    
         
            +
              %body
         
     | 
| 
      
 10 
     | 
    
         
            +
                %h1= git_url
         
     | 
| 
      
 11 
     | 
    
         
            +
                %ul
         
     | 
| 
      
 12 
     | 
    
         
            +
                  - contents.each_with_index do |content, index|
         
     | 
| 
      
 13 
     | 
    
         
            +
                    %li
         
     | 
| 
      
 14 
     | 
    
         
            +
                      %a{:href => "section_#{index + 1}.html"}
         
     | 
| 
      
 15 
     | 
    
         
            +
                        = content.sub(File.join(dir, '/'), '')
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version 
     | 
|
| 
       4 
4 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       5 
5 
     | 
    
         
             
              segments: 
         
     | 
| 
       6 
6 
     | 
    
         
             
              - 0
         
     | 
| 
       7 
     | 
    
         
            -
              - 1
         
     | 
| 
       8 
7 
     | 
    
         
             
              - 2
         
     | 
| 
       9 
     | 
    
         
            -
               
     | 
| 
      
 8 
     | 
    
         
            +
              - 0
         
     | 
| 
      
 9 
     | 
    
         
            +
              version: 0.2.0
         
     | 
| 
       10 
10 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       11 
11 
     | 
    
         
             
            authors: 
         
     | 
| 
       12 
12 
     | 
    
         
             
            - jugyo
         
     | 
| 
         @@ -14,7 +14,7 @@ autorequire: 
     | 
|
| 
       14 
14 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       15 
15 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
            date: 2010-10- 
     | 
| 
      
 17 
     | 
    
         
            +
            date: 2010-10-24 00:00:00 +09:00
         
     | 
| 
       18 
18 
     | 
    
         
             
            default_executable: git2epub
         
     | 
| 
       19 
19 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       20 
20 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     | 
| 
         @@ -78,6 +78,8 @@ files: 
     | 
|
| 
       78 
78 
     | 
    
         
             
            - VERSION
         
     | 
| 
       79 
79 
     | 
    
         
             
            - bin/git2epub
         
     | 
| 
       80 
80 
     | 
    
         
             
            - lib/git2epub.rb
         
     | 
| 
      
 81 
     | 
    
         
            +
            - lib/templates/index.haml
         
     | 
| 
      
 82 
     | 
    
         
            +
            - lib/templates/section.haml
         
     | 
| 
       81 
83 
     | 
    
         
             
            has_rdoc: true
         
     | 
| 
       82 
84 
     | 
    
         
             
            homepage: http://github.com/jugyo/git2epub
         
     | 
| 
       83 
85 
     | 
    
         
             
            licenses: []
         
     |