Commit b49cfbc1d54b6cfa674ba803b3a90fb81c609c8b
1 parent
cc869d5d
Exists in
master
and in
4 other branches
Project snippets moved to /projects
Showing
10 changed files
with
130 additions
and
8 deletions
Show diff stats
app/controllers/projects/snippets_controller.rb
| 1 | -class SnippetsController < ProjectResourceController | 1 | +class Projects::SnippetsController < Projects::ApplicationController |
| 2 | before_filter :module_enabled | 2 | before_filter :module_enabled |
| 3 | before_filter :snippet, only: [:show, :edit, :destroy, :update, :raw] | 3 | before_filter :snippet, only: [:show, :edit, :destroy, :update, :raw] |
| 4 | 4 |
| @@ -0,0 +1,12 @@ | @@ -0,0 +1,12 @@ | ||
| 1 | +.file_holder | ||
| 2 | + .file_title | ||
| 3 | + %i.icon-file | ||
| 4 | + %strong= @snippet.file_name | ||
| 5 | + %span.options | ||
| 6 | + = link_to "raw", raw_project_snippet_path(@project, @snippet), class: "btn btn-tiny", target: "_blank" | ||
| 7 | + .file_content.code | ||
| 8 | + - unless @snippet.content.empty? | ||
| 9 | + %div{class: user_color_scheme_class} | ||
| 10 | + = raw @snippet.colorize(formatter: :gitlab) | ||
| 11 | + - else | ||
| 12 | + %p.nothing_here_message Empty file |
| @@ -0,0 +1,41 @@ | @@ -0,0 +1,41 @@ | ||
| 1 | +%h3.page_title | ||
| 2 | + = @snippet.new_record? ? "New Snippet" : "Edit Snippet ##{@snippet.id}" | ||
| 3 | +%hr | ||
| 4 | +.snippet-form-holder | ||
| 5 | + = form_for [@project, @snippet] do |f| | ||
| 6 | + -if @snippet.errors.any? | ||
| 7 | + .alert.alert-error | ||
| 8 | + %ul | ||
| 9 | + - @snippet.errors.full_messages.each do |msg| | ||
| 10 | + %li= msg | ||
| 11 | + | ||
| 12 | + .clearfix | ||
| 13 | + = f.label :title | ||
| 14 | + .input= f.text_field :title, placeholder: "Example Snippet", class: 'input-xlarge', required: true | ||
| 15 | + .clearfix | ||
| 16 | + = f.label "Lifetime" | ||
| 17 | + .input= f.select :expires_at, lifetime_select_options, {}, {class: 'chosen span2'} | ||
| 18 | + .clearfix | ||
| 19 | + .file-editor | ||
| 20 | + = f.label :file_name, "File" | ||
| 21 | + .input | ||
| 22 | + .file_holder.snippet | ||
| 23 | + .file_title | ||
| 24 | + = f.text_field :file_name, placeholder: "example.rb", class: 'snippet-file-name', required: true | ||
| 25 | + .file_content.code | ||
| 26 | + %pre#editor= @snippet.content | ||
| 27 | + = f.hidden_field :content, class: 'snippet-file-content' | ||
| 28 | + | ||
| 29 | + .form-actions | ||
| 30 | + = f.submit 'Save', class: "btn-save btn" | ||
| 31 | + = link_to "Cancel", project_snippets_path(@project), class: " btn" | ||
| 32 | + - unless @snippet.new_record? | ||
| 33 | + .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}" | ||
| 34 | + | ||
| 35 | + | ||
| 36 | +:javascript | ||
| 37 | + var editor = ace.edit("editor"); | ||
| 38 | + $(".snippet-form-holder form").submit(function(){ | ||
| 39 | + $(".snippet-file-content").val(editor.getValue()); | ||
| 40 | + }); | ||
| 41 | + |
| @@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
| 1 | +%tr | ||
| 2 | + %td | ||
| 3 | + = image_tag gravatar_icon(snippet.author_email), class: "avatar s24" | ||
| 4 | + %a{href: project_snippet_path(snippet.project, snippet)} | ||
| 5 | + %strong= truncate(snippet.title, length: 60) | ||
| 6 | + %td | ||
| 7 | + = snippet.file_name | ||
| 8 | + %td | ||
| 9 | + %span.cgray | ||
| 10 | + - if snippet.expires_at | ||
| 11 | + = snippet.expires_at.to_date.to_s(:short) | ||
| 12 | + - else | ||
| 13 | + Never |
| @@ -0,0 +1 @@ | @@ -0,0 +1 @@ | ||
| 1 | += render "snippets/form" |
| @@ -0,0 +1,19 @@ | @@ -0,0 +1,19 @@ | ||
| 1 | +%h3.page_title | ||
| 2 | + Snippets | ||
| 3 | + %small share code pastes with others out of git repository | ||
| 4 | + | ||
| 5 | + - if can? current_user, :write_snippet, @project | ||
| 6 | + = link_to new_project_snippet_path(@project), class: "btn btn-small add_new pull-right", title: "New Snippet" do | ||
| 7 | + Add new snippet | ||
| 8 | +%br | ||
| 9 | +%table | ||
| 10 | + %thead | ||
| 11 | + %tr | ||
| 12 | + %th Title | ||
| 13 | + %th File Name | ||
| 14 | + %th Expires At | ||
| 15 | + = render @snippets | ||
| 16 | + - if @snippets.empty? | ||
| 17 | + %tr | ||
| 18 | + %td{colspan: 3} | ||
| 19 | + %h3.nothing_here_message Nothing here. |
| @@ -0,0 +1 @@ | @@ -0,0 +1 @@ | ||
| 1 | += render "snippets/form" |
| @@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
| 1 | +%h3.page_title | ||
| 2 | + = @snippet.title | ||
| 3 | + %small= @snippet.file_name | ||
| 4 | + - if can?(current_user, :admin_snippet, @project) || @snippet.author == current_user | ||
| 5 | + = link_to "Edit", edit_project_snippet_path(@project, @snippet), class: "btn btn-small pull-right", title: 'Edit Snippet' | ||
| 6 | + | ||
| 7 | +%br | ||
| 8 | +%div= render 'blob' | ||
| 9 | +%div#notes= render "notes/notes_with_form" |
config/routes.rb
| @@ -244,9 +244,11 @@ Gitlab::Application.routes.draw do | @@ -244,9 +244,11 @@ Gitlab::Application.routes.draw do | ||
| 244 | end | 244 | end |
| 245 | end | 245 | end |
| 246 | 246 | ||
| 247 | - resources :snippets do | ||
| 248 | - member do | ||
| 249 | - get "raw" | 247 | + scope module: :projects do |
| 248 | + resources :snippets do | ||
| 249 | + member do | ||
| 250 | + get "raw" | ||
| 251 | + end | ||
| 250 | end | 252 | end |
| 251 | end | 253 | end |
| 252 | 254 |
spec/routing/project_routing_spec.rb
| @@ -249,13 +249,37 @@ end | @@ -249,13 +249,37 @@ end | ||
| 249 | # project_snippet GET /:project_id/snippets/:id(.:format) snippets#show | 249 | # project_snippet GET /:project_id/snippets/:id(.:format) snippets#show |
| 250 | # PUT /:project_id/snippets/:id(.:format) snippets#update | 250 | # PUT /:project_id/snippets/:id(.:format) snippets#update |
| 251 | # DELETE /:project_id/snippets/:id(.:format) snippets#destroy | 251 | # DELETE /:project_id/snippets/:id(.:format) snippets#destroy |
| 252 | -describe SnippetsController, "routing" do | 252 | +describe Project::SnippetsController, "routing" do |
| 253 | it "to #raw" do | 253 | it "to #raw" do |
| 254 | - get("/gitlabhq/snippets/1/raw").should route_to('snippets#raw', project_id: 'gitlabhq', id: '1') | 254 | + get("/gitlabhq/snippets/1/raw").should route_to('projects/snippets#raw', project_id: 'gitlabhq', id: '1') |
| 255 | end | 255 | end |
| 256 | 256 | ||
| 257 | - it_behaves_like "RESTful project resources" do | ||
| 258 | - let(:controller) { 'snippets' } | 257 | + it "to #index" do |
| 258 | + get("/gitlabhq/snippets").should route_to("projects/snippets#index", project_id: 'gitlabhq') | ||
| 259 | + end | ||
| 260 | + | ||
| 261 | + it "to #create" do | ||
| 262 | + post("/gitlabhq/snippets").should route_to("projects/snippets#create", project_id: 'gitlabhq') | ||
| 263 | + end | ||
| 264 | + | ||
| 265 | + it "to #new" do | ||
| 266 | + get("/gitlabhq/snippets/new").should route_to("projects/snippets#new", project_id: 'gitlabhq') | ||
| 267 | + end | ||
| 268 | + | ||
| 269 | + it "to #edit" do | ||
| 270 | + get("/gitlabhq/snippets/1/edit").should route_to("projects/snippets#edit", project_id: 'gitlabhq', id: '1') | ||
| 271 | + end | ||
| 272 | + | ||
| 273 | + it "to #show" do | ||
| 274 | + get("/gitlabhq/snippets/1").should route_to("projects/snippets#show", project_id: 'gitlabhq', id: '1') | ||
| 275 | + end | ||
| 276 | + | ||
| 277 | + it "to #update" do | ||
| 278 | + put("/gitlabhq/snippets/1").should route_to("projects/snippets#update", project_id: 'gitlabhq', id: '1') | ||
| 279 | + end | ||
| 280 | + | ||
| 281 | + it "to #destroy" do | ||
| 282 | + delete("/gitlabhq/snippets/1").should route_to("projects/snippets#destroy", project_id: 'gitlabhq', id: '1') | ||
| 259 | end | 283 | end |
| 260 | end | 284 | end |
| 261 | 285 |