Commit 093159a8683c381a9f7aa80073ac94c4ed03e108

Authored by randx
1 parent b96af79b

Styled snippets. Raw button for snippet

app/controllers/snippets_controller.rb
1 class SnippetsController < ApplicationController 1 class SnippetsController < ApplicationController
2 before_filter :authenticate_user! 2 before_filter :authenticate_user!
3 before_filter :project 3 before_filter :project
4 - before_filter :snippet, :only => [:show, :edit, :destroy, :update] 4 + before_filter :snippet, :only => [:show, :edit, :destroy, :update, :raw]
5 layout "project" 5 layout "project"
6 6
7 # Authorize 7 # Authorize
@@ -67,7 +67,17 @@ class SnippetsController &lt; ApplicationController @@ -67,7 +67,17 @@ class SnippetsController &lt; ApplicationController
67 redirect_to project_snippets_path(@project) 67 redirect_to project_snippets_path(@project)
68 end 68 end
69 69
  70 + def raw
  71 + send_data(
  72 + @snippet.content,
  73 + :type => "text/plain",
  74 + :disposition => 'inline',
  75 + :filename => @snippet.file_name
  76 + )
  77 + end
  78 +
70 protected 79 protected
  80 +
71 def snippet 81 def snippet
72 @snippet ||= @project.snippets.find(params[:id]) 82 @snippet ||= @project.snippets.find(params[:id])
73 end 83 end
app/views/snippets/_snippet.html.haml
1 %tr 1 %tr
2 %td 2 %td
3 %a{:href => project_snippet_path(snippet.project, snippet)} 3 %a{:href => project_snippet_path(snippet.project, snippet)}
4 - = truncate(snippet.title, :length => 60)  
5 - %span.right.cgray  
6 - = snippet.file_name 4 + %strong= truncate(snippet.title, :length => 60)
  5 + %td
  6 + = snippet.file_name
  7 + %td
  8 + %span.cgray
  9 + - if snippet.expires_at
  10 + = snippet.expires_at.to_date.to_s(:short)
  11 + - else
  12 + Never
app/views/snippets/index.html.haml
@@ -8,5 +8,14 @@ @@ -8,5 +8,14 @@
8 %br 8 %br
9 To add new snippet - click on button. 9 To add new snippet - click on button.
10 10
11 -- unless @snippets.fresh.empty?  
12 - %table.zebra-striped.borders= render @snippets.fresh 11 +%table.admin-table
  12 + %thead
  13 + %tr
  14 + %th Title
  15 + %th File Name
  16 + %th Expires At
  17 + = render @snippets.fresh
  18 + - if @snippets.fresh.empty?
  19 + %tr
  20 + %td{:colspan => 3}
  21 + %h3.nothing_here_message Nothing here.
app/views/snippets/show.html.haml
@@ -13,6 +13,8 @@ @@ -13,6 +13,8 @@
13 .view_file_header 13 .view_file_header
14 %i.icon-file 14 %i.icon-file
15 %strong= @snippet.file_name 15 %strong= @snippet.file_name
  16 + %span.options
  17 + = link_to "raw", raw_project_snippet_path(@project, @snippet), :class => "btn very_small", :target => "_blank"
16 .view_file_content 18 .view_file_content
17 %div{:class => current_user.dark_scheme ? "black" : ""} 19 %div{:class => current_user.dark_scheme ? "black" : ""}
18 = raw @snippet.colorize(options: { linenos: 'True'}) 20 = raw @snippet.colorize(options: { linenos: 'True'})
config/routes.rb
@@ -119,7 +119,12 @@ Gitlab::Application.routes.draw do @@ -119,7 +119,12 @@ Gitlab::Application.routes.draw do
119 end 119 end
120 end 120 end
121 121
122 - resources :snippets 122 + resources :snippets do
  123 + member do
  124 + get "raw"
  125 + end
  126 + end
  127 +
123 resources :hooks, :only => [:index, :create, :destroy] do 128 resources :hooks, :only => [:index, :create, :destroy] do
124 member do 129 member do
125 get :test 130 get :test