thredded_create_app 0.1.17 → 0.1.18

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 317de5cb8dc2f463948d4aaa240ad6d546e88440
4
- data.tar.gz: 6f61cf6b2c942359d761e45f3e85dd7026e5cc7c
3
+ metadata.gz: e5dce72b9a0003fe725e6e4ee50897f6d67c0d51
4
+ data.tar.gz: '09f4480264a614040a97dd322441cd4dac9748c0'
5
5
  SHA512:
6
- metadata.gz: 5be5c1c0ad6a6eaef3a0e8a2e19eee17251486e42d383e75108e7ed1cb6d815a35d25afd950b4abd2d0fde8e70aeb4ec64f514466b3c7a2f35aa1171ee130529
7
- data.tar.gz: a4d0710842921f74c8fdde1b9a47aa9f339a2cd5f1ef7eb0f3be2cd18d38cb4c71e5d8288a8129640e3cb5ff01b550023a2abb5d02b213b6b3052824d64e1ca8
6
+ metadata.gz: 4d2ae61e5101b67ae09d54207c710667c4a84d83ad7f977266a2ecef654723b28584d513c99bb66aa0228f693833980fe21634ec43f52503b4526f1550efb96a
7
+ data.tar.gz: 759a81eccb99b99a6fa9f05b291c31de5b0740a49c0603f7549211a99d432ef3c7a0ca6b1adeb93eae0c7d697b1ba688f4b38f7f76b3edc54bd28b5e6847f282
@@ -9,6 +9,7 @@ require 'thredded_create_app/tasks/add_simple_form'
9
9
  require 'thredded_create_app/tasks/add_devise'
10
10
  require 'thredded_create_app/tasks/add_roadie'
11
11
  require 'thredded_create_app/tasks/add_rails_email_preview'
12
+ require 'thredded_create_app/tasks/add_jquery'
12
13
  require 'thredded_create_app/tasks/add_thredded'
13
14
  require 'thredded_create_app/tasks/add_display_name_to_users'
14
15
  require 'thredded_create_app/tasks/setup_database'
@@ -69,6 +70,7 @@ module ThreddedCreateApp
69
70
  Tasks::AddDevise,
70
71
  Tasks::AddRailsEmailPreview,
71
72
  Tasks::AddRoadie,
73
+ Tasks::AddJquery,
72
74
  Tasks::AddThredded,
73
75
  Tasks::AddDisplayNameToUsers,
74
76
  Tasks::SetupAppSkeleton,
@@ -85,9 +87,13 @@ module ThreddedCreateApp
85
87
 
86
88
  # @final
87
89
  def bundle # rubocop:disable Metrics/AbcSize
