Commit 2c191ab06c61b839c3addf6b2f7e5660675908a2

Authored by Dmitriy Zaporozhets
2 parents 98e1597f 33347efa

Merge branch 'improve/snippets' of /home/git/repositories/gitlab/gitlabhq

app/assets/stylesheets/gitlab_bootstrap/lists.scss
@@ -75,7 +75,6 @@ ul.bordered-list { @@ -75,7 +75,6 @@ ul.bordered-list {
75 display: block; 75 display: block;
76 margin: 0px; 76 margin: 0px;
77 &:last-child { border:none } 77 &:last-child { border:none }
78 -  
79 &.active { 78 &.active {
80 background: #f9f9f9; 79 background: #f9f9f9;
81 a { font-weight: bold; } 80 a { font-weight: bold; }
app/assets/stylesheets/sections/snippets.scss
@@ -7,3 +7,9 @@ @@ -7,3 +7,9 @@
7 } 7 }
8 } 8 }
9 } 9 }
  10 +
  11 +.my-snippets li:first-child {
  12 + h4 { margin-top: 0; }
  13 + padding-top: 0;
  14 +}
  15 +
app/views/projects/snippets/_snippet.html.haml
1 %li 1 %li
2 - .snippet-title  
3 - - if snippet.private?  
4 - %i.icon-lock.cgreen  
5 - - else  
6 - %i.icon-globe.cblue 2 + %h4.snippet-title
7 = link_to reliable_snippet_path(snippet) do 3 = link_to reliable_snippet_path(snippet) do
8 - %h5.inline  
9 - = truncate(snippet.title, length: 60)  
10 - %span.cgray 4 + = truncate(snippet.title, length: 60)
  5 + %span.cgray.monospace.tiny.pull-right
11 = snippet.file_name 6 = snippet.file_name
12 7
13 %small.pull-right.cgray 8 %small.pull-right.cgray
@@ -17,9 +12,10 @@ @@ -17,9 +12,10 @@
17 - else 12 - else
18 Never 13 Never
19 14
20 - .snippet-info.prepend-left-20 15 + .snippet-info
21 = "##{snippet.id}" 16 = "##{snippet.id}"
22 - %span.light 17 + %span
23 by 18 by
24 = image_tag gravatar_icon(snippet.author_email), class: "avatar avatar-inline s16" 19 = image_tag gravatar_icon(snippet.author_email), class: "avatar avatar-inline s16"
25 = snippet.author_name 20 = snippet.author_name
  21 + %span.light #{time_ago_in_words(snippet.created_at)} ago
app/views/projects/snippets/show.html.haml
1 %h3.page-title 1 %h3.page-title
2 - %i.icon-lock.cgreen  
3 = @snippet.title 2 = @snippet.title
4 3
5 %small.pull-right 4 %small.pull-right
app/views/snippets/_form.html.haml
@@ -16,9 +16,6 @@ @@ -16,9 +16,6 @@
16 = f.label "Private?" 16 = f.label "Private?"
17 .input= f.check_box :private, {class: ''} 17 .input= f.check_box :private, {class: ''}
18 .clearfix 18 .clearfix
19 - = f.label "Lifetime"  
20 - .input= f.select :expires_at, lifetime_select_options, {}, {class: 'chosen span2'}  
21 - .clearfix  
22 .file-editor 19 .file-editor
23 = f.label :file_name, "File" 20 = f.label :file_name, "File"
24 .input 21 .input
@@ -30,7 +27,11 @@ @@ -30,7 +27,11 @@
30 = f.hidden_field :content, class: 'snippet-file-content' 27 = f.hidden_field :content, class: 'snippet-file-content'
31 28
32 .form-actions 29 .form-actions
33 - = f.submit 'Save', class: "btn-save btn" 30 + - if @snippet.new_record?
  31 + = f.submit 'Create snippet', class: "btn-create btn"
  32 + - else
  33 + = f.submit 'Save', class: "btn-save btn"
  34 +
