Skip to content

Commit

Permalink
refactoring iphone handling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Riccardo Cambiassi committed Dec 22, 2010
1 parent c60dbc3 commit bdaf289
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 20 deletions.
17 changes: 10 additions & 7 deletions app/controllers/iphone_controller.rb
@@ -1,14 +1,17 @@
class IphoneController < ApplicationController

layout "iphone"

def index
if user_signed_in?
@knots = current_user.knots
render :layout => iphone_layout
else
store_location
render :template => "/iphone/signin"
respond_to do |format|
format.iphone do
if user_signed_in?
@knots = current_user.knots
render :layout => iphone_layout
else
render :template => "/iphone/signin", :layout => "iphone"
end
end
format.html { redirect_to root_path }
end
end

Expand Down
4 changes: 3 additions & 1 deletion app/controllers/knots_controller.rb
Expand Up @@ -51,9 +51,10 @@ def create
if params[:remote]
render :layout => "bookmarklet"
else
redirect_to(request.xhr? ? iphone_path : knots_path)
redirect_to knots_path
end
end
format.iphone { redirect_to iphone_path }
format.xml { render :xml => @knot, :status => :created, :location => @knot }
else
flash[:alert] = I18n.t('controllers.knots.create.failure')
Expand Down Expand Up @@ -137,6 +138,7 @@ def normalize_knot_params(params={})
:summary => params[:s]
}
end
params[:knot][:url].downcase!
return params[:knot]
end

Expand Down
File renamed without changes.
Expand Up @@ -14,7 +14,7 @@
%li
%a.slideup{ :href => "#about"} About
%div.info
%p= "Last knot created #{time_ago_in_words @knots.first.created_at} ago" if @knots.count > 0
%p= "Last knot created #{time_ago_in_words(@knots.first.created_at)} ago" if @knots.count > 0

#read
.toolbar
Expand All @@ -29,7 +29,7 @@
%h1 Add Knot
%a.button.back{ :href => "#home"} Back
%div
- form_for :knot, :url => knots_path do |form|
= form_for :knot, :url => knots_path do |form|
%ul
%li= form.text_field :url, :placeholder => "url"
%li= form.text_field :title, :placeholder => "title"
Expand Down
Expand Up @@ -5,14 +5,14 @@

%div
%h2 Sign in
- form_for :session, :url => session_path do |form|
= form_for :user, :url => new_user_session_path do |form|
%ul
%li= form.text_field :email, :placeholder => "email"
%li= form.password_field :password, :placeholder => "password"
%li= form.submit "Sign in", :class => "submit"

%h2 Sign up
- form_for :user, :url => users_path do |form|
= form_for :user, :url => users_path do |form|
%ul
%li= form.text_field :email, :placeholder => "email"
%li= form.password_field :password, :placeholder => "password"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,5 +1,5 @@
!!! Strict
%html{:lang => "en", "xml:lang" => "en", :xmlns => "http://www.w3.org/1999/xhtml"}
!!!
%html
%head
%title
Filo
Expand All @@ -10,7 +10,7 @@
google.load("jquery", "1.4.2");
= stylesheet_link_tag "jqtouch/jqtouch.css", "jqtouch/jqt/theme.css"
= javascript_include_tag "jqtouch/jqtouch.js", "iphone.js"

= csrf_meta_tag
%body
#jqt
= yield
2 changes: 1 addition & 1 deletion config/initializers/devise.rb
Expand Up @@ -125,7 +125,7 @@
# access, but formats like :xml or :json, should return 401.
# If you have any extra navigational formats, like :iphone or :mobile, you
# should add them to the navigational formats lists. Default is [:html]
# config.navigational_formats = [:html, :iphone]
config.navigational_formats = [:html, :iphone]

# ==> Warden configuration
# If you want to use other strategies, that are not (yet) supported by Devise,
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/mime_types.rb
Expand Up @@ -2,4 +2,4 @@

# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone
Mime::Type.register_alias "text/html", :iphone
4 changes: 1 addition & 3 deletions lib/iphone/iphone_controller.rb
Expand Up @@ -20,8 +20,7 @@ module ClassMethods

def acts_as_iphone_controller
include IphoneController::InstanceMethods
# XXX Clearance doesn't play well with iphone format :(
# before_filter(:set_iphone_format)
before_filter(:set_iphone_format)
helper_method :is_iphone_request?
end
end
Expand All @@ -32,7 +31,6 @@ module InstanceMethods
# Commenting this out as I can't make it work nicely with Clearance
def set_iphone_format
if is_iphone_request? || is_iphone_format? || is_iphone_subdomain?
# XXX Clearance doesn't play well with iphone format :(
request.format = cookies["browser"] == "desktop" ? :html : :iphone
end
end
Expand Down

0 comments on commit bdaf289

Please sign in to comment.