ginatra 2.1.1 → 2.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 CHANGED
@@ -14,3 +14,4 @@ _layouts/
14
14
  .yardoc
15
15
  doc/*
16
16
  pkg/*
17
+ ginatra.gemspec
data/README.md CHANGED
@@ -31,7 +31,18 @@ Next, just do the following (your setup may require sudo):
31
31
 
32
32
  $ gem install ginatra
33
33
 
34
- This pulls down all the required dependencies too.
34
+ This pulls down most of the required dependencies too.
35
+
36
+ The last dependency you need is pygments, an awesome python syntax highlighter.
37
+ To check whether you have it, run:
38
+
39
+ $ which pygmentize
40
+
41
+ If this returns a path pointing to a 'pygmentize' binary, then you're all set.
42
+ If not you'll need to install pygments. Look at the last section of the
43
+ [jekyll wiki "install" page](http://wiki.github.com/mojombo/jekyll/install)
44
+ to see how to install it. Also make sure again that the `pygmentize` binary
45
+ is on your path.
35
46
 
36
47
  If you want to play around with the code, you can clone the repository. This also allows you
37
48
  to use a special rackup file to mount it where you wish. I am yet to sort out some of the
data/Rakefile CHANGED
@@ -2,8 +2,9 @@ require 'rubygems'
2
2
  require 'cucumber/rake/task'
3
3
  require 'spec/rake/spectask'
4
4
 
5
- current_path = File.expand_path(File.dirname(__FILE__))
6
- require "#{current_path}/lib/ginatra"
5
+ $:.unshift File.expand_path("#{File.dirname(__FILE__)}/lib")
6
+
7
+ require "ginatra"
7
8
 
8
9
  task :default => ['rake:spec', 'rake:features']
9
10
 
@@ -54,7 +55,7 @@ namespace :setup do
54
55
 
55
56
  desc "Installs the Required Gems"
56
57
  task :gems do |t|
57
- gems = %w(grit kematzy-sinatra-cache vegas)
58
+ gems = %w(grit kematzy-sinatra-cache)
58
59
  puts %x(gem install #{gems.join(" ")})
59
60
  end
60
61
 
@@ -75,10 +76,11 @@ begin
75
76
  gemspec.email = "sam@lenary.co.uk"
76
77
  gemspec.homepage = "http://lenary.github.com/ginatra"
77
78
  gemspec.authors = ["Sam Elliott", "Ryan Bigg"]
79
+ gemspec.version = Ginatra::VERSION
78
80
  gemspec.add_dependency('sinatra', '>=0.9.4')
79
81
  gemspec.add_dependency('grit', '>=1.1.1')
80
- gemspec.add_dependency('coderay', '>=0.8.0')
81
- gemspec.files.include 'vendor/**/*'
82
+ gemspec.add_dependency('vegas', '>=0.1.0')
83
+ gemspec.add_dependency('open4', '>= 0.9.6')
82
84
  end
83
85
  rescue LoadError
84
86
  puts "Jeweler not available. Install it with: sudo gem install jeweler"
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- current_path = File.expand_path(File.dirname(__FILE__))
3
+ $:.unshift File.expand_path("#{File.dirname(__FILE__)}/../lib")
4
4
 
5
- require "#{current_path}/../lib/ginatra"
5
+ require "ginatra"
6
6
 
7
7
  module Ginatra::Executable
8
8
  HELP = <<HELP
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- current_path = File.expand_path(File.dirname(__FILE__))
3
+ $:.unshift File.expand_path("#{File.dirname(__FILE__)}/../lib")
4
4
 
5
- require "#{current_path}/../lib/ginatra"
5
+ require "ginatra"
6
6
  require "logger"
7
7
 
8
8
  def logger
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- current_path = File.expand_path(File.dirname(__FILE__))
3
+ $:.unshift File.expand_path("#{File.dirname(__FILE__)}/../lib")
4
4
 
5
- require "#{current_path}/../lib/ginatra"
5
+ require "ginatra"
6
6
  require "logger"
7
7
 
8
8
  def logger
@@ -1,10 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- current_path = File.expand_path(File.dirname(__FILE__))
3
+ begin
4
+ require 'rubygems'
5
+ rescue LoadError
6
+ end
7
+ require "vegas"
8
+
9
+ $:.unshift File.expand_path("#{File.dirname(__FILE__)}/../lib")
10
+
11
+ require "ginatra"
4
12
 
5
- require "#{current_path}/../lib/ginatra"
6
- require "#{current_path}/../vendor/vegas/lib/vegas"
7
- Vegas::Runner.new(Ginatra::App, 'ginatra-server', :port => Ginatra::Config.port) do |runner, opts, app|
13
+ Vegas::Runner.new(Ginatra::App, 'ginatra-server', {:port => Ginatra::Config.port, :host => Ginatra::Config.host}) do |runner, opts, app|
8
14
 
9
15
  opts.banner = "Usage: ginatra-server [[options] start | stop | status]"
10
16
 
data/config.ru CHANGED
@@ -1,6 +1,6 @@
1
- current_path = File.expand_path(File.dirname(__FILE__))
1
+ $:.unshift File.expand_path("#{File.dirname(__FILE__)}/lib")
2
2
 
3
- require "#{current_path}/lib/ginatra"
3
+ require "ginatra"
4
4
 
5
5
  map '/' do
6
6
  run Ginatra::App
@@ -5,28 +5,33 @@ rescue LoadError
5
5
  end
