moxie_forum 0.2.4 → 0.2.5
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.
- data/app/views/moxie/posts/_form.html.erb +1 -1
- data/lib/moxie_forum/acts_as_moxie_user/base.rb +4 -0
- data/lib/moxie_forum/engine.rb +5 -7
- data/lib/rails/generators/moxie_forum/moxie_forum_generator.rb +56 -2
- data/lib/rails/generators/moxie_forum/templates/initializer.rb +0 -1
- data/test/generators/moxie_forum_generator_test.rb +10 -10
- data/test/unit/forum_test.rb +2 -5
- metadata +4 -4
data/lib/moxie_forum/engine.rb
CHANGED
@@ -20,14 +20,12 @@ module MoxieForum
|
|
20
20
|
|
21
21
|
initializer "moxie_forum.check_config" do |app|
|
22
22
|
|
23
|
-
#
|
24
|
-
|
25
|
-
config.user_model_name = config.user_model.to_s.classify # [0..0].upcase + config.user_model.to_s[1..9]
|
26
|
-
end
|
23
|
+
# load all the models in the app
|
24
|
+
Dir.glob(RAILS_ROOT + '/app/models/**/*.rb').each { |file| require file }
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
# Figure out which one is the official user class
|
27
|
+
config.user_model = ActiveRecord::Base.send(:subclasses).select { |c| c.respond_to? :i_am_moxie_user }.first
|
28
|
+
config.user_model_name = config.user_model.to_s
|
31
29
|
|
32
30
|
# make sure mount_at ends with trailing slash
|
33
31
|
config.mount_at += '/' unless config.mount_at.last == '/'
|
@@ -43,14 +43,61 @@ class MoxieForumGenerator < Rails::Generators::Base
|
|
43
43
|
def copy_initializer_file
|
44
44
|
copy_file 'initializer.rb', 'config/initializers/moxie_forum.rb'
|
45
45
|
end
|
46
|
+
|
47
|
+
def initialize_user_model
|
48
|
+
begin
|
49
|
+
print " \e[1m\e[34mquestion\e[0m What's the name of your user model? [user.rb] > "
|
50
|
+
model_name = gets.chomp
|
51
|
+
model_name = "user.rb" if model_name.empty?
|
52
|
+
end while not model_name =~ /\.rb/i
|
53
|
+
|
54
|
+
begin
|
55
|
+
print " \e[1m\e[34mquestion\e[0m Would you to auto-add a few necessary lines to the top of #{model_name} [y/n] "
|
56
|
+
answer = gets.chomp
|
57
|
+
end while not answer =~ /[yn]/i
|
58
|
+
|
59
|
+
if answer =~ /y/i
|
60
|
+
begin
|
61
|
+
f = File.open "app/models/#{model_name}"
|
62
|
+
file = f.read; f.close
|
63
|
+
|
64
|
+
# Create the initializer file
|
65
|
+
file.gsub!(/class User < ActiveRecord::Base\n/,
|
66
|
+
"class User < ActiveRecord::Base\n\n" +
|
67
|
+
"\tacts_as_moxie_user\n\n" +
|
68
|
+
"\t# MoxieForum looks for the following optional methods within this class.\n" +
|
69
|
+
"\t#\n" +
|
70
|
+
"\t# def moderator?\n" +
|
71
|
+
"\t# def admin?\n" +
|
72
|
+
"\t# def display_name\n" +
|
73
|
+
"\t# def profile_pic" )
|
74
|
+
|
75
|
+
tmp = File.open "tmp/~model.rb", "w"
|
76
|
+
tmp.write file; tmp.close
|
77
|
+
|
78
|
+
remove_file "app/models/#{model_name}"
|
79
|
+
copy_file '../../../tmp/~model.rb', "app/models/#{model_name}"
|
80
|
+
remove_file 'tmp/~model.rb'
|
81
|
+
rescue
|
82
|
+
puts " \e[1m\e[31merror\e[0m Unable to open #{model_name}, visit ##### for instructions to manually connect your user model"
|
83
|
+
end
|
84
|
+
else
|
85
|
+
puts " \e[1m\e[33mskipping\e[0m Visit ##### for instructions to connect your user model"
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
46
89
|
|
47
90
|
def update_application_template
|
48
91
|
f = File.open "app/views/layouts/application.html.erb"
|
49
92
|
layout = f.read; f.close
|
50
93
|
|
51
94
|
if layout =~ /<%=[ ]+yield[ ]+%>/
|
52
|
-
print " \e[1m\e[34mquestion\e[0m Your layouts/application.html.erb layout currently has the
|
95
|
+
print " \e[1m\e[34mquestion\e[0m Your layouts/application.html.erb layout currently has the " +
|
96
|
+
"line <%= yield %>. MoxieForum needs to change this line to <%= content_for?(:content) ? " +
|
97
|
+
"yield(:content) : yield %> to support its nested layouts. This change should not affect " +
|
98
|
+
"any of your existing layouts or views. "
|
53
99
|
begin
|
100
|
+
print "Is this okay? [y/n] "
|
54
101
|
answer = gets.chomp
|
55
102
|
end while not answer =~ /[yn]/i
|
56
103
|
|
@@ -69,8 +116,15 @@ class MoxieForumGenerator < Rails::Generators::Base
|
|
69
116
|
elsif layout =~ /<%=[ ]+content_for\?\(:content\) \? yield\(:content\) : yield[ ]+%>/
|
70
117
|
puts " \e[1m\e[33mskipping\e[0m layouts/application.html.erb modification is already done."
|
71
118
|
else
|
72
|
-
puts
|
119
|
+
puts " \e[1m\e[31mconflict\e[0m MoxieForum is confused by your " +
|
120
|
+
"layouts/application.html.erb. It does not contain the default line <%= yield %>, you " +
|
121
|
+
"may need to make manual changes to get MoxieForum's nested layouts working. Visit " +
|
122
|
+
"###### for details."
|
73
123
|
end
|
74
124
|
end
|
75
125
|
|
126
|
+
def done
|
127
|
+
puts "\n \e[1m\e[32mdone\e[0m Installation complete! Run rake db:migrate and start up your web server. You can try the forum at http://localhost:3000/forum but full functionality requires you to have a current_user application method. In addition, open your user model rb file for a few comments near the top.\n\n"
|
128
|
+
end
|
129
|
+
|
76
130
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'generators/moxie_forum/moxie_forum_generator'
|
3
|
-
|
4
|
-
class MoxieForumGeneratorTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
1
|
+
# require 'test_helper'
|
2
|
+
# require 'generators/moxie_forum/moxie_forum_generator'
|
3
|
+
#
|
4
|
+
# class MoxieForumGeneratorTest < Test::Unit::TestCase
|
5
|
+
#
|
6
|
+
# def test_install
|
7
|
+
# assert true
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# end
|
data/test/unit/forum_test.rb
CHANGED
@@ -33,7 +33,6 @@ class ForumTest < Test::Unit::TestCase
|
|
33
33
|
|
34
34
|
p = Moxie::Post.create( :topic_id => moxie_topics(:welcome).id,
|
35
35
|
:author_id => 0,
|
36
|
-
:title => "I forgot",
|
37
36
|
:body => "Don't forget to introduce yourself." )
|
38
37
|
|
39
38
|
assert moxie_topics(:welcome).posts.include? p
|
@@ -52,12 +51,10 @@ class ForumTest < Test::Unit::TestCase
|
|
52
51
|
:title => "Dummy topic 2" )
|
53
52
|
p1 = Moxie::Post.create( :topic_id => t1.id,
|
54
53
|
:author_id => 0,
|
55
|
-
:
|
56
|
-
:body => "body" )
|
54
|
+
:body => "Dummy post 1.1" )
|
57
55
|
p2 = Moxie::Post.create( :topic_id => t1.id,
|
58
56
|
:author_id => 0,
|
59
|
-
:
|
60
|
-
:body => "body" )
|
57
|
+
:body => "Dummy post 1.2" )
|
61
58
|
|
62
59
|
assert f.topics.include? t1
|
63
60
|
assert t1.posts.include? p1
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moxie_forum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 5
|
10
|
+
version: 0.2.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Keith Schacht
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-03 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|