From ecd75f84a61f0dac9654e79609e4eaf527ea6fb2 Mon Sep 17 00:00:00 2001 From: charlysisto Date: Tue, 2 Oct 2012 16:51:35 +0200 Subject: [PATCH] added remove feature --- README.md | 1 - app/controllers/jail/githubs_controller.rb | 8 +++++++- app/models/jail/github.rb | 21 +++++++++++++++++---- config/routes.rb | 1 + 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9242eed..2e87d68 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,6 @@ Other approaches where : ## TODO -- remove plugin - plugin installed? (check file existence) - plugin outdated? (overkill ?) - clean routes diff --git a/app/controllers/jail/githubs_controller.rb b/app/controllers/jail/githubs_controller.rb index 1ecb6a0..e9c283a 100644 --- a/app/controllers/jail/githubs_controller.rb +++ b/app/controllers/jail/githubs_controller.rb @@ -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 diff --git a/app/models/jail/github.rb b/app/models/jail/github.rb index 6d93a5a..4bab6ff 100644 --- a/app/models/jail/github.rb +++ b/app/models/jail/github.rb @@ -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 @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 9b51d48..3049c7b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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