90
+ gemfile_contents = File.read('Gemfile')
91
+ gems_to_add = gems.reject do |gem|
92
+ gemfile_contents =~ /^gem\s*['"]#{Regexp.escape(gem[0])}['"]/
93
+ end
88
94
  File.open('Gemfile', 'a') do |f|
89
95
  log_info 'Writing gems to Gemfile'
90
- gems.each do |(name, version, groups, path)|
96
+ gems_to_add.each do |(name, version, groups, path)|
91
97
  f.puts ["gem '#{name}'",
92
98
  (version if version),
93
99
  ("groups: %i(#{groups * ' '})" if groups),
@@ -97,7 +103,7 @@ module ThreddedCreateApp
97
103
  log_info 'Installing gems'
98
104
  run "bundle install#{' --quiet' unless verbose?}" \
99
105
  "#{' --path .bundle' unless File.writable?(Gem.dir)}"
100
- git_commit "Add gems: #{gems.map { |(name, *)| name } * ', '}"
106
+ git_commit "Add gems: #{gems_to_add.map { |(name, *)| name } * ', '}"
101
107
  end
102
108
  end
103
109
  end
@@ -22,9 +22,9 @@ module ThreddedCreateApp
22
22
  private
23
23
 
24
24
  def add_display_name
25
- run_generator 'migration add_display_name_to_users'
26
- copy 'add_display_name_to_users/add_display_name_to_users.rb',
27
- Dir['db/migrate/*_add_display_name_to_users.rb'][0]
25
+ add_migration 'add_display_name_to_users',
26
+ template: 'add_display_name_to_users/' \
27
+ 'add_display_name_to_users.rb.erb'
28
28
  model_path = 'app/models/user.rb'
29
29
  inject_into_file model_path,
30
30
  after: "ApplicationRecord\n",
@@ -84,7 +84,7 @@ module ThreddedCreateApp
84
84
  def uniq_display_name!
85
85
  if display_name.present?
86
86
  new_display_name = display_name
87
- i = 0
87
+ i = 0
88
88
  while User.exists?(display_name: new_display_name)
89
89
  new_display_name = "#{display_name} #{i += 1}"
90
90
  end
@@ -0,0 +1,17 @@
1
+ def change
2
+ <%=
3
+ case database_adapter_name
4
+ when /mysql/i
5
+ 'add_column :users, :display_name, :string, limit: 191'
6
+ when /sqlite/i
7
+ <<~'RUBY'
8
+ add_column :users, :display_name, :string
9
+ change_column_null :users, :display_name, false
10
+ RUBY
11
+ else
12
+ 'add_column :users, :display_name, :string, null: false'
13
+ end
14
+ %>
15
+ DbTextSearch::CaseInsensitive.add_index connection, :users, :display_name,
16
+ unique: true
17
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thredded_create_app/tasks/base'
4
+ module ThreddedCreateApp
5
+ module Tasks
6
+ class AddJquery < Base
7
+ def summary
8
+ 'Add jQuery v3'
9
+ end
10
+
11
+ def before_bundle
12
+ add_gem 'jquery-rails'
13
+ end
14
+
15
+ def after_bundle
16
+ if replace 'app/assets/javascripts/application.js',
17
+ %r{^//= require jquery$},
18
+ '//= require jquery3',
19
+ optional: true
20
+ git_commit 'Use jQuery v3 instead of jQuery v1'
21
+ else
22
+ inject_into_file 'app/assets/javascripts/application.js',
23
+ content: "//= require jquery3\n",
24
+ before: '//='
25
+ git_commit 'Add jQuery'
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -74,9 +74,11 @@ module ThreddedCreateApp
74
74
  end
75
75
 
76
76
  def add_admin_column_to_users
77
- run_generator 'migration add_admin_to_users'
78
- copy 'add_thredded/add_admin_to_users.rb',
79
- Dir['db/migrate/*_add_admin_to_users.rb'][0]
77
+ add_migration 'add_admin_to_users', content: <<~RUBY
78
+ def change
79
+ add_column :users, :admin, :boolean, null: false, default: false
80
+ end
81
+ RUBY
80
82
  end
81
83
 
82
84
  def setup_thredded_emails
@@ -13,11 +13,12 @@ module ThreddedCreateApp
13
13
 
14
14
  attr_reader :app_name, :app_hostname, :app_path, :gems
15
15
 
16
- def initialize(app_path:, verbose: false, **_args)
16
+ def initialize(app_path:, verbose: false, database:, **_args)
17
17
  @app_path = app_path
18
18
  @app_name = File.basename(File.expand_path(app_path))
19
19
  @app_hostname = "#{@app_name.tr(' ', '_').downcase}.com"
20
20
  @verbose = verbose
21
+ @database_adapter_name = database.to_s
21
22
  @gems = []
22
23
  end
23
24
 
@@ -31,6 +32,8 @@ module ThreddedCreateApp
31
32
 
32
33
  protected
33
34
 
35
+ attr_reader :database_adapter_name
36
+
34
37
  def add_gem(gem_name, version: nil, groups: nil, path: nil)
35
38
  log_verbose "+ gem #{gem_name}"
36
39
  @gems << [gem_name, version, groups, path]
@@ -60,11 +63,15 @@ module ThreddedCreateApp
60
63
  return
61
64
  end
62
65
  src = File.read(expanded_src_path)
63
- src = ERB.new(src, nil, '-').result(binding) if process_erb
66
+ src = eval_template(src) if process_erb
64
67
  FileUtils.mkdir_p(File.dirname(target_path))
65
68
  File.write target_path, src, mode: mode
66
69
  end
67
70
 
71
+ def eval_template(src)
72
+ ERB.new(src, nil, '-').result(binding)
73
+ end
74
+
68
75
  def replace(path, pattern, replacement = nil, optional: false)
69
76
  src = File.read(path)
70
77
  changed = if block_given?
@@ -77,6 +84,7 @@ module ThreddedCreateApp
77
84
  "No match found for #{pattern} in #{path}"
78
85
  end
79
86
  File.write path, src
87
+ changed
80
88
  end
81
89
 
82
90
  def add_precompile_asset(asset)
@@ -104,6 +112,14 @@ module ThreddedCreateApp
104
112
  end)
105
113
  end
106
114
 
115
+ def add_migration(name, content: nil, template: nil)
116
+ run_generator "migration #{name}"
117
+ replace Dir["db/migrate/*_#{name}.rb"][0],
118
+ /^ *def change\n *end\n/,
119
+ indent(2, content ||
120
+ eval_template(File.read(expand_src_path(template))))
121
+ end
122
+
107
123
  def inject_into_file(path, content:, after: nil, before: nil)
108
124
  replace path, (after || before), after ? '\0' + content : content + '\0'
109
125
  end
@@ -58,11 +58,6 @@ module ThreddedCreateApp
58
58
  end
59
59
 
60
60
  def add_javascripts
61
- replace 'app/assets/javascripts/application.js',
62
- %r{^//= require jquery$},
63
- '//= require jquery3'
64
- git_commit 'Use jQuery v3 instead of jQuery v1'
65
-
66
61
  copy 'setup_app_skeleton/javascripts/app.js',
67
62
  'app/assets/javascripts/app.js'
68
63
  copy 'setup_app_skeleton/javascripts/app/',
@@ -18,7 +18,10 @@ module ThreddedCreateApp
18
18
  log_info 'Creating config/database.yml from template'
19
19
  copy_template 'setup_database/database.yml.erb', 'config/database.yml'
20
20
  create_db_user
21
- run 'bundle exec rails db:create db:migrate db:seed' \
21
+ run 'bundle exec rails db:create db:migrate' \
22
+ "#{' --quiet' unless verbose?}"
23
+ # On Rails 5.1, running db:seed together with the commands above fails.
24
+ run 'bundle exec rails db:seed' \
22
25
  "#{' --quiet' unless verbose?}"
23
26
  git_commit 'Configure the database'
24
27
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ThreddedCreateApp
4
- VERSION = '0.1.17'
4
+ VERSION = '0.1.18'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thredded_create_app
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.17
4
+ version: 0.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gleb Mazovetskiy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-05 00:00:00.000000000 Z
11
+ date: 2017-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: term-ansicolor
@@ -126,7 +126,8 @@ files:
126
126
  - lib/thredded_create_app/logging.rb
127
127
  - lib/thredded_create_app/tasks/add_devise.rb
128
128
  - lib/thredded_create_app/tasks/add_display_name_to_users.rb
129
- - lib/thredded_create_app/tasks/add_display_name_to_users/add_display_name_to_users.rb
129
+ - lib/thredded_create_app/tasks/add_display_name_to_users/add_display_name_to_users.rb.erb
130
+ - lib/thredded_create_app/tasks/add_jquery.rb
130
131
  - lib/thredded_create_app/tasks/add_memcached_support.rb
131
132
  - lib/thredded_create_app/tasks/add_rails_config.rb
132
133
  - lib/thredded_create_app/tasks/add_rails_email_preview.rb
@@ -136,7 +137,6 @@ files:
136
137
  - lib/thredded_create_app/tasks/add_thredded.rb
137
138
  - lib/thredded_create_app/tasks/add_thredded/_thredded-custom.scss
138
139
  - lib/thredded_create_app/tasks/add_thredded/_thredded-variables.scss
139
- - lib/thredded_create_app/tasks/add_thredded/add_admin_to_users.rb
140
140
  - lib/thredded_create_app/tasks/add_thredded/myapp_thredded.js
141
141
  - lib/thredded_create_app/tasks/add_thredded/spec/features/thredded_spec.rb
142
142
  - lib/thredded_create_app/tasks/add_thredded/thredded.en.yml
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class AddDisplayNameToUsers < ActiveRecord::Migration[5.0]
4
- def up
5
- case connection.adapter_name.to_s
6
- when /mysql/i
7
- add_column :users, :display_name, :string, limit: 191
8
- when /sqlite/i
9
- add_column :users, :display_name, :string
10
- change_column_null :users, :display_name, false
11
- else
12
- add_column :users, :display_name, :string, null: false
13
- end
14
-
15
- DbTextSearch::CaseInsensitive.add_index connection, :users, :display_name,
16
- unique: true
17
- end
18
-
19
- def down
20
- remove_column :users, :display_name
21
- end
22
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class AddAdminToUsers < ActiveRecord::Migration[5.0]
4
- def up
5
- add_column :users, :admin, :boolean, null: false, default: false
6
- end
7
-
8
- def down
9
- remove_column :users, :admin
10
- end
11
- end