wired 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 75a42c0378f69059ddf6c380b5f774104e9848b0
4
- data.tar.gz: ace85e31fdc62ded6053df508890dc32587a90fd
3
+ metadata.gz: be52f22aba7b9c384b79d16b0b40c28135649a23
4
+ data.tar.gz: 535b2ade31c5b4719660e9bfbe13bff88a83e9f6
5
5
  SHA512:
6
- metadata.gz: b3687404a68b0de91cc8f302fc79ff4ebf5f89daff9a0255734ba3875031e98899c9e70af27dec650487ef517468342518d55a5f42ba1616a524958130959f40
7
- data.tar.gz: af62779ca135d3692e2498848abbfb905d0f8a0667cc1ca9fc0b16dc5cae5acebbc45fd5fdb432361622f4880da70a9d631e756a0fa9bddfe5bd6d03b83fe4de
6
+ metadata.gz: 1422cbb691852041844e4a5bfd1abeba06cf66264e7cc39dfe331e9fee657b683e6b845402cf5cfb58e7a159bd2ef5a904d4d14388e8483ba7666b431a9f4f72
7
+ data.tar.gz: a69f16b502dd0a0db644d376c3550d3af58d115242e1bb24c87e9598d366faa4bc751d2db2bc59599848b0ade7ba787a08ac6814e600b72c74d985cd4c081108
data/README.md CHANGED
@@ -15,10 +15,11 @@ Installation
15
15
 
16
16
  Usage
17
17
  ---
18
- `wired app_name`
18
+ `wired APP_NAME --generator GENERATOR_NAME`
19
19
 
20
20
  Params additional to the default rails generator params are:
21
21
 
22
+ * --generator GENERATOR _uses the specified generator, can be: [facebook]_
22
23
  * --skip-heroku _Skips the creation of the Heroku apps_
23
24
  * --skip-github _Skips the creation of a Github repository_
24
25
 
data/bin/wired CHANGED
@@ -1,18 +1,33 @@
1
1
  #!/usr/bin/env ruby
2
- #
3
- if ARGV.any?
4
- if ARGV[0].length < 3 || ARGV[0].length > 20
5
- puts "Name needs to be between 3 and 20 characters. (#{ARGV[0]} is #{ARGV[0].length})"
6
- exit
2
+
3
+ generator_type = ''
4
+
5
+ if ARGV.any?
6
+ ARGV.each_with_index do |argument, index|
7
+ if argument == '--generator'
8
+ generator_type = ARGV[index+1]
9
+ ARGV.delete '--generator'
10
+ ARGV.delete generator_type
11
+ end
7
12
  end
8
13
  end
9
14
 
10
15
  require File.expand_path(File.join('..', 'lib', 'wired', 'generators', 'app_generator'), File.dirname(__FILE__))
16
+ require File.expand_path(File.join('..', 'lib', 'wired', 'generators', 'facebook_generator'), File.dirname(__FILE__))
11
17
  require File.expand_path(File.join('..', 'lib', 'wired', 'actions'), File.dirname(__FILE__))
12
- require File.expand_path(File.join('..', 'lib', 'wired', 'app_builder'), File.dirname(__FILE__))
18
+ require File.expand_path(File.join('..', 'lib', 'wired', 'builders', 'app_builder'), File.dirname(__FILE__))
19
+ require File.expand_path(File.join('..', 'lib', 'wired', 'builders', 'facebook_builder'), File.dirname(__FILE__))
13
20
 
14
21
  templates_root = File.expand_path(File.join("..", "templates"), File.dirname(__FILE__))
15
- Wired::AppGenerator.source_root templates_root
16
- Wired::AppGenerator.source_paths << Rails::Generators::AppGenerator.source_root << templates_root
17
22
 
