webgit 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77fbff2e8f1e1508dc1d11b74d75df5fb0d05ce1
4
- data.tar.gz: 22e0c67767837edea4001cabec84a6fa9193d027
3
+ metadata.gz: e915df541ae8942eee3fb83ffa3eb60dfba205d9
4
+ data.tar.gz: 03af1c6f3fcd40fb42be2f726b0bdcb0c1a703e4
5
5
  SHA512:
6
- metadata.gz: 55007e3e7610ebc6cbbc774868631ef279eea1405a8b17c913454846d221713070eb784eba5730a2e5b62a227c108da91ccabfe1a402434636efe8dbd67cd2ac
7
- data.tar.gz: e5552c6d7a19a2baaf41eeb2c46ac3ebe089e18374ff650a940e21f7d7eee8586af4f9033582e4fadd21d9f2eee613506de6ee73d91cebe4b4902a423a99aaf4
6
+ metadata.gz: bf6e9cfb849ebe092eb7eafbe9ce20e140c8136dbe6e86d19a5087a6147715d599151ca066403b842c7e13d1efeaee930fe284a3d43d650620e8de1d038d9bca
7
+ data.tar.gz: 9fc45c72eb7ec8b39c4a5b160f10dd4b87c81fd0ba7e8cb06c22822685224643c9425b87f0f360fb491d5a5351478d83f976d9f9d58c1a8016bc86a5cc1b6213
data/.gitignore ADDED
@@ -0,0 +1,94 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ .bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ db/*.sqlite3
12
+ db/*.sqlite3-journal
13
+
14
+ .DS_Store
15
+ *.gem
16
+ .rakeTasks
17
+ .generators
18
+
19
+ # Ignore all logfiles and tempfiles.
20
+ log/*.log
21
+ tmp
22
+
23
+ Gemfile.lock
24
+ !/site/Gemfile.lock
25
+
26
+ .sass-cache
27
+ .sass-cache/*
28
+ capybara-*.html
29
+ .rspec
30
+ 。rspec/*
31
+ vendor/bundle
32
+ log/*
33
+ tmp/*
34
+ public/system
35
+ public/system/*
36
+ public/uploads
37
+ public/uploads/*
38
+ coverage/
39
+ spec/tmp/*
40
+
41
+ /.bundle/
42
+ /.yardoc
43
+ /Gemfile.lock
44
+ /_yardoc/
45
+ /coverage/
46
+ /doc/
47
+ /pkg/
48
+ /spec/reports/
49
+ /tmp/
50
+
51
+
52
+ **.orig
53
+ rerun.txt
54
+ pickle-email-*.html
55
+
56
+ *.rbc
57
+ *.sassc
58
+ *~
59
+
60
+ ###############
61
+ # fixed file #
62
+ ###############
63
+ *.exe
64
+ *.txt
65
+ *.def
66
+ *.dsp
67
+ *.lib
68
+ *.doc
69
+ *.dll
70
+ *.lnt
71
+ *.pm
72
+ *.xls
73
+ *.dbg
74
+ *.DBG
75
+ *.o
76
+ *.plg
77
+ *.keep
78
+
79
+ ###############
80
+ # script #
81
+ ###############
82
+ *.bat
83
+
84
+ ###############
85
+ # temp file #
86
+ ###############
87
+ ~*
88
+ *.log
89
+ *.cmm
90
+ *.men
91
+ *.ini
92
+ *.fig
93
+ *.cmp
94
+ *.tmp
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Declare your gem's dependencies in webgit.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ # Declare any dependencies that are still in development here instead of in
9
+ # your gemspec. These might include edge Rails or gems from your path or
10
+ # Git. Remember to move these dependencies to your gemspec before releasing
11
+ # your gem to rubygems.org.
12
+
13
+ # To use debugger
14
+ # gem 'debugger'
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Webgit
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/webgit`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ Webgit is a tool allow you explore your git repostory use browser.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ `gem 'webgit'`
12
+
13
+ And then execute:
14
+
15
+ `bundle`
16
+
17
+ Or install it yourself as:
18
+
19
+ `gem install webgit`
20
+
21
+ ## Usage
22
+
23
+ ```sh
24
+ cd <GIT_REPO_DIR>
25
+ webgit
26
+ ```
27
+
28
+ `http://localhost:9999/`
29
+
30
+ ```
31
+ webgit <GIT_REPO_DIR> <PORT>
32
+ ```
33
+
34
+ `http://localhost:<PORT>/`
35
+
36
+
37
+ ## Development
38
+
39
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
40
+
41
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it ( https://github.com/[my-github-username]/webgit/fork )
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create a new Pull Request
data/Rakefile CHANGED
@@ -1,21 +1 @@
1
- begin
2
- require 'bundler/setup'
3
- rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
- end
6
-
7
- require 'rdoc/task'
8
-
9
- RDoc::Task.new(:rdoc) do |rdoc|
10
- rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = 'Webgit'
12
- rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.rdoc')
14
- rdoc.rdoc_files.include('lib/**/*.rb')
15
- end
16
-
17
-
18
-
19
-
20
- Bundler::GemHelper.install_tasks
21
-
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "webgit"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/bin/webgit ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "webgit"
5
+
6
+ Webgit::App.run!
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+
11
+ # (If you use this, don't forget to add pry to your Gemfile!)
12
+ # require "pry"
13
+ # Pry.start
data/lib/webgit/app.rb ADDED
@@ -0,0 +1,95 @@
1
+ # coding: utf-8
2
+
3
+ module Webgit
4
+ class App < Sinatra::Base
5
+ set :port, lambda{ PORT }
6
+ set :public_folder, File.expand_path("../../../", __FILE__) + '/public'
7
+ set :views, File.expand_path("../../../", __FILE__) + '/views'
8
+ helpers Helpers
9
+
10
+ before "/*" do
11
+ @repo = Rugged::Repository.new(GIT_REPO)
12
+ @branches = @repo.branches
13
+ end
14
+
15
+ get '/objects/:sha/show' do
16
+ begin
17
+ obj = @repo.rev_parse(params[:sha])
18
+ show_object(obj, tree_erb: :show_tree, name: (params[:name] || ""))
19
+ rescue Rugged::ReferenceError => e
20
+ halt 404, "#{params[:splat].first} Not Found!" unless obj
21
+ end
22
+ end
23
+
24
+ get '/preview/:branch/*' do
25
+ @branch = @repo.branches[params[:branch] || @repo.head.name]
26
+ blob = find_object @branch.target.tree
27
+ format = params[:splat].first.split('.')[-1]
28
+ mimes = MIME::Types.of(params[:splat].first)
29
+ mime = if mimes && mimes.first
30
+ mimes.first.content_type
31
+ else
32
+ "text/html"
33
+ end
34
+ response.headers['Cache-Control'] = "public, max-age=864000"
35
+ response.headers['Content-Type'] = mime
36
+ response.headers['Content-Disposition'] = 'inline'
37
+
38
+ blob.content
39
+ end
40
+
41
+ get '/:branch?' do
42
+ @branch = @repo.branches[params[:branch] || @repo.head.name]
43
+ @tree = @branch.target.tree
44
+ erb :tree
45
+ end
46
+
47
+ get '/:branch/*' do
48
+ @branch = @repo.branches[params[:branch] || @repo.head.name]
49
+ obj = find_object @branch.target.tree
50
+ halt 404, "#{params[:splat].first} Not Found!" unless obj
51
+ show_object(obj, name: params[:splat].first)
52
+ end
53
+
54
+ private
55
+ def show_object(obj, options = {})
56
+ if obj.is_a? Rugged::Tree
57
+ @tree = obj
58
+ erb options[:tree_erb] || :tree
59
+ elsif obj.is_a? Rugged::Blob
60
+ @blob = obj
61
+ @format = options[:name].split('.')[-1]
62
+ erb :blob
63
+ else
64
+ halt 500, "Unsupport file type."
65
+ end
66
+ end
67
+
68
+ def find_object(tree)
69
+ obj = tree
70
+ paths = params[:splat].first
71
+ if paths
72
+ paths.split('/').each do|path|
73
+ obj = find_object_in_tree(obj, path)
74
+ break unless obj
75
+ end
76
+ end
77
+ obj
78
+ end
79
+
80
+ def find_object_in_tree(tree, name)
81
+ tree.each do|obj|
82
+ if name == obj[:name]
83
+ oid = obj[:oid]
84
+ return @repo.lookup(obj[:oid])
85
+ end
86
+ end if tree.respond_to?(:each)
87
+ end
88
+
89
+ run! if app_file == $0
90
+
91
+ end
92
+ end
93
+
94
+
95
+
@@ -0,0 +1,104 @@
1
+ # coding: utf-8
2
+ module Webgit
3
+ module Helpers
4
+
5
+ def navigation(branch)
6
+ paths = if params[:splat] && params[:splat].first
7
+ params[:splat].first.split('/')
8
+ else
9
+ []
10
+ end
11
+ i = -1
12
+ nav = paths.map do|p|
13
+ i += 1
14
+ if i < paths.length - 1
15
+ "<a href=#{webgit_path(branch, paths[0..i].join('/'))}>#{p}</a>"
16
+ else
17
+ p
18
+ end
19
+ end.join(" / ")
20
+ nav
21
+ end
22
+
23
+ def git_tree_path(branch, item)
24
+ if params[:splat] && params[:splat].first
25
+ webgit_path(branch, "#{params[:splat].first}/#{item}")
26
+ else
27
+ webgit_path(branch, item)
28
+ end
29
+ end
30
+
31
+ def git_blob_path(branch, item)
32
+ if params[:splat] && params[:splat].first
33
+ webgit_path(branch, "#{params[:splat].first}/#{item}")
34
+ else
35
+ webgit_path(branch, item)
36
+ end
37
+ end
38
+
39
+ def webgit_path(branch, path)
40
+ "/#{branch}/#{path}"
41
+ end
42
+
43
+ def preview_path(branch, path)
44
+ "/preview/#{branch}/#{path}"
45
+ end
46
+
47
+ def show_path(oid, name = nil)
48
+ if (name)
49
+ "/objects/#{oid}/show?name=#{name}"
50
+ else
51
+ "/objects/#{oid}/show"
52
+ end
53
+ end
54
+
55
+ def upper_path(branch)
56
+ path_url = "";
57
+ if params[:splat] && params[:splat].first
58
+ paths = params[:splat].first.split("/")
59
+ path_url = paths.tap{|paths| paths.pop }.join("/")
60
+ end
61
+ webgit_path(branch, path_url)
62
+ end
63
+
64
+ EXT_WITH_LANGUAGE = {
65
+ ru: :ruby,
66
+ rb: :ruby,
67
+ rake: :ruby,
68
+ clj: :clojure,
69
+ h: :c,
70
+ py: :python,
71
+ txt: :text,
72
+ sh: :text,
73
+ js: :java_script,
74
+ htm: :html,
75
+ yml: :yaml
76
+ }
77
+
78
+ def preview(blob, format)
79
+ f = format_to_sym(format)
80
+ path = params[:splat].first
81
+ case f
82
+ when :html, :htm then
83
+ "<div>#{blob.content}</div>"
84
+ when :ruby, :java, :java_script, :python, :scss, :php, :lua, :html, :json, :go, :sql, :yaml, :text, :coffee then
85
+ CodeRay.scan(blob.content.force_encoding('UTF-8'), f).div(:line_numbers => :table, :css => :class)
86
+ when :png, :jpg, :gif then
87
+ "<img src=\"#{preview_path(@branch.name, path)}\" />"
88
+ when '.pdf' then
89
+ "<iframe src=\"#{preview_path(@branch.name, path)}\" width='860' height='800' border='0' style='border:none'></iframe>"
90
+ else
91
+ "Binary File <#{path}>"
92
+ end
93
+ end
94
+
95
+ private
96
+ def format_to_sym(format)
97
+ if format
98
+ EXT_WITH_LANGUAGE.fetch(format.to_sym, format.to_sym)
99
+ else
100
+ :text
101
+ end
102
+ end
103
+ end
104
+ end
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  module Webgit
2
- VERSION = "0.0.2"
3
+ VERSION = "0.1.0"
3
4
  end
