hancock_cms_faq 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +4 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +55 -0
  9. data/Rakefile +1 -0
  10. data/app/assets/javascripts/hancock/faq.coffee +6 -0
  11. data/app/assets/javascripts/hancock/faq/form.coffee +9 -0
  12. data/app/assets/javascripts/hancock/faq/init.coffee +2 -0
  13. data/app/assets/stylesheets/hancock/faq.sass +0 -0
  14. data/app/controllers/concerns/hancock/faq/decorators/categories.rb +17 -0
  15. data/app/controllers/concerns/hancock/faq/decorators/questions.rb +71 -0
  16. data/app/controllers/hancock/faq/categories_controller.rb +7 -0
  17. data/app/controllers/hancock/faq/questions_controller.rb +7 -0
  18. data/app/models/concerns/hancock/faq/decorators/category.rb +36 -0
  19. data/app/models/concerns/hancock/faq/decorators/question.rb +48 -0
  20. data/app/models/hancock/faq/category.rb +11 -0
  21. data/app/models/hancock/faq/question.rb +11 -0
  22. data/app/views/hancock/faq/categories/index.html.slim +10 -0
  23. data/app/views/hancock/faq/categories/show.html.slim +8 -0
  24. data/app/views/hancock/faq/questions/_fields.html.slim +11 -0
  25. data/app/views/hancock/faq/questions/_fields_with_settings.html.slim +20 -0
  26. data/app/views/hancock/faq/questions/_form.html.slim +66 -0
  27. data/app/views/hancock/faq/questions/_form_with_wrapper.html.slim +2 -0
  28. data/app/views/hancock/faq/questions/_question_block.html.slim +33 -0
  29. data/app/views/hancock/faq/questions/_simple_captcha.html.slim +16 -0
  30. data/app/views/hancock/faq/questions/_success.html.slim +3 -0
  31. data/app/views/hancock/faq/questions/create.html.slim +1 -0
  32. data/app/views/hancock/faq/questions/index.html.slim +11 -0
  33. data/app/views/hancock/faq/questions/new.html.slim +6 -0
  34. data/app/views/hancock/faq/questions/show.html.slim +8 -0
  35. data/app/views/hancock/faq/questions/update_captcha.html.slim +16 -0
  36. data/bin/console +14 -0
  37. data/bin/setup +7 -0
  38. data/config/locales/hancock.faq.ru.yml +64 -0
  39. data/hancock_cms_faq.gemspec +36 -0
  40. data/lib/generators/hancock/faq/config/config_generator.rb +13 -0
  41. data/lib/generators/hancock/faq/config/templates/hancock_faq.erb +23 -0
  42. data/lib/generators/hancock/faq/controllers/all_generator.rb +28 -0
  43. data/lib/generators/hancock/faq/controllers/category_generator.rb +43 -0
  44. data/lib/generators/hancock/faq/controllers/decorators_generator.rb +24 -0
  45. data/lib/generators/hancock/faq/controllers/question_generator.rb +43 -0
  46. data/lib/generators/hancock/faq/controllers/templates/categories_controller.erb +10 -0
  47. data/lib/generators/hancock/faq/controllers/templates/questions_controller.erb +10 -0
  48. data/lib/generators/hancock/faq/models/all_generator.rb +28 -0
  49. data/lib/generators/hancock/faq/models/category_generator.rb +43 -0
  50. data/lib/generators/hancock/faq/models/decorators_generator.rb +24 -0
  51. data/lib/generators/hancock/faq/models/question_generator.rb +34 -0
  52. data/lib/generators/hancock/faq/models/templates/category.erb +36 -0
  53. data/lib/generators/hancock/faq/models/templates/question.erb +37 -0
  54. data/lib/hancock/faq/admin.rb +6 -0
  55. data/lib/hancock/faq/admin/category.rb +128 -0
  56. data/lib/hancock/faq/admin/question.rb +104 -0
  57. data/lib/hancock/faq/configuration.rb +53 -0
  58. data/lib/hancock/faq/controllers/categories.rb +88 -0
  59. data/lib/hancock/faq/controllers/questions.rb +174 -0
  60. data/lib/hancock/faq/engine.rb +7 -0
  61. data/lib/hancock/faq/models/category.rb +50 -0
  62. data/lib/hancock/faq/models/mongoid/category.rb +33 -0
  63. data/lib/hancock/faq/models/mongoid/question.rb +72 -0
  64. data/lib/hancock/faq/models/question.rb +85 -0
  65. data/lib/hancock/faq/routes.rb +83 -0
  66. data/lib/hancock/faq/version.rb +5 -0
  67. data/lib/hancock_cms_faq.rb +31 -0
  68. data/release.sh +6 -0
  69. metadata +159 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b805ff6820575b001725be796416aa508ad6c7f9