6
6
  require 'sinatra/base'
7
7
  require 'grit'
8
- require 'coderay'
9
-
10
- current_path = File.expand_path(File.dirname(__FILE__))
11
8
 
12
9
  # The Ginatra Namespace Module
13
10
  module Ginatra; end
14
11
 
15
- # Loading in reverse because RepoList needs to be loaded before MultiRepoList
16
- Dir.glob("#{current_path}/ginatra/*.rb").reverse.each { |f| require f }
12
+ # i feel this is cleaner than the #{current_path} shenanigans ($: is the load path)
13
+ $:.unshift File.dirname(__FILE__)
14
+
15
+ # Loading in whichever order
16
+ require "ginatra/repo"
17
+ require "ginatra/repo_list"
18
+ require "ginatra/config"
19
+ require "ginatra/helpers"
17
20
 
18
- require "#{current_path}/sinatra/partials"
21
+ require "sinatra/partials"
19
22
 
20
23
  # Written myself. i know, what the hell?!
21
24
  module Ginatra
22
25
 
23
26
  # A standard error class for inheritance.
24
- # @todo Look for a refactor.
25
27
  class Error < StandardError; end
26
28
 
27
29
  # An error related to a commit somewhere.
28
- # @todo Look for a refactor.
29
- class CommitsError < Error; end
30
+ class CommitsError < Error
31
+ def initialize(repo)
32
+ super("Something went wrong looking for the commits for #{repo}")
33
+ end
34
+ end
30
35
 
31
36
  # Error raised when commit ref passed in parameters
32
37
  # does not exist in repository
@@ -36,9 +41,7 @@ module Ginatra
36
41
  end
37
42
  end
38
43
 
39
- current_path = File.expand_path(File.dirname(__FILE__))
40
- # @todo look for a refactor that is rip compatible
41
- VERSION = File.new("#{current_path}/../VERSION").read
44
+ VERSION = "2.2.0"
42
45
 
43
46
  # The main application class.
44
47
  #
@@ -46,15 +49,21 @@ module Ginatra
46
49
  # and is what is mounted by the +rackup.ru+ files.
47
50
  class App < Sinatra::Base
48
51
 
52
+ # logger that can be used with the Sinatra code
53
+ def logger
54
+ Ginatra::Config.logger
55
+ end
56
+
49
57
  configure do
50
- current_path = File.expand_path(File.dirname(__FILE__))
51
58
  Config.load!
59
+ set :host, Ginatra::Config[:host]
52
60
  set :port, Ginatra::Config[:port]
53
61
  set :raise_errors, Proc.new { test? }
54
62
  set :show_exceptions, Proc.new { development? }
55
63
  set :dump_errors, true
56
64
  set :logging, Proc.new { !test? }
57
65
  set :static, true
66
+ current_path = File.expand_path(File.dirname(__FILE__))
58
67
  set :public, "#{current_path}/../public"
59
68
  set :views, "#{current_path}/../views"
60
69
  end
@@ -79,8 +88,7 @@ module Ginatra
79
88
  end
80
89
 
81
90
  # The root route
82
- #
83
- # @todo how does this work?
91
+ # This works by interacting with the Ginatra::Repolist singleton.
84
92
  get '/' do
85
93
  erb :index
86
94
  end
@@ -175,6 +183,7 @@ module Ginatra
175
183
  get '/:repo/tree/:tree' do
176
184
  @repo = RepoList.find(params[:repo])
177
185
 
186
+ # this might look silly but it's needed to pass the --verify.
178
187
  if (tag = @repo.git.method_missing('rev_parse', {}, '--verify', "#{params[:tree]}^{tree}")).empty?
179
188
  # we don't have a tree.
180
189
  not_found
@@ -184,8 +193,8 @@ module Ginatra
184
193
 
185
194
  @tree = @repo.tree(params[:tree]) # can also be a ref (i think)
186
195
  @path = {}
187
- @path[:tree] = "/#{params[:repo]}/tree/#{params[:tree]}"
188
- @path[:blob] = "/#{params[:repo]}/blob/#{params[:tree]}"
196
+ @path[:tree] = "#{params[:repo]}/tree/#{params[:tree]}"
197
+ @path[:blob] = "#{params[:repo]}/blob/#{params[:tree]}"
189
198
  erb(:tree)
190
199
  end
191
200
 
@@ -202,12 +211,12 @@ module Ginatra
202
211
  if @tree.is_a?(Grit::Blob)
203
212
  # we need @tree to be a tree. if it's a blob, send it to the blob page
204
213
  # this allows people to put in the remaining part of the path to the file, rather than endless clicks like you need in github
205
- redirect "/#{params[:repo]}/blob/#{params[:tree]}/#{params[:splat].first}"
214
+ redirect "#{params[:repo]}/blob/#{params[:tree]}/#{params[:splat].first}"
206
215
  else
207
216
  etag(@tree.id)
208
217
  @path = {}
209
- @path[:tree] = "/#{params[:repo]}/tree/#{params[:tree]}/#{params[:splat].first}"
210
- @path[:blob] = "/#{params[:repo]}/blob/#{params[:tree]}/#{params[:splat].first}"
218
+ @path[:tree] = "#{params[:repo]}/tree/#{params[:tree]}/#{params[:splat].first}"
219
+ @path[:blob] = "#{params[:repo]}/blob/#{params[:tree]}/#{params[:splat].first}"
211
220
  erb(:tree)