data/lib/webgit.rb CHANGED
@@ -1,5 +1,16 @@
1
+ # coding: utf-8
2
+ require 'sinatra'
1
3
  require 'rugged'
2
- require "webgit/engine"
4
+ require 'coderay'
5
+ require 'mime-types'
6
+
7
+ require "webgit/version"
8
+ require "webgit/helpers"
9
+ require "webgit/app"
3
10
 
4
11
  module Webgit
12
+ GIT_REPO = ARGV[0] || Dir.pwd
13
+ raise "#{GIT_REPO} is not a git repostory." unless File.exists? "#{GIT_REPO}/.git"
14
+
15
+ PORT = ARGV[1] || 9999
5
16
  end
File without changes
@@ -1,3 +1,38 @@
1
+ .box {
2
+ background-color: #f9f9f9;
3
+ padding: 10px;
4
+ margin: 0 0 20px 0; /* negative indent the amount of the padding to maintain the grid system */
5
+ -webkit-border-radius: 6px;
6
+ -moz-border-radius: 6px;
7
+ border-radius: 6px;
8
+ -webkit-box-shadow: 0 0px 2px rgba(0,0,0,.05);
9
+ -moz-box-shadow: 0 0px 2px rgba(0,0,0,.1);
10
+ box-shadow: 0 0px 2px rgba(0,0,0,.05);
11
+ }
12
+
13
+ .box h2.title {
14
+ font-size: 12px;
15
+ margin:0 -10px; padding:0 10px; margin-bottom:8px;
16
+ color:#999; line-height:100%;
17
+ border-bottom:1px solid #ddd; padding-bottom:8px;
18
+ }
19
+ }
20
+
21
+ .box.box_gray {
22
+ background-color: #F5F5F5;
23
+ padding: 0;
24
+ }
25
+ }
26
+
27
+
28
+
29
+
30
+ .CodeRay {
31
+ background-color: #efefef;
32
+ font-family: Monaco, "Courier New", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace;
33
+ color: #000;
34
+ margin-bottom: 14px;
35
+ }
1
36
  .CodeRay {
2
37
  background-color: #efefef;
3
38
  font-family: Monaco, "Courier New", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace;
data/views/blob.erb ADDED
@@ -0,0 +1,5 @@
1
+ <tbody>
2
+ <tr>
3
+ <td colspan="2" class="preview"><%= preview(@blob, @format || :rb) %></td>
4
+ </tr>
5
+ </tbody>
data/views/layout.erb ADDED
@@ -0,0 +1,47 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Webgit(<%= Webgit::GIT_REPO %>)</title>
5
+ <!-- Latest compiled and minified CSS -->
6
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
7
+
8
+ <!-- Optional theme -->
9
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css">
10
+
11
+ <script src="http://code.jquery.com/jquery.min.js"></script>
12
+ <!-- Latest compiled and minified JavaScript -->
13
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
14
+
15
+ <link rel='stylesheet' href='/stylesheets/coderay.css' type='text/css' media="screen, projection">
16
+ </head>
17
+ <body>
18
+
19
+ <div class="box">
20
+ <table class="table table-bordered table-striped table-condensed">
21
+ <thead>
22
+ <tr>
23
+ <td class="dropdown" style="width: 120px;">
24
+ <% if @branch %>
25
+ <a href="javascript:void(0);" class="dropdown-toggle" data-toggle="dropdown"><%= @branch.name %> <b class="caret"></b></a>
26
+ <% else %>
27
+ <a href="javascript:void(0);" class="dropdown-toggle" data-toggle="dropdown"><%= @branches.first.name %> <b class="caret"></b></a>
28
+ <% end %>
29
+ <ul class="dropdown-menu">
30
+ <% @branches.each do|branch| %>
31
+ <li><a href="<%= webgit_path(branch.name, "") %>"><%= branch.name %></a></li>
32
+ <% end %>
33
+ </ul>
34
+ </td>
35
+ <td>
36
+ <% if @branch %>
37
+ <a href="<%= webgit_path(@branch.name, "") %>"><%= @branch.name %></a> / <%= navigation(@branch.name) %>
38
+ <% end %>
39
+ </td>
40
+ </tr>
41
+ </thead>
42
+ <%= yield %>
43
+ </table>
44
+ </div>
45
+
46
+ </body>
47
+ </html>
@@ -0,0 +1,12 @@
1
+ <tbody>
2
+ <% @tree.each_tree do|item| %>
3
+ <tr>
4
+ <td colspan="2"><a href="<%= show_path(item[:oid]) %>"><%= item[:name] %></a></td>
5
+ </tr>
6
+ <% end %>
7
+ <% @tree.each_blob do|item| %>
8
+ <tr>
9
+ <td colspan="2"><a href="<%= show_path(item[:oid], item[:name]) %>"><%= item[:name] %></a></td>
10
+ </tr>
11
+ <% end %>
12
+ </tbody>
data/views/tree.erb ADDED
@@ -0,0 +1,16 @@
1
+ <tbody>
2
+ <tr>
3
+ <td colspan="2"><a href="<%= upper_path(@branch.name) %>">..</a></td>
4
+ </tr>
5
+ <% @tree.each_tree do|item| %>
6
+ <tr>
7
+ <td colspan="2"><a href="<%= git_tree_path(@branch.name, item[:name]) %>"><%= item[:name] %></a></td>
8
+ </tr>
9
+ <% end %>
10
+ <% @tree.each_blob do|item| %>
11
+ <tr>
12
+ <td colspan="2"><a href="<%= git_blob_path(@branch.name, item[:name]) %>"><%= item[:name] %></a></td>
13
+ </tr>
14
+ <% end %>
15
+ </tbody>
16
+
data/webgit.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'webgit/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "webgit"
8
+ spec.version = Webgit::VERSION
9
+ spec.authors = ["James Zhan"]
10
+ spec.email = ["zhiqiangzhan@gmail.com"]
11
+ spec.homepage = "http://www.github.com/jameszhan/webgit"
12
+
13
+ spec.summary = "Git Web Client"
14
+ spec.description = "Git Web Client."
15
+ spec.homepage = "http://www.github.com/jameszhan/webgit"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+
20
+ spec.bindir = "bin"
21
+ spec.executables = spec.files.grep(%r{^bin/webgit}) { |f| File.basename(f) }
22
+
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "sinatra", '~> 1.4'
26
+ spec.add_dependency 'rugged', '~> 0.21'
27
+ spec.add_dependency 'coderay', '~> 1.1'
28
+ spec.add_dependency "mime-types", '~> 2.4'
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.8"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webgit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Zhan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-11 00:00:00.000000000 Z
11
+ date: 2015-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rugged
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,35 +52,76 @@ dependencies:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
54
  version: '1.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mime-types
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.4'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
41
97
  description: Git Web Client.
42
98
  email:
43
99
  - zhiqiangzhan@gmail.com
44
- executables: []
100
+ executables:
101
+ - webgit
45
102
  extensions: []
46
103
  extra_rdoc_files: []
47
104
  files:
105
+ - ".gitignore"
106
+ - CODE_OF_CONDUCT.md
107
+ - Gemfile
108
+ - README.md
48
109
  - README.rdoc
49
110
  - Rakefile
50
- - app/assets/javascripts/webgit/application.js
51
- - app/assets/javascripts/webgit/git.js.coffee
52
- - app/assets/stylesheets/webgit/application.css
53
- - app/assets/stylesheets/webgit/coderay.css
54
- - app/assets/stylesheets/webgit/git.css.scss
55
- - app/controllers/webgit/application_controller.rb
56
- - app/controllers/webgit/git_controller.rb
57
- - app/helpers/webgit/application_helper.rb
58
- - app/helpers/webgit/git_helper.rb
59
- - app/views/layouts/webgit/application.html.erb
60
- - app/views/webgit/git/_nav_header.html.erb
61
- - app/views/webgit/git/blob.html.erb
62
- - app/views/webgit/git/index.html.erb
63
- - app/views/webgit/git/tree.html.erb
64
- - config/routes.rb
65
- - lib/tasks/webgit_tasks.rake
111
+ - bin/console
112
+ - bin/setup
113
+ - bin/webgit
66
114
  - lib/webgit.rb
67
- - lib/webgit/app_config.rb
68
- - lib/webgit/engine.rb
115
+ - lib/webgit/app.rb
116
+ - lib/webgit/helpers.rb
69
117
  - lib/webgit/version.rb
118
+ - public/favicon.ico
119
+ - public/stylesheets/coderay.css
120
+ - views/blob.erb
121
+ - views/layout.erb
122
+ - views/show_tree.erb
123
+ - views/tree.erb
124
+ - webgit.gemspec
70
125
  homepage: http://www.github.com/jameszhan/webgit
71
126
  licenses:
72
127
  - MIT
@@ -1,15 +0,0 @@
1
- // This is a manifest file that'll be compiled into application.js, which will include all the files
2
- // listed below.
3
- //
4
- // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
- //
7
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // compiled file.
9
- //
10
- // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
- // about supported directives.
12
- //
13
- //= require jquery
14
- //= require twitter/bootstrap
15
- //= require_tree .
@@ -1,3 +0,0 @@
1
- # Place all the behaviors and hooks related to the matching controller here.
2
- # All this logic will automatically be available in application.js.
3
- # You can use CoffeeScript in this file: http://coffeescript.org/
@@ -1,14 +0,0 @@
1
- /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the top of the
9
- * compiled file, but it's generally better to create a new file per style scope.
10
- *
11
- *= require twitter/bootstrap
12
- *= require_self
13
- *= require_tree .
14
- */
@@ -1,24 +0,0 @@
1
- // Place all the styles related to the git controller here.
2
- // They will automatically be included in application.css.
3
- // You can use Sass (SCSS) here: http://sass-lang.com/
4
- .box {
5
- background-color: #f9f9f9;
6
- padding: 10px;
7
- margin: 0 0 20px 0; /* negative indent the amount of the padding to maintain the grid system */
8
- -webkit-border-radius: 6px;
9
- -moz-border-radius: 6px;
10
- border-radius: 6px;
11
- -webkit-box-shadow: 0 0px 2px rgba(0,0,0,.05);
12
- -moz-box-shadow: 0 0px 2px rgba(0,0,0,.1);
13
- box-shadow: 0 0px 2px rgba(0,0,0,.05);
14
- h2.title {
15
- font-size: 12px;
16
- margin:0 -10px; padding:0 10px; margin-bottom:8px;
17
- color:#999; line-height:100%;
18
- border-bottom:1px solid #ddd; padding-bottom:8px;
19
- }
20
- &.box_gray {
21
- background-color: #F5F5F5;
22
- padding: 0;
23
- }
24
- }
@@ -1,4 +0,0 @@
1
- module Webgit
2
- class ApplicationController < ActionController::Base
3
- end
4
- end
@@ -1,66 +0,0 @@
1
- module Webgit
2
- class GitController < ApplicationController
3
- before_action :set_repo_branch, except: [:index, :set_current_repo]
4
-
5
- def index
6
-
7
- end
8
-
9
- def set_current_repo
10
- session[:current_repo] = params[:repo_name]
11
- redirect_to webgit_tree_path(:master)
12
- end
13
-
14
- def tree
15
- @tree = find_object
16
- end
17
-
18
- def blob
19
- @blob = find_object
20
- render formats: [:html]
21
- end
22
-
23
- def preview
24
- @blob = find_object
25
- content_type = Mime.fetch(params[:format]){|fallback| "text/html"}.to_s
26
- response.headers['Cache-Control'] = "public, max-age=#{12.hours.to_i}"
27
- response.headers['Content-Type'] = content_type
28
- response.headers['Content-Disposition'] = 'inline'
29
- render text: @blob.content, content_type: content_type
30
- end
31
-
32
- protected
33
- def find_object
34
- obj = @branch.tree
35
- if ps = params[:path]
36
- ps = ps + "." + params[:format] if params[:format]
37
- ps.split('/').each do|p|
38
- obj = find_object_in_tree(obj, p)
39
- break unless obj
40
- end
41
- end
42
- obj
43
- end
44
-
45
- def find_object_in_tree(tree, name)
46
- tree.each do|obj|
47
- if name == obj[:name]
48
- oid = obj[:oid]
49
- return @repo.lookup(obj[:oid])
50
- end
51
- end if tree.respond_to?(:each)
52
- end
53
-
54
- def set_repo_branch
55
- if session[:current_repo] && (path = Webgit::AppConfig::REPOS[session[:current_repo]]['path'])
56
- @repo = Rugged::Repository.new(path)
57
- @branch = @repo.rev_parse(params[:branch])
58
- @branches = Rugged::Branch.each_name(@repo).select{|item| !item.include?('/') && item != params[:branch]}
59
- else
60
- redirect_to webgit_path
61
- end
62
- end
63
-
64
- end
65
-
66
- end
@@ -1,42 +0,0 @@
1
- module Webgit
2
- module ApplicationHelper
3
- EXT_WITH_LANGUAGE = {
4
- ru: :ruby,
5
- rb: :ruby,
6
- rake: :ruby,
7
- clj: :clojure,
8
- h: :c,
9
- py: :python,
10
- txt: :text,
11
- sh: :text,
12
- js: :java_script,
13
- htm: :html
14
- }
15
-
16
- def preview(blob, format)
17
- f = format_to_sym(format)
18
- case f
19
- when :html, :htm then
20
- "<div>#{blob.content}</div>"
21
- when :ruby, :java, :js, :python, :scss, :php, :lua, :html, :json, :go, :sql, :yaml, :text, :coffee then
22
- CodeRay.scan(blob.content.force_encoding('UTF-8'), f).div(:line_numbers => :table, :css => :class)
23
- when :png, :jpg, :gif then
24
- "<img src=\"#{preview_path(params[:branch], params[:path])}.#{params[:format]}\" />"
25
- when '.pdf' then
26
- "<iframe src=\"#{preview_path(params[:branch], params[:path])}.#{params[:format]}\" width='860' height='800' border='0' style='border:none'></iframe>"
27
- else
28
- "Binary File [#{params[:path]}]"
29
- end
30
- end
31
-
32
- private
33
- def format_to_sym(format)
34
- if format
35
- EXT_WITH_LANGUAGE.fetch(format.to_sym, format.to_sym)
36
- else
37
- :text
38
- end
39
- end
40
-
41
- end
42
- end
@@ -1,44 +0,0 @@
1
- module Webgit
2
- module GitHelper
3
-
4
- def navigation
5
- ps = (params[:path] || "").split("/")
6
- i = -1
7
- nav = ps.map do|p|
8
- i += 1
9
- if i < ps.length - 1
10
- link_to p, webgit_tree_path(params[:branch], ps[0..i].join('/'))
11
- else
12
- p
13
- end
14
- end.join(" / ")
15
- raw nav
16
- end
17
-
18
-
19
- def git_tree_path(item)
20
- if params[:path]
21
- webgit_tree_path(params[:branch], "#{params[:path]}/#{item}")
22
- else
23
- webgit_tree_path(params[:branch], item)
24
- end
25
- end
26
-
27
- def git_blob_path(item)
28
- if params[:path]
29
- webgit_blob_path(params[:branch], "#{params[:path]}/#{item}")
30
- else
31
- webgit_blob_path(params[:branch], item)
32
- end
33
- end
34
-
35
- def upper_path()
36
- paths = params[:path].try(:split, "/")
37
- if paths
38
- path_url = paths.tap{|ps|ps.pop}.join("/")
39
- end
40
- webgit_tree_path(params[:branch], path_url)
41
- end
42
-
43
- end
44
- end
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Webgit</title>
5
- <%= stylesheet_link_tag "webgit/application", media: "all" %>
6
- <%= javascript_include_tag "webgit/application" %>
7
- <%= csrf_meta_tags %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>
@@ -1,17 +0,0 @@
1
- <thead>
2
- <tr>
3
- <td class="dropdown" style="width: 120px;">
4
- <%= link_to "javascript:void(0)", class: "dropdown-toggle", data: {toggle: "dropdown"} do %>
5
- <%= params[:branch] %> <b class="caret"></b>
6
- <% end %>
7
- <ul class="dropdown-menu">
8
- <%- @branches.each do|branch| %>
9
- <li><%= link_to branch, webgit_tree_path(branch) %></li>
10
- <%- end %>
11
- </ul>
12
- </td>
13
- <td>
14
- <%= link_to params[:branch], webgit_tree_path(params[:branch]) %> / <%= navigation %>
15
- </td>
16
- </tr>
17
- </thead>
@@ -1,10 +0,0 @@
1
- <div class="box">
2
- <table class="table table-bordered table-striped table-condensed">
3
- <%= render "nav_header" %>
4
- <tbody>
5
- <tr>
6
- <td colspan="2" class="preview"><%=raw preview(@blob, params[:format] || :rb) %></td>
7
- </tr>
8
- </tbody>
9
- </table>
10
- </div>
@@ -1,8 +0,0 @@
1
- <div class="box" style="width:600px;margin:30px auto;line-height:30px;">
2
- <h2 class="title">REPOS</h2>
3
- <ul>
4
- <%- Webgit::AppConfig::REPOS.each do|name, setting| %>
5
- <li><%= link_to name, current_repo_path(name) %></li>
6
- <%- end %>
7
- </ul>
8
- </div>
@@ -1,20 +0,0 @@
1
- <div class="box">
2
- <table class="table table-bordered table-striped table-condensed">
3
- <%= render "nav_header" %>
4
- <tbody>
5
- <tr>
6
- <td colspan="2"><%= link_to "..", upper_path %></td>
7
- </tr>
8
- <%- @tree.each_tree do|item| %>
9
- <tr>
10
- <td colspan="2"><%= link_to item[:name], git_tree_path(item[:name]) %></td>
11
- </tr>
12
- <%- end %>
13
- <%- @tree.each_blob do|item| %>
14
- <tr>
15
- <td colspan="2"><%= link_to item[:name], git_blob_path(item[:name]) %></td>
16
- </tr>
17
- <%- end %>
18
- </tbody>
19
- </table>
20
- </div>
data/config/routes.rb DELETED
@@ -1,10 +0,0 @@
1
- Webgit::Engine.routes.draw do
2
-
3
- root 'git#index'
4
-
5
- get 'current_repo/:repo_name' => 'git#set_current_repo', as: 'current_repo'
6
- get 'tree/:branch(/*path)' => 'git#tree', as: 'webgit_tree'
7
- get 'blob/:branch(/*path)' => 'git#blob', as: 'webgit_blob'
8
- get 'preview/:branch(/*path)' => 'git#preview', as: 'preview'
9
-
10
- end
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :webgit do
3
- # # Task goes here
4
- # end
@@ -1,5 +0,0 @@
1
- module Webgit
2
- class AppConfig
3
- REPOS = YAML.load_file(Rails.root + "config/repos.yml")
4
- end
5
- end
data/lib/webgit/engine.rb DELETED
@@ -1,10 +0,0 @@
1
- module Webgit
2
- class Engine < ::Rails::Engine
3
- isolate_namespace Webgit
4
-
5
- config.before_configuration do
6
- require 'webgit/app_config'
7
- end
8
-
9
- end
10
- end