bbs 1.0.1 → 1.1.0

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: 53f3093c331e334c5e6195734bed223cdc4e9e1a
4
- data.tar.gz: '067806696393bb6e1efecaf9c491f04ff34b0786'
3
+ metadata.gz: 9d40fe869ca12a1eee1a92d410bec8b1cb37d04b
4
+ data.tar.gz: 237334dccf67bea241b9f9d4a38c4831bc926f62
5
5
  SHA512:
6
- metadata.gz: d4627da3dd64d6b6e8e063c92ad15793c857f1f9c2d84cc6cf45bcdc5b8136b0185c9ac01a37a8e6c21211d8dec99e97b5a2793c8ff12d0e5d62612612627b8f
7
- data.tar.gz: 63770c6ef0462fa226835cfd24c5cf30210f8f85f6e714ed329c4d51dd6393a81de53aa9cda07c49d8bc78c20e3a58c628a6a9aab29efc43935f90260561a1e6
6
+ metadata.gz: ff4e4e63e06e86f6e901c08b2715da18c557540d1328462e4f3926f87974c189782cb6c14a8507d3dd4402ce0fcbc762e9bc3deb08b893ccf1066ce56d69d8ee
7
+ data.tar.gz: 18e7d916f9647c1d52ed44f0e0f89bea0bd7a9fe28afc0f6afe91ca3e2d436519775fa9aecfc9776af38a422568cda9b0ed59c98d7827797351fc1ff2e61a7bf
data/README.md CHANGED
@@ -48,6 +48,20 @@ Execute the above command will copy following files into your
48
48
  * config/locales/bbs.ja.yml
49
49
  * config/locales/bbs.en.yml
50
50
 
51
+ ### Generate User/UserProfile/Avatar models
52
+
53
+ ```bash
54
+ $ rails g active_record:bbs User
55
+ ```
56
+
57
+ Execute the above command will generate models(User, UserProfile and Avatar) and its migrations.
58
+
59
+ Uncomment bbs config and specify user model name arbitrary.
60
+
61
+ ```ruby
62
+ config.user_class = 'User'
63
+ ```
64
+
51
65
  ## View Components
52
66
  ### List categories
53
67
 
@@ -29,7 +29,7 @@ module Bbs
29
29
  private
30
30
 
31
31
  def profile_params
32
- params.require(:user_profile).permit(Bbs::UserProfile.permitted_attributes)
32
+ params.require(:user_profile).permit(UserProfile.attribute_names.without(%w(id created_at updated_at)))
33
33
  end
34
34
  end
35
35
  end
@@ -1,7 +1,7 @@
1
1
  module Bbs
2
2
  class Comment < ::Bbs::ApplicationRecord
3
3
  belongs_to :topic, class_name: 'Bbs::Topic'
4
- belongs_to :author, class_name: 'Bbs::User'
4
+ belongs_to :author, class_name: "::#{Bbs.config.user_class_name}"
5
5
 
6
6
  validates :title, :body, presence: true, allow_blank: false
7
7
  end
@@ -3,7 +3,7 @@ module Bbs
3
3
  has_many :comments, class_name: 'Bbs::Comment', dependent: :delete_all
4
4
 
5
5
  belongs_to :category, class_name: 'Bbs::Category'
6
- belongs_to :author, class_name: 'Bbs::User'
6
+ belongs_to :author, class_name: "::#{Bbs.config.user_class_name}"
7
7
 
8
8
  validates :title, :body, presence: true, allow_blank: false
9
9
  end
@@ -2,7 +2,7 @@
2
2
  .bbs-form-group
3
3
  = f.label :avatar_url
4
4
 
5
- = f.collection_radio_buttons :avatar_id, Bbs::Avatar.all, :id, :id do |r|
5
+ = f.collection_radio_buttons :avatar_id, Avatar.all, :id, :id do |r|
6
6
  = r.label { r.radio_button(style: 'width: 1em') + image_tag(r.object.image.url(:medium)) }
7
7
 
8
8
  .bbs-form-group
