From b49cfbc1d54b6cfa674ba803b3a90fb81c609c8b Mon Sep 17 00:00:00 2001 From: Andrew8xx8 <avk@8xx8.ru> Date: Sat, 23 Mar 2013 23:13:51 +0400 Subject: [PATCH] Project snippets moved to /projects --- .../projects/snippets_controller.rb | 2 +- app/views/projects/snippets/_blob.html.haml | 12 ++++++ app/views/projects/snippets/_form.html.haml | 41 +++++++++++++++++++ .../projects/snippets/_snippet.html.haml | 13 ++++++ app/views/projects/snippets/edit.html.haml | 1 + app/views/projects/snippets/index.html.haml | 19 +++++++++ app/views/projects/snippets/new.html.haml | 1 + app/views/projects/snippets/show.html.haml | 9 ++++ config/routes.rb | 8 ++-- spec/routing/project_routing_spec.rb | 32 +++++++++++++-- 10 files changed, 130 insertions(+), 8 deletions(-) create mode 100644 app/views/projects/snippets/_blob.html.haml create mode 100644 app/views/projects/snippets/_form.html.haml create mode 100644 app/views/projects/snippets/_snippet.html.haml create mode 100644 app/views/projects/snippets/edit.html.haml create mode 100644 app/views/projects/snippets/index.html.haml create mode 100644 app/views/projects/snippets/new.html.haml create mode 100644 app/views/projects/snippets/show.html.haml diff --git a/app/controllers/projects/snippets_controller.rb b/app/controllers/projects/snippets_controller.rb index a2e22a670a3..7c3281084f7 100644 --- a/app/controllers/projects/snippets_controller.rb +++ b/app/controllers/projects/snippets_controller.rb @@ -1,4 +1,4 @@ -class SnippetsController < ProjectResourceController +class Projects::SnippetsController < Projects::ApplicationController before_filter :module_enabled before_filter :snippet, only: [:show, :edit, :destroy, :update, :raw] diff --git a/app/views/projects/snippets/_blob.html.haml b/app/views/projects/snippets/_blob.html.haml new file mode 100644 index 00000000000..017a33b34f3 --- /dev/null +++ b/app/views/projects/snippets/_blob.html.haml @@ -0,0 +1,12 @@ +.file_holder + .file_title + %i.icon-file + %strong= @snippet.file_name + %span.options + = link_to "raw", raw_project_snippet_path(@project, @snippet), class: "btn btn-tiny", target: "_blank" + .file_content.code + - unless @snippet.content.empty? + %div{class: user_color_scheme_class} + = raw @snippet.colorize(formatter: :gitlab) + - else + %p.nothing_here_message Empty file diff --git a/app/views/projects/snippets/_form.html.haml b/app/views/projects/snippets/_form.html.haml new file mode 100644 index 00000000000..77162cdcde3 --- /dev/null +++ b/app/views/projects/snippets/_form.html.haml @@ -0,0 +1,41 @@ +%h3.page_title + = @snippet.new_record? ? "New Snippet" : "Edit Snippet ##{@snippet.id}" +%hr +.snippet-form-holder + = form_for [@project, @snippet] do |f| + -if @snippet.errors.any? + .alert.alert-error + %ul + - @snippet.errors.full_messages.each do |msg| + %li= msg + + .clearfix + = f.label :title + .input= f.text_field :title, placeholder: "Example Snippet", class: 'input-xlarge', required: true + .clearfix + = f.label "Lifetime" + .input= f.select :expires_at, lifetime_select_options, {}, {class: 'chosen span2'} + .clearfix + .file-editor + = f.label :file_name, "File" + .input + .file_holder.snippet + .file_title + = f.text_field :file_name, placeholder: "example.rb", class: 'snippet-file-name', required: true + .file_content.code + %pre#editor= @snippet.content + = f.hidden_field :content, class: 'snippet-file-content' + + .form-actions + = f.submit 'Save', class: "btn-save btn" + = link_to "Cancel", project_snippets_path(@project), class: " btn" + - unless @snippet.new_record? + .pull-right= link_to 'Destroy', [@project, @snippet], confirm: 'Are you sure?', method: :delete, class: "btn pull-right danger delete-snippet", id: "destroy_snippet_#{@snippet.id}" + + +:javascript + var editor = ace.edit("editor"); + $(".snippet-form-holder form").submit(function(){ + $(".snippet-file-content").val(editor.getValue()); + }); + diff --git a/app/views/projects/snippets/_snippet.html.haml b/app/views/projects/snippets/_snippet.html.haml new file mode 100644 index 00000000000..a576500c15d --- /dev/null +++ b/app/views/projects/snippets/_snippet.html.haml @@ -0,0 +1,13 @@ +%tr + %td + = image_tag gravatar_icon(snippet.author_email), class: "avatar s24" + %a{href: project_snippet_path(snippet.project, snippet)} + %strong= truncate(snippet.title, length: 60) + %td + = snippet.file_name + %td + %span.cgray + - if snippet.expires_at + = snippet.expires_at.to_date.to_s(:short) + - else + Never diff --git a/app/views/projects/snippets/edit.html.haml b/app/views/projects/snippets/edit.html.haml new file mode 100644 index 00000000000..f81c0b8bc64 --- /dev/null +++ b/app/views/projects/snippets/edit.html.haml @@ -0,0 +1 @@ += render "snippets/form" diff --git a/app/views/projects/snippets/index.html.haml b/app/views/projects/snippets/index.html.haml new file mode 100644 index 00000000000..bacf23d8f8d --- /dev/null +++ b/app/views/projects/snippets/index.html.haml @@ -0,0 +1,19 @@ +%h3.page_title + Snippets + %small share code pastes with others out of git repository + + - if can? current_user, :write_snippet, @project + = link_to new_project_snippet_path(@project), class: "btn btn-small add_new pull-right", title: "New Snippet" do + Add new snippet +%br +%table + %thead + %tr + %th Title + %th File Name + %th Expires At + = render @snippets + - if @snippets.empty? + %tr + %td{colspan: 3} + %h3.nothing_here_message Nothing here. diff --git a/app/views/projects/snippets/new.html.haml b/app/views/projects/snippets/new.html.haml new file mode 100644 index 00000000000..f81c0b8bc64 --- /dev/null +++ b/app/views/projects/snippets/new.html.haml @@ -0,0 +1 @@ += render "snippets/form" diff --git a/app/views/projects/snippets/show.html.haml b/app/views/projects/snippets/show.html.haml new file mode 100644 index 00000000000..12534edf8ba --- /dev/null +++ b/app/views/projects/snippets/show.html.haml @@ -0,0 +1,9 @@ +%h3.page_title + = @snippet.title + %small= @snippet.file_name + - if can?(current_user, :admin_snippet, @project) || @snippet.author == current_user + = link_to "Edit", edit_project_snippet_path(@project, @snippet), class: "btn btn-small pull-right", title: 'Edit Snippet' + +%br +%div= render 'blob' +%div#notes= render "notes/notes_with_form" diff --git a/config/routes.rb b/config/routes.rb index 0028baf8d53..d87dd4abdb0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -244,9 +244,11 @@ Gitlab::Application.routes.draw do end end - resources :snippets do - member do - get "raw" + scope module: :projects do + resources :snippets do + member do + get "raw" + end end end diff --git a/spec/routing/project_routing_spec.rb b/spec/routing/project_routing_spec.rb index 41533f8b4fe..059abe14961 100644 --- a/spec/routing/project_routing_spec.rb +++ b/spec/routing/project_routing_spec.rb @@ -249,13 +249,37 @@ end # project_snippet GET /:project_id/snippets/:id(.:format) snippets#show # PUT /:project_id/snippets/:id(.:format) snippets#update # DELETE /:project_id/snippets/:id(.:format) snippets#destroy -describe SnippetsController, "routing" do +describe Project::SnippetsController, "routing" do it "to #raw" do - get("/gitlabhq/snippets/1/raw").should route_to('snippets#raw', project_id: 'gitlabhq', id: '1') + get("/gitlabhq/snippets/1/raw").should route_to('projects/snippets#raw', project_id: 'gitlabhq', id: '1') end - it_behaves_like "RESTful project resources" do - let(:controller) { 'snippets' } + it "to #index" do + get("/gitlabhq/snippets").should route_to("projects/snippets#index", project_id: 'gitlabhq') + end + + it "to #create" do + post("/gitlabhq/snippets").should route_to("projects/snippets#create", project_id: 'gitlabhq') + end + + it "to #new" do + get("/gitlabhq/snippets/new").should route_to("projects/snippets#new", project_id: 'gitlabhq') + end + + it "to #edit" do + get("/gitlabhq/snippets/1/edit").should route_to("projects/snippets#edit", project_id: 'gitlabhq', id: '1') + end + + it "to #show" do + get("/gitlabhq/snippets/1").should route_to("projects/snippets#show", project_id: 'gitlabhq', id: '1') + end + + it "to #update" do + put("/gitlabhq/snippets/1").should route_to("projects/snippets#update", project_id: 'gitlabhq', id: '1') + end + + it "to #destroy" do + delete("/gitlabhq/snippets/1").should route_to("projects/snippets#destroy", project_id: 'gitlabhq', id: '1') end end -- GitLab