lenary-ginatra 2.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.
Files changed (53) hide show
  1. data/.gitattributes +2 -0
  2. data/.gitignore +13 -0
  3. data/.gitmodules +3 -0
  4. data/README.md +127 -0
  5. data/Rakefile +86 -0
  6. data/TODO.md +10 -0
  7. data/VERSION +1 -0
  8. data/bin/ginatra +60 -0
  9. data/bin/ginatra-daemon +81 -0
  10. data/bin/ginatra-directory +60 -0
  11. data/bin/ginatra-server +28 -0
  12. data/config.ru +7 -0
  13. data/features/pages.feature +33 -0
  14. data/features/step_definitions/page_steps.rb +36 -0
  15. data/features/support/env.rb +12 -0
  16. data/ginatra.gemspec +120 -0
  17. data/lib/ginatra.rb +185 -0
  18. data/lib/ginatra/config.rb +55 -0
  19. data/lib/ginatra/helpers.rb +112 -0
  20. data/lib/ginatra/repo.rb +50 -0
  21. data/lib/ginatra/repo_list.rb +53 -0
  22. data/lib/sinatra/partials.rb +17 -0
  23. data/public/favicon.ico +0 -0
  24. data/rackup.ru +7 -0
  25. data/repos/README.md +8 -0
  26. data/spec/repo_list_spec.rb +22 -0
  27. data/spec/repo_spec.rb +58 -0
  28. data/spec/spec_helper.rb +30 -0
  29. data/vendor/vegas/History.txt +18 -0
  30. data/vendor/vegas/LICENSE +22 -0
  31. data/vendor/vegas/Manifest.txt +5 -0
  32. data/vendor/vegas/README.rdoc +45 -0
  33. data/vendor/vegas/Rakefile +32 -0
  34. data/vendor/vegas/lib/vegas.rb +16 -0
  35. data/vendor/vegas/lib/vegas/runner.rb +270 -0
  36. data/vendor/vegas/test/test_app/bin/test_app +9 -0
  37. data/vendor/vegas/test/test_app/test_app.rb +10 -0
  38. data/vendor/vegas/test/test_apps.rb +22 -0
  39. data/vendor/vegas/test/test_helper.rb +59 -0
  40. data/vendor/vegas/test/test_vegas_runner.rb +8 -0
  41. data/vendor/vegas/vegas.gemspec +45 -0
  42. data/views/_actor_box.erb +13 -0
  43. data/views/_commit_info_box.erb +27 -0
  44. data/views/_header.erb +6 -0
  45. data/views/_tree_part.erb +11 -0
  46. data/views/atom.builder +32 -0
  47. data/views/blob.erb +9 -0
  48. data/views/commit.erb +20 -0
  49. data/views/index.erb +12 -0
  50. data/views/layout.erb +35 -0
  51. data/views/log.erb +64 -0
  52. data/views/tree.erb +24 -0
  53. metadata +158 -0