@@ -0,0 +1,5 @@
1
+ class RemoveBbsUserProfiles < ActiveRecord::Migration[5.0]
2
+ def change
3
+ drop_table :bbs_user_profiles
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class RemoveBbsUsers < ActiveRecord::Migration[5.0]
2
+ def change
3
+ drop_table :bbs_users
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class RemoveBbsAvatars < ActiveRecord::Migration[5.0]
2
+ def change
3
+ drop_table :bbs_avatars
4
+ end
5
+ end
@@ -2,7 +2,7 @@ module Bbs
2
2
  class Configuration
3
3
  attr_accessor :clamp_article_body, :login_path, :latest_topics_count,
4
4
  :topics_per_page, :comments_per_page, :current_user,
5
- :authenticate_user
5
+ :authenticate_user, :user_class, :user_profile_class, :avatar_class
6
6
 
7
7
  def clamp_article_body
8
8
  @clamp_article_body ||= 100
@@ -24,6 +24,9 @@ module Bbs
24
24
  @comments_per_page ||= 10
25
25
  end
26
26
 
27
+ def user_class; @user_class.constantize end
28
+ def user_class_name; @user_class end
29
+
27
30
  def current_user
28
31
  @current_user ||= :current_user
29
32
  end
@@ -1,3 +1,3 @@
1
1
  module Bbs
2
- VERSION = '1.0.1'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -0,0 +1,69 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ module ActiveRecord
4
+ module Generators
5
+ class BbsGenerator < ActiveRecord::Generators::Base
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ def generate_user
9
+ return unless invoke?
10
+
11
+ invoke('active_record:model', [@name]) unless model_file_exists?(@name) # we need blank User model
12
+ inject_into_user
13
+ end
14
+
15
+ def generate_user_profile
16
+ return unless invoke?
17
+
18
+ migration_template user_profile_migration_filename, "db/migrate/#{user_profile_migration_filename}"
19
+ template 'user_profile.rb', 'app/models/user_profile.rb' unless model_file_exists?('UserProfile')
20
+ end
21
+
22
+ def generate_avatar
23
+ return unless invoke?
24
+
25
+ migration_template avatar_migration_filename, "db/migrate/#{avatar_migration_filename}"
26
+ template 'avatar.rb', 'app/models/avatar.rb' unless model_file_exists?('Avatar')
27
+ end
28
+
29
+ private
30
+
31
+ def inject_into_user
32
+ inject_into_class model_path(@name), @name do
33
+ <<-RUBY
34
+ has_one :profile, class_name: 'UserProfile', dependent: :destroy
35
+
36
+ accepts_nested_attributes_for :profile
37
+
38
+ validates_associated :profile
39
+ validates_presence_of :profile
40
+ RUBY
41
+ end
42
+ end
43
+
44
+ def invoke?; behavior == :invoke end
45
+
46
+ def model_exists?(const)
47
+ Object.const_defined?(const) && const.constantize.ancestors.include?(ActiveRecord::Base)
48
+ end
49
+
50
+ def model_file_exists?(const)
51
+ File.exist?(model_path(const))
52
+ end
53
+
54
+ def user_profile_migration_filename
55
+ model_exists?('UserProfile') ? 'change_profile.rb' : 'create_profile.rb'
56
+ end
57
+
58
+ def avatar_migration_filename
59
+ model_exists?('Avatar') ? 'change_avatar.rb' : 'create_avatar.rb'
60
+ end
61
+
62
+ def model_path(model_name)
63
+ Rails.root.join('app', 'models', "#{model_name.underscore}.rb")
64
+ end
65
+
66
+ def user_model_name; @name.underscore end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,7 @@
1
+ class ChangeAvatar < ActiveRecord::Migration<%= ["#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}"] %>
2
+ def self.up
3
+ change_table :avatars do |t|
4
+ t.attachment :avatar
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ class CreateAvatar < ActiveRecord::Migration<%= "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" %>
2
+ def change
3
+ create_table :avatars do |t|
4
+ t.attachment :avatar
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ class Avatar < ApplicationRecord
2
+ has_many :user_profiles, class_name: 'UserProfile'
3
+
4
+ has_attached_file :image, styles: {medium: '48x48>', thumb: '48x48>'}
5
+
6
+ validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/
7
+ end
@@ -0,0 +1,14 @@
1
+ class ChangeProfile < ActiveRecord::Migration<%= "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" %>
2
+ def up
3
+ change_table :user_profiles do |t|
4
+ t.integer :<%= user_model_name %>_id, null: false
5
+ t.string :avatar_url
6
+ t.string :nickname
7
+ end
8
+
9
+ add_foreign_key :user_profiles, :<%= user_model_name.pluralize %>, column: :<%= user_model_name %>_id
10
+ end
11
+
12
+ def down
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ class CreateAvatar < ActiveRecord::Migration<%= "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" %>
2
+ def change
3
+ create_table :avatars do |t|
4
+ t.attachment :image
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ class CreateProfile < ActiveRecord::Migration<%= "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" %>
2
+ def change
3
+ create_table :user_profiles do |t|
4
+ t.integer :<%= user_model_name %>_id, null: false
5
+ t.integer :avatar_id, null: false
6
+ t.string :nickname
7
+
8
+ t.timestamps
9
+ end
10
+
11
+ add_foreign_key :user_profiles, :<%= user_model_name.pluralize %>, column: :<%= user_model_name %>_id
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ class UserProfile < ApplicationRecord
2
+ belongs_to :<%= user_model_name %>, class_name: '<%= @name %>'
3
+ belongs_to :avatar, class_name: 'Avatar'
4
+
5
+ validates :avatar_id, :nickname, presence: true, allow_blank: false
6
+ end
@@ -6,7 +6,7 @@ Bbs.configure do |config|
6
6
  # If you set value `false`, never clamp line.
