gitindex 0.0.2

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: da48b93b79502d02985c6ee0fa6dc4226e59b6ec
4
+ data.tar.gz: 24f315b875d1004f32be12630df1276cd6a9329b
5
+ SHA512:
6
+ metadata.gz: b5fc93addb53976061c7ee6e49f206aae5bf788c761be018871af9cd38f33e96bd444402b5e13f00b6386c0a2e85682eaaadbe83107059ac639d40a88ce8ed0c
7
+ data.tar.gz: 12841b22fe386af3819a2e709f9bafd9c5ef1f81509fd344e3048d00f197c10ba34d15b76ee2f29be459a334fe1ee02aad5904e352d2a0e81caa9588daccb37b
data/bin/gitindex ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ #require_relative '../lib/gitindexcli.rb'
3
+ require_relative '../config/environment.rb'
4
+ cli = GitIndexCLI.new
5
+ cli.call
@@ -0,0 +1,7 @@
1
+ require 'pathname'
2
+ require 'rbconfig'
3
+ require 'pry'
4
+ require 'fileutils'
5
+ require_relative '../lib/gitindexcli.rb'
6
+ require_relative '../lib/gitindex.rb'
7
+ require_relative '../lib/gitrepo.rb'
data/lib/gitindex.rb ADDED
@@ -0,0 +1,67 @@
1
+ class GithubIndex
2
+
3
+ attr_reader :path
4
+
5
+ def initialize(base_dir = "~")
6
+ @base_dir = base_dir
7
+ @path = ""
8
+ @index = ""
9
+ end
10
+
11
+ def generate_index
12
+ puts write_header
13
+ puts "Reading from #{@base_dir}"
14
+ process_directory(@base_dir)
15
+ puts "<ul>#{@index}</ul>"
16
+ puts write_footer
17
+ end
18
+
19
+ private
20
+ def write_header
21
+ header = <<-HTML
22
+ <!doctype html>
23
+ <html>
24
+ <head><title>Github Index</title></head>
25
+ <body>
26
+ <h1>Git Repository Index</h1>
27
+ HTML
28
+ end
29
+
30
+ def process_directory(current_directory)
31
+ contents = Dir.entries(current_directory).slice(2..-1)
32
+ @path = Pathname.new(current_directory)
33
+ if not contents.include?(".git")
34
+ @index << "<li>#{path.basename}"
35
+ contents.each do |content|
36
+ if File.directory?("#{current_directory}/#{content}/")
37
+ @index << "<ul>"
38
+ process_directory("#{current_directory}/#{content}/")
39
+ @index << "</ul>"
40
+ end
41
+ end
42
+ else
43
+ @index << print_repo(current_directory)
44
+ end
45
+ end
46
+
47
+ def print_repo(current_directory)
48
+ repo = "#{@path.basename}"
49
+ remote = find_remote(current_directory)
50
+ repo = "<a href=\"#{remote}\">#{repo}</a>" unless remote.empty?
51
+ return "<li>#{repo}"
52
+ end
53
+
54
+ def find_remote(current_directory)
55
+ repo = GitRepo.new("#{current_directory}/.git/config")
56
+ repo.find_remote
57
+ end
58
+
59
+ def write_footer
60
+ footer = <<-HTML
61
+ <h6>Generated by <a href="https://github.com/randallreedjr/github-index">github-index</a></h6>
62
+ </body>
63
+ </html>
64
+ HTML
65
+ end
66
+
67
+ end
@@ -0,0 +1,56 @@
1
+ class GitIndexCLI
2
+ attr_reader :directory, :path
3
+ def initialize
4
+ @filename = ""
5
+ end
6
+
7
+ def call
8
+ if !mac_OS?
9
+ puts "Sorry, this gem is only compatible with Mac OS"
10
+ else
11
+ greeting
12
+ input = gets.chomp
13
+ if input.downcase != "exit"
14
+ directory_from_input(input)
15
+ determine_path
16
+ create_file
17
+ `open #{@filename}`
18
+ end
19
+ end
20
+ end
21
+
22
+ private
23
+ def greeting
24
+ puts "What directory would you like to map?"
25
+ puts "(leave blank for present working directory)"
26
+ end
27
+
28
+ def directory_from_input(input)
29
+ input.strip.empty? ? @directory = (Dir.pwd) : @directory = input
30
+ end
31
+
32
+ def determine_path
33
+ @path = Pathname.new(directory)
34
+ @path = path.expand_path if path.relative?
35
+ end
36
+
37
+ def create_file
38
+ #file = "#{path}/index.html"
39
+ if !Dir.exists?('/tmp/gitindex')
40
+ FileUtils::mkdir_p '/tmp/gitindex'
41
+ end
42
+ @filename = '/tmp/gitindex/index.html'
43
+ puts "Mapping #{path}..."
44
+ output_message
45
+ $stdout.reopen(@filename, "w")
46
+ GithubIndex.new(path).generate_index
47
+ end
48
+
49
+ def output_message
50
+ puts "If results do not automatically open, type 'open #{@filename}'"
51
+ end
52
+
53
+ def mac_OS?
54
+ return ((/darwin/ =~ RbConfig::CONFIG["arch"]) != nil)
55
+ end
56
+ end
data/lib/gitrepo.rb ADDED
@@ -0,0 +1,21 @@
1
+ class GitRepo
2
+ attr_reader :filename, :remote
3
+ def initialize(filename)
4
+ @filename = filename
5
+ @remote = ""
6
+ end
7
+
8
+ def find_remote()
9
+ file = File.new(filename, "r")
10
+ while (line = file.gets)
11
+ if line.start_with?("[remote")
12
+ @remote = file.gets.gsub("url = git@github.com:", "https://github.com/")
13
+ break
14
+ end
15
+ end
16
+ file.close
17
+ @remote
18
+ end
19
+
20
+
21
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gitindex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Randall Reed, Jr.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Traverses your directory structure, starting at a specified location,
14
+ and creates an HTML tree of your git repositories. Will also link to the origin
15
+ remote if it exists.
16
+ email:
17
+ - randallreedjr@gmail.com
18
+ executables:
19
+ - gitindex
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - bin/gitindex
24
+ - config/environment.rb
25
+ - lib/gitindex.rb
26
+ - lib/gitindexcli.rb
27
+ - lib/gitrepo.rb
28
+ homepage: https://rubygems.org/gems/gitindex
29
+ licenses:
30
+ - MIT
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project:
48
+ rubygems_version: 2.2.2
49
+ signing_key:
50
+ specification_version: 4
51
+ summary: Creates an index of your local git repositories
52
+ test_files: []