From 25e11427953eb8e9c30268ca150cebf58b5c1a24 Mon Sep 17 00:00:00 2001 From: Adam MacLeod Date: Thu, 4 Oct 2012 16:57:50 +1000 Subject: [PATCH] Introduced bootstrap. Fixed a bunch of styling issues and a few controller problems. --- Gemfile | 1 + Gemfile.lock | 9 +++ app/assets/stylesheets/application.css | 7 +++ app/assets/stylesheets/scaffolds.css.scss | 1 + app/controllers/links_controller.rb | 12 ++-- app/controllers/users_controller.rb | 2 +- app/views/comments/_comment.html.erb | 13 +++-- app/views/comments/_comments.html.erb | 9 --- app/views/comments/_form.html.erb | 1 - app/views/comments/index.html.erb | 9 ++- app/views/layouts/application.html.erb | 70 +++++++++++++++++------ app/views/links/_form.html.erb | 8 +-- app/views/links/_link.html.erb | 20 ++++--- app/views/links/_links.html.erb | 13 ----- app/views/links/edit.html.erb | 5 +- app/views/links/index.html.erb | 2 - app/views/links/new.html.erb | 2 +- app/views/links/show.html.erb | 30 ---------- app/views/logins/new.html.erb | 6 +- app/views/logins/show.html.erb | 2 +- app/views/users/_form.html.erb | 6 +- app/views/users/edit.html.erb | 2 +- app/views/users/login.html.erb | 2 - app/views/users/new.html.erb | 2 +- app/views/users/show.html.erb | 10 ++-- config/environments/production.rb | 7 +++ config/routes.rb | 4 ++ 27 files changed, 134 insertions(+), 121 deletions(-) delete mode 100644 app/views/links/show.html.erb delete mode 100644 app/views/users/login.html.erb diff --git a/Gemfile b/Gemfile index 334cd73..3dd4c5f 100644 --- a/Gemfile +++ b/Gemfile @@ -18,6 +18,7 @@ group :assets do gem 'therubyracer', :platforms => :ruby gem 'uglifier', '>= 1.0.3' + gem 'less-rails-bootstrap' end gem 'jquery-rails' diff --git a/Gemfile.lock b/Gemfile.lock index 11d4abd..91861be 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -38,6 +38,7 @@ GEM coffee-script-source execjs coffee-script-source (1.3.3) + commonjs (0.2.6) erubis (2.7.0) execjs (1.4.0) multi_json (~> 1.0) @@ -48,6 +49,13 @@ GEM railties (>= 3.1.0, < 5.0) thor (~> 0.14) json (1.7.5) + less (2.2.2) + commonjs (~> 0.2.6) + less-rails (2.2.3) + actionpack (>= 3.1) + less (~> 2.2.0) + less-rails-bootstrap (2.1.1) + less-rails (~> 2.2.0) libv8 (3.3.10.4) mail (2.4.4) i18n (>= 0.4.0) @@ -110,6 +118,7 @@ DEPENDENCIES bcrypt-ruby (~> 3.0.0) coffee-rails (~> 3.2.1) jquery-rails + less-rails-bootstrap rails (= 3.2.8) sass-rails (~> 3.2.3) sqlite3 diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 3192ec8..19d553b 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -10,4 +10,11 @@ * *= require_self *= require_tree . + *= require twitter/bootstrap */ +.links { + margin-bottom: 1.2em; +} +.link_header { + margin-bottom: 0px; +} diff --git a/app/assets/stylesheets/scaffolds.css.scss b/app/assets/stylesheets/scaffolds.css.scss index 6ec6a8f..9ba36bd 100644 --- a/app/assets/stylesheets/scaffolds.css.scss +++ b/app/assets/stylesheets/scaffolds.css.scss @@ -4,6 +4,7 @@ body { font-family: verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 18px; + padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */ } p, ol, ul, td { diff --git a/app/controllers/links_controller.rb b/app/controllers/links_controller.rb index d211479..e3fb8af 100644 --- a/app/controllers/links_controller.rb +++ b/app/controllers/links_controller.rb @@ -18,7 +18,7 @@ def show @link = Link.find_by_slug(params[:id]) respond_to do |format| - format.html # show.html.erb + format.html { redirect_to @link.link } format.json { render json: @link } end end @@ -38,7 +38,7 @@ def new def edit @link = Link.find_by_slug(params[:id]) unless @link.user == @current_user - redirect_to @link + redirect_to link_comments_url(@link) end end @@ -50,8 +50,8 @@ def create respond_to do |format| if @link.save - format.html { redirect_to @link, notice: 'Link was successfully created.' } - format.json { render json: @link, status: :created, location: @link } + format.html { redirect_to link_comments_url(@link), notice: 'Link was successfully created.' } + format.json { render json: link_comments_url(@link), status: :created, location: link_comments_url(@link) } else format.html { render action: "new" } format.json { render json: @link.errors, status: :unprocessable_entity } @@ -70,7 +70,7 @@ def update format.html { render action: "show" } format.json { head :no_content } elsif @link.update_attributes(params[:link]) - format.html { redirect_to @link, notice: 'Link was successfully updated.' } + format.html { redirect_to link_comments_url(@link), notice: 'Link was successfully updated.' } format.json { head :no_content } else format.html { render action: "edit" } @@ -86,7 +86,7 @@ def destroy @link.destroy respond_to do |format| - format.html { redirect_to links_url } + format.html { redirect_to root_url, notice: 'BLAM! Link was thoroughly destroyed!' } format.json { head :no_content } end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 5ab0a1f..e8fa693 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,5 +1,5 @@ class UsersController < ApplicationController - skip_before_filter :require_login, :only => [:new, :create] + skip_before_filter :require_login, :only => [:new, :show, :create] # GET /users # GET /users.json diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index b9bedeb..b049516 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -1,5 +1,8 @@ - - <%= comment.body %> - <%= link_to comment.user.username, comment.user %> - <%= link_to comment.link.title, link_comments_path(comment.link) %> - +
+ <%= link_to comment.user.username, comment.user %> +

+ <%= comment.body %>
+ <%= link_to 'parent', link_comments_path(comment.link) %> +

+ +
diff --git a/app/views/comments/_comments.html.erb b/app/views/comments/_comments.html.erb index 2929cf2..a0aeb2b 100644 --- a/app/views/comments/_comments.html.erb +++ b/app/views/comments/_comments.html.erb @@ -1,10 +1 @@ - - - - - - - <%= render comments %> - -
CommentUserParent
diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb index a343fae..0fae674 100644 --- a/app/views/comments/_form.html.erb +++ b/app/views/comments/_form.html.erb @@ -1,6 +1,5 @@ <%= form_for([@link, @link.comments.build]) do |f| %>
- <%= f.label :body %>
<%= f.text_area :body %>
diff --git a/app/views/comments/index.html.erb b/app/views/comments/index.html.erb index b62bf48..8b97b22 100644 --- a/app/views/comments/index.html.erb +++ b/app/views/comments/index.html.erb @@ -1,7 +1,12 @@ <%= render :partial => 'links/links', :locals => { :links => [@link] } %> -

Comments

+

<%= @link.body %>

+ +

Comments

<%= render :partial => 'comments', :locals => { :comments => @link.comments } %> -<%= render 'form' %> +<% if @current_user %> +
+ <%= render 'form' %> +<% end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 60ced0c..61db342 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,31 +7,63 @@ <%= csrf_meta_tags %> + -

<%= link_to 'Circled', root_path %>

-
+
+
+
+ <% if flash[:notice] %> +

<%= flash[:notice] %>

+ <% end %> + <% if flash[:error] %> +

<%= flash[:error] %>

+ <% end %> +
+
-<% if @current_user %> -

Welcome, <%= link_to @current_user.username, users_path %>

- <%= form_tag(logins_path, :method => "delete") do %> -
- <%= submit_tag("Log Out") %> + +
+
+ <%= yield %> +
- <% end %> -<% else %> -

<%= link_to 'Log In', logins_path %> | <%= link_to 'Register', new_user_path %>

-<% end %> -
+
+ +
+

© Nobody 2012

+
-<% if flash[:notice] %> -

<%= flash[:notice] %>

-<% end %> -<% if flash[:error] %> -

<%= flash[:error] %>

-<% end %> +
-<%= yield %> diff --git a/app/views/links/_form.html.erb b/app/views/links/_form.html.erb index 56c08d6..3fd3a11 100644 --- a/app/views/links/_form.html.erb +++ b/app/views/links/_form.html.erb @@ -12,19 +12,19 @@ <% end %>
- <%= f.label :title %>
+ <%= f.label :title %> <%= f.text_field :title %>
- <%= f.label :link %>
+ <%= f.label :link %> <%= f.text_field :link %>
- <%= f.label :body %>
+ <%= f.label :body %> <%= f.text_area :body %>
- <%= f.label :slug %>
+ <%= f.label :slug %> <%= @link.slug %>
diff --git a/app/views/links/_link.html.erb b/app/views/links/_link.html.erb index 0983188..841dd41 100644 --- a/app/views/links/_link.html.erb +++ b/app/views/links/_link.html.erb @@ -1,9 +1,11 @@ - "> - <%= link.title %> - <%= link.body %> - <%= link.link %> - <%= link.user.username %> - <%= link_to 'Comments', link_comments_path(link) %> - <%= link_to 'Edit', edit_link_path(link) %> - <%= link_to 'Destroy', link, method: :delete, data: { confirm: 'Are you sure?' } %> - + diff --git a/app/views/links/_links.html.erb b/app/views/links/_links.html.erb index 6764d52..8230bc5 100644 --- a/app/views/links/_links.html.erb +++ b/app/views/links/_links.html.erb @@ -1,14 +1 @@ - - - - - - - - - - - <%= render links %> - -
TitleBodyLinkUser
diff --git a/app/views/links/edit.html.erb b/app/views/links/edit.html.erb index 158de1c..caa25bd 100644 --- a/app/views/links/edit.html.erb +++ b/app/views/links/edit.html.erb @@ -1,6 +1,5 @@ -

Editing link

+

Editing link

<%= render 'form' %> -<%= link_to 'Show', @link %> | -<%= link_to 'Back', links_path %> +<%= link_to 'Cancel', link_comments_path(@link) %> diff --git a/app/views/links/index.html.erb b/app/views/links/index.html.erb index beae492..0bfcbb5 100644 --- a/app/views/links/index.html.erb +++ b/app/views/links/index.html.erb @@ -1,5 +1,3 @@ -

Listing links

- <%= render :partial => 'links', :locals => { :links => @links } %>
diff --git a/app/views/links/new.html.erb b/app/views/links/new.html.erb index 64c66bf..4d363f1 100644 --- a/app/views/links/new.html.erb +++ b/app/views/links/new.html.erb @@ -1,4 +1,4 @@ -

New link

+

New Link

<%= render 'form' %> diff --git a/app/views/links/show.html.erb b/app/views/links/show.html.erb deleted file mode 100644 index a889352..0000000 --- a/app/views/links/show.html.erb +++ /dev/null @@ -1,30 +0,0 @@ -

- Title: - <%= @link.title %> -

- -

- Body: - <%= @link.body %> -

- -

- Link: - <%= @link.link %> -

- -

- User: - <%= @link.user.username %> -

- -

- Slug: - <%= @link.slug %> -

- - -<% if @link.user == @current_user %> - <%= link_to 'Edit', edit_link_path(@link) %> | -<% end %> -<%= link_to 'Back', links_path %> diff --git a/app/views/logins/new.html.erb b/app/views/logins/new.html.erb index 933124d..b5ba87d 100644 --- a/app/views/logins/new.html.erb +++ b/app/views/logins/new.html.erb @@ -1,12 +1,12 @@ -

Login

+

Login

<%= form_tag(logins_path) do %>
- <%= label_tag(:username, "Username:") %> + <%= label_tag(:username, "Username") %> <%= text_field_tag(:username) %>
- <%= label_tag(:password, "Password:") %> + <%= label_tag(:password, "Password") %> <%= password_field_tag(:password) %>
diff --git a/app/views/logins/show.html.erb b/app/views/logins/show.html.erb index 9698b21..e03db91 100644 --- a/app/views/logins/show.html.erb +++ b/app/views/logins/show.html.erb @@ -1,5 +1,5 @@ -

Welcome, <%= @current_user.username %>!

+

Welcome, <%= @current_user.username %>!

We are attempting to redirect you to the home page. Please keep your hands inside the cart at all times.

diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb index e882e18..dc650a1 100644 --- a/app/views/users/_form.html.erb +++ b/app/views/users/_form.html.erb @@ -12,15 +12,15 @@ <% end %>
- <%= f.label :username %>
+ <%= f.label :username %> <%= f.text_field :username %>
- <%= f.label :password %>
+ <%= f.label :password %> <%= f.password_field :password %>
- <%= f.label :password_confirmation %>
+ <%= f.label :password_confirmation %> <%= f.password_field :password_confirmation %>
diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 6b09943..3b6e4a2 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -1,4 +1,4 @@ -

Editing user

+

Editing user

<%= render 'form' %> diff --git a/app/views/users/login.html.erb b/app/views/users/login.html.erb deleted file mode 100644 index 34d15e6..0000000 --- a/app/views/users/login.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -

Users#login

-

Find me in app/views/users/login.html.erb

diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index 7320210..8369d10 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -1,3 +1,3 @@ -

Register

+

Register

<%= render 'form' %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 13d7eed..83dfa38 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -1,13 +1,13 @@ -

<%= @user.username %>

+

<%= @user.username %>

-

Posts

+

Posts

-<%= render :partial => 'links/links', :locals => { :links => @user.links } %> + -

Comments

+

Comments

<%= render :partial => 'comments/comments', :locals => { :comments => @user.comments } %> -<% if @user.id == @current_user.id %> +<% if @user == @current_user %> <%= link_to 'Edit', edit_user_path(@user) %> <% end %> diff --git a/config/environments/production.rb b/config/environments/production.rb index 2d108fe..da4233d 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -64,4 +64,11 @@ # Log the query plan for queries taking more than this (works # with SQLite, MySQL, and PostgreSQL) # config.active_record.auto_explain_threshold_in_seconds = 0.5 + + # https://github.com/metaskills/less-rails-bootstrap-test + config.assets.precompile += [ + 'basic.css', + 'basic_less.css', + 'full_control.css' + ] end diff --git a/config/routes.rb b/config/routes.rb index 97f4f8b..84dbd8d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,6 +7,10 @@ resources :comments end + #resources :comments do + # resources :comments + #end + root :to => "links#index" # The priority is based upon order of creation: