hancock_cms_faq 1.0.2
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 +7 -0
- data/.gitignore +9 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +55 -0
- data/Rakefile +1 -0
- data/app/assets/javascripts/hancock/faq.coffee +6 -0
- data/app/assets/javascripts/hancock/faq/form.coffee +9 -0
- data/app/assets/javascripts/hancock/faq/init.coffee +2 -0
- data/app/assets/stylesheets/hancock/faq.sass +0 -0
- data/app/controllers/concerns/hancock/faq/decorators/categories.rb +17 -0
- data/app/controllers/concerns/hancock/faq/decorators/questions.rb +71 -0
- data/app/controllers/hancock/faq/categories_controller.rb +7 -0
- data/app/controllers/hancock/faq/questions_controller.rb +7 -0
- data/app/models/concerns/hancock/faq/decorators/category.rb +36 -0
- data/app/models/concerns/hancock/faq/decorators/question.rb +48 -0
- data/app/models/hancock/faq/category.rb +11 -0
- data/app/models/hancock/faq/question.rb +11 -0
- data/app/views/hancock/faq/categories/index.html.slim +10 -0
- data/app/views/hancock/faq/categories/show.html.slim +8 -0
- data/app/views/hancock/faq/questions/_fields.html.slim +11 -0
- data/app/views/hancock/faq/questions/_fields_with_settings.html.slim +20 -0
- data/app/views/hancock/faq/questions/_form.html.slim +66 -0
- data/app/views/hancock/faq/questions/_form_with_wrapper.html.slim +2 -0
- data/app/views/hancock/faq/questions/_question_block.html.slim +33 -0
- data/app/views/hancock/faq/questions/_simple_captcha.html.slim +16 -0
- data/app/views/hancock/faq/questions/_success.html.slim +3 -0
- data/app/views/hancock/faq/questions/create.html.slim +1 -0
- data/app/views/hancock/faq/questions/index.html.slim +11 -0
- data/app/views/hancock/faq/questions/new.html.slim +6 -0
- data/app/views/hancock/faq/questions/show.html.slim +8 -0
- data/app/views/hancock/faq/questions/update_captcha.html.slim +16 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/config/locales/hancock.faq.ru.yml +64 -0
- data/hancock_cms_faq.gemspec +36 -0
- data/lib/generators/hancock/faq/config/config_generator.rb +13 -0
- data/lib/generators/hancock/faq/config/templates/hancock_faq.erb +23 -0
- data/lib/generators/hancock/faq/controllers/all_generator.rb +28 -0
- data/lib/generators/hancock/faq/controllers/category_generator.rb +43 -0
- data/lib/generators/hancock/faq/controllers/decorators_generator.rb +24 -0
- data/lib/generators/hancock/faq/controllers/question_generator.rb +43 -0
- data/lib/generators/hancock/faq/controllers/templates/categories_controller.erb +10 -0
- data/lib/generators/hancock/faq/controllers/templates/questions_controller.erb +10 -0
- data/lib/generators/hancock/faq/models/all_generator.rb +28 -0
- data/lib/generators/hancock/faq/models/category_generator.rb +43 -0
- data/lib/generators/hancock/faq/models/decorators_generator.rb +24 -0
- data/lib/generators/hancock/faq/models/question_generator.rb +34 -0
- data/lib/generators/hancock/faq/models/templates/category.erb +36 -0
- data/lib/generators/hancock/faq/models/templates/question.erb +37 -0
- data/lib/hancock/faq/admin.rb +6 -0
- data/lib/hancock/faq/admin/category.rb +128 -0
- data/lib/hancock/faq/admin/question.rb +104 -0
- data/lib/hancock/faq/configuration.rb +53 -0
- data/lib/hancock/faq/controllers/categories.rb +88 -0
- data/lib/hancock/faq/controllers/questions.rb +174 -0
- data/lib/hancock/faq/engine.rb +7 -0
- data/lib/hancock/faq/models/category.rb +50 -0
- data/lib/hancock/faq/models/mongoid/category.rb +33 -0
- data/lib/hancock/faq/models/mongoid/question.rb +72 -0
- data/lib/hancock/faq/models/question.rb +85 -0
- data/lib/hancock/faq/routes.rb +83 -0
- data/lib/hancock/faq/version.rb +5 -0
- data/lib/hancock_cms_faq.rb +31 -0
- data/release.sh +6 -0
- metadata +159 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Hancock::Faq::Models
|
4
|
+
class AllGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
argument :class_name, type: :string
|
7
|
+
argument :category_class_name_arg, type: :string, default: ""
|
8
|
+
|
9
|
+
desc 'Hancock::Faq Models generator'
|
10
|
+
def all
|
11
|
+
generate "hancock:faq:models:question #{camelcased_class_name}"
|
12
|
+
generate "hancock:faq:models:category #{category_class_name}"
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def capitalized_class_name
|
17
|
+
class_name.capitalize
|
18
|
+
end
|
19
|
+
def camelcased_class_name
|
20
|
+
class_name.camelcase
|
21
|
+
end
|
22
|
+
|
23
|
+
def category_class_name
|
24
|
+
category_class_name_arg.blank? ? "#{camelcased_class_name}Category" : category_class_name_arg
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Hancock::Faq::Models
|
4
|
+
class CategoryGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
argument :class_name, type: :string
|
7
|
+
argument :question_class_name_arg, type: :string, default: ""
|
8
|
+
|
9
|
+
desc 'Hancock::Faq Category Model generator'
|
10
|
+
def category
|
11
|
+
template 'category.erb', "app/models/#{file_name}.rb"
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def capitalized_class_name
|
16
|
+
class_name.capitalize
|
17
|
+
end
|
18
|
+
|
19
|
+
def camelcased_class_name
|
20
|
+
class_name.camelcase
|
21
|
+
end
|
22
|
+
|
23
|
+
def file_name
|
24
|
+
underscored_class_name
|
25
|
+
end
|
26
|
+
|
27
|
+
def underscored_class_name
|
28
|
+
camelcased_class_name.underscore
|
29
|
+
end
|
30
|
+
|
31
|
+
def underscored_pluralized_class_name
|
32
|
+
underscored_class_name.pluralize
|
33
|
+
end
|
34
|
+
|
35
|
+
def camelcased_question_class_name
|
36
|
+
question_class_name.camelcase
|
37
|
+
end
|
38
|
+
|
39
|
+
def question_class_name
|
40
|
+
question_class_name_arg.blank? ? camelcased_class_name.sub(/Category$/i, "") : question_class_name_arg
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Hancock::Faq::Models
|
4
|
+
class DecoratorsGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path('../../../../../../app/models/concerns/hancock/faq/decorators', __FILE__)
|
6
|
+
argument :models, type: :array, default: []
|
7
|
+
|
8
|
+
desc 'Hancock::Faq Models generator'
|
9
|
+
def decorators
|
10
|
+
copied = false
|
11
|
+
(models == ['all'] ? permitted_models : models & permitted_models).each do |m|
|
12
|
+
copied = true
|
13
|
+
copy_file "#{m}.rb", "app/models/concerns/hancock/faq/decorators/#{m}.rb"
|
14
|
+
end
|
15
|
+
puts "U need to set models`s name. One of this: #{permitted_models.join(", ")}." unless copied
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def permitted_models
|
20
|
+
['category', 'question']
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Hancock::Faq::Models
|
4
|
+
class QuestionGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
argument :class_name, type: :string
|
7
|
+
|
8
|
+
desc 'Hancock::Faq Question Model generator'
|
9
|
+
def question
|
10
|
+
template 'question.erb', "app/models/#{file_name}.rb"
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def capitalized_class_name
|
15
|
+
class_name.capitalize
|
16
|
+
end
|
17
|
+
|
18
|
+
def camelcased_class_name
|
19
|
+
class_name.camelcase
|
20
|
+
end
|
21
|
+
|
22
|
+
def file_name
|
23
|
+
underscored_class_name
|
24
|
+
end
|
25
|
+
|
26
|
+
def underscored_class_name
|
27
|
+
camelcased_class_name.underscore
|
28
|
+
end
|
29
|
+
|
30
|
+
def underscored_pluralized_class_name
|
31
|
+
underscored_class_name.pluralize
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class <%= camelcased_class_name %> < Hancock::Faq::Category
|
2
|
+
|
3
|
+
def self.question_class
|
4
|
+
<%= camelcased_question_class_name %>
|
5
|
+
end
|
6
|
+
|
7
|
+
|
8
|
+
############# rails_admin ##############
|
9
|
+
def self.rails_admin_add_fields
|
10
|
+
[] #super
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.rails_admin_add_config(config)
|
14
|
+
#super(config)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.admin_can_user_defined_actions
|
18
|
+
[].freeze
|
19
|
+
end
|
20
|
+
def self.admin_cannot_user_defined_actions
|
21
|
+
[].freeze
|
22
|
+
end
|
23
|
+
def self.manager_can_user_defined_actions
|
24
|
+
[].freeze
|
25
|
+
end
|
26
|
+
def self.manager_cannot_user_defined_actions
|
27
|
+
[].freeze
|
28
|
+
end
|
29
|
+
def self.rails_admin_user_defined_visible_actions
|
30
|
+
[].freeze
|
31
|
+
end
|
32
|
+
|
33
|
+
rails_admin(&Hancock::Faq::Admin::Category.config(rails_admin_add_fields) { |config|
|
34
|
+
rails_admin_add_config(config)
|
35
|
+
})
|
36
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class <%= camelcased_class_name %> < Hancock::Faq::Question
|
2
|
+
|
3
|
+
has_and_belongs_to_many :categories, class_name: "<%= camelcased_class_name %>Category", inverse_of: nil
|
4
|
+
alias :<%= underscored_class_name %>_categories :categories
|
5
|
+
|
6
|
+
has_and_belongs_to_many :related_questions, :class_name => "<%= camelcased_class_name %>", :inverse_of => :related_questions
|
7
|
+
alias :related_<%= underscored_pluralized_class_name %> :related_questions
|
8
|
+
|
9
|
+
############# rails_admin ##############
|
10
|
+
def self.rails_admin_add_fields
|
11
|
+
[] #super
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.rails_admin_add_config(config)
|
15
|
+
#super(config)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.admin_can_user_defined_actions
|
19
|
+
[].freeze
|
20
|
+
end
|
21
|
+
def self.admin_cannot_user_defined_actions
|
22
|
+
[].freeze
|
23
|
+
end
|
24
|
+
def self.manager_can_user_defined_actions
|
25
|
+
[].freeze
|
26
|
+
end
|
27
|
+
def self.manager_cannot_user_defined_actions
|
28
|
+
[].freeze
|
29
|
+
end
|
30
|
+
def self.rails_admin_user_defined_visible_actions
|
31
|
+
[].freeze
|
32
|
+
end
|
33
|
+
|
34
|
+
rails_admin(&Hancock::Faq::Admin::Question.config(rails_admin_add_fields) { |config|
|
35
|
+
rails_admin_add_config(config)
|
36
|
+
})
|
37
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
module Hancock::Faq
|
2
|
+
module Admin
|
3
|
+
module Category
|
4
|
+
def self.config(nav_label = nil, fields = {})
|
5
|
+
if nav_label.is_a?(Hash)
|
6
|
+
nav_label, fields = nav_label[:nav_label], nav_label
|
7
|
+
elsif nav_label.is_a?(Array)
|
8
|
+
nav_label, fields = nil, nav_label
|
9
|
+
end
|
10
|
+
|
11
|
+
Proc.new {
|
12
|
+
navigation_label(!nav_label.blank? ? nav_label : "FAQ")
|
13
|
+
|
14
|
+
list do
|
15
|
+
scopes [:sorted, :enabled, nil]
|
16
|
+
|
17
|
+
field :enabled, :toggle
|
18
|
+
field :name do
|
19
|
+
searchable true
|
20
|
+
end
|
21
|
+
# field :image
|
22
|
+
|
23
|
+
field :questions do
|
24
|
+
read_only true
|
25
|
+
|
26
|
+
pretty_value do
|
27
|
+
bindings[:object].questions.to_a.map { |q|
|
28
|
+
route = bindings[:view] || bindings[:controller]
|
29
|
+
model_name = q.rails_admin_model
|
30
|
+
route.link_to(q.full_name, route.rails_admin.show_path(model_name: model_name, id: q.id), title: q.name)
|
31
|
+
}.join("<br>").html_safe
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
field :text_slug do
|
36
|
+
searchable true
|
37
|
+
end
|
38
|
+
group :content, &Hancock::Admin.content_block
|
39
|
+
end
|
40
|
+
|
41
|
+
edit do
|
42
|
+
field :enabled, :toggle
|
43
|
+
field :name
|
44
|
+
# field :sidebar_title, :string
|
45
|
+
|
46
|
+
group :URL, &Hancock::Admin.url_block
|
47
|
+
# group :URL do
|
48
|
+
# active false
|
49
|
+
# field :slugs, :hancock_slugs
|
50
|
+
# field :text_slug
|
51
|
+
# end
|
52
|
+
# field :image, :hancock_image
|
53
|
+
|
54
|
+
group :content, &Hancock::Admin.content_block
|
55
|
+
# group :content do
|
56
|
+
# active false
|
57
|
+
# field :excerpt, :hancock_html
|
58
|
+
# field :content, :hancock_html
|
59
|
+
# end
|
60
|
+
|
61
|
+
if Hancock::Faq.config.seo_support
|
62
|
+
group :seo_n_sitemap, &Hancock::Seo::Admin.seo_n_sitemap_block
|
63
|
+
# group :seo do
|
64
|
+
# active false
|
65
|
+
# field :seo
|
66
|
+
# end
|
67
|
+
# group :sitemap_data do
|
68
|
+
# active false
|
69
|
+
# field :sitemap_data
|
70
|
+
# end
|
71
|
+
end
|
72
|
+
|
73
|
+
Hancock::RailsAdminGroupPatch::hancock_cms_group(self, fields)
|
74
|
+
|
75
|
+
|
76
|
+
group :questions do
|
77
|
+
active false
|
78
|
+
field :questions do
|
79
|
+
read_only true
|
80
|
+
help 'Список вопросов'
|
81
|
+
|
82
|
+
pretty_value do
|
83
|
+
bindings[:object].questions.to_a.map { |q|
|
84
|
+
route = (bindings[:view] || bindings[:controller])
|
85
|
+
model_name = q.rails_admin_model
|
86
|
+
route.link_to(q.name, route.rails_admin.show_path(model_name: model_name, id: q.id), title: q.full_name)
|
87
|
+
}.join("<br>").html_safe
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
show do
|
94
|
+
field :name
|
95
|
+
# field :sidebar_title
|
96
|
+
field :slugs, :hancock_slugs
|
97
|
+
field :text_slug
|
98
|
+
field :enabled
|
99
|
+
# field :image
|
100
|
+
field :excerpt
|
101
|
+
field :content
|
102
|
+
|
103
|
+
Hancock::RailsAdminGroupPatch::hancock_cms_group(self, fields)
|
104
|
+
|
105
|
+
field :questions do
|
106
|
+
read_only true
|
107
|
+
|
108
|
+
pretty_value do
|
109
|
+
bindings[:object].questions.to_a.map { |q|
|
110
|
+
route = (bindings[:view] || bindings[:controller])
|
111
|
+
model_name = q.rails_admin_model
|
112
|
+
route.link_to(i.full_name, route.rails_admin.show_path(model_name: model_name, id: q.id), title: q.name)
|
113
|
+
}.join("<br>").html_safe
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
nested_set({max_depth: 2, scopes: []})
|
119
|
+
|
120
|
+
if block_given?
|
121
|
+
yield self
|
122
|
+
end
|
123
|
+
|
124
|
+
}
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module Hancock::Faq
|
2
|
+
module Admin
|
3
|
+
module Question
|
4
|
+
def self.config(nav_label = nil, fields = {})
|
5
|
+
if nav_label.is_a?(Hash)
|
6
|
+
nav_label, fields = nav_label[:nav_label], nav_label
|
7
|
+
elsif nav_label.is_a?(Array)
|
8
|
+
nav_label, fields = nil, nav_label
|
9
|
+
end
|
10
|
+
|
11
|
+
Proc.new {
|
12
|
+
navigation_label(!nav_label.blank? ? nav_label : "FAQ")
|
13
|
+
|
14
|
+
list do
|
15
|
+
scopes [:by_date, :by_answered_date, :answered, :not_answered, :enabled, nil]
|
16
|
+
|
17
|
+
field :enabled, :toggle
|
18
|
+
field :main_category
|
19
|
+
field :categories
|
20
|
+
field :full_name do
|
21
|
+
searchable true
|
22
|
+
end
|
23
|
+
|
24
|
+
field :question_text do
|
25
|
+
searchable true
|
26
|
+
end
|
27
|
+
field :question_text_after_editing do
|
28
|
+
searchable true
|
29
|
+
end
|
30
|
+
field :author_name do
|
31
|
+
searchable true
|
32
|
+
end
|
33
|
+
field :author_name_text_after_editing do
|
34
|
+
searchable true
|
35
|
+
end
|
36
|
+
field :author_email do
|
37
|
+
searchable true
|
38
|
+
end
|
39
|
+
|
40
|
+
field :answer_text do
|
41
|
+
searchable true
|
42
|
+
end
|
43
|
+
field :answer_author_name do
|
44
|
+
searchable true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
edit do
|
49
|
+
group :categories, &Hancock::Admin.categories_block
|
50
|
+
# group :categories do
|
51
|
+
# active false
|
52
|
+
# field :main_category
|
53
|
+
# field :categories
|
54
|
+
# end
|
55
|
+
field :enabled, :toggle
|
56
|
+
|
57
|
+
group :URL, &Hancock::Admin.url_block
|
58
|
+
# group :URL do
|
59
|
+
# active false
|
60
|
+
# field :slugs, :hancock_slugs
|
61
|
+
# field :text_slug
|
62
|
+
# end
|
63
|
+
|
64
|
+
group 'Данные вопроса' do
|
65
|
+
active false
|
66
|
+
field :question_text, :text
|
67
|
+
field :question_text_after_editing, :hancock_html
|
68
|
+
field :author_name, :string
|
69
|
+
field :author_name_text_after_editing, :string
|
70
|
+
field :author_email, :string
|
71
|
+
end
|
72
|
+
|
73
|
+
group 'Данные ответа' do
|
74
|
+
active false
|
75
|
+
field :answered, :toggle
|
76
|
+
field :answer_text, :hancock_html
|
77
|
+
field :answered_time
|
78
|
+
field :answer_author_name, :string
|
79
|
+
end
|
80
|
+
|
81
|
+
if Hancock::Faq.config.seo_support
|
82
|
+
group :seo_n_sitemap, &Hancock::Seo::Admin.seo_n_sitemap_block
|
83
|
+
# group :seo do
|
84
|
+
# active false
|
85
|
+
# field :seo
|
86
|
+
# end
|
87
|
+
# group :sitemap_data do
|
88
|
+
# active false
|
89
|
+
# field :sitemap_data
|
90
|
+
# end
|
91
|
+
end
|
92
|
+
|
93
|
+
Hancock::RailsAdminGroupPatch::hancock_cms_group(self, fields)
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
if block_given?
|
98
|
+
yield self
|
99
|
+
end
|
100
|
+
}
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|