Skip to content

Commit

Permalink
added remove feature
Browse files Browse the repository at this point in the history
  • Loading branch information
charly committed Oct 2, 2012
1 parent 98c4497 commit ecd75f8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -47,7 +47,6 @@ Other approaches where :

## TODO

- remove plugin
- plugin installed? (check file existence)
- plugin outdated? (overkill ?)
- clean routes
Expand Down
8 changes: 7 additions & 1 deletion app/controllers/jail/githubs_controller.rb
Expand Up @@ -13,7 +13,13 @@ def show
def install
@github = Github.find(params[:name], params[:repo])
@github.install
redirect_to root_path
redirect_to( root_path, :notice => "Installed!" )
end

def remove
@github = Github.find(params[:name], params[:repo])
@github.remove
redirect_to( root_path, :notice => "Removed!" )
end

end
Expand Down
21 changes: 17 additions & 4 deletions app/models/jail/github.rb
Expand Up @@ -45,9 +45,9 @@ def readme
github.markdown.render :text => text
end

def read(path)
# TODO : raise error if path's not a file
self.path= path
# TODO : raise error if path's not a file
def read(apath)
self.path= apath
text = Base64.decode64 contents.content
end

Expand All @@ -58,12 +58,25 @@ def install
download(:img)
end

def remove
delete_file(:js)
delete_file(:css)
delete_file(:img)
end

private
def download(type = :js)
return if spec[type].blank?
target(type).open('w') {|f| f.write( read(spec[:type]) )}
text = read(spec[type])
target(type).open('w') {|f| f.write(text) }
end

def delete_file(type = :js)
return if spec[type].blank?
self.path = spec[type]
t = target(type) and t.exist? and t.delete
end

def target(type)
filename= Pathname(path).basename.to_s
case type
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -3,5 +3,6 @@
root :to => "githubs#index"
match ":name/:repo" => "githubs#show"
match ":name/:repo/install" => "githubs#install"
match ":name/:repo/remove" => "githubs#remove"
match ":name/:repo/*path" => "githubs#show"
end

0 comments on commit ecd75f8

Please sign in to comment.