Commit e7bcbb95c88a42fc31bc0ccbdf6a819780a612ec
1 parent
36e832cc
Exists in
master
and in
4 other branches
Restyle snippets
Showing
14 changed files
with
138 additions
and
93 deletions
Show diff stats
app/controllers/snippets_controller.rb
@@ -15,19 +15,28 @@ class SnippetsController < ApplicationController | @@ -15,19 +15,28 @@ class SnippetsController < ApplicationController | ||
15 | 15 | ||
16 | def user_index | 16 | def user_index |
17 | @user = User.find_by_username(params[:username]) | 17 | @user = User.find_by_username(params[:username]) |
18 | - | ||
19 | - @snippets = @current_user.snippets.fresh.non_expired | ||
20 | - | ||
21 | - @snippets = case params[:scope] | ||
22 | - when 'public' then | ||
23 | - @snippets.public | ||
24 | - when 'private' then | ||
25 | - @snippets.private | ||
26 | - else | ||
27 | - @snippets | ||
28 | - end | 18 | + @snippets = @user.snippets.fresh.non_expired |
19 | + | ||
20 | + if @user == current_user | ||
21 | + @snippets = case params[:scope] | ||
22 | + when 'public' then | ||
23 | + @snippets.public | ||
24 | + when 'private' then | ||
25 | + @snippets.private | ||
26 | + else | ||
27 | + @snippets | ||
28 | + end | ||
29 | + else | ||
30 | + @snippets = @snippets.public | ||
31 | + end | ||
29 | 32 | ||
30 | @snippets = @snippets.page(params[:page]).per(20) | 33 | @snippets = @snippets.page(params[:page]).per(20) |
34 | + | ||
35 | + if @user == current_user | ||
36 | + render 'current_user_index' | ||
37 | + else | ||
38 | + render 'user_index' | ||
39 | + end | ||
31 | end | 40 | end |
32 | 41 | ||
33 | def new | 42 | def new |
@@ -79,7 +88,7 @@ class SnippetsController < ApplicationController | @@ -79,7 +88,7 @@ class SnippetsController < ApplicationController | ||
79 | protected | 88 | protected |
80 | 89 | ||
81 | def snippet | 90 | def snippet |
82 | - @snippet ||= PersonalSnippet.find(params[:id]) | 91 | + @snippet ||= PersonalSnippet.where('author_id = :user_id or private is false', user_id: current_user.id).find(params[:id]) |
83 | end | 92 | end |
84 | 93 | ||
85 | def authorize_modify_snippet! | 94 | def authorize_modify_snippet! |
app/helpers/snippets_helper.rb
@@ -8,4 +8,12 @@ module SnippetsHelper | @@ -8,4 +8,12 @@ module SnippetsHelper | ||
8 | ] | 8 | ] |
9 | options_for_select(options) | 9 | options_for_select(options) |
10 | end | 10 | end |
11 | + | ||
12 | + def reliable_snippet_path(snippet) | ||
13 | + if snippet.project_id? | ||
14 | + project_snippet_path(snippet.project, snippet) | ||
15 | + else | ||
16 | + snippet_path(snippet) | ||
17 | + end | ||
18 | + end | ||
11 | end | 19 | end |
app/views/layouts/_head_panel.html.haml
@@ -19,7 +19,7 @@ | @@ -19,7 +19,7 @@ | ||
19 | = link_to public_root_path, title: "Public area", class: 'has_bottom_tooltip', 'data-original-title' => 'Public area' do | 19 | = link_to public_root_path, title: "Public area", class: 'has_bottom_tooltip', 'data-original-title' => 'Public area' do |
20 | %i.icon-globe | 20 | %i.icon-globe |
21 | %li | 21 | %li |
22 | - = link_to snippets_path, title: "Snippets area", class: 'has_bottom_tooltip', 'data-original-title' => 'Public area' do | 22 | + = link_to user_snippets_path(current_user), title: "My snippets", class: 'has_bottom_tooltip', 'data-original-title' => 'Public area' do |
23 | %i.icon-paste | 23 | %i.icon-paste |
24 | - if current_user.is_admin? | 24 | - if current_user.is_admin? |
25 | %li | 25 | %li |
app/views/layouts/snippets.html.haml
@@ -7,15 +7,12 @@ | @@ -7,15 +7,12 @@ | ||
7 | %nav.main-nav | 7 | %nav.main-nav |
8 | .container | 8 | .container |
9 | %ul | 9 | %ul |
10 | - = nav_link(path: 'dashboard#show', html_options: {class: 'home'}) do | ||
11 | - = link_to root_path, title: "Back to dashboard" do | 10 | + = nav_link(path: 'snippets#user_index', html_options: {class: 'home'}) do |
11 | + = link_to user_snippets_path(current_user), title: "My Snippets" do | ||
12 | %i.icon-home | 12 | %i.icon-home |
13 | = nav_link(path: 'snippets#new') do | 13 | = nav_link(path: 'snippets#new') do |
14 | = link_to new_snippet_path do | 14 | = link_to new_snippet_path do |
15 | New snippet | 15 | New snippet |
16 | - = nav_link(path: 'snippets#user_index') do | ||
17 | - = link_to user_snippets_path(@current_user) do | ||
18 | - My snippets | ||
19 | = nav_link(path: 'snippets#index') do | 16 | = nav_link(path: 'snippets#index') do |
20 | = link_to snippets_path do | 17 | = link_to snippets_path do |
21 | Discover snippets | 18 | Discover snippets |
app/views/projects/snippets/_blob.html.haml
@@ -3,7 +3,10 @@ | @@ -3,7 +3,10 @@ | ||
3 | %i.icon-file | 3 | %i.icon-file |
4 | %strong= @snippet.file_name | 4 | %strong= @snippet.file_name |
5 | %span.options | 5 | %span.options |
6 | - = link_to "raw", raw_project_snippet_path(@project, @snippet), class: "btn btn-tiny", target: "_blank" | 6 | + .btn-group.tree-btn-group.pull-right |
7 | + - if can?(current_user, :admin_project_snippet, @project) || @snippet.author == current_user | ||
8 | + = link_to "Edit", edit_project_snippet_path(@project, @snippet), class: "btn btn-tiny", title: 'Edit Snippet' | ||
9 | + = link_to "raw", raw_project_snippet_path(@project, @snippet), class: "btn btn-tiny", target: "_blank" | ||
7 | .file_content.code | 10 | .file_content.code |
8 | - unless @snippet.content.empty? | 11 | - unless @snippet.content.empty? |
9 | %div{class: user_color_scheme_class} | 12 | %div{class: user_color_scheme_class} |
app/views/projects/snippets/_snippet.html.haml
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 | 1 | +%li |
2 | + .snippet-title | ||
3 | + - if snippet.private? | ||
4 | + %i.icon-lock.cgreen | ||
5 | + - else | ||
6 | + %i.icon-globe.cblue | ||
7 | + = link_to reliable_snippet_path(snippet) do | ||
8 | + %h5.inline | ||
9 | + = truncate(snippet.title, length: 60) | ||
9 | %span.cgray | 10 | %span.cgray |
10 | - - if snippet.expires_at | ||
11 | - = snippet.expires_at.to_date.to_s(:short) | ||
12 | - - else | ||
13 | - Never | 11 | + = snippet.file_name |
12 | + | ||
13 | + %small.pull-right.cgray | ||
14 | + Expires: | ||
15 | + - if snippet.expires_at | ||
16 | + = snippet.expires_at.to_date.to_s(:short) | ||
17 | + - else | ||
18 | + Never | ||
19 | + | ||
20 | + .snippet-info.prepend-left-20 | ||
21 | + = "##{snippet.id}" | ||
22 | + %span.light | ||
23 | + by | ||
24 | + = image_tag gravatar_icon(snippet.author_email), class: "avatar avatar-inline s16" | ||
25 | + = snippet.author_name |
app/views/projects/snippets/index.html.haml
@@ -5,15 +5,9 @@ | @@ -5,15 +5,9 @@ | ||
5 | - if can? current_user, :write_project_snippet, @project | 5 | - if can? current_user, :write_project_snippet, @project |
6 | = link_to new_project_snippet_path(@project), class: "btn btn-small add_new pull-right", title: "New Snippet" do | 6 | = link_to new_project_snippet_path(@project), class: "btn btn-small add_new pull-right", title: "New Snippet" do |
7 | Add new snippet | 7 | Add new snippet |
8 | -%br | ||
9 | -%table | ||
10 | - %thead | ||
11 | - %tr | ||
12 | - %th Title | ||
13 | - %th File Name | ||
14 | - %th Expires At | 8 | +%hr |
9 | +%ul.bordered-list | ||
15 | = render partial: "projects/snippets/snippet", collection: @snippets | 10 | = render partial: "projects/snippets/snippet", collection: @snippets |
16 | - if @snippets.empty? | 11 | - if @snippets.empty? |
17 | - %tr | ||
18 | - %td{colspan: 3} | ||
19 | - %h3.nothing_here_message Nothing here. | 12 | + %li |
13 | + %h3.nothing_here_message Nothing here. |
app/views/projects/snippets/show.html.haml
1 | %h3.page_title | 1 | %h3.page_title |
2 | + %i.icon-lock.cgreen | ||
2 | = @snippet.title | 3 | = @snippet.title |
3 | - %small= @snippet.file_name | ||
4 | - - if can?(current_user, :admin_project_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 | 4 | ||
5 | + %small.pull-right | ||
6 | + = "##{@snippet.id}" | ||
7 | + %span.light | ||
8 | + by | ||
9 | + = image_tag gravatar_icon(@snippet.author_email), class: "avatar avatar-inline s16" | ||
10 | + = @snippet.author_name | ||
7 | %br | 11 | %br |
8 | %div= render 'projects/snippets/blob' | 12 | %div= render 'projects/snippets/blob' |
9 | %div#notes= render "notes/notes_with_form" | 13 | %div#notes= render "notes/notes_with_form" |
app/views/snippets/_blob.html.haml
@@ -3,7 +3,10 @@ | @@ -3,7 +3,10 @@ | ||
3 | %i.icon-file | 3 | %i.icon-file |
4 | %strong= @snippet.file_name | 4 | %strong= @snippet.file_name |
5 | %span.options | 5 | %span.options |
6 | - = link_to "raw", raw_snippet_path(@snippet), class: "btn btn-tiny", target: "_blank" | 6 | + .btn-group.tree-btn-group.pull-right |
7 | + - if @snippet.author == current_user | ||
8 | + = link_to "Edit", edit_snippet_path(@snippet), class: "btn btn-tiny", title: 'Edit Snippet' | ||
9 | + = link_to "Raw", raw_snippet_path(@snippet), class: "btn btn-tiny", target: "_blank" | ||
7 | .file_content.code | 10 | .file_content.code |
8 | - unless @snippet.content.empty? | 11 | - unless @snippet.content.empty? |
9 | %div{class: user_color_scheme_class} | 12 | %div{class: user_color_scheme_class} |
app/views/snippets/_snippet.html.haml
1 | -%tr | ||
2 | - %td | 1 | +%li |
2 | + .snippet-title | ||
3 | - if snippet.private? | 3 | - if snippet.private? |
4 | - %i.icon-lock | 4 | + %i.icon-lock.cgreen |
5 | - else | 5 | - else |
6 | - %i.icon-globe | ||
7 | - = image_tag gravatar_icon(snippet.author_email), class: "avatar s24" | ||
8 | - - if snippet.project_id? | ||
9 | - %a{href: project_snippet_path(snippet.project, snippet)} | ||
10 | - %strong= truncate(snippet.title, length: 60) | ||
11 | - - else | ||
12 | - %a{href: snippet_path(snippet)} | ||
13 | - %strong= truncate(snippet.title, length: 60) | ||
14 | - %td | ||
15 | - = snippet.file_name | ||
16 | - %td | 6 | + %i.icon-globe.cblue |
7 | + = link_to reliable_snippet_path(snippet) do | ||
8 | + %h5.inline | ||
9 | + = truncate(snippet.title, length: 60) | ||
17 | %span.cgray | 10 | %span.cgray |
18 | - - if snippet.expires_at | ||
19 | - = snippet.expires_at.to_date.to_s(:short) | ||
20 | - - else | ||
21 | - Never | ||
22 | - %td | 11 | + = snippet.file_name |
12 | + | ||
13 | + %small.pull-right.cgray | ||
23 | - if snippet.project_id? | 14 | - if snippet.project_id? |
24 | - = link_to snippet.project.name, project_path(snippet.project) | 15 | + = 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 | + | ||
24 | + .snippet-info.prepend-left-20 | ||
25 | + = "##{snippet.id}" | ||
26 | + %span.light | ||
27 | + by | ||
28 | + = image_tag gravatar_icon(snippet.author_email), class: "avatar avatar-inline s16" | ||
29 | + = snippet.author_name | ||
30 | + |
app/views/snippets/_snippets.html.haml
1 | -%table | ||
2 | - %thead | ||
3 | - %tr | ||
4 | - %th Title | ||
5 | - %th File Name | ||
6 | - %th Expires At | ||
7 | - %th Project | ||
8 | - | 1 | +%ul.bordered-list |
9 | = render partial: 'snippet', collection: @snippets | 2 | = render partial: 'snippet', collection: @snippets |
10 | - if @snippets.empty? | 3 | - if @snippets.empty? |
11 | - %tr | ||
12 | - %td{colspan: 4} | ||
13 | - %h3.nothing_here_message Nothing here. | 4 | + %li |
5 | + %h3.nothing_here_message Nothing here. | ||
14 | 6 | ||
15 | = paginate @snippets | 7 | = paginate @snippets |
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +%h3.page_title | ||
2 | + My Snippets | ||
3 | + %small share code pastes with others out of git repository | ||
4 | + = link_to new_snippet_path, class: "btn btn-small add_new pull-right", title: "New Snippet" do | ||
5 | + Add new snippet | ||
6 | + | ||
7 | +%hr | ||
8 | + | ||
9 | +.row | ||
10 | + .span3 | ||
11 | + %ul.nav.nav-pills.nav-stacked | ||
12 | + = nav_tab :scope, nil do | ||
13 | + = link_to "All", user_snippets_path(@user) | ||
14 | + = nav_tab :scope, 'private' do | ||
15 | + = link_to "Private", user_snippets_path(@user, scope: 'private') | ||
16 | + = nav_tab :scope, 'public' do | ||
17 | + = link_to "Public", user_snippets_path(@user, scope: 'public') | ||
18 | + | ||
19 | + .span9 | ||
20 | + = render 'snippets' | ||
21 | + |
app/views/snippets/show.html.haml
1 | %h3.page_title | 1 | %h3.page_title |
2 | - if @snippet.private? | 2 | - if @snippet.private? |
3 | - %i.icon-lock | 3 | + %i.icon-lock.cgreen |
4 | - else | 4 | - else |
5 | - %i.icon-globe | 5 | + %i.icon-globe.cblue |
6 | 6 | ||
7 | = @snippet.title | 7 | = @snippet.title |
8 | - %small= @snippet.file_name | ||
9 | - - if @snippet.author == current_user | ||
10 | - = link_to "Edit", edit_snippet_path(@snippet), class: "btn btn-small pull-right", title: 'Edit Snippet' | ||
11 | 8 | ||
9 | + %small.pull-right | ||
10 | + = "##{@snippet.id}" | ||
11 | + %span.light | ||
12 | + by | ||
13 | + = image_tag gravatar_icon(@snippet.author_email), class: "avatar avatar-inline s16" | ||
14 | + = @snippet.author_name | ||
12 | %br | 15 | %br |
13 | %div= render 'blob' | 16 | %div= render 'blob' |
app/views/snippets/user_index.html.haml
1 | %h3.page_title | 1 | %h3.page_title |
2 | - Snippets by | 2 | + = image_tag gravatar_icon(@user.email), class: "avatar s24" |
3 | = @user.name | 3 | = @user.name |
4 | + %span | ||
5 | + \/ | ||
6 | + Snippets | ||
4 | %small share code pastes with others out of git repository | 7 | %small share code pastes with others out of git repository |
5 | = link_to new_snippet_path, class: "btn btn-small add_new pull-right", title: "New Snippet" do | 8 | = link_to new_snippet_path, class: "btn btn-small add_new pull-right", title: "New Snippet" do |
6 | Add new snippet | 9 | Add new snippet |
7 | 10 | ||
8 | %hr | 11 | %hr |
9 | -.row | ||
10 | - .span3 | ||
11 | - %ul.nav.nav-pills.nav-stacked | ||
12 | - = nav_tab :scope, nil do | ||
13 | - = link_to "All", user_snippets_path(@user) | ||
14 | - = nav_tab :scope, 'private' do | ||
15 | - = link_to "Private", user_snippets_path(@user, scope: 'private') | ||
16 | - = nav_tab :scope, 'public' do | ||
17 | - = link_to "Public", user_snippets_path(@user, scope: 'public') | ||
18 | 12 | ||
19 | - .span9 | ||
20 | - = render 'snippets' | 13 | += render 'snippets' |