Skip to content
This repository has been archived by the owner on May 9, 2018. It is now read-only.

Commit

Permalink
Implement a simple "add repository" form
Browse files Browse the repository at this point in the history
  • Loading branch information
rspeicher committed Apr 20, 2011
1 parent 65795c7 commit ec20817
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 24 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ Basically:
### TODO

* I'd love some HTML/CSS improvements. I am not a designer.
* Add a simple "add my project" form that can provide an easier way to start
indexing a repository besides testing a post-receive hook.

## Copyright

Expand Down
13 changes: 10 additions & 3 deletions app/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class App < Sinatra::Base
:templates => "#{dir}/templates"
}

before do
@flash = flash
end

get '/' do
mustache :index
end
Expand Down Expand Up @@ -53,13 +57,16 @@ class App < Sinatra::Base
# Manually add a username or repository to be indexed
post '/add' do
if params['repo'] =~ GITHUB_USER
flash[:notice] = "Added #{params['repo']} for indexing. Thanks!"
Delayed::Job.enqueue UserJob.new(params['repo'])
status(200)
redirect to('/')
elsif params['repo'] =~ GITHUB_REPO
flash[:notice] = "Added #{params['repo']} for indexing. Thanks!"
Delayed::Job.enqueue RepositoryJob.new(params['repo'])
status(200)
redirect to('/')
else
status(500)
flash[:error] = "Couldn't add repository #{params['repo']}. Sorry!"
redirect to('/')
end
end

Expand Down
30 changes: 27 additions & 3 deletions app/stylesheets/screen.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ $phile_red: #910000;
nav {
height: 30px;
background-color: #fff;
text-align: center;
padding: 10px;

span {
font-size: 1.2em;
}

span.notice {
color: green;
}
span.error {
color: red;
}
}

// Layout -- Header
Expand Down Expand Up @@ -111,8 +124,18 @@ aside.about {
padding: 10px 0;
}

ol {
margin-left: 15px;
fieldset {
padding: 10px;

input[type=text] {
width: 80%;
}

span.hint {
font-size: 0.8em;
color: #888;
word-spacing: 2px;
}
}
}

Expand Down Expand Up @@ -162,12 +185,13 @@ section.gem_info {
}

footer {
font-size: 10px;
text-align: center;
color: #ddd;

// NetworkRedux logo
div.network_redux {
font-size: 18px;
font-size: 14px;
text-transform: uppercase;

a {
Expand Down
23 changes: 11 additions & 12 deletions app/templates/index.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{{# gems }}
<div class="gem">
<div class="count">{{count}}</div>
<div class="gem"><a href="/gems/{{ name }}">{{ name }}</a></div>
<div class="gem"><a href="/gems/{{name}}">{{name}}</a></div>
</div>
{{/ gems }}
</div>
Expand All @@ -22,16 +22,15 @@
and then to provide a simple search interface to find those projects.</p>

<h2>Why don't I see my project?</h2>
<p>Except for a few projects added as seed data, Gemphile is entirely
opt-in. If you'd like to contribute to the site and have us index your
project, follow these steps:
<ol>
<li>Go to your project's administration page</li>
<li>Add a GitHub <a href="http://help.github.com/post-receive-hooks/" target="_blank">post-receive</a> URL to your project</li>
<li>Enter <a href="http://gemphile.org/push">http://gemphile.org/push</a> as the URL</li>
<li>Save and then click "Test Hook"</li>
</ol>
This will pull in your project's current info and let the site keep that information updated.</p>
</div>
<p>We just don't know about it yet! Please add it:</p>
<form method="post" action="/add">
<fieldset>
<input type="text" id="repo" name="repo" placeholder="tsigo/gemphile" />
<input type="submit" name="submit" value="Add" />
<span class="hint">Enter your GitHub username to add all of your public Ruby repositories, or
enter a <code>username/repository</code> combination to add only that repository.</span>
</fieldset>
</form>
</aside>
</div>
</section>
4 changes: 4 additions & 0 deletions app/templates/layout.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

<body>
<nav class="container">
{{# flash }}
<span class="notice">{{ notice }}</span>
<span class="error">{{ error }}</span>
{{/ flash }}
</nav>

<header class="container">
Expand Down
4 changes: 4 additions & 0 deletions app/views/layout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ def development?
def production?
Gemphile::App.production?
end

def flash
@flash
end
end
end
2 changes: 1 addition & 1 deletion public/css/screen.css

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions spec/app/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
describe Gemphile::App do
include Rack::Test::Methods

def flash
last_request.env['x-rack.flash']
end

describe "GET /search" do
context "with an exact match" do
it "should redirect on an exact match" do
Expand Down Expand Up @@ -45,19 +49,22 @@

it "ignores invalid repositories" do
post '/add', :repo => 'tsigo/gemphile/production'
last_response.should_not be_ok
flash.error.should_not be_nil
last_response.should be_redirect
end

it "recognizes a user name" do
Delayed::Job.expects(:enqueue).with { |v| v.is_a?(UserJob) }
post '/add', :repo => 'tsigo'
last_response.should be_ok
flash.notice.should_not be_nil
last_response.should be_redirect
end

it "recognizes a repository" do
Delayed::Job.expects(:enqueue).with { |v| v.is_a?(RepositoryJob) }
post '/add', :repo => 'tsigo/gemphile'
last_response.should be_ok
flash.notice.should_not be_nil
last_response.should be_redirect
end
end
end

0 comments on commit ec20817

Please sign in to comment.