From b699cc2b287d535c788c24bd26e73829550e92ee Mon Sep 17 00:00:00 2001 From: Michael Hartl Date: Wed, 23 Mar 2011 16:14:25 -0700 Subject: [PATCH 1/5] Added Haml to the Gemfile --- Gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile b/Gemfile index c74efed0..f1f35c77 100644 --- a/Gemfile +++ b/Gemfile @@ -4,6 +4,7 @@ gem 'rails', '3.0.5' gem 'gravatar_image_tag', '1.0.0.pre2' gem 'will_paginate', '3.0.pre2' gem 'sqlite3-ruby', '1.3.2', :require => 'sqlite3' +gem 'haml', '~>3.0.25' group :development do gem 'rspec-rails', '2.5.0' From 81cd25393d530225360a122cca7ab337b5baa72e Mon Sep 17 00:00:00 2001 From: Michael Hartl Date: Wed, 23 Mar 2011 17:02:55 -0700 Subject: [PATCH 2/5] Changed the users views to Haml --- Gemfile.lock | 2 ++ app/views/users/_fields.html.haml | 16 ++++++++++++++ app/views/users/_follow.html.haml | 4 ++++ app/views/users/_follow_form.html.haml | 6 ++++++ app/views/users/_unfollow.html.haml | 4 ++++ app/views/users/_user.html.haml | 8 +++++++ app/views/users/edit.html.haml | 11 ++++++++++ app/views/users/index.html.haml | 5 +++++ .../users/{new.html.erb => new.html.erb.old} | 0 app/views/users/new.html.haml | 7 +++++++ app/views/users/show.html.haml | 21 +++++++++++++++++++ app/views/users/show_follow.html.haml | 20 ++++++++++++++++++ 12 files changed, 104 insertions(+) create mode 100644 app/views/users/_fields.html.haml create mode 100644 app/views/users/_follow.html.haml create mode 100644 app/views/users/_follow_form.html.haml create mode 100644 app/views/users/_unfollow.html.haml create mode 100644 app/views/users/_user.html.haml create mode 100644 app/views/users/edit.html.haml create mode 100644 app/views/users/index.html.haml rename app/views/users/{new.html.erb => new.html.erb.old} (100%) create mode 100644 app/views/users/new.html.haml create mode 100644 app/views/users/show.html.haml create mode 100644 app/views/users/show_follow.html.haml diff --git a/Gemfile.lock b/Gemfile.lock index 86f7a739..5b7bec61 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,6 +40,7 @@ GEM rails (>= 3.0.0.beta4) faker (0.3.1) gravatar_image_tag (1.0.0.pre2) + haml (3.0.25) i18n (0.5.0) mail (2.2.15) activesupport (>= 2.3.6) @@ -101,6 +102,7 @@ DEPENDENCIES factory_girl_rails (= 1.0) faker (= 0.3.1) gravatar_image_tag (= 1.0.0.pre2) + haml (~> 3.0.25) rails (= 3.0.5) rspec (= 2.5.0) rspec-rails (= 2.5.0) diff --git a/app/views/users/_fields.html.haml b/app/views/users/_fields.html.haml new file mode 100644 index 00000000..f87aa34a --- /dev/null +++ b/app/views/users/_fields.html.haml @@ -0,0 +1,16 @@ +.field + = f.label :name + %br + = f.text_field :name +.field + = f.label :email + %br + = f.text_field :email +.field + = f.label :password + %br + = f.password_field :password +.field + = f.label :password_confirmation, "Confirmation" + %br + = f.password_field :password_confirmation diff --git a/app/views/users/_follow.html.haml b/app/views/users/_follow.html.haml new file mode 100644 index 00000000..34807089 --- /dev/null +++ b/app/views/users/_follow.html.haml @@ -0,0 +1,4 @@ +- relationship = current_user.relationships.build(:followed_id => @user.id) += form_for(relationship, :remote => true) do |f| + = f.hidden_field :followed_id + .actions= f.submit "Follow" diff --git a/app/views/users/_follow_form.html.haml b/app/views/users/_follow_form.html.haml new file mode 100644 index 00000000..90e666d0 --- /dev/null +++ b/app/views/users/_follow_form.html.haml @@ -0,0 +1,6 @@ +- unless current_user?(@user) + #follow_form + - if current_user.following?(@user) + = render 'unfollow' + - else + = render 'follow' diff --git a/app/views/users/_unfollow.html.haml b/app/views/users/_unfollow.html.haml new file mode 100644 index 00000000..3a5666bc --- /dev/null +++ b/app/views/users/_unfollow.html.haml @@ -0,0 +1,4 @@ +- relationship = current_user.relationships.find_by_followed_id(@user) +- delete = { :method => :delete } += form_for(relationship, :html => delete, :remote => true) do |f| + .actions= f.submit "Unfollow" \ No newline at end of file diff --git a/app/views/users/_user.html.haml b/app/views/users/_user.html.haml new file mode 100644 index 00000000..ab441761 --- /dev/null +++ b/app/views/users/_user.html.haml @@ -0,0 +1,8 @@ +%li + = gravatar_for user, :size => 30 + = link_to user.name, user + - if current_user.admin? + | + - title = "Delete #{user.name}" + - opts = { :method => :delete, :confirm => "You sure?", :title => title } + = link_to "delete", user, opts diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml new file mode 100644 index 00000000..f84fe4c9 --- /dev/null +++ b/app/views/users/edit.html.haml @@ -0,0 +1,11 @@ +%h1 Edit user + += form_for(@user) do |f| + = render 'shared/error_messages', :object => f.object + = render 'fields', :f => f + .actions + = f.submit "Update" + +%div + = gravatar_for @user + %a{ :href => "http://gravatar.com/emails" } change \ No newline at end of file diff --git a/app/views/users/index.html.haml b/app/views/users/index.html.haml new file mode 100644 index 00000000..d4b99e41 --- /dev/null +++ b/app/views/users/index.html.haml @@ -0,0 +1,5 @@ +%h1 All users += will_paginate +%ul.users + = render @users += will_paginate diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb.old similarity index 100% rename from app/views/users/new.html.erb rename to app/views/users/new.html.erb.old diff --git a/app/views/users/new.html.haml b/app/views/users/new.html.haml new file mode 100644 index 00000000..96ecd379 --- /dev/null +++ b/app/views/users/new.html.haml @@ -0,0 +1,7 @@ +%h1 Sign up + += form_for(@user) do |f| + = render 'shared/error_messages', :object => f.object + = render 'fields', :f => f + .actions + = f.submit "Sign up" diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml new file mode 100644 index 00000000..c8c349b6 --- /dev/null +++ b/app/views/users/show.html.haml @@ -0,0 +1,21 @@ +%table.profile{ :summary => "Profile information" } + %tr + %td.main + %h1 + = gravatar_for @user + = @user.name + = render 'follow_form' if signed_in? + - if @user.microposts.any? + %table.microposts{ :summary => "User microposts" } + = render @microposts + = will_paginate @microposts + %td.sidebar.round + %strong Name + = @user.name + %br + %strong URL + = link_to user_path(@user), @user + %br + %strong Microposts + = @user.microposts.count + = render 'shared/stats' diff --git a/app/views/users/show_follow.html.haml b/app/views/users/show_follow.html.haml new file mode 100644 index 00000000..24f12ed3 --- /dev/null +++ b/app/views/users/show_follow.html.haml @@ -0,0 +1,20 @@ +%table{ :summary => "Information about following/followers" } + %tr + %td.mail + %h1= @title + - if @users.any? + %ul.users + = render @users + %td.sidebar.round + %strong Name + = @user.name + %br + %strong URL + = link_to user_path(@user), @user + %br + %strong Microposts + = @user.microposts.count + = render 'shared/stats' + - if @users.any? + - @users.each do |user| + = link_to gravatar_for(user, :size => 30), user From b4d522476ba98db216a0c730c8142502bb1ef8f0 Mon Sep 17 00:00:00 2001 From: Michael Hartl Date: Wed, 23 Mar 2011 17:08:32 -0700 Subject: [PATCH 3/5] Converted the signin page to Haml --- app/views/sessions/new.html.haml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 app/views/sessions/new.html.haml diff --git a/app/views/sessions/new.html.haml b/app/views/sessions/new.html.haml new file mode 100644 index 00000000..4b8fa88d --- /dev/null +++ b/app/views/sessions/new.html.haml @@ -0,0 +1,16 @@ +%h1 Sign in + += form_for(:session, :url => sessions_path) do |f| + .field + = f.label :email + %br + = f.text_field :email + .field + = f.label :password + %br + = f.password_field :password + .actions + = f.submit "Sign in" +%p + New user? + = link_to "Sign up now!", signup_path \ No newline at end of file From 603af0ba449da6ead562cb5684410d44fc5573b1 Mon Sep 17 00:00:00 2001 From: Michael Hartl Date: Wed, 23 Mar 2011 17:17:22 -0700 Subject: [PATCH 4/5] Removed some ERb files --- app/views/sessions/new.html.erb | 17 ----------------- app/views/users/_fields.html.erb | 16 ---------------- app/views/users/_follow.html.erb | 6 ------ app/views/users/_follow_form.html.erb | 9 --------- app/views/users/_unfollow.html.erb | 5 ----- app/views/users/_user.html.erb | 9 --------- app/views/users/edit.html.erb | 14 -------------- app/views/users/index.html.erb | 9 --------- app/views/users/show.html.erb | 24 ------------------------ app/views/users/show_follow.html.erb | 24 ------------------------ 10 files changed, 133 deletions(-) delete mode 100644 app/views/sessions/new.html.erb delete mode 100644 app/views/users/_fields.html.erb delete mode 100644 app/views/users/_follow.html.erb delete mode 100644 app/views/users/_follow_form.html.erb delete mode 100644 app/views/users/_unfollow.html.erb delete mode 100644 app/views/users/_user.html.erb delete mode 100644 app/views/users/edit.html.erb delete mode 100644 app/views/users/index.html.erb delete mode 100644 app/views/users/show.html.erb delete mode 100644 app/views/users/show_follow.html.erb diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb deleted file mode 100644 index 72028c9a..00000000 --- a/app/views/sessions/new.html.erb +++ /dev/null @@ -1,17 +0,0 @@ -

