bbs 1.0.1 → 1.1.0
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 +4 -4
- data/README.md +14 -0
- data/app/controllers/bbs/profiles_controller.rb +1 -1
- data/app/models/bbs/comment.rb +1 -1
- data/app/models/bbs/topic.rb +1 -1
- data/app/views/bbs/profiles/edit.html.haml +1 -1
- data/db/migrate/20170201092549_remove_bbs_user_profiles.rb +5 -0
- data/db/migrate/20170201092550_remove_bbs_users.rb +5 -0
- data/db/migrate/20170201093926_remove_bbs_avatars.rb +5 -0
- data/lib/bbs/configuration.rb +4 -1
- data/lib/bbs/version.rb +1 -1
- data/lib/generators/active_record/bbs_generator.rb +69 -0
- data/lib/generators/active_record/change_avatar.rb +7 -0
- data/lib/generators/active_record/create_avatar.rb +9 -0
- data/lib/generators/active_record/templates/avatar.rb +7 -0
- data/lib/generators/active_record/templates/change_profile.rb +14 -0
- data/lib/generators/active_record/templates/create_avatar.rb +9 -0
- data/lib/generators/active_record/templates/create_profile.rb +13 -0
- data/lib/generators/active_record/templates/user_profile.rb +6 -0
- data/lib/generators/bbs/templates/bbs.rb +4 -1
- metadata +14 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d40fe869ca12a1eee1a92d410bec8b1cb37d04b
|
4
|
+
data.tar.gz: 237334dccf67bea241b9f9d4a38c4831bc926f62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
data/app/models/bbs/comment.rb
CHANGED
@@ -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:
|
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
|
data/app/models/bbs/topic.rb
CHANGED
@@ -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:
|
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,
|
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
|
data/lib/bbs/configuration.rb
CHANGED
@@ -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
|
data/lib/bbs/version.rb
CHANGED
@@ -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,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,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
|
@@ -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
|
-
#
|
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
|
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:
|
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.
|
291
|
+
rubygems_version: 2.6.8
|
281
292
|
signing_key:
|
282
293
|
specification_version: 4
|
283
294
|
summary: Summary of Bbs.
|