34 = link_to "Cancel", snippets_path(@project), class: " btn" 35 = link_to "Cancel", snippets_path(@project), class: " btn"
35 - unless @snippet.new_record? 36 - unless @snippet.new_record?
36 .pull-right= link_to 'Destroy', snippet_path(@snippet), confirm: 'Removed snippet cannot be restored! Are you sure?', method: :delete, class: "btn pull-right danger delete-snippet", id: "destroy_snippet_#{@snippet.id}" 37 .pull-right= link_to 'Destroy', snippet_path(@snippet), confirm: 'Removed snippet cannot be restored! Are you sure?', method: :delete, class: "btn pull-right danger delete-snippet", id: "destroy_snippet_#{@snippet.id}"
app/views/snippets/_snippet.html.haml
1 %li 1 %li
2 - .snippet-title  
3 - - if snippet.private?  
4 - = private_icon  
5 - - else  
6 - = public_icon 2 + %h4.snippet-title
7 = link_to reliable_snippet_path(snippet) do 3 = link_to reliable_snippet_path(snippet) do
8 - %h5.inline  
9 - = truncate(snippet.title, length: 60)  
10 - %span.cgray 4 + = truncate(snippet.title, length: 60)
  5 + - if snippet.private?
  6 + %span.label.label-success
  7 + %i.icon-lock
  8 + private
  9 + %span.cgray.monospace.tiny.pull-right
11 = snippet.file_name 10 = snippet.file_name
12 11
13 %small.pull-right.cgray 12 %small.pull-right.cgray
14 - if snippet.project_id? 13 - if snippet.project_id?
15 = link_to snippet.project.name_with_namespace, project_path(snippet.project) 14 = link_to snippet.project.name_with_namespace, project_path(snippet.project)
16 - %span  
17 - \|  
18 - Expires:  
19 - - if snippet.expires_at  
20 - = snippet.expires_at.to_date.to_s(:short)  
21 - - else  
22 - Never  
23 15
24 - .snippet-info.prepend-left-20 16 + .snippet-info
25 = "##{snippet.id}" 17 = "##{snippet.id}"
26 - %span.light 18 + %span
27 by 19 by
28 - = image_tag gravatar_icon(snippet.author_email), class: "avatar avatar-inline s16", alt: ''  
29 - = snippet.author_name  
30 - 20 + = link_to user_snippets_path(snippet.author) do
  21 + = image_tag gravatar_icon(snippet.author_email), class: "avatar avatar-inline s16", alt: ''
  22 + = snippet.author_name
  23 + %span.light #{time_ago_in_words(snippet.created_at)} ago
app/views/snippets/_snippets.html.haml
@@ -4,4 +4,4 @@ @@ -4,4 +4,4 @@
4 %li 4 %li
5 %h3.nothing_here_message Nothing here. 5 %h3.nothing_here_message Nothing here.
6 6
7 -= paginate @snippets 7 += paginate @snippets, theme: 'gitlab'
app/views/snippets/current_user_index.html.haml
@@ -19,6 +19,6 @@ @@ -19,6 +19,6 @@
19 = nav_tab :scope, 'public' do 19 = nav_tab :scope, 'public' do
20 = link_to "Public", user_snippets_path(@user, scope: 'public') 20 = link_to "Public", user_snippets_path(@user, scope: 'public')
21 21
22 - .span9 22 + .span9.my-snippets
23 = render 'snippets' 23 = render 'snippets'
24 24
app/views/snippets/index.html.haml
@@ -9,7 +9,5 @@ @@ -9,7 +9,5 @@
9 My snippets 9 My snippets
10 10
11 %hr 11 %hr
12 -.row  
13 - .span12  
14 - = render 'snippets' 12 += render 'snippets'
15 13
app/views/snippets/show.html.haml
1 %h3.page-title 1 %h3.page-title
  2 + = @snippet.title
  3 +
2 - if @snippet.private? 4 - if @snippet.private?
3 - %i{:class => "icon-lock cgreen has_bottom_tooltip", "data-original-title" => "Private snippet"}  
4 - - else  
5 - %i{:class => "icon-globe cblue has_bottom_tooltip", "data-original-title" => "Public snippet"} 5 + %span.label.label-success
  6 + %i.icon-lock
  7 + private
