know_more 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +130 -0
  4. data/Rakefile +26 -0
  5. data/app/assets/config/know_more_manifest.js +2 -0
  6. data/app/assets/javascripts/know_more/application.js +13 -0
  7. data/app/assets/stylesheets/know_more/application.css +15 -0
  8. data/app/controllers/know_more/application_controller.rb +5 -0
  9. data/app/controllers/know_more/controller_helpers.rb +14 -0
  10. data/app/controllers/know_more/questionnaire_controller.rb +55 -0
  11. data/app/helpers/know_more/application_helper.rb +4 -0
  12. data/app/jobs/know_more/application_job.rb +4 -0
  13. data/app/mailers/know_more/application_mailer.rb +6 -0
  14. data/app/models/concerns/know_more/application_record.rb +5 -0
  15. data/app/models/concerns/know_more/questionnaire.rb +7 -0
  16. data/app/views/layouts/know_more/application.html.erb +14 -0
  17. data/config/routes.rb +7 -0
  18. data/lib/generators/know_more/init_generator.rb +13 -0
  19. data/lib/generators/know_more/install_generator.rb +45 -0
  20. data/lib/generators/know_more/templates/concerns.rb.erb +23 -0
  21. data/lib/generators/know_more/templates/erb/page_template.erb +39 -0
  22. data/lib/generators/know_more/templates/haml/page_template.erb +32 -0
  23. data/lib/generators/know_more/templates/initializer.rb.erb +4 -0
  24. data/lib/generators/know_more/templates/models/migration.rb.erb +9 -0
  25. data/lib/generators/know_more/templates/models/model.rb.erb +3 -0
  26. data/lib/know_more.rb +6 -0
  27. data/lib/know_more/base.rb +24 -0
  28. data/lib/know_more/configuration.rb +9 -0
  29. data/lib/know_more/engine.rb +16 -0
  30. data/lib/know_more/version.rb +3 -0
  31. data/lib/tasks/know_more_tasks.rake +4 -0
  32. data/spec/rails_helper.rb +57 -0
  33. data/spec/spec_helper.rb +99 -0
  34. data/spec/test_app/Rakefile +6 -0
  35. data/spec/test_app/app/assets/config/manifest.js +5 -0
  36. data/spec/test_app/app/assets/javascripts/application.js +15 -0
  37. data/spec/test_app/app/assets/javascripts/cable.js +13 -0
  38. data/spec/test_app/app/assets/stylesheets/application.css +15 -0
  39. data/spec/test_app/app/channels/application_cable/channel.rb +4 -0
  40. data/spec/test_app/app/channels/application_cable/connection.rb +4 -0
  41. data/spec/test_app/app/controllers/application_controller.rb +8 -0
  42. data/spec/test_app/app/controllers/concerns/know_more/questionnaire_controller_concerns.rb +42 -0
  43. data/spec/test_app/app/controllers/welcome_controller.rb +5 -0
  44. data/spec/test_app/app/helpers/application_helper.rb +2 -0
  45. data/spec/test_app/app/jobs/application_job.rb +2 -0
  46. data/spec/test_app/app/mailers/application_mailer.rb +4 -0
  47. data/spec/test_app/app/models/application_record.rb +3 -0
  48. data/spec/test_app/app/models/questionnaire.rb +3 -0
  49. data/spec/test_app/app/views/know_more/questionnaire/step1.html.haml +29 -0
  50. data/spec/test_app/app/views/know_more/questionnaire/step2.html.haml +31 -0
  51. data/spec/test_app/app/views/know_more/questionnaire/step3.html.haml +30 -0
  52. data/spec/test_app/app/views/layouts/application.html.erb +14 -0
  53. data/spec/test_app/app/views/layouts/mailer.html.erb +13 -0
  54. data/spec/test_app/app/views/layouts/mailer.text.erb +1 -0
  55. data/spec/test_app/app/views/welcome/hello.html.erb +1 -0
  56. data/spec/test_app/bin/bundle +3 -0
  57. data/spec/test_app/bin/rails +4 -0
  58. data/spec/test_app/bin/rake +4 -0
  59. data/spec/test_app/bin/setup +34 -0
  60. data/spec/test_app/bin/update +29 -0
  61. data/spec/test_app/config.ru +5 -0
  62. data/spec/test_app/config/application.rb +23 -0
  63. data/spec/test_app/config/boot.rb +5 -0
  64. data/spec/test_app/config/cable.yml +9 -0
  65. data/spec/test_app/config/database.yml +25 -0
  66. data/spec/test_app/config/environment.rb +5 -0
  67. data/spec/test_app/config/environments/development.rb +54 -0
  68. data/spec/test_app/config/environments/production.rb +86 -0
  69. data/spec/test_app/config/environments/test.rb +42 -0
  70. data/spec/test_app/config/initializers/application_controller_renderer.rb +6 -0
  71. data/spec/test_app/config/initializers/assets.rb +11 -0
  72. data/spec/test_app/config/initializers/backtrace_silencers.rb +7 -0
  73. data/spec/test_app/config/initializers/cookies_serializer.rb +5 -0
  74. data/spec/test_app/config/initializers/filter_parameter_logging.rb +4 -0
  75. data/spec/test_app/config/initializers/inflections.rb +16 -0
  76. data/spec/test_app/config/initializers/know_more.rb +4 -0
  77. data/spec/test_app/config/initializers/mime_types.rb +4 -0
  78. data/spec/test_app/config/initializers/new_framework_defaults.rb +24 -0
  79. data/spec/test_app/config/initializers/session_store.rb +3 -0
  80. data/spec/test_app/config/initializers/wrap_parameters.rb +14 -0
  81. data/spec/test_app/config/locales/en.yml +23 -0
  82. data/spec/test_app/config/puma.rb +47 -0
  83. data/spec/test_app/config/routes.rb +5 -0
  84. data/spec/test_app/config/secrets.yml +22 -0
  85. data/spec/test_app/config/spring.rb +6 -0
  86. data/spec/test_app/db/development.sqlite3 +0 -0
  87. data/spec/test_app/db/migrate/20161027141359_create_questionnaire.rb +12 -0
  88. data/spec/test_app/db/schema.rb +24 -0
  89. data/spec/test_app/lib/know_more/questionnaire_controller_concerns.rb +21 -0
  90. data/spec/test_app/log/development.log +3813 -0
  91. data/spec/test_app/public/404.html +67 -0
  92. data/spec/test_app/public/422.html +67 -0
  93. data/spec/test_app/public/500.html +66 -0
  94. data/spec/test_app/public/apple-touch-icon-precomposed.png +0 -0
  95. data/spec/test_app/public/apple-touch-icon.png +0 -0
  96. data/spec/test_app/public/favicon.ico +0 -0
  97. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/-M/-Mhn0x6IA3ei53dCjTNB4QapIeIWnhFjjvWlObqhWxY.cache +1 -0
  98. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/-h/-hPQhUvmVonbzE86tGolE7GRuNFFf3NsKvt1mwHwIg0.cache +0 -0
  99. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/0S/0SvZGDW10EU46QZko9M15Exl1RDa9Ud5osSt660CuzQ.cache +0 -0
  100. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/24/24PpPX2bi_nuVnh3Bx8Nqj-UO3-1dbdgtFa6v7iPaLo.cache +1 -0
  101. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/6P/6PoXC3inbHQs_iJ8sp-AEYUgrRllcZHE8stF6_FuI2s.cache +3 -0
  102. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/8M/8M6Y8ZU8aBj7dfklYKmqgzKWfv5nIDcx4jR-cMu9Hgc.cache +0 -0
  103. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/Ao/Ao0OdzieB2BHIS0J1OX5-CzoMHHagT-hWe_ospTLEz4.cache +1 -0
  104. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/Ca/Ca7J7u8QQVfncKxGfYDjkhl4ezOotD2PbJTwmY88R08.cache +0 -0
  105. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/D7/D7JZQRMd7o6Oa3O8XYxxcWv4NGy5XUHEBQjbTtTIw0w.cache +1 -0
  106. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/Df/DfqHLjOcuVNA6fgR3rrM8D7q4VveBYvUn9OaxdDb2aI.cache +2 -0
  107. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/E8/E869Vssa93t7BK-iyJUAbuMcVw65khT8ZkFTdkgPoNA.cache +1 -0
  108. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/Eu/EuUPUxyK1i0O9kRow6J2gQlEgannj8ele8bYrOH0WkE.cache +0 -0
  109. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/F5/F5aTSXaWVMd07oSPX3KS5DuFnGw2SlYAYvIl2rt3xKU.cache +2 -0
  110. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/F6/F69NGMZogprXR3htKJ6d0kVkFS9EgtSIrMd_Rv4lQo4.cache +1 -0
  111. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/FW/FWd91hU2C6pptRvlqp8-fMKs0Pgd_JfiT3TPiYXBGoc.cache +1 -0
  112. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/FW/FWlz-VvryvvUjDXSLRDM06krdCHZ6jb2HNM8n2lYvno.cache +1 -0
  113. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/Fh/FhoIJOA98Fe9tpfSEnFORkI01I9KVpmYAx_mXC4gQYo.cache +2 -0
  114. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/G4/G4f_wqyGuSDH5PqO-cG6noP4D5EK3Kylzj3yOte-Z3E.cache +3 -0
  115. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/Jj/Jj08SeolaHESqwfZBGZ0tcinAfB1oMbMugBODKZGtmk.cache +1 -0
  116. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/KU/KUHCmze6iHkktV-xkd_pe8zKkrea7B0GA0AyNzPi8VI.cache +2 -0
  117. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/Ky/KyLnrp_TTwObMeq3b1zzPd9lvWbGgM05pRhE6K26DSw.cache +1 -0
  118. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/LZ/LZodg9A2YVhhIboloe0zr_qCYE_SsB41W42B9a16AvQ.cache +0 -0
  119. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/M6/M66hYfGZ7alPDFVsvZX20gGKa3hoXU4ZX57eWmf-8Q0.cache +1 -0
  120. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/Mb/MbA44Lqly0ejzpXgTsIIH7tnssjDcn_I4grw6t_PNFs.cache +1 -0
  121. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/Nh/Nhqfo87al4XtybNfUPjhR8idEE6eKcbsVOuQtiPqaz8.cache +1 -0
  122. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/On/OnToO1iuSf982Y8PilnSN969yImwD-JWuEdGGU0r4SA.cache +1 -0
  123. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/Q7/Q7Dl2on4OdmHONyXUohOukBoSZQfxX7CBNaiLRxrn14.cache +0 -0
  124. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/QC/QCkY9HlLiOM3vpgoGX8oJvozZ0Cq6p0b6WD2lcwZT5k.cache +0 -0
  125. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/QD/QDMAHR127EpeGWrWbzn7QnNqnYZtH2UUV6ntkBhiUMQ.cache +1 -0
  126. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/Qr/QrbG3GcCwmKIApW0fC5o0iM8upyezEp0NrzhSENYwcs.cache +0 -0
  127. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/Qx/Qx8y8tq3IiNr7Ot7JGhxnFwDma3Bf6LfjWyVxcYpTzk.cache +1 -0
  128. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/S2/S2XG29YYvgWCmY1ULahjx-TNWdzenEHf2EpX5LK_--w.cache +1 -0
  129. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/SH/SHPuXI1rKYgLVra3KoGrRjevUg0nzNAxzNU_v_dPb6U.cache +0 -0
  130. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/Sa/Saez4IhtZGelgfIYfe8FAkCBAh9dUeKVGEmFBTITnmI.cache +0 -0
  131. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/Sx/Sx94HsfcuxHDyseiRaSVTRLw-adn2lGZ8TnytfXZhl8.cache +0 -0
  132. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/W1/W1FyFe4zmJy2UId1DPKUFLtCO2T6Vq5RuBrUMwa5pXQ.cache +1 -0
  133. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/WV/WVC-q51wcBaLCMfUdFscQNqh4o2O9YDD0irl3pEEHII.cache +1 -0
  134. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/XL/XL3leJ5pQba8fRAqDA-mBiHbcBIBiHf9jeJ3xWfrlz8.cache +2 -0
  135. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/Y2/Y2K6yjpdhJfMIKPU5YceGshr_gR1QQG8qmT6gRut14U.cache +2 -0
  136. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/bD/bDD6X4R7ftAQlH7K_0T5HKcaToTfjQ6kSpZZRYBWQmk.cache +3 -0
  137. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/dA/dAosGjt-VaAhIfQVDjUoRM6eI9QUSh1E5X3gnrHu8Ww.cache +0 -0
  138. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/dR/dRYE4MTApQWxIGfHaTh_uT0mmSKhlas_eGk6v3IjScA.cache +1 -0
  139. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/eI/eIEIza6BGcz1akXfzNqRW2GEIb_B4zrgDemllbjKLqI.cache +1 -0
  140. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/f3/f3IV7AH-agFherPIRg6gz-gH_q-pbMlmZYvwA-wgh28.cache +0 -0
  141. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/hC/hCBrZ9RI110j1EhVdHOP-z9uOZwRm9UvutWo6eY1N_g.cache +1 -0
  142. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/iT/iThi-stKgqJGA0IjU1RUrH30vN1eQNdVqLgVCK224mI.cache +1 -0
  143. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/lx/lxV4gmPmZnPnnIMP-IREWrSMXIZM15bHONEqvOQe550.cache +1 -0
  144. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/mS/mSro6DRbSWbZLjFnik8cEUvxGkkHnx30jmzgf90kWqw.cache +1 -0
  145. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/n_/n_xYqQYhwEMQknb3jFQnjlxxBE9TzMNHCdJ-bEyZFIw.cache +2 -0
  146. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/ne/neMAKY2HHX-jQtV34JCN-wAv1gZ4dBtdikwxulpNIU4.cache +1 -0
  147. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/nx/nxTv3sKVUQZADJyM3dPaVmUA78MIsMLD_K279yN_GsI.cache +2 -0
  148. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/oE/oELcpQtiEEZd7OlWIFZoxZmXO6i_0KQDJ9gSO8IMrAo.cache +1 -0
  149. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/oJ/oJN9HcCgMMjADHFGldRpNYSVpaR5KCRFVjou3lEGP_o.cache +1 -0
  150. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/qP/qPmv5snMrDw830S6hSICDcnIy7kVEWoFKXhGKT38lG4.cache +2 -0
  151. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/rD/rDC4aip_9aDeTYE-ixXTrw4TblEowO3UGk8BhYb0UXQ.cache +1 -0
  152. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/rG/rG5N7yI8mYTZmoFfvUWEF8AwRkSz7iwzbzjZgtyD-6Y.cache +1 -0
  153. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/rz/rzYbqBDzAezz5y7RBSX5kN3TmuBZYZzvh4AXBe6I1OQ.cache +2 -0
  154. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/uX/uXdmeUJXaGu-MF3ntZ6-oMn3I-G9Ub6r2UZzqMnqIyU.cache +2 -0
  155. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/uc/uc9nNzmH9YYkXWiQWt8sLWG3L6bnPakFQd3qAj7GI8Q.cache +0 -0
  156. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/wa/waRa6Y4GPI3rPY6lN66-DRb7GRW_AQcee1TP2qFEZzI.cache +0 -0
  157. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/x-/x-CSdYi9brwT6G4vAolSeuvGSaszo1oumOyPyfno7Zk.cache +0 -0
  158. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/x7/x7PYh8DJvPykcEqpVab2vcY9-GFz-3cqtoMlRAu94Uc.cache +2 -0
  159. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/xB/xBNFQ5zX18WjcjNby1R4X3UlLjHy1vAKBCFGDpHMpQE.cache +1 -0
  160. data/spec/test_app/tmp/cache/assets/sprockets/v3.0/xp/xpdRk6Yq3nW29DONCODCnLPuF9MWzGSavMHHQSUshjQ.cache +1 -0
  161. metadata +408 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2ee4ecf0f90a56fc5b2fc704d5c83c9131cd4b8f
