pineapples 0.3.34 → 0.3.345

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/bin/pineapples +13 -13
  3. data/lib/pineapples.rb +3 -1
  4. data/lib/pineapples/actions.rb +6 -0
  5. data/lib/pineapples/actions/base/target.rb +41 -91
  6. data/lib/pineapples/actions/bundle.rb +16 -0
  7. data/lib/pineapples/actions/chmod.rb +3 -2
  8. data/lib/pineapples/actions/copy_file.rb +1 -1
  9. data/lib/pineapples/actions/empty_directory.rb +1 -1
  10. data/lib/pineapples/actions/gsub_file.rb +5 -3
  11. data/lib/pineapples/actions/inside.rb +5 -1
  12. data/lib/pineapples/actions/rails/erb_converters.rb +11 -4
  13. data/lib/pineapples/actions/rails/new_hash_syntax_converter.rb +36 -0
  14. data/lib/pineapples/actions/rails/rails.rb +1 -0
  15. data/lib/pineapples/actions/remove_file.rb +28 -28
  16. data/lib/pineapples/actions/shell.rb +43 -9
  17. data/lib/pineapples/app_generator.rb +154 -38
  18. data/lib/pineapples/helpers.rb +31 -0
  19. data/lib/pineapples/parser.rb +42 -37
  20. data/lib/pineapples/setting.rb +155 -155
  21. data/lib/pineapples/settings.rb +31 -31
  22. data/lib/pineapples/templates/.example.env.tt +15 -0
  23. data/lib/pineapples/templates/.gitignore +3 -0
  24. data/lib/pineapples/templates/.simplecov.tt +11 -0
  25. data/lib/pineapples/templates/Gemfile.tt +23 -5
  26. data/lib/pineapples/templates/Procfile +1 -1
  27. data/lib/pineapples/templates/Procfile.dev.tt +2 -0
  28. data/lib/pineapples/templates/app/assets/javascripts/libs.js +4 -2
  29. data/lib/pineapples/templates/app/assets/stylesheets/application.scss +4 -1
  30. data/lib/pineapples/templates/app/controllers/application_controller.rb.tt +0 -2
  31. data/lib/pineapples/templates/app/controllers/auth!=devise!/confirmations_controller.rb +11 -0
  32. data/lib/pineapples/templates/app/controllers/auth!=devise!/passwords_controller.rb.tt +12 -0
  33. data/lib/pineapples/templates/app/controllers/auth!=devise!/registrations_controller.rb.tt +25 -0
  34. data/lib/pineapples/templates/app/controllers/auth!=devise!/sessions_controller.rb.tt +59 -0
  35. data/lib/pineapples/templates/app/models/user!=needs_user_model!.rb.tt +7 -4
  36. data/lib/pineapples/templates/app/policies!=pundit!/application_policy.rb +49 -0
  37. data/lib/pineapples/templates/app/presenters/base_presenter.rb.tt +24 -0
  38. data/lib/pineapples/templates/app/responders/application_responder.rb +9 -0
  39. data/lib/pineapples/templates/app/services/service.rb +7 -0
  40. data/lib/pineapples/templates/app/views/common/_footer.html.erb +3 -3
  41. data/lib/pineapples/templates/app/views/common/_header.html.erb +5 -5
  42. data/lib/pineapples/templates/app/views/layouts/application.html.erb.tt +0 -1
  43. data/lib/pineapples/templates/app/views/pages/home.html.erb +0 -1
  44. data/lib/pineapples/templates/bin/nginx +4 -0
  45. data/lib/pineapples/templates/bin/rails +1 -0
  46. data/lib/pineapples/templates/bin/rspec +19 -0
  47. data/lib/pineapples/templates/bin/setup +111 -21
  48. data/lib/pineapples/templates/config.ru.tt +3 -0
  49. data/lib/pineapples/templates/config/application.rb.tt +3 -3
  50. data/lib/pineapples/templates/config/boot.rb +5 -5
  51. data/lib/pineapples/templates/config/database.yml.tt +1 -1
  52. data/lib/pineapples/templates/config/environments/{development.rb → development.rb.tt} +6 -1
  53. data/lib/pineapples/templates/config/environments/production.rb +1 -1
  54. data/lib/pineapples/templates/config/environments/test.rb +2 -2
  55. data/lib/pineapples/templates/config/i18n-tasks.yml +2 -0
  56. data/lib/pineapples/templates/config/initializers/{carrierwave.rb → carrierwave!=carrierwave!.rb} +22 -22
  57. data/lib/pineapples/templates/config/initializers/devise!=devise!.rb.tt +262 -0
  58. data/lib/pineapples/templates/config/initializers/kaminari.rb +10 -0
  59. data/lib/pineapples/templates/config/initializers/seed_migrations.rb +15 -0
  60. data/lib/pineapples/templates/config/initializers/simple_form.rb +165 -0
  61. data/lib/pineapples/templates/config/locales/devise.en.yml +60 -0
  62. data/lib/pineapples/templates/config/locales/{en.yml → en.yml.tt} +2 -0
  63. data/lib/pineapples/templates/config/locales/kaminari.en.yml +17 -0
  64. data/lib/pineapples/templates/config/locales/simple_form.en.yml +31 -0
  65. data/lib/pineapples/templates/config/nginx.conf.tt +147 -0
  66. data/lib/pineapples/templates/config/puma/development.rb.tt +27 -0
  67. data/lib/pineapples/templates/config/{puma.rb → puma/production.rb} +5 -5
  68. data/lib/pineapples/templates/config/routes.rb.tt +4 -0
  69. data/lib/pineapples/templates/config/spring.rb +4 -0
  70. data/lib/pineapples/templates/lib/devise!=devise!/{ajax_failure.rb → ajax_failure!=ajax_login!.rb} +0 -0
  71. data/lib/pineapples/templates/lib/logging/custom_rack_logger.rb +7 -9
  72. data/lib/pineapples/templates/lib/logging/custom_request_logger.rb +46 -48
  73. data/lib/pineapples/templates/lib/tasks/admin!=user_role_field!.rake +18 -19
  74. data/lib/pineapples/templates/lib/templates/{erb → erb!=erb!}/scaffold/_form.html.erb +0 -0
  75. data/lib/pineapples/templates/lib/templates/haml!=haml!/scaffold/_form.html.haml +9 -0
  76. data/lib/pineapples/templates/lib/templates/slim!=slim!/scaffold/_form.html.slim +9 -0
  77. data/lib/pineapples/templates/spec/i18n_spec.rb +17 -0
  78. data/lib/pineapples/templates/spec/rails_helper.rb +30 -0
  79. data/lib/pineapples/templates/spec/spec_helper.rb +44 -0
  80. data/lib/pineapples/templates/spec/support/capybara.rb +4 -0
  81. data/lib/pineapples/templates/spec/support/database_cleaner.rb +27 -0
  82. data/lib/pineapples/templates/spec/support/email_matchers.rb +17 -0
  83. data/lib/pineapples/templates/spec/support/factory_girl.rb +14 -0
  84. data/lib/pineapples/templates/spec/support/job_helpers.rb +8 -0
  85. data/lib/pineapples/templates/spec/support/matchers.rb +10 -0
  86. data/lib/pineapples/templates/spec/support/rake_tasks.rb +8 -0
  87. data/lib/pineapples/templates/spec/support/shoulda_matchers.rb +24 -0
  88. data/lib/pineapples/version.rb +2 -2
  89. data/pineapples.gemspec +1 -3
  90. metadata +46 -12
  91. data/lib/pineapples/app_builder.rb +0 -70
  92. data/lib/pineapples/build_tasks/root_files.rb +0 -23
  93. data/lib/pineapples/templates/app/controllers/auth/confirmations_controller.rb +0 -2