Sign in

- -<%= form_for(:session, :url => sessions_path) do |f| %> -
- <%= f.label :email %>
- <%= f.text_field :email %> -
-
- <%= f.label :password %>
- <%= f.password_field :password %> -
-
- <%= f.submit "Sign in" %> -
-<% end %> - -

New user? <%= link_to "Sign up now!", signup_path %>

\ No newline at end of file diff --git a/app/views/users/_fields.html.erb b/app/views/users/_fields.html.erb deleted file mode 100644 index 0b04d327..00000000 --- a/app/views/users/_fields.html.erb +++ /dev/null @@ -1,16 +0,0 @@ -
- <%= f.label :name %>
- <%= f.text_field :name %> -
-
- <%= f.label :email %>
- <%= f.text_field :email %> -
-
- <%= f.label :password %>
- <%= f.password_field :password %> -
-
- <%= f.label :password_confirmation, "Confirmation" %>
- <%= f.password_field :password_confirmation %> -
\ No newline at end of file diff --git a/app/views/users/_follow.html.erb b/app/views/users/_follow.html.erb deleted file mode 100644 index 8fd790d7..00000000 --- a/app/views/users/_follow.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -<%= form_for(current_user.relationships. - build(:followed_id => @user.id), - :remote => true) do |f| %> -
<%= f.hidden_field :followed_id %>
-
<%= f.submit "Follow" %>
-<% end %> \ No newline at end of file diff --git a/app/views/users/_follow_form.html.erb b/app/views/users/_follow_form.html.erb deleted file mode 100644 index e3c5bee3..00000000 --- a/app/views/users/_follow_form.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -<% unless current_user?(@user) %> -
- <% if current_user.following?(@user) %> - <%= render 'unfollow' %> - <% else %> - <%= render 'follow' %> - <% end %> -
-<% end %> \ No newline at end of file diff --git a/app/views/users/_unfollow.html.erb b/app/views/users/_unfollow.html.erb deleted file mode 100644 index e34c12e1..00000000 --- a/app/views/users/_unfollow.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -<%= form_for(current_user.relationships.find_by_followed_id(@user), - :html => { :method => :delete }, - :remote => true) do |f| %> -
<%= f.submit "Unfollow" %>
-<% end %> \ No newline at end of file diff --git a/app/views/users/_user.html.erb b/app/views/users/_user.html.erb deleted file mode 100644 index 532ae15c..00000000 --- a/app/views/users/_user.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -
  • - <%= gravatar_for user, :size => 30 %> - <%= link_to user.name, user %> - <% if current_user.admin? %> - | - <%= link_to "delete", user, :method => :delete, :confirm => "You sure?", - :title => "Delete #{user.name}" %> - <% end %> -
  • \ No newline at end of file diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb deleted file mode 100644 index 3a572b82..00000000 --- a/app/views/users/edit.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -

    Edit user

    - -<%= form_for(@user) do |f| %> - <%= render 'shared/error_messages', :object => f.object %> - <%= render 'fields', :f => f %> -
    - <%= f.submit "Update" %> -
    -<% end %> - -
    - <%= gravatar_for @user %> - change -
    diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb deleted file mode 100644 index d96cda33..00000000 --- a/app/views/users/index.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -

    All users

    - -<%= will_paginate %> - -
      - <%= render @users %> -
    - -<%= will_paginate %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb deleted file mode 100644 index 711a45e0..00000000 --- a/app/views/users/show.html.erb +++ /dev/null @@ -1,24 +0,0 @@ - - - - - -
    -

    - <%= gravatar_for @user %> - <%= @user.name %> -

    - <%= render 'follow_form' if signed_in? %> - <% if @user.microposts.any? %> - - <%= render @microposts %> -
    - <%= will_paginate @microposts %> - <% end %> -
    - diff --git a/app/views/users/show_follow.html.erb b/app/views/users/show_follow.html.erb deleted file mode 100644 index dbc92dbf..00000000 --- a/app/views/users/show_follow.html.erb +++ /dev/null @@ -1,24 +0,0 @@ - - - - - -
    -

    <%= @title %>

    - - <% if @users.any? %> -
      - <%= render @users %> -
    - <% end %> -
    \ No newline at end of file From 849622d4f764fa4b4f7267b0c71829a9a070ed54 Mon Sep 17 00:00:00 2001 From: Michael Hartl Date: Fri, 25 Mar 2011 18:41:01 -0700 Subject: [PATCH 5/5] Even more compact --- app/views/users/index.html.haml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/users/index.html.haml b/app/views/users/index.html.haml index d4b99e41..2e75d926 100644 --- a/app/views/users/index.html.haml +++ b/app/views/users/index.html.haml @@ -1,5 +1,4 @@ %h1 All users = will_paginate -%ul.users - = render @users +%ul.users= render @users = will_paginate