4
+ data.tar.gz: 87add6a36016ec18182aaf15cb415d6a539149fd
5
+ SHA512:
6
+ metadata.gz: 34a23e6577df41b03b5af99565649eae6f344cbf8f17737b316f6795b7e147d363537f63b3bf69e768e4b8959092801e3b440307f0f16787addb74daae002272
7
+ data.tar.gz: f57864e1be1a6fe8a19ef665ec457de39bb856d5c818ca7300cd565c28f0e0b75d3f9b951def2278df51e4ae3166537294496848328c772e87541d3230d1cde6
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1 @@
1
+ hancock_cms_faq
@@ -0,0 +1 @@
1
+ 2.3.1
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hancock_cms_faq.gemspec
4
+ gemspec
@@ -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.
@@ -0,0 +1,55 @@
1
+ # HancockCmsFaq
2
+
3
+ ### Remaded from [EnjoyCMSFaq](https://github.com/enjoycreative/enjoy_cms_faq)
4
+
5
+ FAQ system for [HancockCMS](https://github.com/red-rocks/hancock_cms).
6
+ Question send form, question categories, captcha support
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'hancock_cms_faq'
14
+ ```
15
+
16
+ Then add this
17
+ ```ruby
18
+ gem "recaptcha", require: "recaptcha/rails" # Recaptcha
19
+ ```
20
+ or this
21
+ ```ruby
22
+ gem "glebtv-simple_captcha" # simple_captcha
23
+ ```
24
+ before it for captcha you need. And configure it. If you need
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install hancock_cms_faq
33
+
34
+ ## Usage
35
+
36
+ Add in config/routes.rb
37
+
38
+ ```ruby
39
+ hancock_cms_faq_routes
40
+ ```
41
+
42
+ ## Development
43
+
44
+ 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.
45
+
46
+ 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).
47
+
48
+ ## Contributing
49
+
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/red-rocks/hancock_cms_faq.
51
+
52
+
53
+ ## License
54
+
55
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,6 @@
1
+ #= require ./faq/init
2
+ #= require ./faq/form
3
+
4
+ #= require_self
5
+
6
+ window.hancock_cms.faq.create_ajax_form()
@@ -0,0 +1,9 @@
1
+ window.hancock_cms.faq.create_ajax_form = (form_selector = "#new_hancock_faq_question", wrapper_selector = "#hancock_faq_form" )->
2
+
3
+ $(document).delegate form_selector, "ajax:complete", (event, xhr, status)->
4
+ $(event.currentTarget).closest(wrapper_selector).html(xhr.responseText)
5
+
6
+ $(document).delegate form_selector + " .input", 'click', (e) ->
7
+ e.preventDefault()
8
+ $(e.currentTarget).removeClass("field_with_errors").find('span.error').hide()
9
+ return false
@@ -0,0 +1,2 @@
1
+ window.hancock_cms ||= {}
2
+ window.hancock_cms.faq ||= {}
@@ -0,0 +1,17 @@
1
+ module Hancock::Faq::Decorators
2
+ module Categories
3
+ extend ActiveSupport::Concern
4
+
5
+ # included do
6
+ #
7
+ # def category_class
8
+ # Hancock::Faq::Category
9
+ # end
10
+ # def question_class
11
+ # Hancock::Faq::Question
12
+ # end
13
+ #
14
+ # end
15
+
16
+ end
17
+ end
@@ -0,0 +1,71 @@
1
+ module Hancock::Faq::Decorators
2
+ module Questions
3
+ extend ActiveSupport::Concern
4
+
5
+ # included do
6
+ #
7
+ # def hancock_faq_update_captcha_path
8
+ # url_for(action: :update_captcha, time: Time.new.to_i, only_path: true)
9
+ # end
10
+ # def cache_fields?
11
+ # ['new', 'index'].include? action_name
12
+ # end
13
+ # def cache_key
14
+ # 'hancock_faq_question_fields'.freeze
15
+ # end
16
+ # def fields_partial
17
+ # "hancock/faq/questions/#{(Hancock::Faq.config.model_settings_support ? 'fields' : 'fields_with_settings')}".freeze
18
+ # end
19
+ # def settings_scope
20
+ # if Hancock::Faq.config.model_settings_support
21
+ # question_class.settings
22
+ # elsif defined?(Settings)
23
+ # Settings.ns('FAQ')
24
+ # else
25
+ # nil
26
+ # end
27
+ # end
28
+ #
29
+ # def render_faq_error
30
+ # if request.xhr? && process_ajax
31
+ # render partial: form_partial, status: 422
32
+ # # render json: {errors: @contact_message.errors}, status: 422
33
+ # else
34
+ # flash.now[:alert] = @question.errors.full_messages.join("\n")
35
+ # render action: Hancock::Faq.configuration.recreate_contact_message_action, status: 422
36
+ # end
37
+ # end
38
+ # def process_ajax
39
+ # true
40
+ # end
41
+ # def ajax_success
42
+ # render partial: success_partial
43
+ # # render json: {ok: true}
44
+ # end
45
+ # def redirect_after_done
46
+ # redirect_to action: :sent
47
+ # end
48
+ # def xhr_checker
49
+ # if request.xhr?
50
+ # render layout: false
51
+ # end
52
+ # end
53
+ # def after_initialize
54
+ # end
55
+ # def after_create
56
+ # # overrideable hook for updating message
57
+ # end
58
+ # def form_partial
59
+ # "hancock/faq/questions/form"
60
+ # end
61
+ # def success_partial
62
+ # "hancock/faq/questions/success"
63
+ # end
64
+ # def question_params
65
+ # params[:hancock_faq_question].permit(:question_text, :author_name, :author_email, :captcha, :captcha_key)
66
+ # end
67
+ #
68
+ # end
69
+
70
+ end
71
+ end
@@ -0,0 +1,7 @@
1
+ module Hancock::Faq
2
+ class CategoriesController < ApplicationController
3
+ include Hancock::Faq::Controllers::Categories
4
+
5
+ include Hancock::Faq::Decorators::Categories
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Hancock::Faq
2
+ class QuestionsController < ApplicationController
3
+ include Hancock::Faq::Controllers::Questions
4
+
5
+ include Hancock::Faq::Decorators::Questions
6
+ end
7
+ end
@@ -0,0 +1,36 @@
1
+ module Hancock::Faq::Decorators
2
+ module Category
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ # def self.default_cache_keys
7
+ # []
8
+ # end
9
+ #
10
+ # ############# rails_admin ##############
11
+ # def self.rails_admin_add_fields
12
+ # {}
13
+ # end
14
+ #
15
+ # def self.rails_admin_add_config(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
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,48 @@
1
+ module Hancock::Faq::Decorators
2
+ module Question
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ # def self.default_cache_keys
7
+ # []
8
+ # end
9
+ #
10
+ # def send_emails?
11
+ # true
12
+ # end
13
+ #
14
+ # def mailer_class
15
+ # Hancock::Feedback::ContactMailer
16
+ # end
17
+ #
18
+ # def mailer_method
19
+ # :new_message_email
20
+ # end
21
+ #
22
+ # ############# rails_admin ##############
23
+ # def self.rails_admin_add_fields
24
+ # {}
25
+ # end
26
+ #
27
+ # def self.rails_admin_add_config(config)
28
+ # end
29
+ #
30
+ # def self.admin_can_user_defined_actions
31
+ # [].freeze
32
+ # end
33
+ # def self.admin_cannot_user_defined_actions
34
+ # [].freeze
35
+ # end
36
+ # def self.manager_can_user_defined_actions
37
+ # [].freeze
38
+ # end
39
+ # def self.manager_cannot_user_defined_actions
40
+ # [].freeze
41
+ # end
42
+ # def self.rails_admin_user_defined_visible_actions
43
+ # [].freeze
44
+ # end
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,11 @@
1
+ module Hancock::Faq
2
+ class Category
3
+ include Hancock::Faq::Models::Category
4
+
5
+ include Hancock::Faq::Decorators::Category
6
+
7
+ rails_admin(&Hancock::Faq::Admin::Category.config(rails_admin_add_fields) { |config|
8
+ rails_admin_add_config(config)
9
+ })
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Hancock::Faq
2
+ class Question
3
+ include Hancock::Faq::Models::Question
4
+
5
+ include Hancock::Faq::Decorators::Question
6
+
7
+ rails_admin(&Hancock::Faq::Admin::Question.config(rails_admin_add_fields) { |config|
8
+ rails_admin_add_config(config)
9
+ })
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ - _partial_path = (Hancock::Faq.config.seo_support ? 'shared/obj_with_seo' : 'shared/obj')
2
+ = render _partial_path, obj: (@seo_page || @seo_parent_page)
3
+
4
+
5
+ - @categories.each do |c|
6
+ p= link_to c.name, hancock_faq_category_path(c), title: c.name
7
+
8
+ .newquestionform
9
+ p.newquestiontitle Задать свой вопрос:
10
+ = render partial: "hancock/faq/questions/form_with_wrapper"
@@ -0,0 +1,8 @@
1
+ / - _cache_helper = (Hancock::Faq.config.cache_support ? :hancock_cache : :cache)
2
+
3
+ - _partial_path = (Hancock::Faq.config.seo_support ? 'shared/obj_with_seo' : 'shared/obj')
4
+ = render _partial_path, obj: @category
5
+
6
+ h1= @category.name
7
+ - @questions.each do |q|
8
+ = link_to q.name.html_safe, hancock_faq_question_path(q), title: q.name
@@ -0,0 +1,11 @@
1
+ - label = t('hancock.faq_plugin.fields.author_name.label')
2
+ - placeholder = t('hancock.faq_plugin.fields.author_name.placeholder')
3
+ = f.input :author_name, label: label, input_html: {placeholder: placeholder, autofocus: true}
4
+
5
+ - label = t('hancock.faq_plugin.fields.author_email.label')
6
+ - placeholder = t('hancock.faq_plugin.fields.author_email.placeholder')
7
+ = f.input :author_email, label: label, input_html: {placeholder: placeholder}
8
+
9
+ - label = t('hancock.faq_plugin.fields.question_text.label')
10
+ - placeholder = t('hancock.faq_plugin.fields.question_text.placeholder')
11
+ = f.input :question_text, as: :text, label: label, input_html: {placeholder: placeholder}
@@ -0,0 +1,20 @@
1
+ ruby:
2
+ cache_key ||= 'views/hancock_faq_question_fields'.freeze
3
+ if Hancock::Faq.config.model_settings_support
4
+ settings_scope ||= Hancock::Faq::Question.settings
5
+ elsif defined?(Settings)
6
+ settings_scope ||= Settings.ns('FAQ')
7
+ end
8
+
9
+
10
+ - label = settings_scope.author_name_label(default: t('hancock.faq_plugin.fields.author_name.label'), label: "Заголовок поля ФИО", cache_keys: cache_key)
11
+ - placeholder = settings_scope.author_name_placeholder(default: t('hancock.faq_plugin.fields.author_name.placeholder'), label: "Placeholder поля ФИО", cache_keys: cache_key)
12
+ = f.input :author_name, label: label, input_html: {placeholder: placeholder, autofocus: true}
13
+
14
+ - label = settings_scope.author_email_label(default: t('hancock.faq_plugin.fields.author_email.label'), label: "Заголовок поля e-mail", cache_keys: cache_key)
15
+ - placeholder = settings_scope.author_email_placeholder(default: t('hancock.faq_plugin.fields.author_email.placeholder'), label: "Placeholder поля e-mail", cache_keys: cache_key)
16
+ = f.input :author_email, label: label, input_html: {placeholder: placeholder}
17
+
18
+ - label = settings_scope.question_text_label(default: t('hancock.faq_plugin.fields.question_text.label'), label: "Заголовок поля текст вопроса", cache_keys: cache_key)
19
+ - placeholder = settings_scope.question_text_placeholder(default: t('hancock.faq_plugin.fields.question_text.placeholder'), label: "Placeholder поля текст вопроса", cache_keys: cache_key)
20
+ = f.input :question_text, as: :text, label: label, input_html: {placeholder: placeholder}
@@ -0,0 +1,66 @@
1
+ ruby:
2
+ is_cache_fields ||= ['new', 'index'].include? action_name
3
+ cache_key ||= 'hancock_faq_question_fields'.freeze
4
+ if Hancock::Faq.config.model_settings_support
5
+ settings_scope ||= Hancock::Faq::Question.settings
6
+ elsif defined?(Settings)
7
+ settings_scope ||= Settings.ns('FAQ')
8
+ end
9
+ fields_partial ||= "hancock/faq/questions/#{(Hancock::Faq.config.model_settings_support ? 'fields_with_settings' : 'fields')}".freeze
10
+ recaptcha_options ||= {}
11
+ @question ||= Hancock::Faq::Question.new
12
+ _cache_helper ||= (Hancock::Catalog.config.cache_support ? :hancock_cache : :cache)
13
+
14
+ = simple_form_for @question, url: hancock_faq_questions_path, html: {data: {remote: true }} do |f|
15
+ - if is_cache_fields
16
+ - send _cache_helper, cache_key, skip_digest: true do
17
+ = render partial: fields_partial, locals: {f: f, cache_key: "views/#{cache_key}", settings_scope: settings_scope}
18
+ - else
19
+ = render partial: fields_partial, locals: {f: f, settings_scope: settings_scope}
20
+
21
+ - if Hancock::Faq.config.captcha
22
+ - if Hancock::Faq.config.recaptcha_support
23
+ .input
24
+ - if @recaptcha_error
25
+ span.error.recaptcha_error= @recaptcha_error
26
+ = recaptcha_tags
27
+ - elsif Hancock::Faq.config.simple_captcha_support
28
+ = render partial: "hancock/faq/questions/simple_captcha", locals: {f: f, settings_scope: settings_scope}
29
+
30
+ - if Hancock::Faq.config.model_settings_support
31
+ - label = settings_scope.submit_label(default: t('hancock.send'), label: "Текст на кнопке отправки")
32
+ - else
33
+ - label = t('hancock.send')
34
+ = f.submit label
35
+
36
+
37
+
38
+ / - @question ||= Hancock::Faq::Question.new
39
+ / - if @question.new_record?
40
+ / = simple_form_for @question, url: hancock_faq_questions_path do |f|
41
+ / - unless @message.blank?
42
+ / h3= @message
43
+ / .inputtextblock_q
44
+ /
45
+ / - label = Settings.ns('faq_form').author_name_label( default: "ФИО", label: "Заголовок поля ФИО")
46
+ / = f.input :author_name, label: label
47
+ /
48
+ / - label = Settings.ns('faq_form').author_email_label( default: "E-mail", label: "Заголовок поля E-mail")
49
+ / = f.input :author_email, as: :email, label: label
50
+ /
51
+ / - label = Settings.ns('faq_form').question_text_label( default: "Текст вопроса", label: "Заголовок поля Текст вопроса")
52
+ / = f.input :question_text, as: :text, label: label
53
+ /
54
+ /
55
+ / - if Hancock::Faq.configuration.save_with_captcha
56
+ / .question_captcha
57
+ / - label = Settings.ns('faq_form').captcha_label( default: "Код проверки", label: "Заголовок поля Код проверки")
58
+ / = f.simple_captcha label: label, required: true
59
+ / - unless @question.errors[:captcha].blank?
60
+ / span.error= @question.errors[:captcha].join("<br />").html_safe
61
+ /
62
+ / - label = Settings.ns('faq_form').submit_label( default: "Отправить", label: "Заголовок кнопки Отправить")
63
+ / = f.button :submit, label
64
+ / - else
65
+ / - unless @message.blank?
66
+ / h3= @message