omniauth-scaffold 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +16 -3
  4. data/{LICENSE → LICENSE.txt} +2 -4
  5. data/README.rdoc +19 -0
  6. data/Rakefile +49 -2
  7. data/VERSION +1 -0
  8. data/lib/generators/omniauth/scaffold/scaffold_generator.rb +33 -0
  9. data/lib/generators/omniauth/scaffold/templates/README.rdoc +83 -0
  10. data/lib/generators/omniauth/scaffold/templates/app/controllers/application_controller.rb +28 -0
  11. data/lib/{omniauth-scaffold/templates → generators/omniauth/scaffold/templates/app/controllers}/sessions_controller.rb +0 -0
  12. data/lib/{omniauth-scaffold/templates → generators/omniauth/scaffold/templates/app/controllers}/top_controller.rb +0 -0
  13. data/lib/{omniauth-scaffold/templates → generators/omniauth/scaffold/templates/app/models}/user.rb +1 -6
  14. data/lib/generators/omniauth/scaffold/templates/app/views/layouts/application.html.erb +29 -0
  15. data/lib/generators/omniauth/scaffold/templates/app/views/top/index.html.erb +2 -0
  16. data/lib/generators/omniauth/scaffold/templates/config/initializers/constants.rb +22 -0
  17. data/lib/generators/omniauth/scaffold/templates/config/initializers/local_setting.rb +2 -0
  18. data/lib/generators/omniauth/scaffold/templates/config/initializers/omniauth.rb +4 -0
  19. data/lib/{omniauth-scaffold/templates → generators/omniauth/scaffold/templates/db/migrate}/create_users.rb +2 -2
  20. data/omniauth-scaffold.gemspec +72 -13
  21. data/spec/omniauth-scaffold_spec.rb +7 -0
  22. data/spec/spec_helper.rb +12 -0
  23. metadata +130 -33
  24. data/.gitignore +0 -17
  25. data/README.md +0 -144
  26. data/lib/omniauth-scaffold/templates/README.md +0 -80
  27. data/lib/omniauth-scaffold/templates/application.html.erb +0 -37
  28. data/lib/omniauth-scaffold/templates/application_controller.rb +0 -60
  29. data/lib/omniauth-scaffold/templates/base.css.scss +0 -16
  30. data/lib/omniauth-scaffold/templates/index.html.erb +0 -2
  31. data/lib/omniauth-scaffold/templates/ja.yml +0 -198
  32. data/lib/omniauth-scaffold/templates/omniauth.rb +0 -10
  33. data/lib/omniauth-scaffold/templates/rails_config/development.yml +0 -0
  34. data/lib/omniauth-scaffold/templates/rails_config/production.yml +0 -11
  35. data/lib/omniauth-scaffold/templates/rails_config/rails_config.rb +0 -3
  36. data/lib/omniauth-scaffold/templates/rails_config/settings.local.yml +0 -3
  37. data/lib/omniauth-scaffold/templates/rails_config/settings.yml +0 -11
  38. data/lib/omniauth-scaffold/templates/rails_config/test.yml +0 -0
  39. data/lib/omniauth-scaffold/templates/scaffolds.css.scss +0 -70
  40. data/lib/omniauth-scaffold/version.rb +0 -5
  41. data/lib/omniauth-scaffold.rb +0 -92
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile CHANGED
@@ -1,4 +1,17 @@
1
- source 'https://rubygems.org'
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem 'omniauth-twitter'
6
+ gem 'omniauth-github'
7
+ gem 'omniauth-facebook'
2
8
 
3
- # Specify your gem's dependencies in omniauth-scaffold.gemspec
4
- gemspec
9
+ # Add dependencies to develop your gem here.
10
+ # Include everything needed to run rake, tests, features, etc.
11
+ group :development do
12
+ gem "rspec", "~> 2.8.0"
13
+ gem "rdoc", "~> 3.12"
14
+ # gem "bundler", "~> 1.0.0"
15
+ gem "jeweler", "~> 1.8.3"
16
+ # gem "rcov", ">= 0"
17
+ end
@@ -1,6 +1,4 @@
1
- Copyright (c) 2012 shu0115
2
-
3
- MIT License
1
+ Copyright (c) 2012 Shun Matsumoto
4
2
 
5
3
  Permission is hereby granted, free of charge, to any person obtaining