@@ -1 +1 @@
1
- web: bundle exec puma -C config/puma.rb
1
+ web: bundle exec puma -C config/puma/production.rb
@@ -0,0 +1,2 @@
1
+ nginx: bin/nginx -c <%= app_root %>/config/nginx.conf
2
+ puma: bundle exec puma
@@ -1,2 +1,4 @@
1
- //= require jquery
2
- //= require jquery_ujs
1
+ //= require jquery
2
+ //= require jquery_ujs
3
+ //= require jquery.remotipart
4
+ //= require moment
@@ -1 +1,4 @@
1
- //= require_self
1
+ //= require_self
2
+ #footer {
3
+ font-size: 12px;
4
+ }
@@ -6,8 +6,6 @@ class ApplicationController < ActionController::Base
6
6
  include Pundit
7
7
 
8
8
  <% end -%>
9
- # Prevent CSRF attacks by raising an exception.
10
- # For APIs, you may want to use :null_session instead.
11
9
  protect_from_forgery with: :exception
12
10
  <% if pundit? -%>
13
11
 
@@ -0,0 +1,11 @@
1
+ class Auth::ConfirmationsController < Devise::ConfirmationsController
2
+
3
+ # most often it's needed to customize url of location to redirect user to after confirmation
4
+
5
+ # protected
6
+
7
+ # def after_confirmation_path_for(resource_name, user)
8
+ # edit_user_registration_path
9
+ # end
10
+
11
+ end
@@ -0,0 +1,12 @@
1
+ class Auth::PasswordsController < Devise::PasswordsController
2
+ <% if ajax_login? -%>
3
+ respond_to :html, :js
4
+ <% end -%>
5
+
6
+ # protected
7
+
8
+ # def after_resetting_password_path_for(user)
9
+ # signed_in_root_path(user)
10
+ # end
11
+
12
+ end
@@ -0,0 +1,25 @@
1
+ class Auth::RegistrationsController < Devise::RegistrationsController
2
+ <% if ajax_login? -%>
3
+ respond_to :html, :js
4
+
5
+ <% end -%>
6
+ # def create
7
+ # super do |user|
8
+ # # Custom create logic goes here
9
+ # end
10
+ # end
11
+
12
+ def sign_up_params
13
+ params.permit(:email,
14
+ :password,
15
+ :password_confirmation)
16
+ end
17
+
18
+ def account_update_params
19
+ params.permit(:email,
20
+ :password,
21
+ :password_confirmation,
22
+ :current_password)
23
+ end
24
+
25
+ end
@@ -0,0 +1,59 @@
1
+ class Auth::SessionsController < Devise::SessionsController
2
+ <% if ajax_login? -%>
3
+ after_action :set_csrf_headers, only: [:create, :destroy]
4
+
5
+ respond_to :html, :js
6
+ <% end -%>
7
+
8
+ # def create
9
+ # super do |user|
10
+ # # Custom log-in logic goes here
11
+ # end
12
+ # end
13
+
14
+ # def destroy
15
+ # # custom before log-out logic
16
+ # super
17
+ # # any extra cleaning code, like deleting flash notice
18
+ # end
19
+
20
+ def sign_in_and_redirect(resource_or_scope, *args)
21
+ options = args.extract_options!
22
+ scope = Devise::Mapping.find_scope!(resource_or_scope)
23
+ user = args.last || resource_or_scope
24
+
25
+ respond_to do |format|
26
+ format.html { super }
27
+ format.js do
28
+ sign_in(scope, user, options) if warden.user(scope) != user
29
+ redirect_url = after_ajax_sign_in_path_for(user)
30
+ redirect_to redirect_url if redirect_url.present?
31
+ end
32
+ end
33
+ end
34
+
35
+ <% if ajax_login? -%>
36
+ protected
37
+
38
+ def after_ajax_sign_in_path_for(user)
39
+ redirect_url = after_sign_in_path_for(user)
40
+ if redirect_url.present
41
+ redirect_url = "#{redirect_url}.js" if redirect_url[-3..-1] != '.js'
42
+ redirect_url += redirect_url.match(/\?/) ? '&' : '?'
43
+ redirect_url += "after_sign_in=true"
44
+ end
45
+ redirect_url
46
+ end
47
+
48
+ def after_sign_in_path_for(user)
49
+ stored_location_for(user) || signed_in_root_path(user)
50
+ end
51
+
52
+ def set_csrf_headers
53
+ if request.xhr?
54
+ response.headers['X-CSRF-Token'] = form_authenticity_token.to_s
55
+ response.headers['X-CSRF-Param'] = request_forgery_protection_token.to_s
56
+ end
57
+ end
58
+ <% end -%>
59
+ end
@@ -1,4 +1,11 @@
1
1
  class User < ActiveRecord::Base