212
221
  end
213
222
  end
@@ -239,16 +248,6 @@ module Ginatra
239
248
  redirect "/#{params[:repo]}/tree/#{params[:tree]}/#{params[:splat].first}"
240
249
  else
241
250
  etag(@blob.id)
242
- extension = params[:splat].first.split(".").last
243
- @highlighter = case extension
244
- when 'js'
245
- 'javascript'
246
- when 'css'
247
- 'css'
248
- end
249
-
250
- @highlighter ||= 'ruby'
251
-
252
251
  erb(:blob)
253
252
  end
254
253
  end
@@ -15,9 +15,44 @@ module Ginatra
15
15
  :git_dirs => [File.expand_path("#{current_path}/../../repos/*")],
16
16
  :ignored_files => ['README.md'],
17
17
  :description => "View My Git Repositories",
18
- :port => 9797
18
+ :port => 9797,
19
+ :host => "0.0.0.0",
20
+ :prefix => "/"
19
21
  }
20
22
 
23
+ def self.logger
24
+ return @logger if @logger
25
+
26
+ log_file = Ginatra::Config[:log_file].to_s || STDOUT
27
+
28
+ # create log_file location
29
+ # The log_file config option should be an absolute file system path
30
+ # It doesn't have to exist, but ginatra should have the proper file system privileges to create the directories
31
+ # and files along the specified path
32
+ unless log_file == STDOUT
33
+ parent_dir, separator, file_component = log_file.rpartition("/")
34
+ FileUtils.mkdir_p parent_dir
35
+ FileUtils.touch log_file
36
+ end
37
+
38
+ # determine log level from config file
39
+ # The log_level config option should be one of the Logger::Severity constant names (case doesn't matter)
40
+ # example: :log_level: debug
41
+ log_level = Ginatra::Config[:log_level]
42
+
43
+ if log_level.nil?
44
+ log_level = Logger::WARN
45
+ else
46
+ log_level = Logger.const_get(log_level.to_s.upcase.to_sym)
47
+ log_level = Logger::WARN if log_level.nil?
48
+ end
49
+
50
+ @logger = Logger.new(log_file)
51
+ @logger.level = log_level
52
+ @logger.formatter = Proc.new {|s, t, n, msg| "[#{t}] #{msg}\n"}
53
+ @logger
54
+ end
55
+
21
56
  # Dumps the Default configuration to +CONFIG_PATH+,
22
57
  # WITHOUT regard for what's already there.
23
58
  #
@@ -1,10 +1,22 @@
1
1
  require "digest/md5"
2
+ require "open4"
2
3
 
3
4
  module Ginatra
4
5
  # Helpers used in the views usually,
5
6
  # but not exclusively.
6
7
  module Helpers
7
8
 
9
+ # constructs the URL used in the layout's base tag
10
+ def prefix_url(rest_of_url="")
11
+ prefix = Ginatra::Config[:prefix].to_s
12
+
13
+ if prefix.length > 0 && prefix[-1].chr == "/"
14
+ prefix.chop!
15
+ end
16
+
17
+ "#{prefix}/#{rest_of_url}"
18
+ end
19
+
8
20
  # takes an email and returns a url to a secure gravatar
9
21
  #
10
22
  # @param [String] email the email address
@@ -59,7 +71,7 @@ module Ginatra
59
71
  # @return [String] HTML link to the given ref with class attached.
60
72
  def commit_ref(ref, repo_param)
61
73
  ref_class = ref.class.to_s.split("::")[1].to_s
62
- "<a class=\"ref #{ref_class}\" href=\"/#{repo_param}/#{ref.name}\">#{ref.name}</a>"
74
+ "<a class=\"ref #{ref_class}\" href=\"" + prefix_url("#{repo_param}/#{ref.name}") + "\">#{ref.name}</a>"
63
75
  end
64
76
 
65
77
  # calls +Ginatra::Helpers#commit_ref+ for each ref in the commit
@@ -84,7 +96,7 @@ module Ginatra
84
96
  #
85
97
  # @return [String] the HTML link to the archive.
86
98
  def archive_link(tree, repo_param)
87
- "<a class=\"download\" href=\"/#{repo_param}/archive/#{tree.id}.tar.gz\" title=\"Download a tar.gz snapshot of this Tree\">Download Archive</a>"
99
+ "<a class=\"download\" href=\"" + prefix_url("#{repo_param}/archive/#{tree.id}.tar.gz") + "\" title=\"Download a tar.gz snapshot of this Tree\">Download Archive</a>"
88
100
  end
89
101
 
90
102
  # returns a string including the link to download a patch for a certain
@@ -96,7 +108,7 @@ module Ginatra
96
108
  #
97
109
  # @return [String] the HTML link to the patch
98
110
  def patch_link(commit, repo_param)
99
- "<a class=\"download\" href=\"/#{repo_param}/commit/#{commit.id}.patch\" title=\"Download a patch file of this Commit\">Download Patch</a>"
111
+ "<a class=\"download\" href=\"" + prefix_url("#{repo_param}/commit/#{commit.id}.patch") + "\" title=\"Download a patch file of this Commit\">Download Patch</a>"
100
112
  end
101
113
 
102
114
  # returns a HTML (+<ul>+) list of the files altered in a given commit.
@@ -123,14 +135,6 @@ module Ginatra
123
135
  "<ul id='files'>#{out.join}</ul>"
124
136
  end
125
137
 