@@ -0,0 +1,112 @@
1
+ require "digest/md5"
2
+
3
+ module Ginatra
4
+ # Actually useful stuff
5
+ module Helpers
6
+
7
+ def gravatar_url(email)
8
+ "https://secure.gravatar.com/avatar/#{Digest::MD5.hexdigest(email)}?s=40"
9
+ end
10
+
11
+ def nicetime(date)
12
+ date.strftime("%b %d, %Y – %H:%M")
13
+ end
14
+
15
+ def actor_box(actor, role, date)
16
+ partial(:actor_box, :locals => { :actor => actor, :role => role, :date => date })
17
+ end
18
+
19
+ def actor_boxes(commit)
20
+ o = actor_box(commit.committer, :committer, commit.committed_date)
21
+ if commit.author.name != commit.committer.name
22
+ o = actor_box(commit.author, :author, commit.authored_date) + o
23
+ end
24
+ end
25
+
26
+ def commit_ref(ref, repo_param)
27
+ ref_class = ref.class.to_s.split("::")[1].to_s
28
+ "<a class=\"ref #{ref_class}\" href=\"/#{repo_param}/#{ref.name}\">#{ref.name}</a>"
29
+ end
30
+
31
+ def commit_refs(commit, repo_param)
32
+ commit.refs.map{ |r| commit_ref(r, repo_param) }.join("\n")
33
+ end
34
+
35
+ def archive_link(tree, repo_param)
36
+ "<a class=\"download\" href=\"/#{repo_param}/archive/#{tree.id}.tar.gz\" title=\"Download a tar.gz snapshot of this Tree\">Download Archive</a>"
37
+ end
38
+
39
+ def patch_link(commit, repo_param)
40
+ "<a class=\"download\" href=\"/#{repo_param}/commit/#{commit.id}.patch\" title=\"Download a patch file of this Commit\">Download Patch</a>"
41
+ end
42
+
43
+ # The only reason this doesn't work 100% of the time is because grit doesn't :/
44
+ # if i find a fix, it'll go upstream :D
45
+ def file_listing(commit)
46
+ count = 0
47
+ out = commit.diffs.map do |diff|
48
+ count = count + 1
49
+ if diff.deleted_file
50
+ %(<li class='file_rm'><a href='#file_#{count}'>#{diff.a_path}</a></li>)
51
+ else
52
+ cla = diff.new_file ? "add" : "diff"
53
+ %(<li class='file_#{cla}'><a href='#file_#{count}'>#{diff.a_path}</a></li>)
54
+ end
55
+ end
56
+ "<ul id='files'>#{out.join}</ul>"
57
+ end
58
+
59
+ def diff(diff)
60
+ diff = CodeRay.scan(diff, :diff).div(:line_numbers => :table, :css => :class)
61
+ end
62
+
63
+ # Stolen from rails: ActionView::Helpers::TextHelper#simple_format
64
+ # and simplified to just use <p> tags without any options
65
+ # modified since
66
+ def simple_format(text)
67
+ text.gsub!(/ +/, " ")
68
+ text.gsub!(/\r\n?/, "\n")
69
+ text.gsub!(/\n/, "<br />\n")
70
+ text
71
+ end
72
+
73
+ # stolen from rails: ERB::Util
74
+ def html_escape(s)
75
+ s.to_s.gsub(/[&"<>]/) do |special|
76
+ { '&' => '&amp;',
77
+ '>' => '&gt;',
78
+ '<' => '&lt;',
79
+ '"' => '&quot;' }[special]
80
+ end
81
+ end
82
+ alias :h :html_escape
83
+
84
+ # Stolen and bastardised from rails
85
+ def truncate(text, options={})
86
+ options[:length] ||= 30
87
+ options[:omission] ||= "..."
88
+
89
+ if text
90
+ l = options[:length] - options[:omission].length
91
+ chars = text
92
+ stop = options[:separator] ? (chars.rindex(options[:separator], l) || l) : l
93
+ (chars.length > options[:length] ? chars[0...stop] + options[:omission] : text).to_s
94
+ end
95
+ end
96
+
97
+ # stolen from Marley
98
+ def rfc_date(datetime)
99
+ datetime.strftime("%Y-%m-%dT%H:%M:%SZ") # 2003-12-13T18:30:02Z
100
+ end
101
+
102
+ # stolen from Marley
103
+ def hostname
104
+ (request.env['HTTP_X_FORWARDED_SERVER'] =~ /[a-z]*/) ? request.env['HTTP_X_FORWARDED_SERVER'] : request.env['HTTP_HOST']
105
+ end
106
+
107
+ def atom_feed_link(repo_param, ref=nil)
108
+ "<a href=\"/#{repo_param}#{"/#{ref}" if !ref.nil?}.atom\" title=\"Atom Feed\" class=\"atom\">Feed</a>"
109
+ end
110
+
111
+ end
112
+ end
@@ -0,0 +1,50 @@
1
+ # to make refs work!
2
+ module Grit
3
+ class Commit
4
+ attr_accessor :refs
5
+ end
6
+ end
7
+
8
+ module Ginatra
9
+ # Convenience class for me!
10
+ class Repo
11
+
12
+ attr_reader :name, :param, :description
13
+
14
+ def initialize(path)
15
+ @repo = Grit::Repo.new(path)
16
+ @param = File.split(path).last
17
+ @name = @param
18
+ @description = @repo.description
19
+ @description = "Please edit the #{@repo.path}/description file for this repository and set the description for it." if /^Unnamed repository;/.match(@description)
20
+ @repo
21
+ end
22
+
23
+ def commit(id)
24
+ @commit = @repo.commit(id)
25
+ raise(Ginatra::InvalidCommit.new(id)) if @commit.nil?
26
+ add_refs(@commit)
27
+ @commit
28
+ end
29
+
30
+ def commits(start = 'master', max_count = 10, skip = 0)
31
+ raise(Ginatra::Error.new("max_count cannot be less than 0")) if max_count < 0
32
+ @repo.commits(start, max_count, skip).each do |commit|
33
+ add_refs(commit)
34
+ end
35
+ end
36
+
37
+ # TODO: Perhaps move into commit class.
38
+ def add_refs(commit)
39
+ commit.refs = []
40
+ refs = @repo.refs.select { |ref| ref.commit.id == commit.id }
41
+ commit.refs << refs
42
+ commit.refs.flatten!
43
+ end
44
+
45
+ def method_missing(sym, *args, &block)
46
+ @repo.send(sym, *args, &block)
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,53 @@
1
+ require 'singleton'
2
+
3
+ module Ginatra
4
+ # Convenience class for me!
5
+ class RepoList
6
+ include Singleton
7
+ attr_accessor :list
8
+
9
+ def initialize
10
+ self.list = []
11
+ self.refresh
12
+ end
13
+
14
+ def self.list
15
+ self.instance.refresh
16
+ self.instance.list
17
+ end
18
+
19
+ def refresh
20
+ Ginatra::Config.git_dirs.map! do |git_dir|
21
+ files = Dir.glob(git_dir)
22
+ files.each { |e| add(e) unless Ginatra::Config.ignored_files.include?(File.split(e).last) }
23
+ end
24
+ end
25
+
26
+ def add(path, param = File.split(path).last)
27
+ unless self.has_repo?(param)
28
+ list << Repo.new(path)
29
+ end
30
+ end
31
+
32
+ def has_repo?(local_param)
33
+ !list.find { |r| r.param == local_param }.nil?
34
+ end
35
+
36
+ def find(local_param)
37
+ if repo = list.find { |r| r.param == local_param }
38
+ repo
39
+ else
40
+ refresh
41
+ list.find { |r| r.param == local_param }
42
+ end
43
+ end
44
+
45
+ def self.find(local_param)
46
+ self.instance.find(local_param)
47
+ end
48
+
49
+ def self.method_missing(sym, *args, &block)
50
+ instance.send(sym, *args, &block)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,17 @@
1
+ # stolen from http://github.com/cschneid/irclogger/blob/master/lib/partials.rb
2
+ module Sinatra::Partials
3
+ def partial(template, *args)
4
+ template_array = template.to_s.split('/')
5
+ template = template_array[0..-2].join('/') + "/_#{template_array[-1]}"
6
+ options = args.last.is_a?(Hash) ? args.pop : {}
7
+ options.merge!(:layout => false)
8
+ if collection = options.delete(:collection) then
9
+ collection.inject([]) do |buffer, member|
10
+ buffer << erb(:"#{template}", options.merge(:layout =>
11
+ false, :locals => {template_array[-1].to_sym => member}))
12
+ end.join("\n")
13
+ else
14
+ erb(:"#{template}", options)
15
+ end
16
+ end
17
+ end
File without changes
data/rackup.ru ADDED
@@ -0,0 +1,7 @@
1
+ current_path = File.expand_path(File.dirname(__FILE__))
2
+
3
+ require "#{current_path}/lib/ginatra"
4
+
5
+ map '/' do
6
+ run Ginatra::App
7
+ end
data/repos/README.md ADDED
@@ -0,0 +1,8 @@
1
+ From the top README:
2
+
3
+ > To clone repositories so that Ginatra can see them, clone the repositories into `./repos/` - they will be served automatically. Use the `--bare` switch to both save space and make sure Ginatra can read them. If you rename them, make sure the directory ends in `.git'. For Example:
4
+ >
5
+ > cd repos
6
+ > git clone --bare git://github.com/lenary/ginatra.git
7
+ > git clone --bare git://github.com/mojombo/grit.git fun.git
8
+
@@ -0,0 +1,22 @@
1
+ current_path = File.expand_path(File.dirname(__FILE__))
2
+ require File.join(current_path, "spec_helper")
3
+
4
+ describe "Ginatra" do
5
+
6
+ describe "RepoList" do
7
+
8
+ before do
9
+ @repo_list = Ginatra::RepoList.list
10
+ @repo = Ginatra::RepoList.find("test")
11
+ end
12
+
13
+ it "should be an array of `Ginatra::Repo`s" do
14
+ @repo_list.each { |r| r.should be_an_instance_of(Ginatra::Repo)}
15
+ end
16
+
17
+ it "should contain the test repo" do
18
+ @repo_list.include?(@repo)
19
+ end
20
+
21
+ end
22
+ end
data/spec/repo_spec.rb ADDED
@@ -0,0 +1,58 @@
1
+ current_path = File.expand_path(File.dirname(__FILE__))
2
+ require File.join(current_path, "spec_helper")
3
+
4
+ describe "Ginatra" do
5
+ describe "Repo" do
6
+
7
+ before do
8
+ @repo_list = Ginatra::RepoList
9
+ @ginatra_repo = @repo_list.find("test")
10
+ @grit_repo = Grit::Repo.new(File.join(current_path, "..", "repos", "test"), {})
11
+ @commit = @ginatra_repo.commit("910ff56f585bcdfc3ba105c8846b1df0a6abf069")
12
+ end
13
+
14
+ it "should have a name" do
15
+ @ginatra_repo.name == "test"
16
+ end
17
+
18
+ it "should have a param for urls" do
19
+ @ginatra_repo.param == 'test'
20
+ end
21
+
22
+ it "should have a description" do
23
+ @ginatra_repo.description =~ /description file for this repository and set the description for it./
24
+ end
25
+
26
+ it "should have an array of commits that match the grit array of commits limited to 10 items" do
27
+ @ginatra_repo.commits === @grit_repo.commits
28
+ @ginatra_repo.commits.length == 10
29
+ end
30
+
31
+ it "should be the same thing using #find or #new" do
32
+ @repo_list.find("test") == Ginatra::Repo.new(File.join(current_path, "..", "repos", "test"))
33
+ end
34
+
35
+ it "should contain this commit" do
36
+ @commit.refs.should_not be_empty
37
+ end
38
+
39
+ it "should not contain this other commit" do
40
+ lambda { @ginatra_repo.commit("totallyinvalid") }.should raise_error(Ginatra::InvalidCommit, "Could not find a commit with the id of totallyinvalid")
41
+ end
42
+
43
+ it "should have a list of commits" do
44
+ @ginatra_repo.commits.should_not be_blank
45
+ end
46
+
47
+ it "should raise an error when asked to invert itself" do
48
+ lambda { @ginatra_repo.commits("master", -1) }.should raise_error(Ginatra::Error, "max_count cannot be less than 0")
49
+ end
50
+
51
+ it "should be able to add refs to a commit" do
52
+ @commit.refs = []
53
+ @ginatra_repo.add_refs(@commit)
54
+ @commit.refs.should_not be_empty
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,30 @@
1
+ require 'rubygems'
2
+
3
+ gem 'rspec'
4
+ require 'spec'
5
+
6
+ current_path = File.expand_path(File.dirname(__FILE__))
7
+ require "#{current_path}/../lib/ginatra"
8
+
9
+ gem 'webrat', '>=0.4.4'
10
+ require 'webrat/sinatra'
11
+ gem 'rack-test', '>=0.3.0'
12
+ require 'rack/test'
13
+
14
+ Webrat.configure do |config|
15
+ config.mode = :sinatra
16
+ end
17
+
18
+ Ginatra::App.set :environment, :test
19
+ Ginatra::Config[:git_dirs] = ["#{current_path}/../repos/*"]
20
+
21
+ Spec::Runner.configure do |config|
22
+ def app
23
+ Ginatra::App
24
+ end
25
+
26
+ config.include(Rack::Test::Methods)
27
+ config.include(Webrat::Methods)
28
+ config.include(Webrat::Matchers)
29
+ end
30
+
@@ -0,0 +1,18 @@
1
+ == 0.0.4 2009-08-09
2
+
3
+ * new -L (--skip-launch) option doesn't launch the web browser (thanks bmabey!)
4
+ * rubygems is required only on LoadError
5
+
6
+ == 0.0.3 2009-07-06
7
+
8
+ * Vegas::Runner is now Windows compatible (require win32-process gem)
9
+ * Includes daemon-ization
10
+ * PID tracking
11
+ * Vegas::WINDOWS is a top level boolean
12
+ * Vegas is no longer dependent on Launchy
13
+ * launching browser is done simply with open/start depending on platform
14
+
15
+ == 0.0.1 2009-04-13
16
+
17
+ * 1 major enhancement:
18
+ * Initial release
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2009 Aaron Quint, Quirkey NYC, LLC.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,5 @@
1
+ History.txt
2
+ LICENSE
3
+ README.rdoc
4
+ lib/vegas.rb
5
+ lib/vegas/runner.rb
@@ -0,0 +1,45 @@
1
+ = vegas
2
+
3
+ http://code.quirkey.com/vegas
4
+
5
+ == DESCRIPTION:
6
+
7
+ Vegas aims to solve the simple problem of creating executable versions of Sinatra/Rack apps.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ Currently, Vegas just includes a single class Vegas::Runner which wraps your Sinatra app to give it command line options, daemonization, PID/URL tracking, and browser launching (using Launchy).
12
+
13
+ Lets say you have a gem with a sinatra application. With Vegas you can create a bin that looks like
14
+
15
+ #!/usr/bin/env ruby
16
+ # ./bin/myapp
17
+
18
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/myapp")
19
+ require 'vegas'
20
+
21
+ Vegas::Runner.new(Sinatra::Application, 'myapp')
22
+
23
+
24
+ See the website: http://code.quirkey.com/vegas for full usage/options.
25
+
26
+ === WINDOWS:
27
+
28
+ Using vegas (and gems that depend on it) on Windows works but isn't 100% the same.
29
+ Daemon-ization and browser launching work, but you will see duplicate messages.
30
+
31
+ If you see a warning like:
32
+
33
+ `expand_path': couldn't find HOME environment -- expanding `~/.vegas' (ArgumentError)
34
+
35
+ You have to set your HOME path:
36
+
37
+ c:\> set HOME=%HOMEPATH%
38
+
39
+ == INSTALL:
40
+
41
+ sudo gem install vegas
42
+
43
+ == LICENSE:
44
+
45
+ MIT LICENSE, see LICENSE for details