2
+ <% if devise? -%>
3
+ devise :database_authenticatable, :registerable, :recoverable,
4
+ :rememberable, :trackable, :validatable, :confirmable
5
+ # :omniauthable, omniauth_providers: [:facebook]
6
+ # :lockable, :timeoutable
7
+
8
+ <% end -%>
2
9
  <% if user_role_field? -%>
3
10
  as_enum :role, [:guest, :regular, :trusted, :moderator, :admin],
4
11
  source: :role, map: :string, accessor: :whiny
@@ -14,10 +21,6 @@ class User < ActiveRecord::Base
14
21
  def guest?
15
22
  new_record?
16
23
  end
17
-
18
- def regular?
19
- persisted? && role == :regular
20
- end
21
24
  <% end -%>
22
25
 
23
26
  <% if devise? -%>
@@ -0,0 +1,49 @@
1
+ class ApplicationPolicy
2
+ attr_reader :user
3
+
4
+ def initialize(user, model)
5
+ @user = user
6
+ end
7
+
8
+ def index?
9
+ false
10
+ end
11
+
12
+ # def show?
13
+ # scope.where(id: record.id).exists?
14
+ # end
15
+
16
+ def create?
17
+ false
18
+ end
19
+
20
+ def new?
21
+ create?
22
+ end
23
+
24
+ def update?
25
+ false
26
+ end
27
+
28
+ def edit?
29
+ update?
30
+ end
31
+
32
+ def destroy?
33
+ false
34
+ end
35
+
36
+ class Scope
37
+ attr_reader :user, :scope
38
+
39
+ def initialize(user, scope)
40
+ @user = user
41
+ @scope = scope
42
+ end
43
+
44
+ def resolve
45
+ scope
46
+ end
47
+ end
48
+
49
+ end
@@ -0,0 +1,24 @@
1
+ class BasePresenter < SimpleDelegator
2
+
3
+ def initialize(model, view)
4
+ @model = model
5
+ @view = view
6
+ super(model)
7
+ end
8
+
9
+ def class
10
+ __getobj__.class
11
+ end
12
+
13
+ def h
14
+ @view
15
+ end
16
+ <% if pundit? -%>
17
+
18
+ protected
19
+
20
+ def policy(record)
21
+ h.policy(record)
22
+ end
23
+ <% end -%>
24
+ end
@@ -0,0 +1,9 @@
1
+ class ApplicationResponder < ActionController::Responder
2
+ include Responders::FlashResponder
3
+ include Responders::HttpCacheResponder
4
+ # Redirects resources to the collection path (index action) instead
5
+ # of the resource path (show action) for POST/PUT/DELETE requests.
6
+ # include Responders::CollectionResponder
7
+
8
+ # include ModalResponder
9
+ end
@@ -0,0 +1,7 @@
1
+ module Service
2
+
3
+ def self.call(*args)
4
+ new(*args).call
5
+ end
6
+
7
+ end
@@ -1,3 +1,3 @@
1
- <footer class="footer">
2
-
3
- </footer>
1
+ <footer class="footer">
2
+
3
+ </footer>
@@ -1,5 +1,5 @@
1
- <header class="header">
2
- <nav class="header-nav">
3
- <%= link_to t(:home), root_path %>
4
- </nav>
5
- </header>
1
+ <header class="header">
2
+ <nav class="header-nav">
3
+ <%= link_to t('menu.home'), root_path %>
4
+ </nav>
5
+ </header>
@@ -3,7 +3,6 @@
3
3
  <head>