126
- # returns some html containing the Coderay'd diff files.
127
- #
128
- # @param [String] diff the diff you want highlighted
129
- # @return [String] the highlighted diff
130
- def diff(diff)
131
- diff = CodeRay.scan(diff, :diff).div(:line_numbers => :table, :css => :class)
132
- end
133
-
134
138
  # Formats the text to remove multiple spaces and newlines, and then inserts
135
139
  # HTML linebreaks.
136
140
  #
@@ -209,8 +213,7 @@ module Ginatra
209
213
  end
210
214
 
211
215
  # Returns the Hostname of the given install.
212
- #
213
- # @todo Where is this used?
216
+ # used in the atom feeds.
214
217
  #
215
218
  # stolen from Marley
216
219
  #
@@ -226,8 +229,28 @@ module Ginatra
226
229
  #
227
230
  # @return [String] the HTML containing the link to the feed.
228
231
  def atom_feed_link(repo_param, ref=nil)
229
- "<a href=\"/#{repo_param}#{"/#{ref}" if !ref.nil?}.atom\" title=\"Atom Feed\" class=\"atom\">Feed</a>"
232
+ "<a href=\"" + prefix_url("#{repo_param}#{"/#{ref}" if !ref.nil?}.atom") + "\" title=\"Atom Feed\" class=\"atom\">Feed</a>"
230
233
  end
231
234
 
235
+ def pygmentize(content, filename=nil)
236
+ type = !filename ? "diff" : pygmentize_type(filename)
237
+ html_output = ''
238
+ Open4.popen4("pygmentize -l #{type} -f html") do |pid, stdin, stdout, stderr|
239
+ stdin.puts content
240
+ stdin.close
241
+ html_output = stdout.read.strip
242
+ [stdout, stderr].each {|io| io.close }
243
+ end
244
+ html_output
245
+ end
246
+
247
+ def pygmentize_type(filename)
248
+ type =''
249
+ Open4.popen4("pygmentize -N #{filename}") do |pid, stdin, stdout, stderr|
250
+ type = stdout.read.strip
251
+ [stdin, stdout, stderr].each {|io| io.close }
252
+ end
253
+ type
254
+ end
232
255
  end
233
256
  end
@@ -82,5 +82,14 @@ module Ginatra
82
82
  @repo.send(sym, *args, &block)
83
83
  end
84
84
 
85
+ # to correspond to the #method_missing definition
86
+ def respond_to?(sym)
87
+ @repo.respond_to?(sym) || super
88
+ end
89
+
90
+ # not sure why we need this but whatever.
91
+ def to_s
92
+ @name.to_s
93
+ end
85
94
  end
86
95
  end
@@ -26,13 +26,13 @@ module Ginatra
26
26
 
27
27
  # searches through the configured directory globs to find all the repositories
28
28
  # and adds them if they're not already there.
29
- #
30
- # @todo Docs: what the hell does this return?
31
29
  def refresh
32
- Ginatra::Config.git_dirs.map! do |git_dir|
30
+ list.clear
31
+ Ginatra::Config.git_dirs.map do |git_dir|
33
32
  files = Dir.glob(git_dir)
34
33
  files.each { |e| add(e) unless Ginatra::Config.ignored_files.include?(File.split(e).last) }
35
34
  end
35
+ list
36
36
  end
37
37
 
38
38
  # adds a Repo corresponding to the path it found a git repo at in the configured
@@ -41,12 +41,18 @@ module Ginatra
41
41
  # @param [String] path the path of the git repo
42
42
  # @param [String] param the param of the repo if it differs,
43
43
  # for looking to see if it's already on the list
44
- #
45
- # @todo Docs: what does this return?
46
44
  def add(path, param = File.split(path).last)
47
45
  unless self.has_repo?(param)
48
- list << Repo.new(path)
46
+ begin
47
+ list << Repo.new(path)
48
+ rescue Grit::InvalidGitRepositoryError
49
+ # If the path is not a git repository, then this error is raised
50
+ # and causes an error page to result.
51
+ # Is it preferable to just log that the error happened and not show the error page?
52
+ Ginatra::Config.logger.info "Invalid git repository at #{path}. Did you create the directory and forget to run 'git init' inside that directory?"
53
+ end
49
54
  end
55
+ list
50
56
  end
51
57
 
52
58
  # checks to see if the list contains a repo with a param
@@ -83,12 +89,14 @@ module Ginatra
83
89
 
84
90
  # allows missing methods to cascade to the instance,
85
91
  #
86
- # @todo do we need this?
87
- # @todo update the respond_to? method if we do.
88
- #
89
92
  # Caution! contains: Magic
90
93
  def self.method_missing(sym, *args, &block)
91
94
  instance.send(sym, *args, &block)
92
95
  end
96
+
97
+ # updated to correspond to the method_missing definition
98
+ def self.respond_to?(sym)
99
+ instance.respond_to?(sym) || super
100
+ end
93
101
  end
94
102
  end
data/rackup.ru CHANGED
@@ -1,6 +1,6 @@
1
- current_path = File.expand_path(File.dirname(__FILE__))
1
+ $:.unshift File.expand_path("#{File.dirname(__FILE__)}/lib")
2
2
 
3
- require "#{current_path}/lib/ginatra"
3
+ require "ginatra"
4
4
 
5
5
  map '/' do
6
6
  run Ginatra::App
@@ -2,7 +2,7 @@ current_path = File.expand_path(File.dirname(__FILE__))
2
2
  require File.join(current_path, "spec_helper")
3
3
 
4
4
  describe "Ginatra" do
5
-
5
+
6
6
  describe "RepoList" do
7
7
 
8
8
  before do
@@ -18,5 +18,64 @@ describe "Ginatra" do
18
18
  @repo_list.include?(@repo)
19
19
  end
20
20
 
21
+ it "has_repo? works for existing repo" do
22
+ Ginatra::RepoList.instance.has_repo?("test").should == true
23
+ end
24
+
25
+ it "has_repo? works for non-existant repo" do
26
+ Ginatra::RepoList.instance.has_repo?("bad-test").should == false
27
+ end
28
+
29
+ describe "New repos added to repo directory" do
30
+
31
+ NEW_REPO_NAME = "temp-new-repo"
32
+ REPO_DIR = File.join(current_path, "..", "repos")
33
+
34
+ def print_repos_found
35
+ Ginatra::Config.git_dirs.map! do |git_dir|
36
+ files = Dir.glob(git_dir)
37
+ files.each { |e| STDOUT.puts(e) unless Ginatra::Config.ignored_files.include?(File.split(e).last) }
38
+ end
39
+ end
40
+
41
+ before(:each) do
42
+ FileUtils.cd(REPO_DIR) do |dir|
43
+ FileUtils.mkdir(NEW_REPO_NAME)
44
+ FileUtils.cd(NEW_REPO_NAME) do |dir|
45
+ `git init`
46
+ end
47
+ end
48
+ end
49
+
50
+ it "should detect new repo after refresh" do
51
+ repo_list = Ginatra::RepoList.list # calling this should refresh the list
52
+
53
+ Ginatra::RepoList.instance.has_repo?(NEW_REPO_NAME).should == true
54
+
55
+ new_repo = Ginatra::RepoList.find(NEW_REPO_NAME)
56
+ repo_list.should include(new_repo)
57
+ end
58
+
59
+ it "should detect when a repo has been removed after refresh" do
60
+ repo_list = Ginatra::RepoList.list # calling this should refresh the list
61
+
62
+ Ginatra::RepoList.instance.has_repo?(NEW_REPO_NAME).should == true
63
+
64
+ new_repo = Ginatra::RepoList.find(NEW_REPO_NAME)
65
+ repo_list.should include(new_repo)
66
+
67
+ # remove the new repository from the file system
68
+ FileUtils.rm_rf File.join(REPO_DIR, NEW_REPO_NAME), :secure => true
69
+
70
+ repo_list = Ginatra::RepoList.list # refresh the repo list
71
+
72
+ Ginatra::RepoList.instance.has_repo?(NEW_REPO_NAME).should == false
73
+ repo_list.should_not include(new_repo)
74
+ end
75
+
76
+ after(:each) do
77
+ FileUtils.rm_rf File.join(REPO_DIR, NEW_REPO_NAME), :secure => true
78
+ end
79
+ end
21
80
  end
22
81
  end
@@ -7,7 +7,16 @@ current_path = File.expand_path(File.dirname(__FILE__))
7
7
  require "#{current_path}/../lib/ginatra"
8
8
 
9
9
  gem 'webrat', '>=0.4.4'
10
- require 'webrat/sinatra'
10
+ begin
11
+ # When using webrat 0.6.0, there is no webrat/sinatra.rb file.
12
+ # Looking at the gem's code, it looks like it autoloads the sinatra adapter at webrat/adapters/sinatra.rb.
13
+ # So requiring just 'webrat' will also load the sinatra adapater, which is done in the rescue clause.
14
+ require 'webrat/sinatra'
15
+ rescue LoadError
16
+ STDERR.puts "WARNING: could not load webrat/sinatra: #{__FILE__}:#{__LINE__}"
17
+ require 'webrat'
18
+ end
19
+
11
20
  gem 'rack-test', '>=0.3.0'
12
21
  require 'rack/test'
13
22
 
@@ -3,21 +3,21 @@
3
3
  <dl>
4
4
  <dt>commit:</dt>
5
5
  <dd>
6
- <a href='/<%= repo.param %>/commit/<%= commit.id_abbrev %>'>
6
+ <a href='<%= prefix_url(repo.param) %>/commit/<%= commit.id_abbrev %>'>
7
7
  <code><%= commit.id %></code>
8
8
  </a>
9
9
  </dd><br>
10
10
 
11
11
  <dt>tree:</dt>
12
12
  <dd>
13
- <a href='/<%= repo.param %>/tree/<%= commit.tree.id[0..7] %>'>
13
+ <a href='<%= prefix_url(repo.param) %>/tree/<%= commit.tree.id[0..7] %>'>
14
14
  <code><%= commit.tree.id %></code>
15
15
  </a>
16
16
  </dd><br>
17
17
  <% commit.parents.each do |parent| %>
18
18
  <dt>parent:</dt>
19
19
  <dd>
20
- <a href='/<%= repo.param %>/commit/<%= parent.id_abbrev %>'>
20
+ <a href='<%= prefix_url(repo.param) %>/commit/<%= parent.id_abbrev %>'>
21
21
  <code><%= parent.id %></code>
22
22
  </a>
23
23
  </dd>
@@ -1,5 +1,5 @@
1
1
  <h2>
2
- <a href='/<%= repo.param %>'><%= repo.name %></a>
2
+ <a href='<%= prefix_url(repo.param) %>'><%= repo.name %></a>
3
3
  </h2>
4
4
  <div class='repo-info'>
5
5
  <%= repo.description.split("\n").first %>
@@ -5,7 +5,7 @@
5
5
  <%= partial(:tree_part, :locals => {:current_tree => next_tree, :tree_path => new_path, :path => path }) %>
6
6
  <% end %>
7
7
  <% current_tree.blobs.each do |next_blob| %>
8
- <li class="blob"><a href="<%= path[:blob] %><%= tree_path %>/<%= next_blob.basename %>"><%= next_blob.basename %></a></li>
8
+ <li class="blob"><a href="<%= prefix_url(path[:blob]) %><%= tree_path %>/<%= next_blob.basename %>"><%= next_blob.basename %></a></li>
9
9
  <% end %>
10
10
  </ul>
11
11
  </li>
@@ -1,7 +1,7 @@
1
1
  xml.instruct! :xml, :version => '1.0', :encoding => 'utf-8'
2
2
  xml.feed :'xml:lang' => 'en-US', :xmlns => 'http://www.w3.org/2005/Atom' do
3
3
  base_title = "#{@repo.name}: "
4
- base_url = "http://#{hostname}/#{@repo.param}"
4
+ base_url = "http://#{hostname}" + prefix_url("#{@repo.param}")
5
5
  if params[:ref]
6
6
  url = base_url + "/#{params[:ref]}"
7
7
  title = base_title + params[:ref]
@@ -2,8 +2,8 @@
2
2
  <h3>Blob: <%= params[:splat].first %></h3>
3
3
  <div class="active">
4
4
  <div class="blob">
5
- <h4><img src="/img/doc.png" /><%= @blob.name %></h4>
6
- <%= CodeRay.scan(@blob.data, @highlighter).div(:line_numbers => :table, :css => :class) %>
5
+ <h4><img src="<%= prefix_url("img/doc.png") %>" /><%= @blob.name %></h4>
6
+ <%= pygmentize(@blob.data, @blob.name) %>
7
7
  </div>
8
8
  <div class="clearfix">&nbsp;</div>
9
9
  </div>
@@ -12,8 +12,8 @@
12
12
  <% count = 0 %>
13
13
  <% @commit.diffs.select { |d| !d.deleted_file && !d.new_file }.each do |diff| %>
14
14
  <% count += 1 %>
15
- <h4><img src="/img/doc.png" /><a name='file_<%= count %>'><code><%= diff.b_path %></code></a></h4>
16
- <div class="diff"><%= diff((diff.diff)) %></div>
15
+ <h4><img src="<%= prefix_url("img/doc.png") %>" /><a name='file_<%= count %>'><code><%= diff.b_path %></code></a></h4>
16
+ <div class="diff"><%= pygmentize(diff.diff) %></div>
17
17
  <% end %>
18
18
  </div>
19
19
  </div>
@@ -5,7 +5,7 @@
5
5
  </div>
6
6
  <dl>
7
7
  <% Ginatra::RepoList.list.each do |repo| %>
8
- <dt><a href="/<%= repo.param %>"><%= repo.name %></a></dt>
8
+ <dt><a href="<%= prefix_url(repo.param) %>"><%= repo.name %></a></dt>
9
9
  <dd><%=h repo.description %></dd>
10
10
  <% end %>
11
11
  </dl>
@@ -4,26 +4,27 @@
4
4
  <head>
5
5
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
6
  <title>Ginatra</title>
7
- <link rel="stylesheet" href="/src/index.css" type="text/css" media="screen" />
8
- <link rel="stylesheet" href="/src/default.css" type="text/css" media="screen" />
9
-
10
- <script type="text/javascript" src="/src/highlight.pack.js"></script>
7
+ <link rel="stylesheet" href="<%= prefix_url("src/index.css") %>" type="text/css" media="screen" />
8
+ <link rel="stylesheet" href="<%= prefix_url("src/default.css") %>" type="text/css" media="screen" />
9
+
10
+ <script type="text/javascript" src="<%= prefix_url("src/highlight.pack.js") %>"></script>
11
11
  <script type="text/javascript">
12
12
  hljs.initHighlightingOnLoad();
13
13
  </script>
14
- <script src="/src/jquery-1.3.2.min.js" type="text/javascript"></script>
15
- <script src="/src/ginatra.js" type="text/javascript"></script>
14
+ <script src="<%= prefix_url("src/jquery-1.3.2.min.js") %>" type="text/javascript"></script>
15
+ <script src="<%= prefix_url("src/ginatra.js") %>" type="text/javascript"></script>
16
+
16
17
  <!--[if lt IE 8]>
17
18
  <script src="http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE8.js" type="text/javascript"></script>
18
19
  <style type="text/css" media="screen">
19
- * { behavior: url("/src/iepngfix.htc") }
20
+ * { behavior: url("<%= prefix_url("src/iepngfix.htc") %>") }
20
21
  </style>
21
22
  <![endif]-->
22
23
  </head>
23
24
  <body>
24
25
  <div id="content">
25
26
  <div id="inner">
26
- <h1><a href="/">Ginatra</a></h1>
27
+ <h1><a href="<%= prefix_url %>">Ginatra</a></h1>
27
28
  <%= yield %>
28
29
  </div>
29
30
  <div id="footer-spacer">&nbsp;</div>
@@ -2,7 +2,7 @@
2
2
  <h3>Commits<% if params[:ref] %>: <%= params[:ref] %><% end %> <%= atom_feed_link(@repo.param, params[:ref]) %></h3>
3
3
  <div class="active">
4
4
  <% if @previous_commits %>
5
- <a href='/<%= params[:repo] %>/<%= params[:ref] %>/<%= params[:page] - 1 %>'>Previous</a>
5
+ <a href='<%= prefix_url(params[:repo]) %>/<%= params[:ref] %>/<%= params[:page] - 1 %>'>Previous</a>
6
6
  <% end %>
7
7
 
8
8
  <% if @separator %>
@@ -10,7 +10,7 @@
10
10
  <% end %>
11
11
 
12
12
  <% if @next_commits %>
13
- <a href='/<%= params[:repo] %>/<%= params[:ref] %>/<%= params[:page] + 1 %>'>Next</a>
13
+ <a href='<%= prefix_url(params[:repo]) %>/<%= params[:ref] %>/<%= params[:page] + 1 %>'>Next</a>
14
14
  <% end %>
15
15
  <div class='list'>
16
16
  <div id='heads'>
@@ -18,7 +18,7 @@
18
18
  <ul>
19
19
  <% @repo.heads.each do |head| %>
20
20
  <li>
21
- <a href="/<%=h @repo.param %>/<%=h head.name %>">
21
+ <a href="<%=h prefix_url(@repo.param) %>/<%=h head.name %>">
22
22
  <%=h head.name %>
23
23
  </a>
24
24
  </li>
@@ -32,7 +32,7 @@
32
32
  <ul>
33
33
  <% @repo.tags.each do |tag| %>
34
34
  <li>
35
- <a href="/<%=h @repo.param %>/commit/<%=h tag.name %>">
35
+ <a href="<%=h prefix_url(@repo.param) %>/commit/<%=h tag.name %>">
36
36
  <%=h tag.name %>
37
37
  </a>
38
38
  </li>
@@ -45,7 +45,7 @@
45
45
  </div>
46
46
  <div id='commit-log'>
47
47
  <% @commits.each do |commit| %>
48
- <% url = "/#{@repo.param}/commit/#{commit.id_abbrev}" %>
48
+ <% url = prefix_url("#{@repo.param}/commit/#{commit.id_abbrev}") %>
49
49
  <div id='commit_<%= commit.id_abbrev %>' class='commit' onclick="location.href='<%= url %>'">
50
50
  <div class='right'>
51
51
  <span class='id'>
@@ -3,21 +3,21 @@
3
3
  <div class="active">
4
4
  <ul class="commit-tree">
5
5
  <% @tree.trees.each do |tree| %>
6
- <% tree_path = "/#{tree.name}"%>
7
- <li class="tree"><a href="<%= @path[:tree] %><%= tree_path %>"><%= tree.basename %></a>
6
+ <% tree_path = "#{tree.name}"%>
7
+ <li class="tree"><a href="<%= prefix_url(@path[:tree]) %><%= tree_path %>"><%= tree.basename %></a>
8
8
  <ul>
9
9
  <% tree.trees.each do |next_tree| %>
10
10
  <% new_path = tree_path + "/#{next_tree.name}" %>
11
11
  <%= partial(:tree_part, :locals => {:current_tree => next_tree, :tree_path => new_path, :path => @path }) %>
12
12
  <% end %>
13
13
  <% tree.blobs.each do |next_blob| %>
14
- <li class="blob"><a href="<%= @path[:blob] %><%= tree_path %>/<%= next_blob.basename %>"><%= next_blob.basename %></a></li>
14
+ <li class="blob"><a href="<%= prefix_url(@path[:blob]) %>/<%= tree_path %>/<%= next_blob.basename %>"><%= next_blob.basename %></a></li>
15
15
  <% end %>
16
16
  </ul>
17
17
  </li>
18
18
  <% end %>
19
19
  <% @tree.blobs.each do |blob| %>
20
- <li class="blob"><a href="<%= @path[:blob] %>/<%= blob.basename %>"><%= blob.basename %></a></li>
20
+ <li class="blob"><a href="<%= prefix_url(@path[:blob]) %>/<%= blob.basename %>"><%= blob.basename %></a></li>
21
21
  <% end %>
22
22
  </ul>
23
23
  <div class="clearfix">&nbsp;</div>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ginatra
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Elliott
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-12-28 00:00:00 +01:00
13
+ date: 2010-01-06 00:00:00 +00:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -34,14 +34,24 @@ dependencies:
34
34
  version: 1.1.1
35
35
  version:
36
36
  - !ruby/object:Gem::Dependency
37
- name: coderay
37
+ name: vegas
38
38
  type: :runtime
39
39
  version_requirement:
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  requirements:
42
42
  - - ">="
43
43
  - !ruby/object:Gem::Version
44
- version: 0.8.0
44
+ version: 0.1.0
45
+ version:
46
+ - !ruby/object:Gem::Dependency
47
+ name: open4
48
+ type: :runtime
49
+ version_requirement:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.6
45
55
  version:
46
56
  description: Host your own git repository browser through the power of Sinatra and Grit
47
57
  email: sam@lenary.co.uk
@@ -57,11 +67,8 @@ extra_rdoc_files:
57
67
  files:
58
68
  - .gitattributes
59
69
  - .gitignore
60
- - .gitmodules
61
70
  - README.md
62
71
  - Rakefile
63
- - TODO.md
64
- - VERSION
65
72
  - bin/ginatra
66
73
  - bin/ginatra-daemon
67
74
  - bin/ginatra-directory
@@ -70,7 +77,6 @@ files:
70
77
  - features/pages.feature
71
78
  - features/step_definitions/page_steps.rb
72
79
  - features/support/env.rb
73
- - ginatra.gemspec
74
80
  - lib/ginatra.rb
75
81
  - lib/ginatra/config.rb
76
82
  - lib/ginatra/helpers.rb
@@ -86,9 +92,7 @@ files:
86
92
  - public/src/blank.gif
87
93
  - public/src/colour.css
88
94
  - public/src/commit.css
89
- - public/src/default.css
90
95
  - public/src/ginatra.js
91
- - public/src/highlight.pack.js
92
96
  - public/src/iepngfix.htc
93
97
  - public/src/index.css
94
98
  - public/src/jquery-1.3.2.min.js
@@ -1,3 +0,0 @@
1
- [submodule "vendor/vegas"]
2
- path = vendor/vegas
3
- url = git://github.com/quirkey/vegas.git
data/TODO.md DELETED
@@ -1,10 +0,0 @@
1
- TODO
2
- ====
3
-
4
- Suggestions
5
- -----------
6
-
7
- - Multiple directory or glob-based repo paths [raggi]
8
- - Rake tasks for demo [raggi]
9
- - Rake tasks for adding repos [lenary]
10
- - A New Name [qrush]
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 2.1.1
@@ -1,108 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{ginatra}
8
- s.version = "2.1.1"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Sam Elliott", "Ryan Bigg"]
12
- s.date = %q{2009-12-28}
13
- s.description = %q{Host your own git repository browser through the power of Sinatra and Grit}
14
- s.email = %q{sam@lenary.co.uk}
15
- s.executables = ["ginatra", "ginatra-daemon", "ginatra-directory", "ginatra-server"]
16
- s.extra_rdoc_files = [
17
- "README.md"
18
- ]
19
- s.files = [
20
- ".gitattributes",
21
- ".gitignore",
22
- ".gitmodules",
23
- "README.md",
24
- "Rakefile",
25
- "TODO.md",
26
- "VERSION",
27
- "bin/ginatra",
28
- "bin/ginatra-daemon",
29
- "bin/ginatra-directory",
30
- "bin/ginatra-server",
31
- "config.ru",
32
- "features/pages.feature",
33
- "features/step_definitions/page_steps.rb",
34
- "features/support/env.rb",
35
- "ginatra.gemspec",
36
- "lib/ginatra.rb",
37
- "lib/ginatra/config.rb",
38
- "lib/ginatra/helpers.rb",
39
- "lib/ginatra/repo.rb",
40
- "lib/ginatra/repo_list.rb",
41
- "lib/sinatra/partials.rb",
42
- "public/favicon.ico",
43
- "public/img/add.png",
44
- "public/img/diff.png",
45
- "public/img/doc.png",
46
- "public/img/rm.png",
47
- "public/img/tree.png",
48
- "public/src/blank.gif",
49
- "public/src/colour.css",
50
- "public/src/commit.css",
51
- "public/src/default.css",
52
- "public/src/ginatra.js",
53
- "public/src/highlight.pack.js",
54
- "public/src/iepngfix.htc",
55
- "public/src/index.css",
56
- "public/src/jquery-1.3.2.min.js",
57
- "public/src/lists.css",
58
- "public/src/reset.css",
59
- "public/src/table.css",
60
- "public/src/type.css",
61
- "rackup.ru",
62
- "repos/README.md",
63
- "spec/repo_list_spec.rb",
64
- "spec/repo_spec.rb",
65
- "spec/spec_helper.rb",
66
- "views/_actor_box.erb",
67
- "views/_commit_info_box.erb",
68
- "views/_header.erb",
69
- "views/_tree_part.erb",
70
- "views/atom.builder",
71
- "views/blob.erb",
72
- "views/commit.erb",
73
- "views/index.erb",
74
- "views/layout.erb",
75
- "views/log.erb",
76
- "views/tree.erb"
77
- ]
78
- s.homepage = %q{http://lenary.github.com/ginatra}
79
- s.rdoc_options = ["--charset=UTF-8"]
80
- s.require_paths = ["lib"]
81
- s.rubygems_version = %q{1.3.5}
82
- s.summary = %q{A Gitweb Clone in Sinatra and Grit}
83
- s.test_files = [
84
- "spec/repo_list_spec.rb",
85
- "spec/repo_spec.rb",
86
- "spec/spec_helper.rb"
87
- ]
88
-
89
- if s.respond_to? :specification_version then
90
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
91
- s.specification_version = 3
92
-
93
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
94
- s.add_runtime_dependency(%q<sinatra>, [">= 0.9.4"])
95
- s.add_runtime_dependency(%q<grit>, [">= 1.1.1"])
96
- s.add_runtime_dependency(%q<coderay>, [">= 0.8.0"])
97
- else
98
- s.add_dependency(%q<sinatra>, [">= 0.9.4"])
99
- s.add_dependency(%q<grit>, [">= 1.1.1"])
100
- s.add_dependency(%q<coderay>, [">= 0.8.0"])
101
- end
102
- else
103
- s.add_dependency(%q<sinatra>, [">= 0.9.4"])
104
- s.add_dependency(%q<grit>, [">= 1.1.1"])
105
- s.add_dependency(%q<coderay>, [">= 0.8.0"])
106
- end
107
- end
108
-