Permalink
Browse files

Box model with new responsive layout

Now using the box model for layouts, thanks to infews.  Responsive layout should work on all devices.
Added compass for box model mixins
Adding debugger gem, bundling without development on travis as requested in the travis docs
  • Loading branch information...
1 parent 73fbf92 commit b909544fe7243e46c13a8272ab5889c036f86471 @mkocher committed Jun 3, 2012
View
@@ -5,3 +5,4 @@ before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
script: "bundle exec rake db:create db:migrate db:test:prepare default"
+bundler_args: --without development
View
11 Gemfile
@@ -14,17 +14,20 @@ group :test, :development do
gem 'capybara'
gem 'capybara-webkit'
gem 'launchy'
- gem 'heroku'
gem 'sqlite3'
gem 'database_cleaner'
end
+group :development do
+ gem 'debugger'
+ gem 'heroku'
+end
+
group :assets do
+ gem 'compass-rails'
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
gem 'bootstrap-sass'
gem 'font-awesome-sass-rails'
-end
-
-
+end
View
@@ -44,14 +44,29 @@ GEM
json
childprocess (0.3.2)
ffi (~> 1.0.6)
+ chunky_png (1.2.5)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.3.3)
+ columnize (0.3.6)
+ compass (0.12.1)
+ chunky_png (~> 1.2)
+ fssm (>= 0.2.7)
+ sass (~> 3.1)
+ compass-rails (1.0.2)
+ compass (>= 0.12.0, < 0.14)
database_cleaner (0.7.2)
+ debugger (1.1.3)
+ columnize (>= 0.3.1)
+ debugger-linecache (~> 1.1.1)
+ debugger-ruby_core_source (~> 1.1.2)
+ debugger-linecache (1.1.1)
+ debugger-ruby_core_source (>= 1.1.1)
+ debugger-ruby_core_source (1.1.3)
diff-lcs (1.1.3)
erubis (2.7.0)
excon (0.13.4)
@@ -66,6 +81,7 @@ GEM
font-awesome-sass-rails (0.2.0)
railties (>= 3.1.1)
sass-rails (>= 3.1.1)
+ fssm (0.2.9)
hashie (1.2.0)
heroku (2.26.2)
heroku-api (~> 0.2.1)
@@ -197,7 +213,9 @@ DEPENDENCIES
capybara
capybara-webkit
coffee-rails (~> 3.2.1)
+ compass-rails
database_cleaner
+ debugger
factory_girl_rails
font-awesome-sass-rails
heroku
@@ -15,10 +15,59 @@
@import "bootstrap";
@import "bootstrap-responsive";
@import 'font-awesome';
+@import "compass/css3/box";
-body { padding: 60px 0 60px 0; }
+@media (min-width: 979px) {
+ body {
+ padding: 60px 0 60px 0;
+ }
+}
+
+html, body {
+ height: 100%;
+}
+
+a:hover {
+ text-decoration: none;
+}
ul.large-font li {
line-height: 32px;
font-size: 24px;
-}
+}
+
+.outer {
+ height: 100%;
+ @include display-box;
+ @include box-orient(horizontal);
+ @include box-pack(top);
+ @include box-align(top);
+
+ @media (max-width: 979px) {
+ @include box-orient(vertical);
+ }
+}
+
+.two-wide {
+ @include display-box;
+ @include box-orient(horizontal);
+ @include box-pack(top);
+ @include box-align(top);
+ @include box-flex(1);
+ width: 100%;
+
+ @media (max-width: 480px) {
+ @include box-orient(vertical);
+ }
+}
+
+.kind {
+ width: 100%;
+ height: 100%;
+ margin: 0 10px;
+
+ @include display-box;
+ @include box-orient(vertical);
+ @include box-pack(top);
+ @include box-flex(1);
+}
@@ -11,11 +11,7 @@ def create
def new
@post = Post.find_by_id(params[:post_id])
@item = Item.new(params[:item])
- if params[:kind]
- render "items/new_#{params[:kind]}"
- else
- render "items/new"
- end
+ render_custom_item_template @item
end
def index
@@ -31,7 +27,7 @@ def destroy
def edit
@item = Item.find(params[:id])
- render 'items/new'
+ render_custom_item_template @item
end
def update
@@ -40,7 +36,17 @@ def update
if @item.save
redirect_to @item.post ? edit_post_path(@item.post) : '/'
else
- render 'items/new'
+ render_custom_item_template @item
+ end
+ end
+
+ private
+
+ def render_custom_item_template(item)
+ if item.possible_template_name && template_exists?(item.possible_template_name)
+ render item.possible_template_name
+ else
+ render "items/new"
end
end
end
@@ -2,4 +2,8 @@ module ApplicationHelper
def wordpress_enabled?
!!(ENV['WORDPRESS_USER'] && ENV['WORDPRESS_PASSWORD'] && ENV['WORDPRESS_BLOG'])
end
+
+ def dynamic_new_item_path(opts={})
+ @post ? new_post_item_path(@post, opts) : new_item_path(opts)
+ end
end
View
@@ -1,5 +1,5 @@
class Item < ActiveRecord::Base
- KINDS = ['New face', 'Help', 'Interesting']
+ KINDS = ['New face', 'Help', 'Interesting', 'Event']
belongs_to :post
@@ -15,4 +15,8 @@ def self.public
def self.orphans
where(post_id: nil).order("created_at ASC").group_by(&:kind)
end
+
+ def possible_template_name
+ kind && "items/new_#{kind.downcase.gsub(" ", '_')}"
+ end
end
@@ -1,23 +1,29 @@
-<div class='row'>
- <% Item::KINDS.each do |kind| %>
- <div class='span4'>
- <h1><%= kind.pluralize %></h1>
- <hr>
- <% if items[kind].present? %>
- <ul class='large-font'>
- <% items[kind].each do |item| %>
- <li>
- <%= item.title %>
- <%= link_to edit_item_path(item) do %>
- <i class="icon-pencil"></i>
- <% end %>
- <%= link_to item, confirm: 'Are you sure?',
- method: :delete do %>
- <i class='icon-trash'></i>
- <% end %>
- </li>
+<div class='outer'>
+ <% Item::KINDS.each_slice(2) do |pair_of_kinds| %>
+ <div class='two-wide'>
+ <% pair_of_kinds.each do |kind| %>
+ <div class='kind'>
+ <h2><%= kind.pluralize %> <%= link_to dynamic_new_item_path('item[kind]' => kind), 'data-kind' => kind do %>
+ <i class="icon-plus"></i></h2>
+ <% end %>
+ <hr>
+ <% if items[kind].present? %>
+ <ul class='large-font'>
+ <% items[kind].each do |item| %>
+ <li>
+ <%= item.title %>
+ <%= link_to edit_item_path(item) do %>
+ <i class="icon-pencil"></i>
+ <% end %>
+ <%= link_to item, confirm: 'Are you sure?',
+ method: :delete do %>
+ <i class='icon-trash'></i>
+ <% end %>
+ </li>
+ <% end %>
+ </ul>
<% end %>
- </ul>
+ </div>
<% end %>
</div>
<% end %>
@@ -1,12 +1,6 @@
<%= render partial: 'as_html', locals: { items: @items } %>
-<div class='row'>
- <div class='span4'><%= link_to "Add New Face", new_item_path(kind: 'face'), class: 'btn' %></div>
- <div class='span4'><%= link_to "Add Help", new_item_path('item[kind]' => 'Help'), class: 'btn' %></div>
- <div class='span4'><%= link_to "Add Interesting", new_item_path('item[kind]' => 'Interesting'), class: 'btn' %></div>
-</div>
-
<div class="navbar navbar-fixed-bottom">
<div class="navbar-inner">
<div class="container">
@@ -22,16 +22,14 @@
</div>
-<div class='container-fluid'>
- <% if flash[:error] %>
- <p class="alert alert-error"><%= flash[:error] %></p>
- <% end %>
- <% if flash[:notice] %>
- <p class="alert alert-success"><%= flash[:notice] %></p>
- <% end %>
+<% if flash[:error] %>
+ <p class="alert alert-error"><%= flash[:error] %></p>
+<% end %>
+<% if flash[:notice] %>
+ <p class="alert alert-success"><%= flash[:notice] %></p>
+<% end %>
- <%= yield %>
-</div>
+<%= yield %>
</body>
</html>
@@ -2,7 +2,7 @@
<div class='row'>
<div class='span4'><%= link_to "Add New Face", new_post_item_path(@post, kind: 'face'), class: 'btn' %></div>
- <div class='span4'><%= link_to "Add Help", new_post_item_path(@post, 'item[kind]' => 'Help'), class: 'btn' %></div>
+ <div class='span4'><%= link_to "Add Help", dynamic_new_item_path('item[kind]' => 'Help'), class: 'btn' %></div>
<div class='span4'><%= link_to "Add Interesting", new_post_item_path(@post, 'item[kind]' => 'Interesting'), class: 'btn' %></div>
</div>
@@ -35,12 +35,13 @@
it "should create a new Item object" do
get :new
assigns[:item].should be_new_record
+ response.should render_template('items/new')
response.should be_ok
end
- it "should render a new face form if requested" do
- get :new, kind: 'face'
- response.should render_template('items/new_face')
+ it "should render the custom template for the kind if there is one" do
+ get :new, item: { kind: 'New face' }
+ response.should render_template('items/new_new_face')
end
it "uses the params to create the new item so you can set defaults in the link" do
@@ -116,6 +117,12 @@
assigns[:item].should == item
response.should render_template 'items/new'
end
+
+ it "should render the custom template for the kind if there is one" do
+ item = create(:item, kind: 'New face')
+ get :edit, id: item.id
+ response.should render_template('items/new_new_face')
+ end
end
describe "#update" do
@@ -132,5 +139,19 @@
item.reload.title.should == "New Title"
response.should redirect_to(edit_post_path(item.post))
end
+
+ describe "when the item is invalid" do
+ it "should render new" do
+ item = create(:item)
+ put :update, id: item.id, post_id: item.post, item: { title: "" }
+ response.should render_template('items/new')
+ end
+
+ it "should render a custom template if there is one" do
+ item = create(:item, kind: 'New face')
+ put :update, id: item.id, post_id: item.post, item: { title: "" }
+ response.should render_template('items/new_new_face')
+ end
+ end
end
end
@@ -5,11 +5,11 @@
mock_omniauth
visit '/auth/google_apps/callback'
visit '/'
- click_link 'Add New Face'
+ find('a[data-kind="New face"] i').click
fill_in 'item_title', :with => "Johnathon McKenzie"
click_button 'Create New Face'
- click_link 'Add Help'
+ find('a[data-kind=Help] i').click
fill_in 'item_title', :with => "IE8 doesn't work"
fill_in 'item_description', :with => "No, srsly. It doesn't work"
click_button 'Create Item'

0 comments on commit b909544

Please sign in to comment.