4
+ data.tar.gz: 61a96f9affcbd9871f76b5f0091013948326d27d
5
+ SHA512:
6
+ metadata.gz: 8f1f38c587b068cb74c95d984f4e13fdb90fbb775249ee3062f67be2cd29628befecd4dc4ec11168353cebb2c1728d3eb7f14ba7d2c62384ba2e323ee8b351e8
7
+ data.tar.gz: 597048168233919337459e88dd12bf9b2845771149695bc341dc6d9cbcc665d170fee9dc34a29e2d45f1033419c2b5cc156c23f07c5bf3bd86f99fe5ffefa698
@@ -0,0 +1,20 @@
1
+ Copyright 2016 julien
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,130 @@
1
+ # KnowMore
2
+
3
+ This gem aims to provide a general questionnaire scaffold, with which you can quickly make you own questionnaire page.
4
+
5
+ ## Installation
6
+
7
+ This is a Rails-based gem. It can only work with you Rails application.
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'know_more'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle install
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install know_more
22
+ ```
23
+
24
+ ## Usage
25
+ How to use KnowMore to generate questionnaire scaffold to you?
26
+
27
+ ```sh
28
+ rails g know_more:init
29
+ ```
30
+
31
+ This will generate a initializer file, where you can config the questionnaire steps and the url to go when questionnaire is finished
32
+
33
+ Configure the the initializer file `config/initializers/know\_more.rb`
34
+
35
+ Then run the install generator, which will give you templates, controller concerns, model and migration file.
36
+
37
+ ```sh
38
+ rails g know_more:install MODEL
39
+ ```
40
+ This will generate template with erb engine, you can use `--haml` to generate haml template
41
+
42
+ The argument MODEL indicates the questionnaire model name
43
+
44
+ It will also create a migration, you can add other attribute to this migration
45
+
46
+ ### What the generated files used for
47
+ 1. `app/controllers/concerns/know_more/questionnaire_controller_concerns.rb`
48
+
49
+ This file is included by the QuestionnaireController(in the gem), you can add the behaviour
50
+ that you want to do in each step
51
+
52
+ Here is an example:
53
+ ```rb
54
+
55
+ module KnowMore
56
+ # this module is used to define the functions
57
+ # that will actually run in the KnowMore/QuestionnaireController
58
+ module QuestionnaireControllerConcerns
59
+ def self.included(base)
60
+ # define the behaviour when included
61
+ base.before_action :set_questionnaire
62
+ end
63
+
64
+ # _stepN function will be called by questionnaire#stepN
65
+
66
+ def _step1
67
+ end
68
+
69
+ def _step1_update
70
+ @questionnaire.update(questionnaire_params)
71
+ end
72
+
73
+ def _step2
74
+ end
75
+
76
+ def _step2_update
77
+ @questionnaire.update(questionnaire_params)
78
+ end
79
+
80
+ private
81
+ def set_questionnaire
82
+ @questionnaire = current_questionnaire
83
+ end
84
+
85
+ def questionnaire_params
86
+ params.require(:questionnaire).permit(:attribute1, :attribute2, :attribute3)
87
+ end
88
+ end
89
+ end
90
+ ```
91
+ 2. `app/models/MODEL.rb`
92
+ This is the questionnaire model, it has an attribute progress which records which step the client was on.
93
+ Cooperating with `require_questionnaire!`, you can force your client to continue with the previous questionnaire.
94
+
95
+ Then include the module KnowMore::ControllerHelpers into your ApplicationController or BaseController
96
+ and implement your own `current_questionnaire`
97
+
98
+ ```rb
99
+ class ApplicationController < ActionController::Base
100
+ include KnowMore::ControllerHelpers
101
+
102
+ def current_questionnaire
103
+ # your implementation
104
+ end
105
+ end
106
+ ```
107
+
108
+ ### Notice
109
+
110
+ 1. The questionnaire returned by current\_questionnaire should be created at first.
111
+ Because the process of doing questionnaire is only editing
112
+
113
+ 2. In the `KnowMore::ControllerHelpers`, it provide a helper function `require_questionnaire!`, it could force user to finish questionnaire before going to a controller
114
+ by redirecting the user to the last step of the questionnaire
115
+ ```rb
116
+ before_action :require_questionnaire!
117
+ ```
118
+
119
+ ## Todo
120
+
121
+ 1. add welcome page configuration
122
+ 2. allow copy the controller to user app so that user can modify the questionnaire controller
123
+ 4. support rename step
124
+
125
+
126
+ ## Contributing
127
+ Contribution directions go here.
128
+
129
+ ## License
130
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,26 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'KnowMore'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/test_app/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/know_more .js
2
+ //= link_directory ../stylesheets/know_more .css
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ module KnowMore
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,14 @@
1
+ module KnowMore
2
+ module ControllerHelpers
3
+ def current_questionnaire
4
+ raise 'You must implement current_questionnaire in your controller'
5
+ end
6
+
7
+ def require_questionnaire!
8
+ return if current_questionnaire.nil?
9
+ unless current_questionnaire.done?
10
+ redirect_to know_more.send("questionnaire_#{current_questionnaire.progress}_url"), status: :see_other
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,55 @@
1
+ require "#{Rails.root}/app/controllers/concerns/know_more/questionnaire_controller_concerns.rb"
2
+
3
+ module KnowMore
4
+ class QuestionnaireController < ::ApplicationController
5
+ include QuestionnaireControllerConcerns
6
+
7
+ KnowMore.config.pages.times do |n|
8
+ step_index = n + 1
9
+
10
+ # define the new methods
11
+ define_method "step#{step_index}" do
12
+ set_current_status(step_index) if current_questionnaire.progress != "step#{step_index}"
13
+ self.send("_step#{step_index}")
14
+ render "know_more/questionnaire/step#{step_index}"
15
+ end
16
+
17
+ # define the update methods
18
+ define_method "step#{step_index}_update" do
19
+ self.send("_step#{step_index}_update")
20
+
21
+ if params[:direction] == 'previous'
22
+ i = step_index - 1
23
+ redirect_to self.send("questionnaire_step#{i}_url"), status: :see_other if i > 0
24
+ else # default is go to the next page
25
+ i = step_index + 1
26
+ # for the last step, set questionnaire progress to be done
27
+ # and go the config.redirect_url
28
+ if step_index == KnowMore.config.pages
29
+ current_questionnaire.done!
30
+ redirect_to KnowMore.config.redirect_url
31
+ else
32
+ redirect_to self.send("questionnaire_step#{i}_url"), status: :see_other if i <= KnowMore.config.pages
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ def set_current_status(n)
39
+ current_questionnaire.send("step#{n}!") unless current_questionnaire.done?
40
+ end
41
+ def set_next_status
42
+ unless current_questionnaire.done?
43
+ current_questionnaire.progress = ::Questionnaire.progresses[current_questionnaire.progress] + 1
44
+ current_questionnaire.save
45
+ end
46
+ end
47
+
48
+ def set_previous_status
49
+ if ::Questionnaire.progresses[current_questionnaire.progress] > 0
50
+ current_questionnaire.progress = ::Questionnaire.progresses[current_questionnaire.progress] -1
51
+ current_questionnaire.save
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,4 @@
1
+ module KnowMore
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module KnowMore
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module KnowMore
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module KnowMore
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module KnowMore
2
+ module Questionnaire
3
+ def self.included(base)
4
+ base.enum progress: (1..KnowMore.config.pages).map{|n| "step#{n}".to_sym}.append(:done)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Know more</title>
5
+ <%= stylesheet_link_tag "know_more/application", media: "all" %>
6
+ <%= javascript_include_tag "know_more/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,7 @@
1
+ KnowMore::Engine.routes.draw do
2
+ KnowMore.config.pages.times do |n|
3
+
4
+ get "/questionnaire/step#{n+1}", to: "questionnaire#step#{n+1}", as: "questionnaire_step#{n+1}"
5
+ patch "/questionnaire/step#{n+1}", to: "questionnaire#step#{n+1}_update", as: "questionnaire_step#{n+1}_update"
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ require 'rails/generators/base'
2
+
3
+ module KnowMore
4
+ class InitGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../templates', __FILE__)
6
+ desc 'Generate initializer'
7
+
8
+ def copy_initializer
9
+ template 'initializer.rb.erb', 'config/initializers/know_more.rb'
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,45 @@
1
+ require 'rails/generators/base'
2
+
3
+ module KnowMore
4
+ class InstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../templates', __FILE__)
6
+ class_option :haml, :desc => 'Generate Haml pages instead of erb', :type => :boolean
7
+ # class_option :slim, :desc => 'Generate Slim pages instead of erb', :type => :boolean
8
+
9
+ argument :model_name
10
+
11
+ desc 'Create views, migration and model for Rails application'
12
+
13
+ def before_all
14
+ @model_name = model_name.underscore
15
+ end
16
+
17
+ def copy_views
18
+ KnowMore.config.pages.times do |n|
19
+ @n = n+1
20
+ copy_template
21
+ end
22
+ end
23
+
24
+ def copy_concerns
25
+ template 'concerns.rb.erb', 'app/controllers/concerns/know_more/questionnaire_controller_concerns.rb'
26
+ end
27
+
28
+ def generate_model
29
+ template 'models/model.rb.erb', "app/models/#{@model_name}.rb"
30
+ end
31
+
32
+ def generate_migration
33
+ template 'models/migration.rb.erb', "db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_create_#{model_name}.rb"
34
+ end
35
+
36
+ private
37
+ def copy_template
38
+ template_engine = 'erb'
39
+ if options.haml?
40
+ template_engine = 'haml'
41
+ end
42
+ template "#{template_engine}/page_template.erb", "app/views/know_more/questionnaire/step#{@n}.html.#{template_engine}"
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,23 @@
1
+ module KnowMore
2
+ # this module is used to define the functions
3
+ # that will actually run in the KnowMore/QuestionnaireController
4
+ module QuestionnaireControllerConcerns
5
+ def self.included(base)
6
+ # define the behaviour when included
7
+ base.before_action :set_questionnaire
8
+ end
9
+
10
+ # _stepN function will be called by questionnaire#stepN
11
+ <% KnowMore.config.pages.times do |n| %>
12
+ def _step<%= n+1 %>
13
+ end
14
+
15
+ def _step<%= n+1 %>_update
16
+ end
17
+ <% end %>
18
+ private
19
+ def set_questionnaire
20
+ @questionnaire = current_questionnaire
21
+ end
22
+ end
23
+ end