enjoy_cms_faq 0.3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +1 -0
- data/app/controllers/concerns/enjoy/catalog/decorators/question_categories.rb +5 -0
- data/app/controllers/concerns/enjoy/catalog/decorators/questions.rb +5 -0
- data/app/controllers/concerns/enjoy/faq/decorators/question_categories.rb +5 -0
- data/app/controllers/concerns/enjoy/faq/decorators/questions.rb +5 -0
- data/app/controllers/enjoy/faq/question_categories_controller.rb +7 -0
- data/app/controllers/enjoy/faq/questions_controller.rb +7 -0
- data/app/models/concerns/enjoy/faq/decorators/question.rb +5 -0
- data/app/models/concerns/enjoy/faq/decorators/question_category.rb +5 -0
- data/app/models/enjoy/faq/question.rb +11 -0
- data/app/models/enjoy/faq/question_category.rb +11 -0
- data/app/views/enjoy/faq/question_categories/index.html.slim +2 -0
- data/app/views/enjoy/faq/question_categories/show.html.slim +3 -0
- data/app/views/enjoy/faq/questions/_new_question_form.html.slim +29 -0
- data/app/views/enjoy/faq/questions/_question_block.html.slim +30 -0
- data/app/views/enjoy/faq/questions/create.html.slim +1 -0
- data/app/views/enjoy/faq/questions/index.html.slim +7 -0
- data/app/views/enjoy/faq/questions/new.html.slim +3 -0
- data/app/views/enjoy/faq/questions/show.html.slim +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/config/initializers/rails_admin.rb +8 -0
- data/config/routes.rb +18 -0
- data/enjoy_cms_faq.gemspec +34 -0
- data/lib/enjoy/faq/admin/question.rb +82 -0
- data/lib/enjoy/faq/admin/question_category.rb +146 -0
- data/lib/enjoy/faq/admin.rb +6 -0
- data/lib/enjoy/faq/configuration.rb +40 -0
- data/lib/enjoy/faq/controllers/question_categories.rb +76 -0
- data/lib/enjoy/faq/controllers/questions.rb +80 -0
- data/lib/enjoy/faq/engine.rb +7 -0
- data/lib/enjoy/faq/models/mongoid/question.rb +52 -0
- data/lib/enjoy/faq/models/mongoid/question_category.rb +30 -0
- data/lib/enjoy/faq/models/question.rb +40 -0
- data/lib/enjoy/faq/models/question_category.rb +33 -0
- data/lib/enjoy/faq/version.rb +5 -0
- data/lib/enjoy_cms_faq.rb +53 -0
- data/release.sh +7 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ca9208c855af41955936c55fa9a857d2c938591f
|
4
|
+
data.tar.gz: 5f20fe1ce0890f397065b791402c73579679d7d1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8961fb74dd49a8a6c284b295d0c79f52cfe90908d2fceafbf071bd6d5056e14c51c52d809d2337db86190242fa9d059b546dc7454f018df58ee413e944c4e0a8
|
7
|
+
data.tar.gz: 1e1426a6891263ac91b20b94dd41b704cfbfc228a760cacd4390542ae5d8b7a9c690d5ec819635337c9d49ae86bc2e8ceade4f598debfce766a884cdb1fe7906
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Alexander Kiseliev
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# EnjoyCmsFaq
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/enjoy_cms_faq`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'enjoy_cms_faq'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install enjoy_cms_faq
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/enjoy_cms_faq.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Enjoy::Faq
|
2
|
+
class QuestionCategory
|
3
|
+
include Enjoy::Faq::Models::QuestionCategory
|
4
|
+
|
5
|
+
include Enjoy::Faq::Decorators::QuestionCategory
|
6
|
+
|
7
|
+
rails_admin(&Enjoy::Faq::Admin::QuestionCategory.config(rails_admin_add_fields) { |config|
|
8
|
+
rails_admin_add_config(config)
|
9
|
+
})
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
- @question ||= Enjoy::Faq::Question.new
|
2
|
+
- if @question.new_record?
|
3
|
+
= simple_form_for @question, url: enjoy_cms_faq.questions_path do |f|
|
4
|
+
- unless @message.blank?
|
5
|
+
h3= @message
|
6
|
+
.inputtextblock_q
|
7
|
+
|
8
|
+
- label = Settings.ns('faq_form').author_name_label( default: "ФИО", label: "Заголовок поля ФИО")
|
9
|
+
= f.input :author_name, label: label
|
10
|
+
|
11
|
+
- label = Settings.ns('faq_form').author_email_label( default: "E-mail", label: "Заголовок поля E-mail")
|
12
|
+
= f.input :author_email, as: :email, label: label
|
13
|
+
|
14
|
+
- label = Settings.ns('faq_form').question_text_label( default: "Текст вопроса", label: "Заголовок поля Текст вопроса")
|
15
|
+
= f.input :question_text, as: :text, label: label
|
16
|
+
|
17
|
+
|
18
|
+
- if Enjoy::Faq.configuration.save_with_captcha
|
19
|
+
.question_captcha
|
20
|
+
- label = Settings.ns('faq_form').captcha_label( default: "Код проверки", label: "Заголовок поля Код проверки")
|
21
|
+
= f.simple_captcha label: label, required: true
|
22
|
+
- unless @question.errors[:captcha].blank?
|
23
|
+
span.error= @question.errors[:captcha].join("<br />").html_safe
|
24
|
+
|
25
|
+
- label = Settings.ns('faq_form').submit_label( default: "Отправить", label: "Заголовок кнопки Отправить")
|
26
|
+
= f.button :submit, label
|
27
|
+
- else
|
28
|
+
- unless @message.blank?
|
29
|
+
h3= @message
|
@@ -0,0 +1,30 @@
|
|
1
|
+
.qtable
|
2
|
+
- _question_category = q.question_category
|
3
|
+
- if _question_category
|
4
|
+
= link_to _question_category.name, _question_category, title: _question_category.name
|
5
|
+
|
6
|
+
.qtext_block
|
7
|
+
.questionblock
|
8
|
+
.questiontext
|
9
|
+
.qname
|
10
|
+
p= q.author_name
|
11
|
+
.qemail
|
12
|
+
p= q.author_email
|
13
|
+
.qdate
|
14
|
+
p= q.created_at
|
15
|
+
.qtext
|
16
|
+
- if q.question_text_after_editing.blank?
|
17
|
+
p== q.question_text
|
18
|
+
- else
|
19
|
+
p== q.question_text_after_editing
|
20
|
+
|
21
|
+
.answertext
|
22
|
+
- if q.answered or (current_user and current_user.admin?)
|
23
|
+
.aqname
|
24
|
+
p= q.answer_author_name
|
25
|
+
.aqdate
|
26
|
+
p= q.answered_time
|
27
|
+
.aqtext
|
28
|
+
p== q.answer_text
|
29
|
+
|
30
|
+
.mentionsdivider
|
@@ -0,0 +1 @@
|
|
1
|
+
= render partial: "enjoy/faq/questions/new_question_form"
|
@@ -0,0 +1,7 @@
|
|
1
|
+
- @questions.each do |q|
|
2
|
+
.question_block{data-question-id="#{q._id.to_s}"}
|
3
|
+
= render partial: "enjoy/faq/questions/question_block", locals: {q: q}
|
4
|
+
|
5
|
+
.newquestionform
|
6
|
+
p.newquestiontitle Задать свой вопрос:
|
7
|
+
= render partial: "enjoy/faq/questions/new_question_form"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "enjoy_cms_faq"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/config/routes.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Enjoy::Faq::Engine.routes.draw do
|
2
|
+
routes_config = Enjoy::Faq.configuration.routes_config
|
3
|
+
|
4
|
+
if !routes_config or routes_config[:use_questions_path]
|
5
|
+
resources :questions, only: [:show, :new, :create] do
|
6
|
+
get '(/page/:page)', action: :index, on: :collection, as: ""
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
if !routes_config or routes_config[:use_question_categories_path]
|
11
|
+
resources :question_categories, only: [:index, :show] do
|
12
|
+
get 'items(/page/:page)', action: :questions, on: :member, as: :items
|
13
|
+
end
|
14
|
+
end
|
15
|
+
if !routes_config or routes_config[:use_faq_path]
|
16
|
+
get 'faq' => 'question_categories#index', as: :faq
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "enjoy/faq/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "enjoy_cms_faq"
|
8
|
+
spec.version = Enjoy::Faq::VERSION
|
9
|
+
spec.authors = ["Alexander Kiseliev"]
|
10
|
+
spec.email = ["dev@enjoycreate.ru"]
|
11
|
+
|
12
|
+
spec.summary = %q{FAQ system with EnjoyCMS support.}
|
13
|
+
spec.description = %q{FAQ system with EnjoyCMS support.}
|
14
|
+
spec.homepage = "https://github.com/enjoycreative/enjoy_cms_faq"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
# end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
|
33
|
+
spec.add_dependency 'enjoy_cms', "~> 0.3.0"
|
34
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Enjoy::Faq
|
2
|
+
module Admin
|
3
|
+
module Question
|
4
|
+
def self.config(fields = {})
|
5
|
+
Proc.new {
|
6
|
+
navigation_label "FAQ"
|
7
|
+
|
8
|
+
list do
|
9
|
+
scopes [:by_date, :by_answered_date, :answered, :not_answered, :enabled, nil]
|
10
|
+
|
11
|
+
field :enabled, :toggle
|
12
|
+
field :question_categories
|
13
|
+
field :full_name
|
14
|
+
end
|
15
|
+
|
16
|
+
edit do
|
17
|
+
field :question_categories
|
18
|
+
field :enabled, :toggle
|
19
|
+
|
20
|
+
field :slugs, :enum do
|
21
|
+
enum_method do
|
22
|
+
:slugs
|
23
|
+
end
|
24
|
+
visible do
|
25
|
+
bindings[:view].current_user.admin?
|
26
|
+
end
|
27
|
+
multiple do
|
28
|
+
true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
field :text_slug
|
32
|
+
|
33
|
+
group 'Данные вопроса' do
|
34
|
+
field :question_text, :text
|
35
|
+
field :question_text_after_editing, :enjoy_html
|
36
|
+
field :author_name, :string
|
37
|
+
field :author_name_text_after_editing, :string
|
38
|
+
field :author_email, :string
|
39
|
+
end
|
40
|
+
|
41
|
+
group 'Данные ответа' do
|
42
|
+
field :answered, :toggle
|
43
|
+
field :answer_text, :enjoy_html
|
44
|
+
field :answered_time
|
45
|
+
field :answer_author_name, :string
|
46
|
+
end
|
47
|
+
|
48
|
+
group :seo do
|
49
|
+
active false
|
50
|
+
field :seo do
|
51
|
+
active true
|
52
|
+
end
|
53
|
+
end
|
54
|
+
group :sitemap_data do
|
55
|
+
active false
|
56
|
+
field :sitemap_data do
|
57
|
+
active true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
fields.each_pair do |name, type|
|
62
|
+
if type.nil?
|
63
|
+
field name
|
64
|
+
else
|
65
|
+
if type.is_a?(Array)
|
66
|
+
field name, type[0], &type[1]
|
67
|
+
else
|
68
|
+
field name, type
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
if block_given?
|
76
|
+
yield self
|
77
|
+
end
|
78
|
+
}
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
module Enjoy::Faq
|
2
|
+
module Admin
|
3
|
+
module QuestionCategory
|
4
|
+
def self.config(fields = {})
|
5
|
+
Proc.new {
|
6
|
+
navigation_label "FAQ"
|
7
|
+
|
8
|
+
list do
|
9
|
+
scopes [:sorted, :enabled, nil]
|
10
|
+
|
11
|
+
field :enabled, :toggle
|
12
|
+
field :name
|
13
|
+
# field :image
|
14
|
+
|
15
|
+
field :questions do
|
16
|
+
read_only true
|
17
|
+
|
18
|
+
pretty_value do
|
19
|
+
bindings[:object].questions.to_a.map { |q|
|
20
|
+
route = bindings[:view] || bindings[:controller]
|
21
|
+
model_name = q.rails_admin_model
|
22
|
+
route.link_to(q.full_name, route.rails_admin.show_path(model_name: model_name, id: q.id), title: q.name)
|
23
|
+
}.join("<br>").html_safe
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
edit do
|
29
|
+
field :enabled, :toggle
|
30
|
+
field :name
|
31
|
+
# field :sidebar_title, :string
|
32
|
+
field :slugs, :enum do
|
33
|
+
enum_method do
|
34
|
+
:slugs
|
35
|
+
end
|
36
|
+
visible do
|
37
|
+
bindings[:view].current_user.admin?
|
38
|
+
end
|
39
|
+
multiple do
|
40
|
+
true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
field :text_slug
|
44
|
+
# field :image, :jcrop do
|
45
|
+
# jcrop_options do
|
46
|
+
# :image_jcrop_options
|
47
|
+
# end
|
48
|
+
# end
|
49
|
+
field :excerpt, :enjoy_html
|
50
|
+
field :content, :enjoy_html
|
51
|
+
|
52
|
+
group :seo do
|
53
|
+
active false
|
54
|
+
field :seo do
|
55
|
+
active true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
group :sitemap_data do
|
59
|
+
active false
|
60
|
+
field :sitemap_data do
|
61
|
+
active true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
fields.each_pair do |name, type|
|
66
|
+
if type.nil?
|
67
|
+
field name
|
68
|
+
else
|
69
|
+
if type.is_a?(Array)
|
70
|
+
field name, type[0], &type[1]
|
71
|
+
else
|
72
|
+
field name, type
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
field :questions do
|
78
|
+
read_only true
|
79
|
+
help 'Список вопросов'
|
80
|
+
|
81
|
+
pretty_value do
|
82
|
+
bindings[:object].questions.to_a.map { |q|
|
83
|
+
route = (bindings[:view] || bindings[:controller])
|
84
|
+
model_name = q.rails_admin_model
|
85
|
+
route.link_to(q.name, route.rails_admin.show_path(model_name: model_name, id: q.id), title: q.full_name)
|
86
|
+
}.join("<br>").html_safe
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
show do
|
92
|
+
field :name
|
93
|
+
# field :sidebar_title
|
94
|
+
field :slugs, :enum do
|
95
|
+
enum_method do
|
96
|
+
:slugs
|
97
|
+
end
|
98
|
+
visible do
|
99
|
+
bindings[:view].current_user.admin?
|
100
|
+
end
|
101
|
+
multiple do
|
102
|
+
true
|
103
|
+
end
|
104
|
+
end
|
105
|
+
field :text_slug
|
106
|
+
field :enabled
|
107
|
+
# field :image
|
108
|
+
field :excerpt
|
109
|
+
field :content
|
110
|
+
|
111
|
+
fields.each_pair do |name, type|
|
112
|
+
if type.nil?
|
113
|
+
field name
|
114
|
+
else
|
115
|
+
if type.is_a?(Array)
|
116
|
+
field name, type[0], &type[1]
|
117
|
+
else
|
118
|
+
field name, type
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
field :questions do
|
124
|
+
read_only true
|
125
|
+
|
126
|
+
pretty_value do
|
127
|
+
bindings[:object].questions.to_a.map { |q|
|
128
|
+
route = (bindings[:view] || bindings[:controller])
|
129
|
+
model_name = q.rails_admin_model
|
130
|
+
route.link_to(i.full_name, route.rails_admin.show_path(model_name: model_name, id: q.id), title: q.name)
|
131
|
+
}.join("<br>").html_safe
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
nested_set({max_depth: 2, scopes: []})
|
137
|
+
|
138
|
+
if block_given?
|
139
|
+
yield self
|
140
|
+
end
|
141
|
+
|
142
|
+
}
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Enjoy
|
2
|
+
module Faq
|
3
|
+
def self.configuration
|
4
|
+
@configuration ||= Configuration.new
|
5
|
+
end
|
6
|
+
def self.config
|
7
|
+
@configuration ||= Configuration.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.configure
|
11
|
+
yield configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
class Configuration
|
15
|
+
attr_accessor :author_name_required
|
16
|
+
|
17
|
+
attr_accessor :default_answer_author_name
|
18
|
+
|
19
|
+
attr_accessor :save_with_captcha
|
20
|
+
attr_accessor :captcha_error_message
|
21
|
+
|
22
|
+
attr_accessor :routes_config
|
23
|
+
|
24
|
+
def initialize
|
25
|
+
@author_name_required = true
|
26
|
+
|
27
|
+
@default_answer_author_name = "Администрация сайта"
|
28
|
+
|
29
|
+
@save_with_captcha = true
|
30
|
+
@captcha_error_message = "Код с картинки введен неверно"
|
31
|
+
|
32
|
+
@routes_config = {
|
33
|
+
use_questions_path: true,
|
34
|
+
use_question_categories_path: true,
|
35
|
+
use_faq_path: true
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Enjoy::Faq
|
2
|
+
module Controllers
|
3
|
+
module QuestionCategories
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def index
|
7
|
+
@question_categories = question_category_class.enabled.sorted.to_a
|
8
|
+
@root_categories = question_category_class.enabled.roots.sorted.all.to_a
|
9
|
+
# index_crumbs
|
10
|
+
end
|
11
|
+
|
12
|
+
def show
|
13
|
+
@question_category = question_category_class.enabled.find(params[:id])
|
14
|
+
if !@question_category.text_slug.blank? and @question_category.text_slug != params[:id]
|
15
|
+
redirect_to @question_category, status_code: 301
|
16
|
+
return
|
17
|
+
end
|
18
|
+
@seo_parent_page = find_seo_page(question_categories_path)
|
19
|
+
|
20
|
+
@children = @question_category.children.enabled.sorted.all.to_a
|
21
|
+
@questions = @question_category.questions.enabled.sorted.all.to_a
|
22
|
+
|
23
|
+
# index_crumbs
|
24
|
+
# category_crumbs
|
25
|
+
end
|
26
|
+
|
27
|
+
def page_title
|
28
|
+
if @question_category
|
29
|
+
@question_category.page_title
|
30
|
+
else
|
31
|
+
super
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def question_category_class
|
37
|
+
Enjoy::Faq::QuestionCategory
|
38
|
+
end
|
39
|
+
def question_class
|
40
|
+
Enjoy::Faq::Question
|
41
|
+
end
|
42
|
+
|
43
|
+
# def index_crumbs
|
44
|
+
# if @seo_parent_page
|
45
|
+
# catalog_title = Settings.ns('breadcrumbs').catalog_title(default: "Каталог", label: "'Каталог' в breadcrumbs")
|
46
|
+
# _crumb = catalog_title
|
47
|
+
# _crumb = @seo_parent_page.name if _crumb.blank?
|
48
|
+
# _crumb = @seo_parent_page.title if _crumb.blank?
|
49
|
+
# _crumb = @seo_parent_page.h1 if _crumb.blank?
|
50
|
+
# add_crumb _crumb, @seo_parent_page.fullpath
|
51
|
+
# else
|
52
|
+
# catalog_title = Settings.ns('breadcrumbs').catalog_title(default: "Каталог", label: "'Каталог' в breadcrumbs")
|
53
|
+
# _crumb = catalog_title
|
54
|
+
# add_crumb _crumb, item_categories_path
|
55
|
+
# end
|
56
|
+
# end
|
57
|
+
#
|
58
|
+
# def category_crumbs
|
59
|
+
# if @item_category
|
60
|
+
# _parent = @item_category.parent
|
61
|
+
# if _parent
|
62
|
+
# _crumb = _parent.name if _crumb.blank?
|
63
|
+
# _crumb = _parent.title if _crumb.blank?
|
64
|
+
# _crumb = _parent.h1 if _crumb.blank?
|
65
|
+
# add_crumb _crumb, item_category_path(_parent)
|
66
|
+
# _crumb = nil
|
67
|
+
# end
|
68
|
+
# _crumb = @item_category.name if _crumb.blank?
|
69
|
+
# _crumb = @item_category.title if _crumb.blank?
|
70
|
+
# _crumb = @item_category.h1 if _crumb.blank?
|
71
|
+
# add_crumb _crumb, item_category_path(@item_category)
|
72
|
+
# end
|
73
|
+
# end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module Enjoy::Faq
|
2
|
+
module Controllers
|
3
|
+
module Questions
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def index
|
7
|
+
@questions = question_class.enabled.sorted.to_a
|
8
|
+
# index_crumbs
|
9
|
+
end
|
10
|
+
|
11
|
+
def show
|
12
|
+
@question = question_class.enabled.find(params[:id])
|
13
|
+
if !@question.text_slug.blank? and @question.text_slug != params[:id]
|
14
|
+
redirect_to @question, status_code: 301
|
15
|
+
return
|
16
|
+
end
|
17
|
+
@parent_seo_page = find_seo_page(question_categories_path) if @seo_page.blank?
|
18
|
+
# item_crumbs
|
19
|
+
end
|
20
|
+
|
21
|
+
def page_title
|
22
|
+
if @question
|
23
|
+
@question.page_title
|
24
|
+
else
|
25
|
+
super
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def create
|
30
|
+
@question = question_class.new(question_params)
|
31
|
+
|
32
|
+
_method = Enjoy::Faq.configuration.save_with_captcha ? :save_with_captcha : :save
|
33
|
+
if @question.send(_method)
|
34
|
+
@message = "Успешно создано все"
|
35
|
+
else
|
36
|
+
@message = "Косяки есть"
|
37
|
+
end
|
38
|
+
|
39
|
+
if request.xhr?
|
40
|
+
render layout: false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def question_params
|
46
|
+
params[:question].permit(:question_text, :author_name, :author_email, :captcha, :captcha_key)
|
47
|
+
end
|
48
|
+
|
49
|
+
def question_category_class
|
50
|
+
Enjoy::Faq::QuestionCategory
|
51
|
+
end
|
52
|
+
def question_class
|
53
|
+
Enjoy::Faq::Question
|
54
|
+
end
|
55
|
+
|
56
|
+
# def item_crumbs
|
57
|
+
# if @item
|
58
|
+
# if @item.item_categories.enabled.count == 1
|
59
|
+
# if @parent_seo_page
|
60
|
+
# _crumb = @parent_seo_page.name
|
61
|
+
# _crumb = @parent_seo_page.title if _crumb.blank?
|
62
|
+
# _crumb = @parent_seo_page.h1 if _crumb.blank?
|
63
|
+
# add_crumb _crumb, @parent_seo_page.fullpath
|
64
|
+
# end
|
65
|
+
#
|
66
|
+
# @item_category = @item.item_categories.enabled.first
|
67
|
+
# _crumb = @item_category.name
|
68
|
+
# _crumb = @item_category.title if _crumb.blank?
|
69
|
+
# _crumb = @item_category.h1 if _crumb.blank?
|
70
|
+
# add_crumb _crumb, item_category_path(@item_category)
|
71
|
+
# end
|
72
|
+
# _crumb = @item.name
|
73
|
+
# _crumb = @item.title if _crumb.blank?
|
74
|
+
# _crumb = @item.h1 if _crumb.blank?
|
75
|
+
# add_crumb _crumb, item_path(@item)
|
76
|
+
# end
|
77
|
+
# end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Enjoy::Faq
|
2
|
+
module Models
|
3
|
+
module Mongoid
|
4
|
+
module Question
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
include Enjoy::HtmlField
|
8
|
+
|
9
|
+
included do
|
10
|
+
|
11
|
+
field :question_text
|
12
|
+
enjoy_cms_html_field :question_text_after_editing, localize: Enjoy.configuration.localize
|
13
|
+
field :author_name
|
14
|
+
field :author_name_text_after_editing, localize: Enjoy.configuration.localize
|
15
|
+
field :author_email
|
16
|
+
|
17
|
+
field :answered, type: Boolean, default: false
|
18
|
+
enjoy_cms_html_field :answer_text, localize: Enjoy.configuration.localize
|
19
|
+
field :answered_time, type: Time
|
20
|
+
field :answer_author_name, default: Enjoy::Faq.configuration.default_answer_author_name
|
21
|
+
|
22
|
+
has_and_belongs_to_many :question_categories, class_name: "Enjoy::Faq::QuestionCategory", inverse_of: nil
|
23
|
+
alias :categories :question_categories
|
24
|
+
|
25
|
+
acts_as_nested_set
|
26
|
+
scope :sorted, -> { order_by([:lft, :asc]) }
|
27
|
+
|
28
|
+
scope :after_now, -> { where(:created_at.lt => Time.now) }
|
29
|
+
scope :by_date, -> { desc(:created_at) }
|
30
|
+
scope :by_answered_date, -> { desc(:answered_time) }
|
31
|
+
scope :answered, -> { where(answered: true) }
|
32
|
+
scope :not_answered, -> { where(answered: false) }
|
33
|
+
|
34
|
+
scope :recent, ->(count = 5) { enabled.after_now.by_date.limit(count) }
|
35
|
+
end
|
36
|
+
|
37
|
+
def question_category
|
38
|
+
self.question_categories.enabled.sorted.first
|
39
|
+
end
|
40
|
+
|
41
|
+
def question_text_output
|
42
|
+
self.question_text_after_editing.blank? ? self.question_text : self.question_text_after_editing
|
43
|
+
end
|
44
|
+
|
45
|
+
def author_name_output
|
46
|
+
self.author_name_text_after_editing.blank? ? self.author_name : self.author_name_text_after_editing
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Enjoy::Faq
|
2
|
+
module Models
|
3
|
+
module Mongoid
|
4
|
+
module QuestionCategory
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
include Enjoy::HtmlField
|
8
|
+
|
9
|
+
included do
|
10
|
+
field :name, type: String, localize: Enjoy.configuration.localize
|
11
|
+
|
12
|
+
acts_as_nested_set
|
13
|
+
scope :sorted, -> { order_by([:lft, :asc]) }
|
14
|
+
|
15
|
+
enjoy_cms_html_field :excerpt, type: String, localize: Enjoy.configuration.localize, default: ""
|
16
|
+
enjoy_cms_html_field :content, type: String, localize: Enjoy.configuration.localize, default: ""
|
17
|
+
end
|
18
|
+
|
19
|
+
def questions
|
20
|
+
question_class.in(question_category_ids: self.id)
|
21
|
+
end
|
22
|
+
|
23
|
+
def all_questions
|
24
|
+
question_class.any_in(question_category_ids: self.self_and_descendants.map(&:id))
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Enjoy::Faq
|
2
|
+
module Models
|
3
|
+
module Question
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
include Enjoy::Model
|
6
|
+
include Enjoy::Enableable
|
7
|
+
|
8
|
+
include Enjoy::Seoable
|
9
|
+
include Enjoy::SitemapDataField
|
10
|
+
include ManualSlug
|
11
|
+
|
12
|
+
include Enjoy::Faq.orm_specific('Question')
|
13
|
+
|
14
|
+
included do
|
15
|
+
manual_slug :full_name
|
16
|
+
|
17
|
+
apply_simple_captcha message: Enjoy::Faq.configuration.captcha_error_message
|
18
|
+
|
19
|
+
validates_email_format_of :author_email
|
20
|
+
if Enjoy::Faq.config.author_name_required
|
21
|
+
validates_presence_of :author_name
|
22
|
+
end
|
23
|
+
validates_presence_of :question_text, :author_email
|
24
|
+
end
|
25
|
+
|
26
|
+
def name
|
27
|
+
"#{self.question_text_output} (#{self.author_name_output})"
|
28
|
+
end
|
29
|
+
|
30
|
+
def full_name
|
31
|
+
"#{self.author_name_output}: \"#{self.question_text_output}\""
|
32
|
+
end
|
33
|
+
|
34
|
+
def question_category_class
|
35
|
+
Enjoy::Faq::QuestionCategory
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Enjoy::Faq
|
2
|
+
module Models
|
3
|
+
module QuestionCategory
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
include Enjoy::Model
|
6
|
+
|
7
|
+
include Enjoy::Enableable
|
8
|
+
include Enjoy::Seoable
|
9
|
+
include Enjoy::SitemapDataField
|
10
|
+
include ManualSlug
|
11
|
+
|
12
|
+
include Enjoy::Faq.orm_specific('QuestionCategory')
|
13
|
+
|
14
|
+
included do
|
15
|
+
manual_slug :name
|
16
|
+
end
|
17
|
+
|
18
|
+
def clean_excerpt
|
19
|
+
self.excerpt ||= ""
|
20
|
+
Rails::Html::FullSanitizer.new.sanitize(self.excerpt.strip)
|
21
|
+
end
|
22
|
+
|
23
|
+
def clean_content
|
24
|
+
self.content ||= ""
|
25
|
+
Rails::Html::FullSanitizer.new.sanitize(self.content.strip)
|
26
|
+
end
|
27
|
+
|
28
|
+
def question_class
|
29
|
+
Enjoy::Faq::Question
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "enjoy/faq/version"
|
2
|
+
|
3
|
+
require 'money-rails'
|
4
|
+
|
5
|
+
require 'enjoy_cms_mongoid'
|
6
|
+
require 'rails_admin_sort_embedded'
|
7
|
+
require 'rails_admin_jcrop'
|
8
|
+
|
9
|
+
require 'enjoy/faq/configuration'
|
10
|
+
require 'enjoy/faq/engine'
|
11
|
+
|
12
|
+
module Enjoy
|
13
|
+
module Faq
|
14
|
+
class << self
|
15
|
+
def orm
|
16
|
+
:mongoid
|
17
|
+
end
|
18
|
+
def mongoid?
|
19
|
+
Enjoy::Faq.orm == :mongoid
|
20
|
+
end
|
21
|
+
def active_record?
|
22
|
+
Enjoy::Faq.orm == :active_record
|
23
|
+
end
|
24
|
+
def model_namespace
|
25
|
+
"Enjoy::Faq::Models::#{Enjoy::Catalog.orm.to_s.camelize}"
|
26
|
+
end
|
27
|
+
def orm_specific(name)
|
28
|
+
"#{model_namespace}::#{name}".constantize
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
autoload :Admin, 'enjoy/faq/admin'
|
33
|
+
module Admin
|
34
|
+
autoload :Question, 'enjoy/faq/admin/question'
|
35
|
+
autoload :QuestionCategory, 'enjoy/faq/admin/question_category'
|
36
|
+
end
|
37
|
+
|
38
|
+
module Models
|
39
|
+
autoload :Question, 'enjoy/faq/models/question'
|
40
|
+
autoload :QuestionCategory, 'enjoy/faq/models/question_category'
|
41
|
+
|
42
|
+
module Mongoid
|
43
|
+
autoload :Question, 'enjoy/faq/models/mongoid/question'
|
44
|
+
autoload :QuestionCategory, 'enjoy/faq/models/mongoid/question_category'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
module Controllers
|
49
|
+
autoload :Questions, 'enjoy/faq/controllers/questions'
|
50
|
+
autoload :QuestionCategories, 'enjoy/faq/controllers/question_categories'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/release.sh
ADDED
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: enjoy_cms_faq
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Kiseliev
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: enjoy_cms
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.3.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.3.0
|
55
|
+
description: FAQ system with EnjoyCMS support.
|
56
|
+
email:
|
57
|
+
- dev@enjoycreate.ru
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- app/controllers/concerns/enjoy/catalog/decorators/question_categories.rb
|
69
|
+
- app/controllers/concerns/enjoy/catalog/decorators/questions.rb
|
70
|
+
- app/controllers/concerns/enjoy/faq/decorators/question_categories.rb
|
71
|
+
- app/controllers/concerns/enjoy/faq/decorators/questions.rb
|
72
|
+
- app/controllers/enjoy/faq/question_categories_controller.rb
|
73
|
+
- app/controllers/enjoy/faq/questions_controller.rb
|
74
|
+
- app/models/concerns/enjoy/faq/decorators/question.rb
|
75
|
+
- app/models/concerns/enjoy/faq/decorators/question_category.rb
|
76
|
+
- app/models/enjoy/faq/question.rb
|
77
|
+
- app/models/enjoy/faq/question_category.rb
|
78
|
+
- app/views/enjoy/faq/question_categories/index.html.slim
|
79
|
+
- app/views/enjoy/faq/question_categories/show.html.slim
|
80
|
+
- app/views/enjoy/faq/questions/_new_question_form.html.slim
|
81
|
+
- app/views/enjoy/faq/questions/_question_block.html.slim
|
82
|
+
- app/views/enjoy/faq/questions/create.html.slim
|
83
|
+
- app/views/enjoy/faq/questions/index.html.slim
|
84
|
+
- app/views/enjoy/faq/questions/new.html.slim
|
85
|
+
- app/views/enjoy/faq/questions/show.html.slim
|
86
|
+
- bin/console
|
87
|
+
- bin/setup
|
88
|
+
- config/initializers/rails_admin.rb
|
89
|
+
- config/routes.rb
|
90
|
+
- enjoy_cms_faq.gemspec
|
91
|
+
- lib/enjoy/faq/admin.rb
|
92
|
+
- lib/enjoy/faq/admin/question.rb
|
93
|
+
- lib/enjoy/faq/admin/question_category.rb
|
94
|
+
- lib/enjoy/faq/configuration.rb
|
95
|
+
- lib/enjoy/faq/controllers/question_categories.rb
|
96
|
+
- lib/enjoy/faq/controllers/questions.rb
|
97
|
+
- lib/enjoy/faq/engine.rb
|
98
|
+
- lib/enjoy/faq/models/mongoid/question.rb
|
99
|
+
- lib/enjoy/faq/models/mongoid/question_category.rb
|
100
|
+
- lib/enjoy/faq/models/question.rb
|
101
|
+
- lib/enjoy/faq/models/question_category.rb
|
102
|
+
- lib/enjoy/faq/version.rb
|
103
|
+
- lib/enjoy_cms_faq.rb
|
104
|
+
- release.sh
|
105
|
+
homepage: https://github.com/enjoycreative/enjoy_cms_faq
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.4.8
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: FAQ system with EnjoyCMS support.
|
129
|
+
test_files: []
|