Permalink
Browse files

some tweaks to merge with the changes on master

  • Loading branch information...
2 parents b7ddcb6 + c86869c commit b90389a1f47093e7a244f70d1dd5b32836ccdb17 @dust3d committed Apr 10, 2011
View
@@ -18,6 +18,9 @@ gem 'compass'
gem 'geokit'
+gem "will_paginate", :git=>"git://github.com/mislav/will_paginate.git", :branch=>"rails3"
+
+
group :development, :test do
gem 'rspec-rails'
gem 'factory_girl'
View
@@ -1,3 +1,10 @@
+GIT
+ remote: git://github.com/mislav/will_paginate.git
+ revision: b1a5beeec9f56ecbe3594fcdca76d92b6767ce50
+ branch: rails3
+ specs:
+ will_paginate (3.0.pre3)
+
PATH
remote: vendor/gems
specs:
@@ -120,3 +127,4 @@ DEPENDENCIES
rspec-rails
sqlite3-ruby
twitter-auth!
+ will_paginate!
@@ -1,50 +0,0 @@
-class ChatsController < ApplicationController
- before_filter :login_required
- protect_from_forgery :except => :post
- respond_to :json
- include ApplicationHelper
- delegate :link_to, :auto_link, :sanitize, :to => 'ActionController::Base.helpers'
-
- def index
- @posts = Post.order('created_at DESC')
- end
-
- def users
- @users = User.select([:id, :name]).where("name like ?", "%#{params[:q]}%")
- respond_to do |format|
- format.json { render :json => @users.map(&:attributes) }
- end
- end
-
- def send_data
- if current_user.present?
- user = current_user
- body = params[:chat_input]
- else
- user = User.find(params[:id])
- body = params[:body]
- end
- msg = sanitize(
- auto_link(
- auto_image(
- auto_mention(body)
- ), :html => { :target => '_blank' }
- ), :tags => %w(a img mark), :attributes => %w(href src alt target)
- )
- if user.posts.create!(:chat_input => msg, :lat => params[:lat], :lon => params[:lon])
- post_data = {
- :command => :broadcast,
- :body => msg,
- :name => user.name,
- :profile_image_url => user.profile_image_url,
- :twitter_login => user.login,
- :type => :to_channels_without_signature,
- :channels => 'groupon_go'
- }
- Pusher['groupon_go'].trigger!('new_post', post_data)
- end
- render :nothing => true
- end
-
-end
-
@@ -1,19 +0,0 @@
-class PostController < ApplicationController
- before_filter :login_required
- def index
- @posts = Post.all.order(:created_at)
- end
-
- def post
- #Juggernaut.send_to_channels_without_sign(params[:chat_input], ['iphone'])
- #
- #render :juggernaut => {:type => :send_to_channels, :channels => ['web']} do |page|
- # page.insert_html :top, 'chat_data', "<li>#{h params[:chat_input]}</li>"
- #end
- #render :nothing => true
- @post = Post.create(params[:post])
- #Pusher['groupon_go'].trigger!('post', {:post => params[:post]})
- redirect_to :controller => :chat, :action => :send_date, :post => @post
- end
-
-end
@@ -0,0 +1,49 @@
+class PostsController < ApplicationController
+ include ApplicationHelper
+ before_filter :login_required, :except => [:create]
+ delegate :link_to, :auto_link, :sanitize, :to => 'ActionController::Base.helpers'
+ protect_from_forgery :except => [:create]
+
+ def index
+ @posts = Post.order('created_at DESC').includes(:user)
+ respond_to do |format|
+ format.html
+ format.json { render :json => @posts.collect {|post| {:profile_image_url => post.user.profile_image_url,:twitter_login => post.user.login, :name => post.user.name, :message => sanitize(auto_link(auto_image(post.message), :html => { :target => '_blank' }), :tags => %w(a img), :attributes => %w(href src alt target)), :time_ago => post.created_at} } }
+ end
+ end
+
+ def create
+ if current_user.present?
+ user = current_user
+ body = params[:post].present? ? params[:post][:message] : params[:message]
+ else
+ user = User.find_by_twitter_id(params[:user_id])
+ body = params[:message]
+ end
+ msg = sanitize(
+ auto_link(
+ auto_image(
+ auto_mention(body)
+ ), :html => { :target => '_blank' }
+ ), :tags => %w(a img mark), :attributes => %w(href src alt target)
+ )
+ post = Post.new(:message => msg, :lat => params[:lat], :lon =>params[:lon])
+ if post.valid?
+ post.save!
+ user.posts << post
+ post_data = {
+ :command => :broadcast,
+ :body => msg,
+ :name => user.name,
+ :profile_image_url => user.profile_image_url,
+ :location => post.location,
+ :twitter_login => user.login,
+ :type => :to_channels_without_signature,
+ :channels => 'groupon_go'
+ }
+ Pusher["groupon_go_#{ Rails.env }"].trigger!('new_post', post_data)
+ end
+ render :nothing => true
+ end
+
+end
@@ -0,0 +1,14 @@
+class UsersController < ApplicationController
+
+ def index
+ if params[:q].present?
+ @users = User.select([:id, :name]).where("name like ?", "%#{params[:q]}%")
+ else
+ @users = User.all
+ end
+ respond_to do |format|
+ format.json { render :json => @users.map(&:attributes) }
+ end
+ end
+
+end
View
@@ -1,7 +1,7 @@
class Post < ActiveRecord::Base
belongs_to :user
validates_associated :user
- validates :chat_input, :presence => true
+ validates :message, :presence => true
before_save :geocode
@@ -160,4 +160,20 @@ a {
}
}
}
+}
+#load_more{
+ input {
+ &[type="submit"] {
+ font-weight: bold;
+ border: 1px solid #8abd43;
+ padding: 11px 0;
+ @include column(4, true);
+ @include linear-gradient(color-stops($green, darken($green, 10%)));
+ color: #fff;
+ text-shadow: 0 -1px 1px darken($green, 30%);
+ &:active {
+ @include linear-gradient(color-stops(darken($green, 2%), $green));
+ }
+ }
+ }
}
@@ -15,7 +15,7 @@
</span>
<div class='message'>
- {{{ chat_input }}}
+ {{{ message }}}
</div>
<div class='timestamp'>
{{ time_ago }} ago
@@ -1,4 +1,5 @@
#container
+ %span{:id => 'rails_env', 'data-value' => Rails.env, :class => 'js_attribute'}
#intro
%h1
@@ -11,11 +12,11 @@
Feel free to grab stories and send pull requests—we'll be merging and redeploying all day.
#type_wrapper
- - form_tag send_data_chat_path(:format => :json), :id => 'message_post_form' do
- = text_field_tag :chat_input, '', :placeholder => "#{current_user.name}: "
+ - form_for Post.new, :format => :json, :id => 'message_post_form' do |f|
= hidden_field_tag :lat, '', :id => "lat"
= hidden_field_tag :lon, '', :id => "lon"
- = submit_tag 'Post'
+ = f.text_field :message, :placeholder => "#{current_user.name}: "
+ = f.submit 'Post'
%span.error
You can't submit an empty message!
%span.loading
@@ -24,4 +25,4 @@
%ul#chat_data
- @posts.each do |post|
- = raw Mustache.render(File.read('./app/views/chats/_post.html.mustache'), {:profile_image_url => post.user.profile_image_url,:twitter_login => post.user.login, :name => post.user.name, :chat_input => post.chat_input, :location => post.location, :time_ago => time_ago_in_words(post.created_at)})
+ = raw Mustache.render(File.read('./app/views/posts/_post.html.mustache'), {:profile_image_url => post.user.profile_image_url,:twitter_login => post.user.login, :name => post.user.name, :message => post.message, :location => post.location, :time_ago => time_ago_in_words(post.created_at)})
View
@@ -12,13 +12,9 @@
# Sample resource route (maps HTTP verbs to controller actions automatically):
# resources :products
- resource :chat do
- post 'send_data'
- end
-
resources :posts
- match "/users.json" => 'chats#users'
+ match "/users.json" => 'chats#users'
match "/mustache_templates.js" => MustacheCacher
# Sample resource route with options:
@@ -56,7 +52,7 @@
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
- root :to => "chats#index"
+ root :to => "posts#index"
# See how all your routes lay out with "rake routes"
@@ -0,0 +1,9 @@
+class RenameChatInputToMessage < ActiveRecord::Migration
+ def self.up
+ rename_column :posts, :chat_input, :message
+ end
+
+ def self.down
+ rename_column :posts, :message, :chat_input
+ end
+end
View
@@ -10,10 +10,10 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110409195933) do
+ActiveRecord::Schema.define(:version => 20110410174141) do
create_table "posts", :force => true do |t|
- t.text "chat_input"
+ t.text "message"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
View
Binary file not shown.
@@ -1,47 +1,65 @@
if (navigator.userAgent.match(/Mobile|WebOS/i)) var mobile = true;
+var env;
$(function() {
- $('#chat_input').keypress(function(){
+ $('#post_message').keypress(function(){
$(this).removeAttr('style');
$('.error').hide();
$('.loading').hide();
});
- $('#message_post_form').submit(function(e) {
+ $('#new_post').submit(function(e) {
e.preventDefault();
- var msg = $('#chat_input').val();
+ var msg = $('#post_message').val();
if (msg !== "") {
$('.loading').show();
$(this).request(function(response) {
- $('#chat_input').val('');
+ $('#post_message').val('');
$('.loading').fadeOut('fast');
});
} else {
- $('#chat_input').css({
+ $('#post_message').css({
'border-color': 'red'
}).focus();
$('.error').show();
}
});
- $('#chat_input').focus();
-});
+ env = $('#rails_env').data('value');
-$(function() {
- $("#chat_input").keyup(function(e){
+ var pusher = new Pusher('534d197146cf867179ee');
+ var channel = pusher.subscribe('groupon_go_' + env);
+
+ pusher.bind('new_post',
+ function(data) {
+ var tmpl = MustacheTemplates['posts/_post'];
+ var post = {
+ profile_image_url: data.profile_image_url,
+ twitter_login: data.twitter_login,
+ name: data.name,
+ login: data.twiter_login,
+ message: data.body,
+ time_ago: 'less than a minute'
+ };
+ $('#chat_data').prepend(Mustache.to_html(tmpl, post));
+ }
+ );
+
+ $('#post_message').focus();
+
+ $("#post_message").keyup(function(e){
if($(this).val().match(/@[\S]+/i)){
- var q = $(this).val().match(/(?:@)([\S]+)/i)[1]
+ var q = $(this).val().match(/(?:@)([\S]+)/i)[1];
$.get('/users.json?q=' + q, function(data){
- var current_val = $('#chat_input').val()
-
- //$('#chat_input').val(current_val.replace(q, data[0].name))
- })
+ var current_val = $('#post_message').val();
+ $('#post_message').val(current_val.replace(q, data[0].name));
+ });
}
- })
+ });
+
});
-
(function($) {
$.fn.request = function(success) {
var jqopts = {
@@ -54,31 +72,9 @@ $(function() {
};
})(jQuery);
-var pusher = new Pusher('534d197146cf867179ee');
-
-var channel = pusher.subscribe('groupon_go');
-
-pusher.bind('new_post',
- function(data) {
- var tmpl = MustacheTemplates['chats/_post'];
- var post = {
- profile_image_url: data.profile_image_url,
- twitter_login: data.twitter_login,
- name: data.name,
- login: data.twiter_login,
- chat_input: data.body,
- time_ago: 'less than a minute'
- };
- if (mobile) {
- $('#chat_data').append(Mustache.to_html(tmpl, post));
- } else {
- $('#chat_data').prepend(Mustache.to_html(tmpl, post));
- }
-
- }
-);
-
+// Get users loction and set latitude and longitude to hidden input
+// in form
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(
@@ -116,4 +112,3 @@ if (navigator.geolocation)
}
);
}
-
Oops, something went wrong.

0 comments on commit b90389a

Please sign in to comment.