public
Fork of jnewland/git-wiki
Description: Apparently the best way to represent a Git repository is something called an Indirectly Cycling Giraffe. Doc wiki and issue tracking right in your repo. Centralization through decentralization.
Homepage: http://github.com/rue/giraffe
Clone URL: git://github.com/rue/giraffe.git
rue (author)
Wed Jan 21 10:58:53 -0800 2009
commit  d9b8d8308671acb201b81c474203f574bef5708d
tree    85aaa04fd254ec1c827359f6c8d5b43967c09a98
parent  be260490fe35bf195174d5867217889f2c8f9c56
giraffe / run_giraffe_run.rb
100644 157 lines (126 sloc) 3.882 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
require "autocode"
 
here = File.dirname __FILE__
waves = ENV["WAVES"] || File.join(here, "waves", "lib")
 
$LOAD_PATH.unshift File.join(here, "lib"),
                    File.join(here, "resources"),
                    waves
 
module Giraffe
 
  # Register.
  #
  Waves << self
 
  # All of our resources live here.
  #
  module Resources
    include AutoCode
 
    auto_load true, :directories => "resources"
 
    # First-tier resource mapper.
    #
    # Requests are forwarded to the correct Resource, which
    # then deals with accepted methods and further resolution.
    #
    # Since the matching is done sequentially, the most commonly
    # used resources are toward the bottom. The exception to this
    # are naturally the prefixless page paths which match last
    # (and are obviously the most common..oh, the competition.)
    #
    # NOTE: If hoarding the names from the front of the path is a
    # problem (e.g. you want to have a page named "commit"
    # for whatever silly reason), consider transforming
    # the filenames to use WikiCase for URIs. I.e.,
    #
    # /commit => some commit resource
    #
    # but
    #
    # /Commit => commit.txt # Or whatever
    #
    class Main
      include Waves::Resources::Mixin
 
      # Normal pages have no particular prefix.
      #
      on(true, true) { to :page }
 
      # Empty path is the home page.
      #
      on(true, []) {
        Giraffe.wiki!
        request.redirect Giraffe.home, 301
      }
 
      # /diff/ from an earlier to current version.
      #
      #on(:get, ["diff", true]) { to :diff }
 
      # /plaintext/ corresponding to a page's source.
      #
      on(true, ["plaintext", true]) { to :plaintext }
 
      # /changes/ to the file, directory or repository as commits.
      #
      on(true, ["changes", 0..-1]) { to :changes }
 
      # /grep/ for results for term given in the path.
      #
      on(true, ["grep", true]) { to :grep }
 
      # /s?for=term forwards to /grep/term? for fun and profit.
      #
      on(true, "s") {
        if query["for"] and not query["for"].empty?
          request.redirect "/grep/#{query["for"]}", 303
        end
 
        response.status = 400
        "Search term was empty!"
      }
 
      # /pages/ in the repository or a subdirectory.
      #
      on(true, ["pages", 0..-1]) { to :pages }
 
      # /editable/ page that can be used to update the real page.
      #
      on(true, ["editable", true]) { to :editable }
#
## Generate patchfile for diff
##
#get "/a/patch/(.+)/(.+)" do
# path, name = File.split(params[:matches][1])
# commit = params[:matches][2]
#
# diff = Page.from_uri(path, name).object.diff commit
#
# header "Content-Type" => "text/x-diff"
# header "Content-Disposition" => "filename=patch.diff"
#
# send_data diff, :type => "text/x-diff", :disposition => "inline"
#end
 
##
#get '/d/(.+)/(.+)' do
# path, name = *File.split(params[:matches][1])
# commit = params[:matches][2]
#
# @page = Page.from_uri path, name
# @diff = @page.object.diff commit
#
# @commit = commit[0..7] + "..."
#
# show :delta, "Diff of #{@page.pretty_name.last} against #{commit}"
#end
    end
 
  end
 
 
  # Configuration settings.
  #
  module Configurations
 
    # Sane default config. Can be run standalone or from rackup.
    #
    class Development < Waves::Configurations::Default
      reloadable [Giraffe::Resources]
 
      # When running standalone.
      server Waves::Servers::Mongrel
      host "0.0.0.0"
      port 8080
 
      resource Giraffe::Resources::Main
 
      application {
        use Rack::ShowExceptions
        use Rack::Static, :urls => %w[ /giraffe /favicon.ico ],
                          :root => "public"
        run Waves::Dispatchers::Default.new
      }
    end
 
    class Production < Development
    end
 
  end
 
end
 
require "giraffe"