Commit 0712e78597e5954ea61def4c0a6836a3d5b5d275
1 parent
ca4e2ad1
Exists in
master
and in
4 other branches
Snippet restyle
Showing
4 changed files
with
67 additions
and
57 deletions
Show diff stats
app/models/snippet.rb
| @@ -28,6 +28,7 @@ class Snippet < ActiveRecord::Base | @@ -28,6 +28,7 @@ class Snippet < ActiveRecord::Base | ||
| 28 | 28 | ||
| 29 | scope :fresh, order("created_at DESC") | 29 | scope :fresh, order("created_at DESC") |
| 30 | scope :non_expired, where(["expires_at IS NULL OR expires_at > ?", Time.current]) | 30 | scope :non_expired, where(["expires_at IS NULL OR expires_at > ?", Time.current]) |
| 31 | + scope :expired, where(["expires_at IS NOT NULL AND expires_at < ?", Time.current]) | ||
| 31 | 32 | ||
| 32 | def self.content_types | 33 | def self.content_types |
| 33 | [ | 34 | [ |
app/views/snippets/_form.html.haml
| 1 | -%div | ||
| 2 | - .ui-box.width-100p | ||
| 3 | - %h3 | ||
| 4 | - = @snippet.new_record? ? "New snippet" : "Edit snippet ##{@snippet.id}" | ||
| 5 | - = form_for [@project, @snippet] do |f| | ||
| 6 | - .data.no-padding | ||
| 7 | - %table.no-borders | ||
| 8 | - -if @snippet.errors.any? | ||
| 9 | - %tr | ||
| 10 | - %td Errors | ||
| 11 | - %td | ||
| 12 | - #error_explanation | ||
| 13 | - - @snippet.errors.full_messages.each do |msg| | ||
| 14 | - %span= msg | ||
| 15 | - %br | 1 | += form_for [@project, @snippet] do |f| |
| 2 | + %div | ||
| 3 | + %span.entity-info | ||
| 4 | + - if @snippet.new_record? | ||
| 5 | + = link_to project_snippets_path(@project) do | ||
| 6 | + .entity-button | ||
| 7 | + Back | ||
| 8 | + %i | ||
| 9 | + - else | ||
| 10 | + = link_to project_snippet_path(@project, @snippet) do | ||
| 11 | + .entity-button | ||
| 12 | + Back | ||
| 13 | + %i | ||
| 14 | + %h2= @snippet.new_record? ? "New Snippet" : "Edit Snippet ##{@snippet.id}" | ||
| 16 | 15 | ||
| 17 | - %tr | ||
| 18 | - %td= f.label :title | ||
| 19 | - %td= f.text_field :title, :placeholder => "Example Snippet" | ||
| 20 | - %tr | ||
| 21 | - %td= f.label :file_name | ||
| 22 | - %td= f.text_field :file_name, :placeholder => "example.rb" | ||
| 23 | - %tr | ||
| 24 | - %td= f.label "Lifetime" | ||
| 25 | - %td= f.select :expires_at, lifetime_select_options | ||
| 26 | - %tr | ||
| 27 | - %td{:colspan => 2} | ||
| 28 | - = f.label :content, "Code" | 16 | + %hr |
| 17 | + %table.no-borders | ||
| 18 | + -if @snippet.errors.any? | ||
| 19 | + %tr | ||
| 20 | + %td{:colspan => 2} | ||
| 21 | + #error_explanation | ||
| 22 | + - @snippet.errors.full_messages.each do |msg| | ||
| 23 | + %span= msg | ||
| 29 | %br | 24 | %br |
| 30 | - %br | ||
| 31 | - = f.text_area :content | ||
| 32 | 25 | ||
| 33 | - .buttons | ||
| 34 | - = f.submit 'Save', :class => "grey-button" | ||
| 35 | - - if can?(current_user, :admin_snippet, @project) || @snippet.author == current_user | ||
| 36 | - .right= link_to 'Destroy', [@project, @snippet], :confirm => 'Are you sure?', :method => :delete, :class => "grey-button delete-snippet negative", :id => "destroy_snippet_#{@snippet.id}" | 26 | + %tr |
| 27 | + %td= f.label :title | ||
| 28 | + %td= f.text_field :title, :placeholder => "Example Snippet" | ||
| 29 | + %tr | ||
| 30 | + %td= f.label :file_name | ||
| 31 | + %td= f.text_field :file_name, :placeholder => "example.rb" | ||
| 32 | + %tr | ||
| 33 | + %td= f.label "Lifetime" | ||
| 34 | + %td= f.select :expires_at, lifetime_select_options, {}, :style => "width:200px;" | ||
| 35 | + %tr | ||
| 36 | + %td{:colspan => 2} | ||
| 37 | + = f.label :content, "Code" | ||
| 38 | + %br | ||
| 39 | + %br | ||
| 40 | + = f.text_area :content | ||
| 41 | + | ||
| 42 | + .merge-tabs | ||
| 43 | + = f.submit 'Save', :class => "grey-button" | ||
| 44 | + - unless @snippet.new_record? | ||
| 45 | + .right= link_to 'Destroy', [@project, @snippet], :confirm => 'Are you sure?', :method => :delete, :class => "red-button delete-snippet", :id => "destroy_snippet_#{@snippet.id}" | ||
| 46 | + | ||
| 47 | + | ||
| 48 | + | ||
| 49 | +:javascript | ||
| 50 | + $(function(){ | ||
| 51 | + $('select#snippet_expires_at').chosen(); | ||
| 52 | + }); | ||
| 53 | + |
app/views/snippets/_snippet.html.haml
| 1 | -- unless snippet.expired? | ||
| 2 | - %tr{ :id => dom_id(snippet), :class => "snippet", :url => project_snippet_path(@project, snippet) } | ||
| 3 | - %td | ||
| 4 | - = image_tag gravatar_icon(snippet.author.email), :class => "left", :width => 40, :style => "padding:0 5px;" | ||
| 5 | - %span | ||
| 6 | - %strong= html_escape snippet.title | ||
| 7 | - %br | ||
| 8 | - %br | ||
| 9 | - %div.author | ||
| 10 | - %strong= truncate snippet.author.name, :lenght => 20 | ||
| 11 | - %cite.cgray | ||
| 12 | - = time_ago_in_words(snippet.updated_at) | ||
| 13 | - ago | ||
| 14 | - .right.action-links | ||
| 15 | - - if can?(current_user, :admin_snippet, @project) || snippet.author == current_user | ||
| 16 | - = link_to 'Edit', edit_project_snippet_path(@project, snippet), :class => "cgray" | ||
| 17 | - - if can?(current_user, :admin_snippet, @project) || snippet.author == current_user | ||
| 18 | - = link_to 'Destroy', [@project, snippet], :confirm => 'Are you sure?', :method => :delete, :remote => true, :class => "cred delete-snippet negative", :id => "destroy_snippet_#{snippet.id}" | 1 | +%a.update-item{:href => project_snippet_path(snippet.project, snippet)} |
| 2 | + = image_tag gravatar_icon(snippet.author_email), :class => "left", :width => 40 | ||
| 3 | + %span.update-title | ||
| 4 | + = truncate(snippet.title, :length => 60) | ||
| 5 | + %span.update-author | ||
| 6 | + %strong= snippet.author_name | ||
| 7 | + authored | ||
| 8 | + = time_ago_in_words(snippet.created_at) | ||
| 9 | + ago | ||
| 10 | + .right | ||
| 11 | + %span.tag.commit= snippet.file_name | ||
| 12 | + |
app/views/snippets/index.html.haml
| @@ -4,9 +4,7 @@ | @@ -4,9 +4,7 @@ | ||
| 4 | - if can? current_user, :write_snippet, @project | 4 | - if can? current_user, :write_snippet, @project |
| 5 | .right= link_to 'New Snippet', new_project_snippet_path(@project), :class => "grey-button append-bottom-10" | 5 | .right= link_to 'New Snippet', new_project_snippet_path(@project), :class => "grey-button append-bottom-10" |
| 6 | 6 | ||
| 7 | -%table#snippets-table | ||
| 8 | - = render @snippets.fresh | ||
| 9 | - | ||
| 10 | -:javascript | ||
| 11 | - $('.delete-snippet').live('ajax:success', function() { | ||
| 12 | - $(this).closest('tr').fadeOut(); }); | 7 | +- unless @snippets.fresh.empty? |
| 8 | + %div{ :class => "update-data ui-box ui-box-small ui-box-big" } | ||
| 9 | + .data | ||
| 10 | + = render @snippets.fresh |