6 8
7 - = @snippet.title 9 + .pull-right
  10 + = link_to new_snippet_path, class: "btn btn-small add_new grouped btn-primary", title: "New Snippet" do
  11 + Add new snippet
8 12
9 - %small.pull-right 13 +
  14 +.append-bottom-20
  15 + .pull-right
10 = "##{@snippet.id}" 16 = "##{@snippet.id}"
11 %span.light 17 %span.light
12 by 18 by
13 - = image_tag gravatar_icon(@snippet.author_email), class: "avatar avatar-inline s16"  
14 - = @snippet.author_name 19 + = link_to user_snippets_path(@snippet.author) do
  20 + = image_tag gravatar_icon(@snippet.author_email), class: "avatar avatar-inline s16"
  21 + = @snippet.author_name
  22 +
  23 + .back-link
  24 + - if @snippet.author == current_user
  25 + = link_to user_snippets_path(current_user) do
  26 + ← my snippets
  27 + - else
  28 + = link_to snippets_path do
  29 + ← discover snippets
  30 +
15 %div= render 'blob' 31 %div= render 'blob'
app/views/snippets/user_index.html.haml
@@ -4,7 +4,6 @@ @@ -4,7 +4,6 @@
4 %span 4 %span
5 \/ 5 \/
6 Snippets 6 Snippets
7 - %small share code pastes with others out of git repository  
8 = link_to new_snippet_path, class: "btn btn-small add_new pull-right", title: "New Snippet" do 7 = link_to new_snippet_path, class: "btn btn-small add_new pull-right", title: "New Snippet" do
9 Add new snippet 8 Add new snippet
10 9
db/fixtures/development/12_snippets.rb 0 → 100644
@@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
  1 +ActiveRecord::Base.observers.disable :all
  2 +
  3 +Gitlab::Seeder.quiet do
  4 + contents = [
  5 + `curl https://gist.github.com/randx/4275756/raw/da2f262920c96d1a970d48bf2e99147954b1f4bd/glus1204.sh`,
  6 + `curl https://gist.github.com/randx/3754594/raw/11026a295e6ef3a151c635707a3e1e8e15fc4725/gitlab_setup.sh `,
  7 + `curl https://gist.github.com/randx/3065552/raw/29fbd09f4605a5ea22a5a9095e35fd1938dea4d6/gistfile1.sh`,
  8 + ]
  9 +
  10 + (1..50).each do |i|
  11 + user = User.all.sample
  12 +
  13 + PersonalSnippet.seed(:id, [{
  14 + id: i,
  15 + author_id: user.id,
  16 + title: Faker::Lorem.sentence(3),
  17 + file_name: Faker::Internet.domain_word + '.sh',
  18 + private: [true, false].sample,
  19 + content: contents.sample,
  20 + }])
  21 + print('.')
  22 + end
  23 +end
  24 +
features/steps/snippets/snippets.rb
@@ -24,12 +24,11 @@ class SnippetsFeature < Spinach::FeatureSteps @@ -24,12 +24,11 @@ class SnippetsFeature < Spinach::FeatureSteps
24 24
25 And 'I submit new snippet "Personal snippet three"' do 25 And 'I submit new snippet "Personal snippet three"' do
26 fill_in "personal_snippet_title", :with => "Personal snippet three" 26 fill_in "personal_snippet_title", :with => "Personal snippet three"
27 - select "forever", :from => "personal_snippet_expires_at"  
28 fill_in "personal_snippet_file_name", :with => "my_snippet.rb" 27 fill_in "personal_snippet_file_name", :with => "my_snippet.rb"
29 within('.file-editor') do 28 within('.file-editor') do
30 find(:xpath, "//input[@id='personal_snippet_content']").set 'Content of snippet three' 29 find(:xpath, "//input[@id='personal_snippet_content']").set 'Content of snippet three'
31 end 30 end
32 - click_button "Save" 31 + click_button "Create snippet"
33 end 32 end
34 33
35 Then 'I should see snippet "Personal snippet three"' do 34 Then 'I should see snippet "Personal snippet three"' do