Skip to content

Commit

Permalink
finished 3rd screencast
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Berry committed Oct 19, 2009
1 parent cf4ad71 commit 308cc53
Show file tree
Hide file tree
Showing 28 changed files with 1,364 additions and 16 deletions.
1 change: 1 addition & 0 deletions app/controllers/flits_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions app/views/home/_flits_list.html.erb
Original file line number Diff line number Diff line change
@@ -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>
39 changes: 23 additions & 16 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -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 %>
Expand All @@ -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 }%>
13 changes: 13 additions & 0 deletions app/views/home/show.html.erb
Original file line number Diff line number Diff line change
@@ -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 }%>
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<head>
<title><%= h(yield(:title) || "Untitled") %></title>
<%= stylesheet_link_tag 'application' %>
<%= javascript_include_tag :defaults %>
<%= yield(:head) %>
</head>
<body>
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
188 changes: 188 additions & 0 deletions public/javascripts/jquery-ui.js

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions public/javascripts/jquery.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions public/javascripts/jrails.js

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

13 changes: 13 additions & 0 deletions public/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
43 changes: 43 additions & 0 deletions vendor/plugins/jrails/CHANGELOG
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions vendor/plugins/jrails/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
21 changes: 21 additions & 0 deletions vendor/plugins/jrails/README.rdoc
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions vendor/plugins/jrails/Rakefile
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"
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
4 changes: 4 additions & 0 deletions vendor/plugins/jrails/VERSION.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
:patch: 1
:major: 0
:minor: 5
30 changes: 30 additions & 0 deletions vendor/plugins/jrails/bin/jrails
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions vendor/plugins/jrails/init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'rails/init.rb'
9 changes: 9 additions & 0 deletions vendor/plugins/jrails/install.rb
Original file line number Diff line number Diff line change
@@ -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!"
Loading

0 comments on commit 308cc53

Please sign in to comment.