7
7
  #config.clamp_article_body = 10
8
8
 
9
- # spedify sign in path
9
+ # specify sign in path
10
10
  #config.login_path = '/users/sign_in'
11
11
 
12
12
  # set number of latest topics inside component
@@ -18,6 +18,9 @@ Bbs.configure do |config|
18
18
  # set number of topics per page
19
19
  #config.comments_per_page = 10
20
20
 
21
+ # required: set user class name
22
+ #config.user_class = 'User'
23
+
21
24
  # set current_user method
22
25
  config.current_user = :current_user
23
26
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bbs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-12 00:00:00.000000000 Z
11
+ date: 2017-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -249,10 +249,21 @@ files:
249
249
  - db/migrate/20160928082713_create_bbs_avatars.rb
250
250
  - db/migrate/20160930093905_add_avatar_id_to_user.rb
251
251
  - db/migrate/20161028081055_rename_avatar_column.rb
252
+ - db/migrate/20170201092549_remove_bbs_user_profiles.rb
253
+ - db/migrate/20170201092550_remove_bbs_users.rb
254
+ - db/migrate/20170201093926_remove_bbs_avatars.rb
252
255
  - lib/bbs.rb
253
256
  - lib/bbs/configuration.rb
254
257
  - lib/bbs/engine.rb
255
258
  - lib/bbs/version.rb
259
+ - lib/generators/active_record/bbs_generator.rb
260
+ - lib/generators/active_record/change_avatar.rb
261
+ - lib/generators/active_record/create_avatar.rb
262
+ - lib/generators/active_record/templates/avatar.rb
263
+ - lib/generators/active_record/templates/change_profile.rb
264
+ - lib/generators/active_record/templates/create_avatar.rb
265
+ - lib/generators/active_record/templates/create_profile.rb
266
+ - lib/generators/active_record/templates/user_profile.rb
256
267
  - lib/generators/bbs/config_generator.rb
257
268
  - lib/generators/bbs/templates/bbs.rb
258
269
  - lib/generators/bbs/views_generator.rb
@@ -277,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
277
288
  version: '0'
278
289
  requirements: []
279
290
  rubyforge_project:
280
- rubygems_version: 2.5.2
291
+ rubygems_version: 2.6.8
281
292
  signing_key:
282
293
  specification_version: 4
283
294
  summary: Summary of Bbs.