4
4
  <meta charset="UTF-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
7
6
  <meta name="description" content="">
8
7
  <%%= csrf_meta_tags %>
9
8
  <title><%%= title %></title>
@@ -1,4 +1,3 @@
1
1
  <p>
2
2
  Welcome Home!
3
3
  </p>
4
-
@@ -0,0 +1,4 @@
1
+ # this wrapper script is used to kill processes listening to port 80
2
+ # to avoid 'Address already in use' error from nginx
3
+ sudo fuser -k 80/tcp;
4
+ sudo nginx $1 $2
@@ -3,6 +3,7 @@ begin
3
3
  load File.expand_path('../spring', __FILE__)
4
4
  rescue LoadError
5
5
  end
6
+
6
7
  APP_PATH = File.expand_path('../../config/application', __FILE__)
7
8
  require_relative '../config/boot'
8
9
  require 'rails/commands'
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ load File.expand_path("../spring", __FILE__)
4
+ rescue LoadError
5
+ end
6
+ #
7
+ # This file was generated by Bundler.
8
+ #
9
+ # The application 'rspec' is installed as part of a gem, and
10
+ # this file is here to facilitate running it.
11
+ #
12
+
13
+ require 'pathname'
14
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', Pathname.new(__FILE__).realpath)
15
+
16
+ require 'rubygems'
17
+ require 'bundler/setup'
18
+
19
+ load Gem.bin_path('rspec-core', 'rspec')
@@ -1,33 +1,123 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'pathname'
3
3
  require 'fileutils'