6
4
  a copy of this software and associated documentation files (the
@@ -19,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
17
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
18
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
19
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = omniauth-scaffold
2
+
3
+ Scaffold to use OmniAuth.
4
+
5
+ == Contributing to omniauth-scaffold
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 Shun Matsumoto. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile CHANGED
@@ -1,2 +1,49 @@
1
- #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "omniauth-scaffold"
18
+ gem.homepage = "http://github.com/shu0115/omniauth-scaffold"
19
+ gem.license = "MIT"
20
+ gem.summary = "OmniAuth Scaffold"
21
+ gem.description = "Scaffold to use OmniAuth."
22
+ gem.email = "s.matsumoto0115@gmail.com"
23
+ gem.authors = ["Shun Matsumoto"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "omniauth-scaffold #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,33 @@
1
+ require 'rails/generators'
2
+
3
+ module Omniauth
4
+ module Generators
5
+ class ScaffoldGenerator < ::Rails::Generators::Base
6
+
7
+ source_root File.expand_path("../templates", __FILE__)
8
+ desc "This generator scaffold to use OmniAuth"
9
+
10
+ def generate_scaffold
11
+ copy_file "config/initializers/omniauth.rb", "config/initializers/omniauth.rb"
12
+ copy_file "config/initializers/local_setting.rb", "config/initializers/local_setting.rb"
13
+ copy_file "config/initializers/constants.rb", "config/initializers/constants.rb"
14
+
15
+ insert_into_file "config/routes.rb", " match \"/auth/:provider/callback\" => \"sessions#callback\"\n match \"/auth/failure\" => \"sessions#failure\"\n match \"/logout\" => \"sessions#destroy\", :as => :logout\n", after: "# first created -> highest priority.\n"
16
+ insert_into_file "config/routes.rb", " root :to => 'top#index'\n", after: "# root :to => 'welcome#index'\n"
17
+ insert_into_file "config/routes.rb", " match ':controller(/:action(/:id))(.:format)'\n", after: "# match ':controller(/:action(/:id))(.:format)'\n"
18
+
19
+ copy_file "db/migrate/create_users.rb", "db/migrate/20000101000000_create_users.rb"
20
+ copy_file "app/models/user.rb", "app/models/user.rb"
21
+ copy_file "app/controllers/sessions_controller.rb", "app/controllers/sessions_controller.rb"
22
+ copy_file "app/controllers/application_controller.rb", "app/controllers/application_controller.rb"
23
+ copy_file "app/controllers/top_controller.rb", "app/controllers/top_controller.rb"
24
+ copy_file "app/views/layouts/application.html.erb", "app/views/layouts/application.html.erb"
25
+ copy_file "app/views/top/index.html.erb", "app/views/top/index.html.erb"
26
+
27
+ remove_file 'public/index.html'
28
+ remove_file 'README'
29
+ copy_file "README.rdoc", "README.rdoc"
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,83 @@
1
+ = APP_NAME
2
+
3
+ APP_DESCRIPTION
4
+
5
+ = Local Setting
6
+
7
+ ・参考
8
+
9
+ 作業ディレクトリ:「~/labo」
10
+ 「$ 〜」: コマンド
11
+
12
+  ※「$」は入力不要
13
+
14
+ ・vi操作方法
15
+ 「$ vi ファイル名」
16
+ [ i ]:入力モードへ移行
17
+ [ ESC ]:コマンドモードへ移行
18
+ [ :wq ]:保存して終了
19
+
20
+ === リポジトリをローカルへ作成
21
+
22
+ $ cd ~/labo
23
+
24
+ $ git clone git@github.com:shu0115/APP_NAME.git
25
+ $ cd APP_NAME
26
+
27
+ === Twitterアプリ登録
28
+
29
+ https://dev.twitter.com/apps/new
30
+
31
+ Name: [ (アプリケーションの名前) ]
32
+ Description: [ (アプリケーションの説明) ]
33
+ WebSite: [ http://0.0.0.0:3000/ ]
34
+ Callback URL: [ http://0.0.0.0:3000/ ] ※登録しないと動かない
35
+
36
+ □ Yes, I agree <= チェック
37
+
38
+ CAPTCHA入力後「Create your Twitter application」を押下
39
+
40
+ === ローカル用Twitterキー設定
41
+
42
+ $ vi config/initializers/local_setting.rb
43
+ -----
44
+ # Twitter OAuth Local Setting
45
+ ENV['TWITTER_KEY'] = "YOUR_CONSUMER_KEY"
46
+ ENV['TWITTER_SECRET'] = "YOUR_CONSUMER_SECRET"
47
+ -----
48
+
49
+  ※Twitterアプリ登録完了後に表示された「Consumer key」を「YOUR_CONSUMER_KEY」に、「Consumer secret」を「YOUR_CONSUMER_SECRET」にそれぞれ入力する
50
+
51
+ === 定数定義設定
52
+
53
+ ・アプリ名設定
54
+
55
+ $ vi config/initializers/constants.rb
56
+ -----
57
+ # ---------- 共通定義 ---------- #
58
+ APP_NAME = "YOUR_APP_NAME"
59
+ -----
60
+
61
+  ※「YOUR_APP_NAME」を自分のアプリ名に修正
62
+
63
+ === Rails起動
64
+
65
+ ・Gemインストール
66
+
67
+ bundle install
68
+
69
+ ・ローカルDB作成
70
+
71
+ rake db:migrate
72
+
73
+ ・ローカルサーバ起動
74
+
75
+ bundle exec rails s
76
+
77
+ ・ページアクセス
78
+
79
+ http://0.0.0.0:3000/
80
+
81
+ = Copyright
82
+
83
+ Copyright (c) 2012 Shun Matsumoto.
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ class ApplicationController < ActionController::Base
3
+
4
+ protect_from_forgery
5
+
6
+ # セッション有効期限延長
7
+ before_filter :reset_session_expires
8
+
9
+ private
10
+
11
+ #-----------------------#
12
+ # reset_session_expires #
13
+ #-----------------------#
14
+ # セッション期限延長
15
+ def reset_session_expires
16
+ request.session_options[:expire_after] = 2.weeks
17
+ end
18
+
19
+ #--------------#
20
+ # current_user #
21
+ #--------------#
22
+ def current_user
23
+ @current_user ||= User.where( id: session[:user_id] ).first
24
+ end
25
+
26
+ helper_method :current_user
27
+
28
+ end
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
  class User < ActiveRecord::Base
3
- attr_accessible :provider, :uid, :name, :screen_name, :image, :token, :secret
3
+ # attr_accessible :title, :body
4
4
 
5
5
  private
6
6
 
@@ -18,11 +18,6 @@ class User < ActiveRecord::Base
18
18
  user[:image] = auth["info"]["image"]
19
19
  end
20
20
 
21
- unless auth["credentials"].blank?
22
- user.token = auth['credentials']['token']
23
- user.secret = auth['credentials']['secret']
24
- end
25
-
26
21
  user.save
27
22
 
28
23
  return user
@@ -0,0 +1,29 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= APP_NAME %></title>
5
+ <%= stylesheet_link_tag "application", :media => "all" %>
6
+ <%= javascript_include_tag "application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%# ----- 追加 ----- %>
12
+ <% if current_user %>
13
+ <%# ログイン済み %>
14
+ <%= current_user.name %> :
15
+ || <%= link_to "Logout" , logout_path %>
16
+ <% else %>
17
+ <%# 未ログイン %>
18
+ <%= link_to "Login", "/auth/#{DEFAULT_PROVIDER}" %>
19
+ <% end %>
20
+
21
+ <%# 通知/エラーメッセージ %>
22
+ <%= simple_format( flash[:notice], style: "color: green;" ) unless flash[:notice].blank? %>
23
+ <%= simple_format( flash[:alert], style: "color: red;" ) unless flash[:alert].blank? %>
24
+ <%# ----- /追加 ----- %>
25
+
26
+ <%= yield %>
27
+
28
+ </body>
29
+ </html>
@@ -0,0 +1,2 @@
1
+
2
+ <h1>Welcome to <%= APP_NAME %></h1>
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+
3
+ # ---------- 環境別定義 ---------- #
4
+ if Rails.env.production?
5
+ #----------------#
6
+ # Production環境 #
7
+ #----------------#
8
+ DEFAULT_PROVIDER = "twitter"
9
+ # DEFAULT_PROVIDER = "facebook"
10
+ # DEFAULT_PROVIDER = "github"
11
+ else
12
+ #--------------------#
13
+ # Production環境以外 #
14
+ #--------------------#
15
+ # DEFAULT_PROVIDER = "developer"
16
+ DEFAULT_PROVIDER = "twitter"
17
+ # DEFAULT_PROVIDER = "facebook"
18
+ # DEFAULT_PROVIDER = "github"
19
+ end
20
+
21
+ # ---------- 共通定義 ---------- #
22
+ APP_NAME = "YOUR_APP_NAME"
@@ -0,0 +1,2 @@
1
+ ENV['TWITTER_KEY'] = "YOUR_CONSUMER_KEY"
2
+ ENV['TWITTER_SECRET'] = "YOUR_CONSUMER_SECRET"
@@ -0,0 +1,4 @@
1
+ Rails.application.config.middleware.use OmniAuth::Builder do
2
+ provider :developer unless Rails.env.production?
3
+ provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET']
4
+ end
@@ -1,13 +1,13 @@
1
1
  class CreateUsers < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :users do |t|
4
+ # ----- 追加 ----- #
4
5
  t.string :provider
5
6
  t.string :uid
6
7
  t.string :name
7
8
  t.string :screen_name
8
9
  t.string :image
9
- t.string :token
10
- t.string :secret
10
+ # ----- /追加 ----- #
11
11
 
12
12
  t.timestamps
13
13
  end
@@ -1,17 +1,76 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
1
4
  # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/omniauth-scaffold/version', __FILE__)
3
5
 
4
- Gem::Specification.new do |gem|
5
- gem.authors = ["shu0115"]
6
- gem.email = ["raisondetre0115@gmail.com"]
7
- gem.description = %q{Scaffold for OmniAuth.}
8
- gem.summary = %q{OmniAuth Scaffold}
9
- gem.homepage = "https://github.com/shu0115/omniauth-scaffold"
6
+ Gem::Specification.new do |s|
7
+ s.name = "omniauth-scaffold"
8
+ s.version = "0.1.0"
10
9
 
11
- gem.files = `git ls-files`.split($\)
12
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
- gem.name = "omniauth-scaffold"
15
- gem.require_paths = ["lib"]
16
- gem.version = Omniauth::Scaffold::VERSION
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Shun Matsumoto"]
12
+ s.date = "2012-04-26"
13
+ s.description = "Scaffold to use OmniAuth."
14
+ s.email = "s.matsumoto0115@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/generators/omniauth/scaffold/scaffold_generator.rb",
28
+ "lib/generators/omniauth/scaffold/templates/README.rdoc",
29
+ "lib/generators/omniauth/scaffold/templates/app/controllers/application_controller.rb",
30
+ "lib/generators/omniauth/scaffold/templates/app/controllers/sessions_controller.rb",
31
+ "lib/generators/omniauth/scaffold/templates/app/controllers/top_controller.rb",
32
+ "lib/generators/omniauth/scaffold/templates/app/models/user.rb",
33
+ "lib/generators/omniauth/scaffold/templates/app/views/layouts/application.html.erb",
34
+ "lib/generators/omniauth/scaffold/templates/app/views/top/index.html.erb",
35
+ "lib/generators/omniauth/scaffold/templates/config/initializers/constants.rb",
36
+ "lib/generators/omniauth/scaffold/templates/config/initializers/local_setting.rb",
37
+ "lib/generators/omniauth/scaffold/templates/config/initializers/omniauth.rb",
38
+ "lib/generators/omniauth/scaffold/templates/db/migrate/create_users.rb",
39
+ "omniauth-scaffold.gemspec",
40
+ "spec/omniauth-scaffold_spec.rb",
41
+ "spec/spec_helper.rb"
42
+ ]
43
+ s.homepage = "http://github.com/shu0115/omniauth-scaffold"
44
+ s.licenses = ["MIT"]
45
+ s.require_paths = ["lib"]
46
+ s.rubygems_version = "1.8.23"
47
+ s.summary = "OmniAuth Scaffold"
48
+
49
+ if s.respond_to? :specification_version then
50
+ s.specification_version = 3
51
+
52
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
+ s.add_runtime_dependency(%q<omniauth-twitter>, [">= 0"])
54
+ s.add_runtime_dependency(%q<omniauth-github>, [">= 0"])
55
+ s.add_runtime_dependency(%q<omniauth-facebook>, [">= 0"])
56
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
57
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
58
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
59
+ else
60
+ s.add_dependency(%q<omniauth-twitter>, [">= 0"])
61
+ s.add_dependency(%q<omniauth-github>, [">= 0"])
62
+ s.add_dependency(%q<omniauth-facebook>, [">= 0"])
63
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
64
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
65
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
66
+ end
67
+ else
68
+ s.add_dependency(%q<omniauth-twitter>, [">= 0"])
69
+ s.add_dependency(%q<omniauth-github>, [">= 0"])
70
+ s.add_dependency(%q<omniauth-facebook>, [">= 0"])
71
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
72
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
73
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
74
+ end
17
75
  end
76
+
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "OmniauthScaffold" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'omniauth-scaffold'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end