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
def authorize!(oauth_hash, user) | |
User::Oauth2Service.new(oauth_hash, user).workflow self do | |
# Account successfully created, or user successfully logged in. Now sign in user. | |
on_sign_in do |account, provider_title| | |
session.delete("omniauth.auth") | |
session.delete("provider_title") | |
if account.user.confirmed? | |
sign_in_user_and_redirect(account.user, provider_title) | |
else |
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
# Oauth-specific user methods | |
class User::Oauth2Service | |
def initialize(auth, user = nil) | |
@policy = policy(auth) | |
@user = user || User.where(email: @policy.email).first_or_initialize | |
@account = Oauth2::Account.where(provider: @policy.provider, uid: @policy.uid).first_or_initialize | |
end | |
def workflow(controller, &block) | |
@controller = controller |
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
# encoding: utf-8 | |
module Papillon::Controller | |
extend ActiveSupport::Concern | |
module ClassMethods | |
# TODO Write specs this | |
mattr_accessor :papillon_dsl, :papillon_resource, :papillon_controller_builder | |
def papillon(resource_class, options = {}, &block) | |
self.papillon_dsl ||= Papillon::Dsl.new(options, &block) |
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 Papillon | |
class Railtie < Rails::Railtie | |
initializer "papillon.action_controller" do | |
ActiveSupport.on_load(:action_controller) do | |
ActionController::Base.send :include, Papillon::Controller | |
end | |
end | |
end | |
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
# Render index page | |
class IndexFor | |
DEFAULT_OPTIONS = { | |
by: nil, | |
pagination: :bottom, # top, bottom, both | |
}.with_indifferent_access | |
attr_reader :resource, :options, :block, :h | |
def initialize(resource, options = {}, view_context, &block) |
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 Url | |
module Parser | |
# Youtube | |
YOUTUBE_REGEX = [ | |
/watch\?v=(?<slug>[A-Za-z0-9_-]+)/, | |
/(?:www\.)?youtube\.com\/(?:embed|v)\/(?<slug>[A-Za-z0-9_-]+)/, | |
/youtu\.be\/(?<slug>[A-Za-z0-9_-]+)/, | |
] | |
# Vimeo |
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
// With SVG.js | |
var width = 500 | |
var height = 20 | |
var lineHeight = 3 | |
var step = 10 | |
var draw = SVG('canvas') | |
var rect = draw.rect(width, height).fill('#f09') | |
for (var i = 1; i < width/step; i++) { |
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
# Организация | |
class Organization < ActiveRecord::Base | |
has_many :organization_members, class_name: 'Organization::Member', dependent: :destroy | |
has_many :members, through: :organization_members | |
attr_accessible :name | |
end | |
# Член организации | |
class Organization::Member < ActiveRecord::Base |
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 CarrierWave | |
module MiniMagick | |
# Rotates the image based on the EXIF Orientation | |
# According to http://jpegclub.org/exif_orientation.html | |
def auto_orient | |
manipulate! do |image| | |
case image['EXIF:Orientation'].to_i | |
when 2 | |
image.flop | |
when 3 |
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
%w[ | |
CollectionSelectInput | |
DateTimeInput | |
GroupedCollectionSelectInput | |
NumericInput | |
PasswordInput | |
RangeInput | |
StringInput | |
TextInput |