18
- Wired::AppGenerator.start
23
+ case generator_type
24
+ when 'facebook'
25
+ generator = Wired::FacebookGenerator
26
+ else
27
+ generator = Wired::AppGenerator
28
+ end
29
+
30
+ generator.source_root templates_root
31
+ generator.source_paths << Rails::Generators::AppGenerator.source_root << templates_root
32
+
33
+ generator.start
@@ -0,0 +1,158 @@
1
+ module Wired
2
+ class AppBuilder < Rails::AppBuilder
3
+ include Wired::Actions
4
+
5
+ def readme
6
+ template 'README.md.erb', 'README.md'
7
+ end
8
+
9
+ def remove_doc_folder
10
+ remove_dir 'doc'
11
+ end
12
+
13
+ def remove_public_index
14
+ remove_file 'public/index.html'
15
+ end
16
+
17
+ def remove_rails_logo_image
18
+ remove_file 'app/assets/images/rails.png'
19
+ end
20
+
21
+ def remove_turbo_links
22
+ replace_in_file "app/assets/javascripts/application.js", /\/\/= require turbolinks\n/, ''
23
+ end
24
+
25
+ def replace_gemfile
26
+ remove_file 'Gemfile'
27
+ copy_file 'Gemfile_clean', 'Gemfile'
28
+ end
29
+
30
+ def set_ruby_to_version_being_used
31
+ inject_into_file 'Gemfile', "\n\nruby '#{RUBY_VERSION}'",
32
+ after: /source 'https:\/\/rubygems.org'/
33
+ end
34
+
35
+ def setup_database_config
36
+ template 'database.yml.erb', 'config/database.yml', :force => true
37
+ end
38
+
39
+ def create_database
40
+ bundle_command 'exec rake db:create'
41
+ end
42
+
43
+ def create_partials_directory
44
+ empty_directory 'app/views/application'
45
+ end
46
+
47
+ def create_shared_flashes
48
+ copy_file '_flashes.html.erb',
49
+ 'app/views/application/_flashes.html.erb'
50
+ end
51
+
52
+ def create_application_layout
53
+ template 'layout.html.erb.erb',
54
+ 'app/views/layouts/application.html.erb',
55
+ :force => true
56
+ end
57
+
58
+ def configure_time_zone
59
+ config = <<-RUBY
60
+ config.time_zone = 'Amsterdam'
61
+
62
+ RUBY
63
+ inject_into_class 'config/application.rb', 'Application', config
64
+ end
65
+
66
+ def set_asset_sync
67
+ config = <<-RUBY
68
+ config.action_controller.asset_host = ENV["ASSET_HOST"]
69
+ RUBY
70
+ inject_into_class 'config/application.rb', 'Application', config
71
+ inject_into_file 'config/environments/production.rb', config, :after => "config.action_controller.asset_host = \"http://assets.example.com\"\n"
72
+ end
73
+
74
+ def customize_error_pages
75
+ meta_tags =<<-EOS
76
+ <meta charset='utf-8' />
77
+ EOS
78
+
79
+ %w(500 404 422).each do |page|
80
+ inject_into_file "public/#{page}.html", meta_tags, :after => "<head>\n"
81
+ replace_in_file "public/#{page}.html", /<!--.+-->\n/, ''
82
+ end
83
+ end
84
+
85
+ def remove_routes_comment_lines
86
+ replace_in_file 'config/routes.rb',
87
+ /Application\.routes\.draw do.*end/m,
88
+ "Application.routes.draw do\nend"
89
+ end
90
+
91
+ def gitignore_files
92
+ concat_file 'wired_gitignore', '.gitignore'
93
+ [
94
+ 'app/models',
95
+ 'app/assets/images',
96
+ 'app/views/pages',
97
+ 'db/migrate',
98
+ 'log',
99
+ 'spec/support',
100
+ 'spec/lib',
101
+ 'spec/models',
102
+ 'spec/views',
103
+ 'spec/controllers',
104
+ 'spec/helpers',
105
+ 'spec/support/matchers',
106
+ 'spec/support/mixins',
107
+ 'spec/support/shared_examples'
108
+ ].each do |dir|
109
+ empty_directory_with_keep_file dir
110
+ end
111
+ end
112
+
113
+ def setup_git
114
+ run 'git init'
115
+ run "git add ."
116
+ run "git commit -m 'initial commit'"
117
+ run "git checkout -b develop"
118
+ end
119
+
120
+ def deploy_github
121
+ github_result = run "hub create -p wirelab/#{app_name_clean}"
122
+ if github_result
123
+ puts "Github repo wirelab/#{app_name_clean} created."
124
+ else
125
+ puts "Github creation wirelab/#{app_name_clean} failed."
126
+ puts "Wired generation halted due to error."
127
+ puts "You might want to remove the created Rails app and retry."
128
+ exit
129
+ end
130
+ run "git push --all"
131
+ end
132
+
133
+ def powder_setup
134
+ run 'powder link'
135
+ end
136
+
137
+ def create_heroku_apps
138
+ %w(staging acceptance production).each do |env|
139
+ heroku_name = (env == "production") ? app_name_clean : "#{app_name_clean}-#{env}"
140
+ heroku_result = run "heroku create #{heroku_name} --remote=#{env} --region eu"
141
+
142
+ if heroku_result
143
+ puts "Heroku app #{heroku_name} created."
144
+ else
145
+ puts "Heroku app #{heroku_name} failed."
146
+ puts "Wired generation halted due to error."
147
+ puts "You might want to remove the GitHub repo and previously created heroku apps and retry."
148
+ exit
149
+ end
150
+ if env == 'production'
151
+ %w(papertrail pgbackups newrelic memcachier).each do |addon|
152
+ run "heroku addons:add #{addon} --remote=#{env}"
153
+ end
154
+ end
155
+ end
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,131 @@
1
+ module Wired
2
+ class FacebookBuilder < AppBuilder
3
+ def update_readme
4
+ append_file "README.md", "* FB_APP_ID\n* FB_PAGE_NAME"
5
+ facebook_readme =<<-FACEBOOK
6
+ # Facebook Apps
7
+ * [Production](https://developers.facebook.com/apps/FB_APP_ID) _FB_APP_ID_
8
+ * [Acceptance](https://developers.facebook.com/apps/) _FB_APP_ID_
9
+ * [Staging](https://developers.facebook.com/apps/FB_APP_ID) _FB_APP_ID_
10
+ * [Development](https://developers.facebook.com/apps/FB_APP_ID) _FB_APP_ID_
11
+
12
+ ***
13
+
14
+ FACEBOOK
15
+ inject_into_file "README.md", facebook_readme, :before => "# Variables\n"
16
+ end
17
+
18
+ def add_routes
19
+ facebook_routes =<<-ROUTES
20
+ root :to => 'tab#home'
21
+ post '/' => 'tab#home'
22
+
23
+ get 'cookie' => 'sessions#cookie', as: 'cookie'
24
+ ROUTES
25
+ inject_into_file "config/routes.rb", facebook_routes, :before => "end"
26
+ end
27
+
28
+ def add_controllers
29
+ copy_file 'facebook/tab_controller.rb', 'app/controllers/tab_controller.rb'
30
+ end
31
+
32
+ def add_stylesheets
33
+ say 'Copy stylesheets'
34
+ copy_file 'facebook/reset.css.scss', 'app/assets/stylesheets/resets.css.scss'
35
+ copy_file 'facebook/_variables.css.scss', 'app/assets/stylesheets/_variables.css.scss'
36
+ end
37
+
38
+ def add_channel_file
39
+ copy_file 'facebook/channel.html', 'public/channel.html'
40
+ end
41
+
42
+ def create_views
43
+ empty_directory 'app/views/tab'
44
+ home_page =<<-HOME
45
+ Home pagina, show fangate: <%= @show_fangate %>
46
+ HOME
47
+ File.open("app/views/tab/home.html.erb", 'w') { |file| file.write(home_page) }
48
+ end
49
+
50
+ def add_cookie_fix
51
+ copy_file 'facebook/sessions_controller.rb', 'app/controllers/sessions_controller.rb'
52
+ copy_file 'facebook/cookie.html.erb', 'app/views/sessions/cookie.html.erb'
53
+ facebook_cookie_fix =<<-COOKIE_FIX
54
+ helper_method :allow_iframe_requests
55
+ helper_method :current_user
56
+ before_filter :cookie_fix
57
+ before_filter :add_global_javascript_variables
58
+ before_filter :set_origin
59
+ before_filter :set_p3p
60
+
61
+ def cookie
62
+ # third party cookie fix
63
+ end
64
+
65
+ private
66
+ def set_p3p
67
+ headers['P3P'] = 'CP="ALL DSP COR CURa ADMa DEVa OUR IND COM NAV"'
68
+ end
69
+
70
+ def set_origin
71
+ response.headers["Access-Control-Allow-Origin: facebook.com"]
72
+ end
73
+
74
+ def current_user
75
+ @current_user ||= User.find_by_fbid session[:fbid]
76
+ end
77
+
78
+ def cookie_fix
79
+ cookies[:cookie_fix] = "cookie" #third party cookie fix
80
+ end
81
+
82
+ def allow_iframe_requests
83
+ response.headers.delete 'X-Frame-Options'
84
+ end
85
+
86
+ def add_global_javascript_variables
87
+ Gon.global.facebook = { 'app_id' => ENV["FB_APP_ID"] }
88
+ Gon.global.current_user = current_user.fbid if current_user.present?
89
+ end
90
+ COOKIE_FIX
91
+ inject_into_file "app/controllers/application_controller.rb", facebook_cookie_fix, :before => "end"
92
+ copy_file 'facebook/cookie_fix.js.coffee', 'app/assets/javascripts/cookie_fix.js.coffee'
93
+ copy_file 'facebook/facebook.js.coffee', 'app/assets/javascripts/facebook.js.coffee'
94
+ end
95
+
96
+ def add_javascripts_to_manifest
97
+ inject_into_file 'app/assets/javascripts/application.js', "//= require facebook\n", :before => '//= require_tree .'
98
+ inject_into_file 'app/assets/javascripts/application.js', "//= require cookie_fix\n", :before => '//= require_tree .'
99
+ end
100
+
101
+ def generate_user
102
+ user_token_method =<<-USER_TOKEN_METHOD
103
+ def self.create_or_update_by_access_token(access_token)
104
+ @graph = Koala::Facebook::API.new access_token
105
+ profile = @graph.get_object 'me'
106
+ user = where(fbid: profile['id']).first_or_initialize
107
+ user.first_name = profile['first_name']
108
+ user.last_name = "\#{profile['middle_name']} \#{profile['last_name']}".strip
109
+ user.email = profile['email']
110
+ user
111
+ end
112
+ USER_TOKEN_METHOD
113
+ run 'rails g model User first_name last_name email fbid'
114
+ inject_into_file "app/models/user.rb", user_token_method, :before => "end"
115
+ copy_file 'facebook/users_controller.rb', 'app/controllers/users_controller.rb'
116
+ end
117
+
118
+ def run_migrations
119
+ bundle_command 'exec rake db:migrate'
120
+ end
121
+
122
+ def powder_setup
123
+ super
124
+ copy_file 'facebook/env', '.env'
125
+ end
126
+
127
+ def create_initializers
128
+ #do nothing
129
+ end
130
+ end
131
+ end
@@ -9,13 +9,19 @@ module Wired
9
9
  class_option 'skip-github', type: :boolean, default: false,
10
10
  desc: 'Skips the creation of a Github repository'
11
11
 
12
- @@type = ""
13
-
14
12
  def finish_template
15
13
  invoke :wired_customization
16
14
  super
17
15
  end
18
16
 
17
+ def app_name_clean
18
+ clean = app_name.parameterize
19
+ clean = clean.gsub '_', '-'
20
+ clean = "wl_#{clean}" if clean.length < 3
21
+ clean = clean[0..19] if clean.length > 20
22
+ clean
23
+ end
24
+
19
25
  def wired_customization
20
26
  invoke :remove_files_we_dont_need
21
27
  invoke :customize_gemfile
@@ -33,44 +39,6 @@ module Wired
33
39
 
34
40
  def application_setup
35
41
  build :powder_setup
36
-
37
- choices = ["facebook", "teaser"]
38
- type = ask "Applicationtype? (#{choices.join ', '})"
39
- if choices.include? type
40
- @@type = type
41
- case type
42
- when "facebook"
43
- say "Setting up a Facebook application"
44
- invoke :facebook_setup
45
- when "teaser"
46
- say "Setting up a teaser with email registration"
47
- #invoke :teaser_setup
48
- end
49
- else
50
- say "Applicationtype should be one of: #{choices.join ', '}"
51
- invoke :application_setup
52
- end
53
- end
54
-
55
- def facebook_setup
56
- if @@type == "facebook"
57
- build :update_readme_for_facebook
58
- build :add_facebook_routes
59
- build :add_facebook_channel_file
60
- build :add_facebook_controllers
61
- build :add_facebook_stylesheets
62
- build :create_facebook_views
63
- build :add_cookie_fix
64
- build :add_javascripts_to_manifest
65
- build :generate_user_model
66
- build :run_migrations
67
- end
68
- end
69
-
70
- def teaser_setup
71
- if @@type == "teaser"
72
- say "There's no teaser setup yet"
73
- end
74
42
  end
75
43
 
76
44
  def remove_files_we_dont_need
@@ -139,13 +107,6 @@ module Wired
139
107
 
140
108
  def todo
141
109
  say "\n ------TODO------"
142
- case @@type
143
- when "facebook"
144
- say "* Create Facebook apps on https://developers.facebook.com"
145
- say "* Update FB_APP_ID env variables locally, on Heroku and in the readme"
146
- when "teaser"
147
- say "* Build entire app"
148
- end
149
110
  end
150
111
 
151
112
  def run_bundle
@@ -155,7 +116,7 @@ module Wired
155
116
  protected
156
117
 
157
118
  def get_builder_class
158
- Wired::AppBuilder
119
+ AppBuilder
159
120
  end
160
121
  end
161
122
  end
@@ -0,0 +1,30 @@
1
+ module Wired
2
+ class FacebookGenerator < AppGenerator
3
+ def application_setup
4
+ super
5
+ build :update_readme
6
+ build :add_routes
7
+ build :add_channel_file
8
+ build :add_controllers
9
+ build :add_stylesheets
10
+ build :create_views
11
+ build :add_cookie_fix
12
+ build :add_javascripts_to_manifest
13
+ build :generate_user
14
+ build :run_migrations
15
+ build :create_initializers
16
+ end
17
+
18
+ def todo
19
+ super
20
+ say "* Create Facebook apps on https://developers.facebook.com"
21
+ say "* Update FB_APP_ID env variables locally, on Heroku and in the readme"
22
+ end
23
+
24
+ protected
25
+
26
+ def get_builder_class
27
+ FacebookBuilder
28
+ end
29
+ end
30
+ end
data/lib/wired/version.rb CHANGED
@@ -1,3 +1,3 @@
1
- module Wired
2
- VERSION = '0.1.0'
1
+ module Wired
2
+ VERSION = '0.1.1'
3
3
  end
@@ -16,4 +16,3 @@
16
16
  * FOG_DIRECTORY
17
17
  * FOG_PROVIDER
18
18
  * GOOGLE_ANALYTICS_ID
19
-
@@ -16,4 +16,25 @@ window.fbAsyncInit = ->
16
16
  channelUrl : window.location.protocol + '//' + window.location.hostname + '/channel.html'
17
17
  status : true
18
18
  xfbml : true
19
- cookie: true
19
+ cookie: true
20
+
21
+ $ ->
22
+ $('a#facebook-login').click (event) ->
23
+ event.preventDefault()
24
+ unless $('a#facebook-login').hasClass 'submitting'
25
+ $('a#facebook-login').addClass 'submitting'
26
+ FB.login (response) ->
27
+ if response.authResponse
28
+ $.ajax '/users',
29
+ type: 'POST'
30
+ dataType: 'json'
31
+ data:
32
+ user:
33
+ access_token: response.authResponse.accessToken
34
+ success: (response) ->
35
+ window.location = response.redirect
36
+ error: (event) ->
37
+ $('a#facebook-login').removeClass 'submitting'
38
+ alert "Er is iets mis gegaan, probeer het later nog eens!"
39
+ , scope: 'email'
40
+ false
@@ -1,21 +1,20 @@
1
1
  class TabController < ApplicationController
2
2
  include Mobylette::RespondToMobileRequests
3
3
  protect_from_forgery except: [:home]
4
- after_action :allow_facebook_iframe
5
4
 
6
- def home
5
+ def home
7
6
  @liked = false
8
7
  if params[:signed_request]
9
8
  set_fbid_session_if_authenticated_before_with_facebook
10
9
  @show_fangate = !liked?
11
10
  else
12
11
  @show_fangate = false
13
- redirect_to "http://www.facebook.com/#{ENV['FB_PAGE_NAME']}/app_#{ENV['FB_APP_ID']}" unless is_mobile_view?
12
+ redirect_to "http://www.facebook.com/#{ENV['FB_PAGE_NAME']}/app_#{ENV['FB_APP_ID']}" unless is_mobile_request?
14
13
  end
15
14
  end
16
15
 
17
16
  private
18
- def liked?
17
+ def liked?
19
18
  if params[:signed_request]
20
19
  encoded_request = params[:signed_request]
21
20
  json_request = decode_data(encoded_request)
@@ -31,7 +30,7 @@ class TabController < ApplicationController
31
30
  encoded_request = params[:signed_request]
32
31
  json_request = decode_data(encoded_request)
33
32
  signed_request = JSON.parse(json_request)
34
-
33
+
35
34
  session[:fbid] = signed_request['user_id']
36
35
  end
37
36
  end
@@ -46,8 +45,4 @@ class TabController < ApplicationController
46
45
  encoded_sig, payload = signed_request.split('.')
47
46
  data = base64_url_decode(payload)
48
47
  end
49
-
50
- def allow_facebook_iframe
51
- response.headers['X-Frame-Options'] = "ALLOW-FROM https://www.facebook.com"
52
- end
53
48
  end
@@ -0,0 +1,20 @@
1
+ class UsersController < ApplicationController
2
+ respond_to :json
3
+
4
+ def create
5
+ @user = User.create_or_update_by_access_token user_params[:access_token]
6
+
7
+ #todo catch koala error if access_token invalid
8
+ @user.entry = Entry.new if @user.entry.nil?
9
+ if @user.save
10
+ session[:id] = @user.id
11
+ render json: {redirect: edit_vote_path(@user.entry)}, status: :ok
12
+ else
13
+ render json: {}, status: :unprocessable_entity
14
+ end
15
+ end
16
+
17
+ def user_params
18
+ params.require(:user).permit(:access_token)
19
+ end
20
+ end
data/wired.gemspec CHANGED
@@ -5,13 +5,13 @@ require 'date'
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = 'wired'
8
- s.version = Wired::VERSION
9
- s.date = Date.today.strftime('%Y-%m-%d')
8
+ s.version = Wired::VERSION
9
+ s.date = Date.today.strftime('%Y-%m-%d')
10
10
  s.summary = 'Wirelab Generator'
11
11
  s.description = 'The Wirelab application generator'
12
12
  s.authors = ['Wirelab Creative']
13
13
  s.email = 'bart@wirelab.nl'
14
- s.homepage = 'https://github.com/Wirelab/wired'
14
+ s.homepage = 'https://github.com/wirelab/wired'
15
15
  s.files = `git ls-files`.split("\n").
16
16
  reject { |file| file =~ /^\./ }.
17
17
  reject { |file| file =~ /^(rdoc|pkg)/ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wired
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wirelab Creative
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-12 00:00:00.000000000 Z
11
+ date: 2013-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -66,8 +66,10 @@ files:
66
66
  - Rakefile
67
67
  - bin/wired
68
68
  - lib/wired/actions.rb
69
- - lib/wired/app_builder.rb
69
+ - lib/wired/builders/app_builder.rb
70
+ - lib/wired/builders/facebook_builder.rb
70
71
  - lib/wired/generators/app_generator.rb
72
+ - lib/wired/generators/facebook_generator.rb
71
73
  - lib/wired/version.rb
72
74
  - templates/Gemfile_clean
73
75
  - templates/README.md.erb
@@ -79,15 +81,15 @@ files:
79
81
  - templates/facebook/cookie.html.erb
80
82
  - templates/facebook/cookie_fix.js.coffee
81
83
  - templates/facebook/env
82
- - templates/facebook/export_controller.rb
83
84
  - templates/facebook/facebook.js.coffee
84
85
  - templates/facebook/reset.css.scss
85
86
  - templates/facebook/sessions_controller.rb
86
87
  - templates/facebook/tab_controller.rb
88
+ - templates/facebook/users_controller.rb
87
89
  - templates/layout.html.erb.erb
88
90
  - templates/wired_gitignore
89
91
  - wired.gemspec
90
- homepage: https://github.com/Wirelab/wired
92
+ homepage: https://github.com/wirelab/wired
91
93
  licenses:
92
94
  - MIT
93
95
  metadata: {}
@@ -1,264 +0,0 @@
1
- module Wired
2
- class AppBuilder < Rails::AppBuilder
3
- include Wired::Actions
4
-
5
- def readme
6
- template 'README.md.erb', 'README.md'
7
- end
8
-
9
- def remove_doc_folder
10
- remove_dir 'doc'
11
- end
12
-
13
- def remove_public_index
14
- remove_file 'public/index.html'
15
- end
16
-
17
- def remove_rails_logo_image
18
- remove_file 'app/assets/images/rails.png'
19
- end
20
-
21
- def remove_turbo_links
22
- replace_in_file "app/assets/javascripts/application.js", /\/\/= require turbolinks\n/, ''
23
- end
24
-
25
- def replace_gemfile
26
- remove_file 'Gemfile'
27
- copy_file 'Gemfile_clean', 'Gemfile'
28
- end
29
-
30
- def set_ruby_to_version_being_used
31
- inject_into_file 'Gemfile', "\n\nruby '#{RUBY_VERSION}'",
32
- after: /source 'https:\/\/rubygems.org'/
33
- end
34
-
35
- def setup_database_config
36
- template 'database.yml.erb', 'config/database.yml', :force => true
37
- end
38
-
39
- def create_database
40
- bundle_command 'exec rake db:create'
41
- end
42
-
43
- def run_migrations
44
- bundle_command 'exec rake db:migrate'
45
- end
46
-
47
- def generate_user_model
48
- run 'rails g model User name:string email:string fbid:string'
49
- end
50
-
51
- def create_partials_directory
52
- empty_directory 'app/views/application'
53
- end
54
-
55
- def create_shared_flashes
56
- copy_file '_flashes.html.erb',
57
- 'app/views/application/_flashes.html.erb'
58
- end
59
-
60
- def create_application_layout
61
- template 'layout.html.erb.erb',
62
- 'app/views/layouts/application.html.erb',
63
- :force => true
64
- end
65
-
66
- def configure_time_zone
67
- config = <<-RUBY
68
- config.time_zone = 'Amsterdam'
69
-
70
- RUBY
71
- inject_into_class 'config/application.rb', 'Application', config
72
- end
73
-
74
- def set_asset_sync
75
- config = <<-RUBY
76
- config.action_controller.asset_host = ENV["CUSTOM_ASSET_HOST"]
77
- RUBY
78
- inject_into_class 'config/application.rb', 'Application', config
79
- inject_into_file 'config/environments/production.rb', config, :after => "config.action_controller.asset_host = \"http://assets.example.com\"\n"
80
- end
81
-
82
- def customize_error_pages
83
- meta_tags =<<-EOS
84
- <meta charset='utf-8' />
85
- EOS
86
-
87
- %w(500 404 422).each do |page|
88
- inject_into_file "public/#{page}.html", meta_tags, :after => "<head>\n"
89
- replace_in_file "public/#{page}.html", /<!--.+-->\n/, ''
90
- end
91
- end
92
-
93
- def remove_routes_comment_lines
94
- replace_in_file 'config/routes.rb',
95
- /Application\.routes\.draw do.*end/m,
96
- "Application.routes.draw do\nend"
97
- end
98
-
99
- def gitignore_files
100
- concat_file 'wired_gitignore', '.gitignore'
101
- [
102
- 'app/models',
103
- 'app/assets/images',
104
- 'app/views/pages',
105
- 'db/migrate',
106
- 'log',
107
- 'spec/support',
108
- 'spec/lib',
109
- 'spec/models',
110
- 'spec/views',
111
- 'spec/controllers',
112
- 'spec/helpers',
113
- 'spec/support/matchers',
114
- 'spec/support/mixins',
115
- 'spec/support/shared_examples'
116
- ].each do |dir|
117
- empty_directory_with_keep_file dir
118
- end
119
- end
120
-
121
- def setup_git
122
- run 'git init'
123
- run "git add ."
124
- run "git commit -m 'initial commit'"
125
- run "git checkout -b develop"
126
- end
127
-
128
- def deploy_github
129
- github_result = run "hub create -p wirelab/#{app_name}"
130
- if github_result
131
- puts "Github repo wirelab/#{app_name} created."
132
- else
133
- puts "Github creation wirelab/#{app_name} failed."
134
- puts "Wired generation halted due to error."
135
- puts "You might want to remove the created Rails app and retry."
136
- exit
137
- end
138
- run "git push --all"
139
- end
140
-
141
- def powder_setup
142
- run 'powder link'
143
- copy_file 'facebook/env', '.env'
144
- end
145
-
146
- def update_readme_for_facebook
147
- append_file "README.md", "* FB_APP_ID\n* FB_PAGE_NAME"
148
- facebook_readme =<<-FACEBOOK
149
- # Facebook Apps
150
- * [Production](https://developers.facebook.com/apps/FB_APP_ID) _FB_APP_ID_
151
- * [Acceptance](https://developers.facebook.com/apps/) _FB_APP_ID_
152
- * [Staging](https://developers.facebook.com/apps/FB_APP_ID) _FB_APP_ID_
153
- * [Development](https://developers.facebook.com/apps/FB_APP_ID) _FB_APP_ID_
154
-
155
- ***
156
-
157
- FACEBOOK
158
- inject_into_file "README.md", facebook_readme, :before => "# Variables\n"
159
- end
160
-
161
- def add_facebook_routes
162
- facebook_routes =<<-ROUTES
163
- root :to => 'tab#home'
164
- post '/' => 'tab#home'
165
-
166
- get 'cookie' => 'sessions#cookie', as: 'cookie'
167
-
168
- #admin
169
- get 'admin/export' => 'admin#export'
170
- ROUTES
171
- inject_into_file "config/routes.rb", facebook_routes, :before => "end"
172
- end
173
-
174
- def add_facebook_controllers
175
- copy_file 'facebook/tab_controller.rb', 'app/controllers/tab_controller.rb'
176
- copy_file 'facebook/export_controller.rb', 'app/controllers/export_controller.rb'
177
- end
178
-
179
- def add_facebook_stylesheets
180
- say 'Copy stylesheets'
181
- copy_file 'facebook/reset.css.scss', 'app/assets/stylesheets/resets.css.scss'
182
- copy_file 'facebook/_variables.css.scss', 'app/assets/stylesheets/_variables.css.scss'
183
- end
184
-
185
- def add_facebook_channel_file
186
- copy_file 'facebook/channel.html', 'public/channel.html'
187
- end
188
-
189
- def create_facebook_views
190
- empty_directory 'app/views/tab'
191
- home_page =<<-HOME
192
- Home pagina, show fangate: <%= @show_fangate %>
193
- HOME
194
- File.open("app/views/tab/home.html.erb", 'w') { |file| file.write(home_page) }
195
- end
196
-
197
- def add_cookie_fix
198
- copy_file 'facebook/sessions_controller.rb', 'app/controllers/sessions_controller.rb'
199
- copy_file 'facebook/cookie.html.erb', 'app/views/sessions/cookie.html.erb'
200
- facebook_cookie_fix =<<-COOKIE_FIX
201
- helper_method :current_user
202
- before_filter :cookie_fix
203
- before_filter :add_global_javascript_variables
204
- before_filter :set_origin
205
- before_filter :set_p3p
206
-
207
- def cookie
208
- # third party cookie fix
209
- end
210
-
211
- private
212
- def set_p3p
213
- headers['P3P'] = 'CP="ALL DSP COR CURa ADMa DEVa OUR IND COM NAV"'
214
- end
215
-
216
- def set_origin
217
- response.headers["Access-Control-Allow-Origin: facebook.com"]
218
- end
219
-
220
- def current_user
221
- @current_user ||= User.find_by_fbid session[:fbid]
222
- end
223
-
224
- def cookie_fix
225
- cookies[:cookie_fix] = "cookie" #third party cookie fix
226
- end
227
-
228
- def add_global_javascript_variables
229
- Gon.global.facebook = { 'app_id' => ENV["FB_APP_ID"] }
230
- Gon.global.current_user = current_user.fbid if current_user.present?
231
- end
232
- COOKIE_FIX
233
- inject_into_file "app/controllers/application_controller.rb", facebook_cookie_fix, :before => "end"
234
- copy_file 'facebook/cookie_fix.js.coffee', 'app/assets/javascripts/cookie_fix.js.coffee'
235
- copy_file 'facebook/facebook.js.coffee', 'app/assets/javascripts/facebook.js.coffee'
236
- end
237
-
238
- def add_javascripts_to_manifest
239
- inject_into_file 'app/assets/javascripts/application.js', "//= require facebook\n", :before => '//= require_tree .'
240
- inject_into_file 'app/assets/javascripts/application.js', "//= require cookie_fix\n", :before => '//= require_tree .'
241
- end
242
-
243
- def create_heroku_apps
244
- %w(staging acceptance production).each do |env|
245
- heroku_name = (env == "production") ? app_name : "#{app_name}-#{env}"
246
- heroku_result = run "heroku create #{heroku_name} --remote=#{env} --region eu"
247
-
248
- if heroku_result
249
- puts "Heroku app #{heroku_name} created."
250
- else
251
- puts "Heroku app #{heroku_name} failed."
252
- puts "Wired generation halted due to error."
253
- puts "You might want to remove the GitHub repo and previously created heroku apps and retry."
254
- exit
255
- end
256
- if env == 'production'
257
- %w(papertrail pgbackups newrelic memcachier).each do |addon|
258
- run "heroku addons:add #{addon} --remote=#{env}"
259
- end
260
- end
261
- end
262
- end
263
- end
264
- end
@@ -1,13 +0,0 @@
1
- class ExportController < ApplicationController
2
- before_action :authenticate
3
- def index
4
- render 'export', layout: false
5
- end
6
-
7
- private
8
- def authenticate
9
- authenticate_or_request_with_http_basic do |username, password|
10
- username == 'USER_NAME' && password == 'PASSWORD'
11
- end
12
- end
13
- end