Created
October 11, 2010 16:18
-
-
Save alexsergeyev/620786 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module AutoLocale | |
module Helpers | |
def switch_to_lang(lang) | |
lang == options.locales.first ? request.path_info : request.path_info.sub(/^\//, "/#{lang}/") | |
end | |
def has_locale?(url) | |
url =~ /^\/(#{options.locales.join('|')})\/?/ | |
end | |
def link_to_with_locale (*args, &block) | |
unless !options.respond_to?(:locales) || has_locale?(args[0]) || has_locale?(args[1]) || I18n.locale == options.locales.first | |
block_given? ? args[0] = "/#{I18n.locale}#{args[0]}" : args[1] = "/#{I18n.locale}#{args[1]}" | |
end | |
link_to_without_locale(*args, &block) | |
end | |
end | |
# Helpers | |
def self.registered(app) | |
app.helpers AutoLocale::Helpers | |
Padrino::Helpers::AssetTagHelpers.send :include, AutoLocale::Helpers | |
Padrino::Helpers::AssetTagHelpers.alias_method_chain :link_to, :locale | |
app.set :locales, [:en] | |
app.before do | |
if request.path_info =~ /^\/(#{options.locales.join('|')})\/?/ | |
I18n.locale = $1.to_sym | |
else | |
I18n.locale = options.locales.first | |
end | |
request.path_info.gsub!(/\/[a-z]{2}\//,"/") | |
end | |
end | |
# self.registered | |
end | |
# AutoLocale | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Allow the metal piece to run in isolation | |
require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails) | |
require 'sinatra' | |
class Auth < Sinatra::Application | |
#enable :sessions | |
configure do | |
FB = YAML.load_file(File.dirname(__FILE__) + "/../../config/facebooker.yml") | |
end | |
helpers do | |
# Load portal and setup facebook oauth | |
def facebook_client | |
portal = Portal.find(params[:portal_id]) | |
if RAILS_ENV == "production" && @portal.facebook_api_key | |
facebook_connect = FB["production"]["alternative_keys"][portal.facebook_api_key] | |
elsif request.host == '127.0.0.1' #debugging keys with callback domain 127.0.0.1 | |
facebook_connect = {"secret_key" => 'XXXXXXXX', "application_id" => 'XXXX' } | |
portal = Portal.find_by_default_start_portal(true) | |
else | |
facebook_connect = FB[RAILS_ENV] | |
end | |
facebook_connect["application_id"] = portal.facebook_api_key unless facebook_connect["application_id"] | |
callback_url = "#{request.scheme}://#{request.host}:#{request.port}/auth/facebook/callback?portal_id=#{portal.id}" | |
return FacebookOAuth::Client.new( | |
:application_id => facebook_connect["application_id"], | |
:application_secret => facebook_connect["secret_key"], | |
:callback => callback_url) | |
end | |
end | |
get '/auth/facebook' do | |
client = facebook_client | |
if params[:format] == "mobile" | |
redirect "#{client.authorize_url}&display=touch" | |
else | |
redirect client.authorize_url | |
end | |
end | |
get '/auth/facebook/callback' do | |
client = facebook_client | |
access_token = client.authorize(:code => params[:code]) # it's possible to load data from facebook by this access_token.token | |
info = client.me.info | |
current_user = User.find_by_fb_user_id(info["id"]) | |
if current_user | |
session[:user_id] = current_user.id | |
else | |
current_user = User.new( | |
:name => info["name"], | |
:login => info["name"].downcase.gsub(" ","_"), | |
:password => "", :email => "", | |
:fb_user_id => info["id"], | |
:portal_id => @portal.id, | |
:original_potal_id => @portal.id) | |
if current_user.save | |
session[:user_id] = current_user.id | |
end | |
end | |
redirect "/home" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- content_for(:title) do | |
#{t 'nav.contacts'} - #{t 'nav.company'} | |
- content_for(:updated_at) do | |
=@updated_at | |
%h1= t 'nav.contacts' | |
%article#contacts | |
%div.column | |
-@locations.each do |location| | |
%h2=location.city | |
%ul.vcard | |
%li.org.fn{:style => "display:none"}=t('main.company_full') | |
%li.adr.work | |
%span.street-address=location.address | |
%li.adr.work | |
%span.postal-code=location.post_code | |
%span.locality=location.city | |
%span.country-name{:style => "display:none"}=location.country | |
%li | |
%span.field_name=t('vcard.phone') | |
%a.tel.work{:href => "tel:#{location.phone}"}=phone_format(location.phone) | |
%li.tel.work | |
%span.field_name.type="Fax" | |
%a.tel.work{:href => "tel:#{location.fax}"}=phone_format(location.fax) | |
%li | |
%span.field_name=t('vcard.email') | |
%a.email{:href => "mailto:#{location.email}"}=location.email | |
%div.column | |
%h2="form.contact.header" | |
-form_tag '/contacts', :class => 'contact-form', :id => "contact-form", :method => 'post' do | |
%ul.mail | |
%li=text_field_tag :name, :placeholder => t('contact.name') | |
%li=text_field_tag :email,:placeholder => t('contact.email') | |
%li=text_area_tag :body,:placeholder => t('contact.body') | |
%li=submit_tag t("contact.send") | |
~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment