Skip to content

Commit

Permalink
Add jQuery Masonry
Browse files Browse the repository at this point in the history
  • Loading branch information
rmi22186 committed Sep 16, 2013
1 parent d017447 commit 1350def
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 34 deletions.
3 changes: 2 additions & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
//
//= require jquery
//= require jquery_ujs
//= require jquery.masonry.min.js
//= require bootstrap
//= require_tree .
//= require_tree .
4 changes: 4 additions & 0 deletions app/assets/javascripts/pins.js.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/

jQuery ->
$('#pins').imagesLoaded ->
$('#pins').masonry itemSelector: ".box"
28 changes: 28 additions & 0 deletions app/assets/stylesheets/styles.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,32 @@ body {
a {
color: $gray;
}
}

/* required for jQuer Masonry */

.box {
margin: 5px;
padding: 5px;
font-size: 11px;
line-height: 1.4em;
float: left;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
box-shadow: 1px 1px 10px #444;
width: 214px;
}

.box img {
display:block;
width: 100%;
-webkit-border-radius: 5px;
moz-border-radius: 5px;
border-radius: 5px;
box-shadow: 1px, 1px, 10px, #444;
}

.description {
margin: 10px 0 5px;
}
2 changes: 1 addition & 1 deletion app/controllers/pins_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class PinsController < ApplicationController
# GET /pins
# GET /pins.json
def index
@pins = Pin.all
@pins = Pin.order("created_at desc")

respond_to do |format|
format.html # index.html.erb
Expand Down
2 changes: 1 addition & 1 deletion app/models/pin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class Pin < ActiveRecord::Base
size: { less_than: 5.megabytes }

belongs_to :user

has_attached_file :image, styles: { medium: "320x240>"}

end
1 change: 1 addition & 0 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

<ul class="nav pull-right">
<% if user_signed_in? %>
<li><%= link_to "Add +", new_pin_path %></li>
<li><%= link_to "Edit Profile", edit_user_registration_path %></li>
<li><%= link_to "Logout", destroy_user_session_path, method: :delete %></li>
<% else %>
Expand Down
26 changes: 16 additions & 10 deletions app/views/pins/_pin.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<tr>
<td><%= image_tag pin.image(:medium) %></td>
<td><%= pin.description %></td>
<td><%= link_to 'Show', pin %></td>
<% if current_user == pin.user %>
<td><%= link_to 'Edit', edit_pin_path(pin) %></td>
<td><%= link_to 'Destroy', pin, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<% end %>

</tr>
<div class="box">

<%= link_to (image_tag pin.image(:medium)), pin %>
<p class="description">
<%= pin.description %>
</p>
<strong>
Posted by <%= pin.user.name%>
</strong>
<p>
<% if current_user == pin.user %>
<%= link_to 'Edit', edit_pin_path(pin) %>
<%= link_to 'Destroy', pin, method: :delete, data: { confirm: 'Are you sure?' } %>
</p>
<% end %>
</div>
24 changes: 3 additions & 21 deletions app/views/pins/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
<h1>Listing pins</h1>

<table class="table table-striped">
<thead>
<tr>
<th>Image</th>
<th>Description</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>

<tbody>
<%= render @pins %>
</tbody>
</table>

<br />

<%= link_to 'New Pin', new_pin_path %>
<div id="pins">
<%= render @pins %>
</div>
10 changes: 10 additions & 0 deletions vendor/assets/javascripts/jquery.masonry.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions vendor/assets/javascripts/masonry.pkgd.min.js

Large diffs are not rendered by default.

0 comments on commit 1350def

Please sign in to comment.