Permalink
Browse files

finished 3rd screencast

  • Loading branch information...
1 parent cf4ad71 commit 308cc53784e7321aeee4f3f306dc244413a2904b @cavneb committed Oct 19, 2009
@@ -3,6 +3,7 @@ class FlitsController < ApplicationController
def create
flit = current_user.flits.build(params[:flit])
+ flit.message = flit.message[0..140]
flit.created_at = Time.now # HACK
flit.save!
redirect_to root_path
@@ -6,4 +6,21 @@ def index
@last_flit = current_user.flits.last
end
+ def show
+ @user = User.find_by_username(params[:username])
+ @flits = @user.all_flits
+ end
+
+ def toggle_follow
+ @user = User.find_by_username(params[:username])
+ if current_user.is_friend? @user
+ flash[:notice] = "You are no longer following @#{@user.username}"
+ current_user.remove_friend(@user)
+ else
+ flash[:notice] = "You are now following @#{@user.username}"
+ current_user.add_friend(@user)
+ end
+ redirect_to user_flits_path(@user.username)
+ end
+
end
View
@@ -26,6 +26,17 @@ def add_friend(friend)
end
end
+ def remove_friend(friend)
+ friendship = Friendship.find(:first, :conditions => ["user_id = ? and friend_id = ?", self.id, friend.id])
+ if friendship
+ friendship.destroy
+ end
+ end
+
+ def is_friend?(friend)
+ return self.friends.include? friend
+ end
+
def all_flits
Flit.find(:all, :conditions => ["user_id in (?)", friends.map(&:id).push(self.id)], :order => "created_at desc")
end
@@ -0,0 +1,15 @@
+<ul id="flits_list">
+ <% flits.each do |flit| %>
+ <li<% if flits.first == flit %> class="first"<% end %>>
+ <%= image_tag flit.user.gravatar_url %>
+ <div class="flit_message_container">
+ <%= link_to flit.user.username %>
+ <%= h flit.message %>
+ <div class="time_ago">
+ <%= distance_of_time_in_words_to_now(flit.created_at) %> ago
+ </div>
+ </div>
+ <div class="clear"></div>
+ </li>
+ <% end %>
+</ul>
@@ -1,6 +1,27 @@
+<script type="text/javascript">
+$(function() {
+ $('#flit_message').keyup(function() {
+ var content_length = $(this).val().length;
+ var remaining = 140 - content_length
+ $('#char_count').html(remaining);
+ if (remaining < 21 && remaining > 9) {
+ $('#char_count').removeClass('red');
+ $('#char_count').addClass('dark_red');
+ } else if (remaining <= 9) {
+ $('#char_count').removeClass('dark_red');
+ $('#char_count').addClass('red');
+ } else {
+ $('#char_count').removeClass('dark_red').removeClass('red');
+ }
+ })
+})
+</script>
+
<%- form_for Flit.new do |f| -%>
<div id="new_flit_form">
- <h3>What are you doing?</h3>
+ <h3 style="float: left;">What are you doing?</h3>
+ <h3 id="char_count">140</h3>
+ <div class="clear"></div>
<%= f.text_area :message %>
<div id="latest_message">
<strong>Latest: </strong><%= h @last_flit.message %>
@@ -13,18 +34,4 @@
</div>
<%- end -%>
-<ul id="flits_list">
- <% @flits.each do |flit| %>
- <li<% if @flits.first == flit %> class="first"<% end %>>
- <%= image_tag flit.user.gravatar_url %>
- <div class="flit_message_container">
- <%= link_to flit.user.username %>
- <%= h flit.message %>
- <div class="time_ago">
- <%= distance_of_time_in_words_to_now(flit.created_at) %> ago
- </div>
- </div>
- <div class="clear"></div>
- </li>
- <% end %>
-</ul>
+<%= render :partial => "flits_list", :locals => { :flits => @flits }%>
@@ -0,0 +1,13 @@
+<h1><%= image_tag @user.gravatar_url, :align => "top" %> <%= @user.username %></h1>
+
+<%- form_tag toggle_follow_path do -%>
+ <% if current_user.is_friend? @user %>
+ <%= submit_tag "Following", :class => "button" %>
+ <% else %>
+ <%= submit_tag "Not Following", :class => "button" %>
+ <% end %>
+<%- end -%>
+
+&nbsp;
+
+<%= render :partial => "flits_list", :locals => { :flits => @flits }%>
@@ -4,6 +4,7 @@
<head>
<title><%= h(yield(:title) || "Untitled") %></title>
<%= stylesheet_link_tag 'application' %>
+ <%= javascript_include_tag :defaults %>
<%= yield(:head) %>
</head>
<body>
View
@@ -5,6 +5,8 @@
map.resources :sessions
map.resources :users
map.resources :flits
+ map.user_flits '/:username', :controller => 'home', :action => 'show'
+ map.toggle_follow '/:username/toggle_follow', :controller => 'home', :action => 'toggle_follow'
map.root :controller => "home"
# The priority is based upon order of creation: first created -> highest priority.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -110,6 +110,7 @@ input.button {
#flits_list li div.flit_message_container {
float: left;
margin-left: 10px;
+ width: 450px;
}
#flits_list li div.flit_message_container a {
color: #2276bb;
@@ -160,3 +161,15 @@ input.button {
font-size: 12px;
list-style: disc;
}
+#char_count {
+ float: right;
+ font-size: 23px;
+ font-weight: bold !important;
+ color: #aaa;
+}
+.dark_red {
+ color: #5C0002 !important;
+}
+.red {
+ color: #D40D12 !important;
+}
@@ -0,0 +1,43 @@
+0.5.0 (31 July 2009)
+* Gemification
+* Support for Ruby 1.9.X
+* Updated to jQuery 1.3.2
+* Updated to jQuery UI 1.7.2
+* Created a jrails binary (runs rake tasks) because rails does not (yet?) pickup
+tasks from gem plugins
+* Changed default to use jQuery compatibility name (not $)
+* Created a scrub task that will remove the prototype / script.aculo.us
+javascript files
+* better approximate scriptaculous effect names
+* add support for page[:element_id].visual_effect(:effect) as well as page.visual_effect(:effect, :element_id)
+* added a reset form function to jrails.js (stolen from jquery form)
+* can now use jquery selectors in all functions
+* added javascript_function helper to render inline rjs helpers
+* better support for sortable_element
+
+0.4.0 (16 June 2008)
+* updated to jquery-ui 1.5 & merged js into single file
+* Added jQuery.noConflict support
+* support for value/val
+* additional support for update/delete methods
+* support for success/failure hash
+* setRequestHeader now gets called globally
+* Better support for droppables, sortables
+* Add support for prototype AJAX callbacks
+* better support for AJAX form calls
+
+0.3.0 (22 Feb 2008)
+* updated to jquery-fx 1.0b and jquery-ui 1.5b
+* Add text/javascript request header to fix format.js
+* Added Tasks (thanks ggarside)
+* Improve visual_effects methods
+* Fixed some RJS calls
+* Fixed observer code for ie
+
+0.2.0 (26 Nov 2007)
+* Vastly Improved FX
+* Improved Form Observers
+* Fixed Rails <= 1.2.6 Compatibility
+
+0.1.0 (15 Nov 2007)
+* Initial release
@@ -0,0 +1,18 @@
+Copyright (c) 2008 Aaron Eisenberger
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,21 @@
+= jRails
+
+jRails is a drop-in jQuery replacement for the Rails Prototype/script.aculo.us helpers.
+
+== Resources
+
+Install
+
+* .script/plugin install git://github.com/aaronchi/jrails.git
+
+Project Site
+
+* http://code.google.com/p/ennerchi
+
+Web Site
+
+* http://www.ennerchi.com/projects/jrails
+
+Group Site
+
+* http://groups.google.com/group/jrails
@@ -0,0 +1,18 @@
+require 'rubygems'
+require 'rake'
+
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gem|
+ gem.name = "jrails"
+ gem.summary = "jRails is a drop-in jQuery replacement for the Rails Prototype/script.aculo.us helpers."
+ gem.description = "Using jRails, you can get all of the same default Rails helpers for javascript functionality using the lighter jQuery library."
+ gem.email = "aaronchi@gmail.com"
+ gem.homepage = "http://ennerchi.com/projects/jrails"
+ gem.authors = ["Aaron Eisenberger", "Patrick Hurley"]
+ gem.rubyforge_project = "jrails"
+ gem.files = FileList["[A-Z]*.rb","{bin,javascripts,lib,rails,tasks}/**/*"]
+ end
+rescue LoadError
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
+end
@@ -0,0 +1,4 @@
+---
+:patch: 1
+:major: 0
+:minor: 5
@@ -0,0 +1,30 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'rake'
+
+RAILS_ROOT = Dir.pwd
+rakeapp = Rake.application
+fname =File.join(File.dirname(__FILE__), '..', 'tasks', 'jrails.rake')
+load fname
+
+task :help do
+ puts "jrails [command]\n\n"
+ rakeapp.options.show_task_pattern = Regexp.new('^[hius]')
+ rakeapp.display_tasks_and_comments
+end
+
+desc 'Installs the jQuery and jRails javascripts to public/javascripts'
+task :install do
+ Rake::Task['jrails:js:install'].invoke
+end
+
+desc 'Remove the prototype / script.aculo.us javascript files'
+task :scrub do
+ Rake::Task['jrails:js:scrub'].invoke
+end
+
+rakeapp.init("jrails")
+task :default => [:help]
+
+rakeapp.top_level
@@ -0,0 +1 @@
+require 'rails/init.rb'
@@ -0,0 +1,9 @@
+# Install hook code here
+puts "Copying files..."
+dir = "javascripts"
+["jquery-ui.js", "jquery.js", "jrails.js"].each do |js_file|
+ dest_file = File.join(RAILS_ROOT, "public", dir, js_file)
+ src_file = File.join(File.dirname(__FILE__) , dir, js_file)
+ FileUtils.cp_r(src_file, dest_file)
+end
+puts "Files copied - Installation complete!"
Oops, something went wrong.

0 comments on commit 308cc53

Please sign in to comment.