4
+ begin
5
+ require 'highline'
6
+ rescue LoadError
7
+ # If highline is missing, we'll gracefully omit ansi color output
8
+ end
9
+
10
+ def setup!
11
+ inside_app_root do
12
+ test 'ruby -v' => ruby_version
13
+
14
+ say_title 'Installing dependencies'
15
+ run 'gem install bundler --no-document --conservative'
16
+ run 'rbenv rehash' if rbenv_installed?
17
+ run 'bundle check || bundle install'
18
+ run "rbenv rehash" if rbenv_installed?
19
+
20
+ say_title 'Copying sample files'
21
+ copy '.example.env'
22
+ copy '.example.rspec'
23
+
24
+ test_local_env_contains_required_keys
25
+
26
+ say_title 'Preparing database'
27
+ run 'bundle exec rake db:setup'
28
+
29
+ # run 'pre-commit install' if pre_commit_available?
30
+ end
31
+ end
32
+
33
+ def inside_app_root(&block)
34
+ app_root = Pathname.new File.expand_path('../../', __FILE__)
35
+ Dir.chdir(app_root, &block)
36
+ end
37
+
38
+ def ruby_version
39
+ @ruby_version ||= begin
40
+ IO.read(".ruby-version").strip
41
+ end
42
+ end
43
+
44
+ def test(options)
45
+ command, output = options.first
46
+
47
+ say(:yellow, "test #{command}") do
48
+ unless `#{command}`.include?(output)
49
+ die("#{command} does not include #{output}")
50
+ end
51
+ end
52
+ end
53
+
54
+ def run(command)
55
+ say(:light_blue, "run #{command}") do
56
+ shell = "#{command} > /dev/null"
57
+ with_clean_bundler_env do
58
+ system(shell) or die("#{command} exited with non-zero status}")
59
+ end
60
+ end
61
+ end
62
+
63
+ def with_clean_bundler_env(&block)
64
+ return block.call unless defined?(Bundler)
65
+ Bundler.with_clean_env(&block)
66
+ end
67
+
68
+ def rbenv_installed?
69
+ @rbenv_installed = `which rbenv`.length > 0 if @rbenv_installed.nil?
70
+ @rbenv_installed
71
+ end
4
72
 
5
- # path to your application root.
6
- APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
73
+ def pre_commit_available?
74
+ @pre_commit_available = `which pre-commit`.length > 0 if @pre_commit_available.nil?
75
+ @pre_commit_available
76
+ end
7
77
 
8
- Dir.chdir APP_ROOT do
9
- # This script is a starting point to setup your application.
10
- # Add necessary setup steps to this file:
78
+ def copy(example_path)
79
+ copy_path = example_path.sub(/\.?example/, '')
80
+ return if File.exist?(copy_path)
11
81
 
12
- puts "== Installing dependencies =="
13
- system "gem install bundler --conservative"
14
- system "bundle check || bundle install"
82
+ say(:magenta, "copy #{example_path} #{copy_path}") do
83
+ FileUtils.cp(example_path, copy_path)
84
+ end
85
+ end
15
86
 
16
- # puts "\n== Copying sample files =="
17
- # unless File.exist?("config/database.yml")
18
- # system "cp config/database.yml.sample config/database.yml"
19
- # end
87
+ def test_local_env_contains_required_keys
88
+ keys = ->(file) { IO.readlines(file).map { |line| line[/^([^#\s][^=\s]*)/, 1] }.compact }
20
89
 
21
- # Add binstubs to PATH via export PATH=".git/safe/../../bin:$PATH" in your shell rc file
22
- FileUtils.mkdir_p '.git/safe'
90
+ say(:light_yellow, 'test .env contents') do
91
+ missing = keys['.example.env'] - keys['.env']
92
+ if missing.any?
93
+ die("Your .env file is missing #{missing.join(', ')}")
94
+ end
95
+ end
96
+ end
23
97
 
24
- puts "\n== Preparing database =="
25
- system "bundle exec rake db:setup"
98
+ def say(color, message, output_stream = $stdout, &block)
99
+ if defined?(HighLine::String)
100
+ message.sub!(/^(\S*)/) { HighLine::String.new($1).public_send(color) }
101
+ end
26
102
 
27
- puts "\n== Removing old logs and tempfiles =="
28
- system "rm -f log/*"
29
- system "rm -rf tmp/cache"
103
+ if block_given?
104
+ output_stream.print("#{message}… ")
105
+ yield
106
+ say(:light_green, "✔︎")
107
+ else
108
+ output_stream.puts(message)
109
+ end
110
+ end
30
111
 
31
- puts "\n== Restarting application server =="
32
- system "touch tmp/restart.txt"
112
+ def say_title(title)
113
+ puts
114
+ puts "== #{title} =="
33
115
  end
116
+
117
+ def die(message)
118
+ puts
119
+ say(:light_red, "FAIL #{message}", $stderr)
120
+ exit 1
121
+ end
122
+
123
+ setup!