incline 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (303) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/Gemfile +17 -0
  4. data/Gemfile.lock +186 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.rdoc +208 -0
  7. data/Rakefile +37 -0
  8. data/app/assets/fonts/incline/.keep +0 -0
  9. data/app/assets/images/incline/.keep +0 -0
  10. data/app/assets/images/incline/barcode-B.svg +181 -0
  11. data/app/assets/javascripts/incline/activate_classed_items.js +11 -0
  12. data/app/assets/javascripts/incline/application.js +30 -0
  13. data/app/assets/javascripts/incline/bootstrap-datepicker.js +1800 -0
  14. data/app/assets/javascripts/incline/datatables.js +22193 -0
  15. data/app/assets/javascripts/incline/escapeHtml.js +10 -0
  16. data/app/assets/javascripts/incline/inline_actions.js +479 -0
  17. data/app/assets/javascripts/incline/jquery.doubleScroll.js +112 -0
  18. data/app/assets/javascripts/incline/jquery.number.js +764 -0
  19. data/app/assets/javascripts/incline/regexMask.js +27 -0
  20. data/app/assets/javascripts/incline/select2/i18n/en.js +3 -0
  21. data/app/assets/javascripts/incline/select2/select2.full.js +6436 -0
  22. data/app/assets/stylesheets/incline/application.css +18 -0
  23. data/app/assets/stylesheets/incline/bootstrap-theme.min.css +5 -0
  24. data/app/assets/stylesheets/incline/custom.scss +279 -0
  25. data/app/assets/stylesheets/incline/datatables.css +494 -0
  26. data/app/assets/stylesheets/incline/datepicker3.css +790 -0
  27. data/app/assets/stylesheets/incline/select2.css +484 -0
  28. data/app/controllers/incline/access_groups_controller.rb +127 -0
  29. data/app/controllers/incline/access_test_controller.rb +30 -0
  30. data/app/controllers/incline/account_activations_controller.rb +28 -0
  31. data/app/controllers/incline/application_controller.rb +11 -0
  32. data/app/controllers/incline/contact_controller.rb +34 -0
  33. data/app/controllers/incline/password_resets_controller.rb +113 -0
  34. data/app/controllers/incline/security_controller.rb +100 -0
  35. data/app/controllers/incline/sessions_controller.rb +50 -0
  36. data/app/controllers/incline/users_controller.rb +304 -0
  37. data/app/controllers/incline/welcome_controller.rb +19 -0
  38. data/app/helpers/incline/.keep +0 -0
  39. data/app/mailers/incline/application_mailer_base.rb +11 -0
  40. data/app/mailers/incline/contact_form.rb +19 -0
  41. data/app/mailers/incline/user_mailer.rb +45 -0
  42. data/app/models/incline/access_group.rb +121 -0
  43. data/app/models/incline/access_group_group_member.rb +12 -0
  44. data/app/models/incline/access_group_user_member.rb +10 -0
  45. data/app/models/incline/action_group.rb +12 -0
  46. data/app/models/incline/action_security.rb +222 -0
  47. data/app/models/incline/contact_message.rb +37 -0
  48. data/app/models/incline/disable_info.rb +20 -0
  49. data/app/models/incline/password_reset.rb +14 -0
  50. data/app/models/incline/password_reset_request.rb +14 -0
  51. data/app/models/incline/user.rb +437 -0
  52. data/app/models/incline/user_login_history.rb +30 -0
  53. data/app/views/incline/access_groups/_details.json.jbuilder +10 -0
  54. data/app/views/incline/access_groups/_form.html.erb +19 -0
  55. data/app/views/incline/access_groups/_list.html.erb +60 -0
  56. data/app/views/incline/access_groups/_messages.json.jbuilder +6 -0
  57. data/app/views/incline/access_groups/edit.html.erb +2 -0
  58. data/app/views/incline/access_groups/index.html.erb +6 -0
  59. data/app/views/incline/access_groups/index.json.jbuilder +16 -0
  60. data/app/views/incline/access_groups/new.html.erb +2 -0
  61. data/app/views/incline/access_groups/show.html.erb +9 -0
  62. data/app/views/incline/access_groups/show.json.jbuilder +11 -0
  63. data/app/views/incline/contact/new.html.erb +22 -0
  64. data/app/views/incline/contact_form/contact.html.erb +16 -0
  65. data/app/views/incline/contact_form/contact.text.erb +13 -0
  66. data/app/views/incline/password_resets/edit.html.erb +16 -0
  67. data/app/views/incline/password_resets/new.html.erb +12 -0
  68. data/app/views/incline/security/_details.json.jbuilder +7 -0
  69. data/app/views/incline/security/_form.html.erb +20 -0
  70. data/app/views/incline/security/_list.html.erb +89 -0
  71. data/app/views/incline/security/_messages.json.jbuilder +6 -0
  72. data/app/views/incline/security/edit.html.erb +2 -0
  73. data/app/views/incline/security/index.html.erb +6 -0
  74. data/app/views/incline/security/index.json.jbuilder +16 -0
  75. data/app/views/incline/security/show.html.erb +31 -0
  76. data/app/views/incline/security/show.json.jbuilder +11 -0
  77. data/app/views/incline/sessions/new.html.erb +26 -0
  78. data/app/views/incline/user_mailer/account_activation.html.erb +7 -0
  79. data/app/views/incline/user_mailer/account_activation.text.erb +6 -0
  80. data/app/views/incline/user_mailer/invalid_password_reset.html.erb +3 -0
  81. data/app/views/incline/user_mailer/invalid_password_reset.text.erb +5 -0
  82. data/app/views/incline/user_mailer/password_reset.html.erb +8 -0
  83. data/app/views/incline/user_mailer/password_reset.text.erb +7 -0
  84. data/app/views/incline/users/_details.json.jbuilder +32 -0
  85. data/app/views/incline/users/_form.html.erb +21 -0
  86. data/app/views/incline/users/_list.html.erb +102 -0
  87. data/app/views/incline/users/_messages.json.jbuilder +6 -0
  88. data/app/views/incline/users/disable_confirm.html.erb +19 -0
  89. data/app/views/incline/users/edit.html.erb +5 -0
  90. data/app/views/incline/users/index.html.erb +6 -0
  91. data/app/views/incline/users/index.json.jbuilder +16 -0
  92. data/app/views/incline/users/new.html.erb +5 -0
  93. data/app/views/incline/users/show.html.erb +12 -0
  94. data/app/views/incline/users/show.json.jbuilder +11 -0
  95. data/app/views/incline/welcome/home.html.erb +5 -0
  96. data/app/views/layouts/application.html.erb +1 -0
  97. data/app/views/layouts/incline/_account_menu.html.erb +18 -0
  98. data/app/views/layouts/incline/_app_menu_anon.html.erb +1 -0
  99. data/app/views/layouts/incline/_app_menu_authenticated.html.erb +1 -0
  100. data/app/views/layouts/incline/_footer.html.erb +13 -0
  101. data/app/views/layouts/incline/_header.html.erb +21 -0
  102. data/app/views/layouts/incline/_html_mailer.html.erb +5 -0
  103. data/app/views/layouts/incline/_incline_app.html.erb +25 -0
  104. data/app/views/layouts/incline/_messages.html.erb +3 -0
  105. data/app/views/layouts/incline/_shim.html.erb +3 -0
  106. data/app/views/layouts/incline/_text_mailer.text.erb +1 -0
  107. data/app/views/layouts/incline/application.html.erb +1 -0
  108. data/app/views/layouts/mailer.html.erb +2 -0
  109. data/app/views/layouts/mailer.text.erb +2 -0
  110. data/bin/rails +12 -0
  111. data/bin/test_scaffold.sh +10 -0
  112. data/config/routes.rb +61 -0
  113. data/db/migrate/20170511230126_create_incline_users.rb +26 -0
  114. data/db/migrate/20170515003052_create_incline_access_groups.rb +10 -0
  115. data/db/migrate/20170515003221_create_incline_user_login_histories.rb +12 -0
  116. data/db/migrate/20170515150908_create_incline_access_group_user_members.rb +11 -0
  117. data/db/migrate/20170515151058_create_incline_access_group_group_members.rb +11 -0
  118. data/db/migrate/20170517193432_add_comments_to_incline_user.rb +5 -0
  119. data/db/migrate/20170622132700_create_incline_action_securities.rb +16 -0
  120. data/db/migrate/20170622172712_create_incline_action_groups.rb +11 -0
  121. data/db/migrate/20170622195742_add_non_standard_to_action_security.rb +5 -0
  122. data/db/migrate/20170622230422_add_visible_to_action_security.rb +5 -0
  123. data/db/seeds.rb +81 -0
  124. data/exe/new_incline_app +42 -0
  125. data/lib/generators/incline/install_generator.rb +259 -0
  126. data/lib/generators/incline/templates/_app_menu_anon.html.erb +1 -0
  127. data/lib/generators/incline/templates/_app_menu_authenticated.html.erb +1 -0
  128. data/lib/generators/incline/templates/incline_application.css +17 -0
  129. data/lib/generators/incline/templates/incline_application.html.erb +1 -0
  130. data/lib/generators/incline/templates/incline_application.js +12 -0
  131. data/lib/generators/incline/templates/incline_database.yml +25 -0
  132. data/lib/generators/incline/templates/incline_email.yml +20 -0
  133. data/lib/generators/incline/templates/incline_mailer.html.erb +2 -0
  134. data/lib/generators/incline/templates/incline_mailer.text.erb +2 -0
  135. data/lib/generators/incline/templates/incline_users.yml +64 -0
  136. data/lib/generators/incline/templates/incline_version.rb +3 -0
  137. data/lib/incline/auth_engine_base.rb +52 -0
  138. data/lib/incline/data_tables_request.rb +336 -0
  139. data/lib/incline/date_time_formats.rb +6 -0
  140. data/lib/incline/engine.rb +212 -0
  141. data/lib/incline/errors.rb +15 -0
  142. data/lib/incline/extensions/action_controller_base.rb +526 -0
  143. data/lib/incline/extensions/action_mailer_base.rb +66 -0
  144. data/lib/incline/extensions/action_view_base.rb +489 -0
  145. data/lib/incline/extensions/active_record_base.rb +308 -0
  146. data/lib/incline/extensions/application.rb +137 -0
  147. data/lib/incline/extensions/application_configuration.rb +50 -0
  148. data/lib/incline/extensions/connection_adapter.rb +55 -0
  149. data/lib/incline/extensions/date_time_value.rb +123 -0
  150. data/lib/incline/extensions/date_value.rb +77 -0
  151. data/lib/incline/extensions/decimal_value.rb +55 -0
  152. data/lib/incline/extensions/erb_scaffold_generator.rb +31 -0
  153. data/lib/incline/extensions/float_value.rb +59 -0
  154. data/lib/incline/extensions/form_builder.rb +617 -0
  155. data/lib/incline/extensions/integer_value.rb +54 -0
  156. data/lib/incline/extensions/jbuilder_generator.rb +38 -0
  157. data/lib/incline/extensions/jbuilder_template.rb +39 -0
  158. data/lib/incline/extensions/main_app.rb +40 -0
  159. data/lib/incline/extensions/numeric.rb +63 -0
  160. data/lib/incline/extensions/object.rb +31 -0
  161. data/lib/incline/extensions/resource_route_generator.rb +53 -0
  162. data/lib/incline/extensions/session.rb +113 -0
  163. data/lib/incline/extensions/string.rb +50 -0
  164. data/lib/incline/extensions/test_case.rb +764 -0
  165. data/lib/incline/extensions/time_zone_converter.rb +40 -0
  166. data/lib/incline/global_status.rb +236 -0
  167. data/lib/incline/helpers/route_hash_formatter.rb +46 -0
  168. data/lib/incline/json_log_formatter.rb +96 -0
  169. data/lib/incline/json_logger.rb +17 -0
  170. data/lib/incline/log.rb +153 -0
  171. data/lib/incline/number_formats.rb +17 -0
  172. data/lib/incline/recaptcha.rb +346 -0
  173. data/lib/incline/user_manager.rb +212 -0
  174. data/lib/incline/validators/email_validator.rb +45 -0
  175. data/lib/incline/validators/ip_address_validator.rb +32 -0
  176. data/lib/incline/validators/recaptcha_validator.rb +37 -0
  177. data/lib/incline/validators/safe_name_validator.rb +31 -0
  178. data/lib/incline/version.rb +3 -0
  179. data/lib/incline/work_path.rb +75 -0
  180. data/lib/incline.rb +197 -0
  181. data/lib/tasks/incline_tasks.rake +4 -0
  182. data/lib/templates/erb/scaffold/_form.html.erb +43 -0
  183. data/lib/templates/erb/scaffold/_list.html.erb +81 -0
  184. data/lib/templates/erb/scaffold/edit.html.erb +1 -0
  185. data/lib/templates/erb/scaffold/index.html.erb +6 -0
  186. data/lib/templates/erb/scaffold/new.html.erb +1 -0
  187. data/lib/templates/erb/scaffold/show.html.erb +34 -0
  188. data/lib/templates/jbuilder/scaffold/_details.json.jbuilder +20 -0
  189. data/lib/templates/jbuilder/scaffold/index.json.jbuilder +16 -0
  190. data/lib/templates/jbuilder/scaffold/show.json.jbuilder +16 -0
  191. data/lib/templates/rails/scaffold_controller/controller.rb +128 -0
  192. data/test/controllers/incline/access_groups_controller_test.rb +65 -0
  193. data/test/controllers/incline/access_test_controller_test.rb +53 -0
  194. data/test/controllers/incline/contact_controller_test.rb +32 -0
  195. data/test/controllers/incline/security_controller_test.rb +39 -0
  196. data/test/controllers/incline/welcome_controller_test.rb +16 -0
  197. data/test/dummy/README.rdoc +28 -0
  198. data/test/dummy/Rakefile +6 -0
  199. data/test/dummy/app/assets/images/.keep +0 -0
  200. data/test/dummy/app/assets/javascripts/application.js +12 -0
  201. data/test/dummy/app/assets/stylesheets/application.css +17 -0
  202. data/test/dummy/app/controllers/application_controller.rb +5 -0
  203. data/test/dummy/app/controllers/concerns/.keep +0 -0
  204. data/test/dummy/app/helpers/application_helper.rb +2 -0
  205. data/test/dummy/app/mailers/.keep +0 -0
  206. data/test/dummy/app/models/.keep +0 -0
  207. data/test/dummy/app/models/concerns/.keep +0 -0
  208. data/test/dummy/app/views/layouts/application.html.erb +1 -0
  209. data/test/dummy/app/views/layouts/incline/_app_menu_anon.html.erb +1 -0
  210. data/test/dummy/app/views/layouts/incline/_app_menu_authenticated.html.erb +1 -0
  211. data/test/dummy/app/views/layouts/mailer.html.erb +2 -0
  212. data/test/dummy/app/views/layouts/mailer.text.erb +2 -0
  213. data/test/dummy/bin/bundle +3 -0
  214. data/test/dummy/bin/rails +4 -0
  215. data/test/dummy/bin/rake +4 -0
  216. data/test/dummy/bin/setup +29 -0
  217. data/test/dummy/config/application.rb +38 -0
  218. data/test/dummy/config/boot.rb +5 -0
  219. data/test/dummy/config/database.yml +34 -0
  220. data/test/dummy/config/email.yml +24 -0
  221. data/test/dummy/config/environment.rb +5 -0
  222. data/test/dummy/config/environments/development.rb +45 -0
  223. data/test/dummy/config/environments/production.rb +85 -0
  224. data/test/dummy/config/environments/test.rb +44 -0
  225. data/test/dummy/config/initializers/assets.rb +11 -0
  226. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  227. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  228. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  229. data/test/dummy/config/initializers/inflections.rb +16 -0
  230. data/test/dummy/config/initializers/mime_types.rb +4 -0
  231. data/test/dummy/config/initializers/session_store.rb +3 -0
  232. data/test/dummy/config/initializers/to_time_preserves_timezone.rb +10 -0
  233. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  234. data/test/dummy/config/locales/en.yml +23 -0
  235. data/test/dummy/config/routes.rb +6 -0
  236. data/test/dummy/config.ru +4 -0
  237. data/test/dummy/db/schema.rb +108 -0
  238. data/test/dummy/lib/assets/.keep +0 -0
  239. data/test/dummy/log/.keep +0 -0
  240. data/test/dummy/public/404.html +67 -0
  241. data/test/dummy/public/422.html +67 -0
  242. data/test/dummy/public/500.html +66 -0
  243. data/test/dummy/public/favicon.ico +0 -0
  244. data/test/extensions/action_controller_base_extensions_test.rb +21 -0
  245. data/test/extensions/action_mailer_base_extensions_test.rb +20 -0
  246. data/test/extensions/action_view_base_extensions_test.rb +267 -0
  247. data/test/extensions/active_record_extensions_test.rb +173 -0
  248. data/test/extensions/application_configuration_extensions_test.rb +46 -0
  249. data/test/extensions/application_extensions_test.rb +23 -0
  250. data/test/extensions/connection_adapter_extensions_test.rb +54 -0
  251. data/test/extensions/date_time_value_extensions_test.rb +104 -0
  252. data/test/extensions/date_value_extensions_test.rb +102 -0
  253. data/test/extensions/decimal_value_extensions_test.rb +85 -0
  254. data/test/extensions/erb_scaffold_generator_extensions_test.rb +17 -0
  255. data/test/extensions/float_value_extensions_test.rb +78 -0
  256. data/test/extensions/form_builder_extensions_test.rb +28 -0
  257. data/test/extensions/integer_value_extensions_test.rb +78 -0
  258. data/test/extensions/jbuilder_generator_extensions_test.rb +21 -0
  259. data/test/extensions/jbuilder_template_extensions_test.rb +47 -0
  260. data/test/extensions/main_app_extensions_test.rb +55 -0
  261. data/test/extensions/numeric_extensions_test.rb +76 -0
  262. data/test/extensions/object_extensions_test.rb +104 -0
  263. data/test/extensions/session_extensions_test.rb +69 -0
  264. data/test/extensions/string_extensions_test.rb +32 -0
  265. data/test/extensions/test_case_extensions_test.rb +538 -0
  266. data/test/extensions/time_zone_converter_extensions_test.rb +10 -0
  267. data/test/fixtures/incline/access_group_group_members.yml +1 -0
  268. data/test/fixtures/incline/access_group_user_members.yml +1 -0
  269. data/test/fixtures/incline/access_groups.yml +13 -0
  270. data/test/fixtures/incline/action_groups.yml +6 -0
  271. data/test/fixtures/incline/action_securities.yml +18 -0
  272. data/test/fixtures/incline/user_login_histories.yml +1 -0
  273. data/test/fixtures/incline/users.yml +64 -0
  274. data/test/incline_test.rb +63 -0
  275. data/test/integration/incline/users_edit_test.rb +180 -0
  276. data/test/integration/incline/users_login_test.rb +105 -0
  277. data/test/integration/incline/users_signup_test.rb +147 -0
  278. data/test/integration/navigation_test.rb +11 -0
  279. data/test/lib/data_tables_request_test.rb +245 -0
  280. data/test/lib/date_time_formats_test.rb +111 -0
  281. data/test/lib/global_status_test.rb +89 -0
  282. data/test/lib/json_log_formatter_test.rb +43 -0
  283. data/test/lib/log_test.rb +36 -0
  284. data/test/lib/recaptcha_test.rb +75 -0
  285. data/test/lib/user_manager_test.rb +47 -0
  286. data/test/lib/work_path_test.rb +18 -0
  287. data/test/models/incline/access_group_group_member_test.rb +30 -0
  288. data/test/models/incline/access_group_test.rb +60 -0
  289. data/test/models/incline/access_group_user_member_test.rb +29 -0
  290. data/test/models/incline/action_group_test.rb +27 -0
  291. data/test/models/incline/action_security_test.rb +176 -0
  292. data/test/models/incline/contact_message_test.rb +66 -0
  293. data/test/models/incline/disable_info_test.rb +29 -0
  294. data/test/models/incline/password_reset_request_test.rb +35 -0
  295. data/test/models/incline/password_reset_test.rb +51 -0
  296. data/test/models/incline/user_login_history_test.rb +31 -0
  297. data/test/models/incline/user_test.rb +91 -0
  298. data/test/test_helper.rb +42 -0
  299. data/test/validators/email_validator_test.rb +102 -0
  300. data/test/validators/ip_address_validator_test.rb +107 -0
  301. data/test/validators/recaptcha_validator_test.rb +57 -0
  302. data/test/validators/safe_name_validator_test.rb +101 -0
  303. metadata +584 -0
@@ -0,0 +1,3 @@
1
+ module Incline
2
+ VERSION = "0.1.5"
3
+ end
@@ -0,0 +1,75 @@
1
+ module Incline
2
+ ##
3
+ # This class simply locates a temporary working directory for the application.
4
+ #
5
+ # By default we shoot for shared memory such as /run/shm or /dev/shm. If those
6
+ # fail, we look to /tmp.
7
+ #
8
+ class WorkPath
9
+
10
+ ##
11
+ # Gets the temporary working directory location for the application.
12
+ #
13
+ def self.location
14
+ @location ||= get_location
15
+ end
16
+
17
+ ##
18
+ # Gets a path for a specific temporary file.
19
+ #
20
+ def self.path_for(filename)
21
+ location + '/' + filename
22
+ end
23
+
24
+ ##
25
+ # Gets the path to the system status file.
26
+ #
27
+ # This file is used by long running processes to log their progress.
28
+ #
29
+ def self.system_status_file
30
+ @system_status_file ||= path_for('system_status')
31
+ end
32
+
33
+ private
34
+
35
+ def self.app_name
36
+ @app_name ||= Rails.application.class.name.underscore.gsub('/','_')
37
+ end
38
+
39
+ def self.try_path(path)
40
+ path += '/incline_' + app_name
41
+
42
+ Incline::Log::debug "Trying path '#{path}'..."
43
+
44
+ # must exist or be able to be created.
45
+ unless Dir.exist?(path) || Dir.mkdir(path)
46
+ Incline::Log::debug 'Could not create path.'
47
+ return nil
48
+ end
49
+
50
+ # must be able to write and delete a test file.
51
+ test_file = path + '/test.file'
52
+ begin
53
+ File.delete(test_file) if File.exist?(test_file)
54
+ File.write(test_file, 'This is only a test file and can safely be deleted.')
55
+ File.delete(test_file)
56
+ rescue
57
+ Incline::Log::debug 'Could not create test file.'
58
+ path = nil
59
+ end
60
+
61
+ path
62
+ end
63
+
64
+ def self.get_location
65
+ %w(/run/shm /var/run/shm /dev/shm /tmp).each do |root|
66
+ if Dir.exist?(root)
67
+ loc = try_path(root)
68
+ return loc unless loc.blank?
69
+ end
70
+ end
71
+ nil
72
+ end
73
+
74
+ end
75
+ end
data/lib/incline.rb ADDED
@@ -0,0 +1,197 @@
1
+ require 'incline/version'
2
+ require 'incline/log'
3
+
4
+ ##
5
+ # A Rails quick start library.
6
+ module Incline
7
+
8
+ ##
9
+ # Gets the automatic email configuration for the Incline application.
10
+ #
11
+ # The primary configuration should be stored in +config/email.yml+.
12
+ # If this file is missing, automatic email configuration is skipped and must be manually specified in your
13
+ # application's environment initializer (eg - config/environment/production.rb).
14
+ #
15
+ # test:
16
+ # ...
17
+ # development:
18
+ # ...
19
+ # production:
20
+ # default_url: www.example.com
21
+ # default_recipient: contact@example.com
22
+ # sender: noreply@example.com
23
+ # auth: :plain
24
+ # start_tls: true
25
+ # ssl: false
26
+ # server: smtp.example.com
27
+ # port: 587
28
+ #
29
+ # You shouldn't use an open relay, a warning will be thrown if you do.
30
+ # But you don't want your login credentials stored in +config/email.yml+ either.
31
+ # Instead, credentials (if any) should be stored in +config/secrets.yml+.
32
+ #
33
+ # test:
34
+ # ...
35
+ # development:
36
+ # ...
37
+ # production:
38
+ # email:
39
+ # user: noreply@example.com
40
+ # password: super-secret-password
41
+ # secret_key_base: ...
42
+ #
43
+ def self.email_config
44
+ @email_config ||=
45
+ begin
46
+ yaml = Rails.root.join('config', 'email.yml')
47
+ if File.exist?(yaml)
48
+ cfg = File.exist?(yaml) ? YAML.load_file(yaml) : { }
49
+ cfg = (cfg[Rails.env] || {}).symbolize_keys
50
+
51
+ cfg = {
52
+ port: 25,
53
+ auth: :plain,
54
+ start_tls: true,
55
+ ssl: false
56
+ }.merge(cfg)
57
+
58
+ Incline::Log::warn 'The email configuration is missing the "user" key.' if cfg[:user].blank?
59
+ Incline::Log::warn 'The email configuration is missing the "password" key.' if cfg[:password].blank?
60
+ Incline::Log::error 'The email configuration is missing the "server" key.' if cfg[:server].blank?
61
+ Incline::Log::error 'The email configuration is missing the "sender" key.' if cfg[:sender].blank?
62
+ Incline::Log::error 'The email configuration is missing the "default_url" key.' if cfg[:default_url].blank?
63
+ Incline::Log::error 'The email configuration is missing the "default_recipient" key.' if cfg[:default_recipient].blank?
64
+
65
+ def cfg.valid?
66
+ return false if self[:sender].blank? || self[:server].blank? || self[:default_url].blank? || self[:default_recipient].blank?
67
+ true
68
+ end
69
+
70
+ cfg.freeze
71
+ else
72
+ Incline::Log::info 'The configuration file "email.yml" does not exist, automatic email configuration disabled.'
73
+ cfg = {}
74
+
75
+ def cfg.valid?
76
+ false
77
+ end
78
+
79
+ cfg.freeze
80
+ end
81
+ end
82
+
83
+ end
84
+
85
+ ##
86
+ # Gets a list of key gems with their versions.
87
+ #
88
+ # This is useful for informational displays.
89
+ #
90
+ # Supply one or more patterns for gem names.
91
+ # If you supply none, then the default pattern list is used.
92
+ def self.gem_list(*patterns)
93
+ patterns =
94
+ if patterns.blank?
95
+ default_gem_patterns
96
+ elsif patterns.first.is_a?(::TrueClass)
97
+ default_gem_patterns + patterns[1..-1]
98
+ else
99
+ patterns
100
+ end
101
+
102
+ patterns = patterns.flatten.inject([]) { |m,v| m << v unless m.include?(v); m }
103
+
104
+ gems = Gem::Specification.to_a.sort{ |a,b| a.name <=> b.name }
105
+
106
+ patterns.inject([]) do |ret,pat|
107
+ gems
108
+ .select { |g| (pat.is_a?(::String) && g.name == pat) || (pat.is_a?(::Regexp) && g.name =~ pat) }
109
+ .each do |g|
110
+ ret << [ g.name, g.version.to_s ] unless ret.find { |(name,_)| name == g.name }
111
+ end
112
+ ret
113
+ end
114
+
115
+ end
116
+
117
+ ##
118
+ # Gets a list of routes for the current application.
119
+ #
120
+ # The returned list contains hashes with :engine, :controller, :action, :name, :verb, and :path keys.
121
+ def self.route_list
122
+ @route_list ||=
123
+ begin
124
+ require 'action_dispatch/routing/inspector'
125
+ get_routes(Rails.application.routes.routes).sort do |a,b|
126
+ if a[:engine] == b[:engine]
127
+ if a[:controller] == b[:controller]
128
+ if a[:action] == b[:action]
129
+ a[:path] <=> b[:path]
130
+ else
131
+ a[:action] <=> b[:action]
132
+ end
133
+ else
134
+ a[:controller] <=> b[:controller]
135
+ end
136
+ else
137
+ a[:engine] <=> b[:engine]
138
+ end
139
+ end
140
+ end
141
+ end
142
+
143
+ ##
144
+ # Performs a database migration against the configured database.
145
+ def self.migrate!
146
+ ActiveRecord::Migrator.migrate File.expand_path('../../db/migrate', __FILE__), nil
147
+ end
148
+
149
+ private
150
+
151
+ def self.default_gem_patterns
152
+ @default_gem_patterns ||= [ Rails.application.class.parent_name.underscore, 'rails', /\Aincline(?:-.*)\z/ ]
153
+ end
154
+
155
+ def self.get_routes(routes, engine_path = '', engines = [])
156
+ result = []
157
+
158
+ routes = routes
159
+ .collect{|r| ActionDispatch::Routing::RouteWrapper.new(r)}
160
+ .reject{|r| r.internal?}
161
+
162
+ routes.each do |r|
163
+ if r.engine?
164
+ eng_path = r.path
165
+ unless engines.include?(eng_path)
166
+ eng_routes = r.rack_app.routes
167
+ if eng_routes.is_a?(ActionDispatch::Routing::RouteSet)
168
+ engines << eng_path
169
+ result += get_routes(eng_routes.routes, eng_path, engines)
170
+ end
171
+ end
172
+ else
173
+ result << {
174
+ engine: engine_path,
175
+ controller: r.controller,
176
+ action: r.action,
177
+ verb: r.verb,
178
+ path: engine_path + r.path
179
+ }
180
+ end
181
+ end
182
+
183
+ result.inject([]) do |ret,item|
184
+ existing = ret.find{|r| r[:engine] == item[:engine] && r[:controller] == item[:controller] && r[:action] == item[:action]}
185
+ if existing
186
+ existing[:verb] += '|' + item[:verb]
187
+ else
188
+ ret << item
189
+ end
190
+ ret
191
+ end
192
+ end
193
+
194
+ end
195
+
196
+ # Include engine after defining base module.
197
+ require 'incline/engine'
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :incline do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,43 @@
1
+ <%%= error_summary @<%= singular_table_name %> %>
2
+
3
+ <div class="col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3">
4
+ <div class="panel panel-primary">
5
+ <div class="panel-heading">
6
+ <%%= @<%= singular_table_name %>.new_record? ? 'New' : 'Update' %> <%= singular_table_name.titleize %>
7
+ </div>
8
+ <div class="panel-body">
9
+ <%%= form_for(@<%= singular_table_name %>) do |f| %>
10
+ <%- attributes.each do |attribute| -%>
11
+ <%- if attribute.type == :boolean -%>
12
+ <%%= f.check_box_form_group :<%= attribute.column_name %> %>
13
+ <%- elsif attribute.type == :date || (attribute.type == :datetime && attribute.column_name =~ /date/ && !(attribute.column_name =~ /time/)) -%>
14
+ <%%= f.datepicker_form_group :<%= attribute.column_name %> %>
15
+ <%- elsif (attribute.type == :references) || (attribute.type == :integer && attribute.column_name =~ /_id\z/) -%>
16
+ <%- if (ref_class = (attribute.column_name.gsub(/_id\z/,'').classify.constantize rescue nil)) -%>
17
+ <%%= f.select_form_group :<%= attribute.column_name %>, <%= ref_class %>.all, :id, :to_s, label_text: <%= attribute.column_name.gsub(/_id\z/,'').humanize.inspect %>, field_class: 'form-control select2' %>
18
+ <%- else -%>
19
+ <%%= f.text_form_group :<%= attribute.column_name %>, field_type: :number, field_class: "form-control integer", label_text: <%= attribute.column_name.gsub(/_id\z/, '').humanize.inspect %> %>
20
+ <%- end -%>
21
+ <%- elsif attribute.type == :integer -%>
22
+ <%%= f.text_form_group :<%= attribute.column_name %>, field_type: :number, field_class: "form-control integer" %>
23
+ <%- elsif attribute.type == :float -%>
24
+ <%%= f.text_form_group :<%= attribute.column_name %>, field_type: :number, field_class: "form-control float" %>
25
+ <%- elsif attribute.type == :string -%>
26
+ <%%= f.text_form_group :<%= attribute.column_name %> %>
27
+ <%- elsif attribute.password_digest? -%>
28
+ <%%= f.text_form_group :password, field_type: :password %>
29
+ <%%= f.text_form_group :password_confirmation, field_type: :password %>
30
+ <%- else -%>
31
+ <div class="form-group">
32
+ <%%= f.label :<%= attribute.column_name %> %>
33
+ <%%= f.<%= attribute.field_type %> :<%= attribute.column_name %>, class: "form-control" %>
34
+ </div>
35
+ <%- end -%>
36
+ <%- end -%>
37
+ <%%= f.submit class: "btn btn-primary" %>
38
+ <%%= link_to "Cancel", @<%= singular_table_name %>.new_record? ? <%= index_helper %>_path : <%= singular_table_name %>_path(@<%= singular_table_name %>), class: "btn btn-default" %>
39
+ <%% end %>
40
+ </div>
41
+ </div>
42
+ </div>
43
+
@@ -0,0 +1,81 @@
1
+ <table id="dt-<%= plural_table_name %>" class="table" style="width: 100%;">
2
+ <thead>
3
+ <tr>
4
+ <%- attributes.reject(&:password_digest?).each do |attribute| -%>
5
+ <th><%= attribute.human_name %></th>
6
+ <%- end -%>
7
+ <th class="text-right"><%%= link_to 'New', new_<%= singular_table_name %>_path, class: 'btn btn-success btn-xs inline_form' %></th>
8
+ </tr>
9
+ </thead>
10
+ </table>
11
+
12
+ <%% provide :scripts do %>
13
+ <script type="text/javascript">
14
+ //<![CDATA[
15
+ $(function() {
16
+ function filter_column(column, text) {
17
+ var dt = $('#dt-<%= plural_table_name %>').dataTable().api();
18
+ var col = dt.column(column);
19
+
20
+ if (col.search() !== text) {
21
+ col.search(text).draw();
22
+ }
23
+ }
24
+
25
+ $('#dt-<%= plural_table_name %>').DataTable({
26
+ dom: '<"panel-body"<"col-sm-6 col-sm-offset-6"fr>>t<"panel-body"<"col-sm-6"i><"col-sm-6"p>>',
27
+ ajax: {
28
+ url: '<%%= api_path %>',
29
+ type: 'POST'
30
+ },
31
+ columns: [
32
+ <%- attributes.reject(&:password_digest?).each do |attribute| -%>
33
+ {
34
+ // the data to display.
35
+ data: '<%= attribute.name %>',
36
+ <%- if attribute.type == :boolean -%>
37
+ // for booleans, show a checkmark instead of true/false.
38
+ render: function (data, type) {
39
+ if (type === 'display')
40
+ return data ? '<i class="glyphicon glyphicon-ok glyphicon-small"></i>' : '';
41
+ else
42
+ return data;
43
+ },
44
+ <%- end -%>
45
+ // can this column be used for sorting?
46
+ orderable: true,
47
+ // can this column be used for searching?
48
+ searchable: true
49
+ },
50
+ <%- end %>
51
+ {
52
+ orderable: false,
53
+ searchable: false,
54
+ data: function (row, type, set, meta) {
55
+ if (type === 'display') {
56
+ var ret = '<div class="text-right">';
57
+
58
+ // the show icon.
59
+ ret += '<a href="javascript:inlineForm(\'' + row.DT_Path + '\')" title="Details" class="btn btn-default btn-xs"><i class="glyphicon glyphicon-zoom-in"></i></a>';
60
+
61
+ // the edit icon.
62
+ ret += '<a href="javascript:inlineForm(\'' + row.DT_Path + '/edit\')" title="Edit" class="btn btn-default btn-xs"><i class="glyphicon glyphicon-pencil"></i></a>';
63
+
64
+ // the delete icon.
65
+ ret += '<a href="javascript:inlineAction(\'' + row.DT_Path + '\',\'delete\')" title="Remove" class="btn btn-danger btn-xs" data-confirm="Are you sure you want to remove this <%= singular_table_name.humanize %>?"><i class="glyphicon glyphicon-trash"></i></a>';
66
+
67
+ ret += '</div>';
68
+ return ret;
69
+ } else {
70
+ return row.DT_Path;
71
+ }
72
+ }
73
+ }
74
+ ],
75
+ responsive: true,
76
+ serverSide: true
77
+ });
78
+ });
79
+ //]]>
80
+ </script>
81
+ <%% end %>
@@ -0,0 +1 @@
1
+ <%%= render 'form' %>
@@ -0,0 +1,6 @@
1
+ <div class="panel panel-primary">
2
+ <div class="panel-heading">
3
+ <h4 class="panel-title"><%= plural_table_name.titleize %></h4>
4
+ </div>
5
+ <%%= render partial: 'list', locals: { api_path: api_<%= plural_table_name %>_path } %>
6
+ </div>
@@ -0,0 +1 @@
1
+ <%%= render 'form' %>
@@ -0,0 +1,34 @@
1
+
2
+ <div class="col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3">
3
+ <div class="panel panel-primary">
4
+ <div class="panel-heading">
5
+ <h4 class="panel-title">
6
+ <%= singular_table_name.titleize %>
7
+ </h4>
8
+ </div>
9
+ <div class="panel-body">
10
+ <%- attributes.reject(&:password_digest?).each do |attribute| -%>
11
+ <div class="row">
12
+ <div class="col-sm-6 col-md-4">
13
+ <strong><%= attribute.human_name %>:</strong>
14
+ </div>
15
+ <div class="col-sm-6 col-md-8">
16
+ <%- if attribute.type == :boolean -%>
17
+ <%%= @<%= singular_table_name %>.<%= attribute.name %> ? 'Yes' : 'No' %>
18
+ <%- elsif attribute.type == :integer -%>
19
+ <%%= @<%= singular_table_name %>.<%= attribute.name %> ? number_with_delimiter(@<%= singular_table_name %>.<%= attribute.name %>) : '0' %>
20
+ <%- elsif attribute.type == :float -%>
21
+ <%%= @<%= singular_table_name %>.<%= attribute.name %> ? number_with_precision(@<%= singular_table_name %>.<%= attribute.name %>, delimiter: ',', precision: 2) : '0' %>
22
+ <%- elsif attribute.type == :datetime -%>
23
+ <%%= @<%= singular_table_name %>.<%= attribute.name %> ? @<%= singular_table_name %>.<%= attribute.name %>.strftime('%m/%d/%Y') : '[Invalid Date]' %>
24
+ <%- else -%>
25
+ <%%= @<%= singular_table_name %>.<%= attribute.name %> %>
26
+ <%- end -%>
27
+ </div>
28
+ </div>
29
+ <%- end -%>
30
+ <br>
31
+ <%%= link_to 'Cancel', <%= index_helper %>_path, class: 'btn btn-default' %>
32
+ </div>
33
+ </div>
34
+ </div>
@@ -0,0 +1,20 @@
1
+ unless <%= singular_table_name %>.new_record?
2
+ json.set! 'DT_RowId', "<%= singular_table_name %>_#{<%= singular_table_name %>.id}"
3
+ json.set! 'DT_Path', <%= singular_table_name %>_path(<%= singular_table_name %>)
4
+ if <%= singular_table_name %>.destroyed?
5
+ json.set! 'DT_RowAction', 'remove'
6
+ end
7
+ end
8
+ <%- attributes.reject(&:password_digest?).each do |attribute| -%>
9
+ <%- if attribute.type == :references -%>
10
+ json.set! '<%= attribute.name %>', h(<%= singular_table_name %>.<%= attribute.name %>.to_s)
11
+ <%- elsif attribute.type == :datetime || attribute.type == :time -%>
12
+ json.set! '<%= attribute.name %>', <%= singular_table_name %>.<%= attribute.name %>&.utc&.strftime('%m/%d/%Y %H:%M:%S')
13
+ <%- elsif attribute.type == :date -%>
14
+ json.set! '<%= attribute.name %>', <%= singular_table_name %>.<%= attribute.name %>&.strftime('%m/%d/%Y')
15
+ <%- elsif attribute.type == :string || attribute.type == :text -%>
16
+ json.set! '<%= attribute.name %>', h(<%= singular_table_name %>.<%= attribute.name %>)
17
+ <%- else -%>
18
+ json.set! '<%= attribute.name %>', <%= singular_table_name %>.<%= attribute.name %>
19
+ <%- end -%>
20
+ <%- end -%>
@@ -0,0 +1,16 @@
1
+ if @dt_request&.provided?
2
+ json.set! 'draw', @dt_request.draw
3
+ json.set! 'recordsTotal', @dt_request.records_total
4
+ json.set! 'recordsFiltered', @dt_request.records_filtered
5
+ json.data do
6
+ json.array!(@dt_request.records) do |<%= singular_table_name %>|
7
+ json.partial! 'details', locals: { <%= singular_table_name %>: <%= singular_table_name %> }
8
+ end
9
+ end
10
+ if @dt_request.error?
11
+ json.set! 'error', @dt_request.error
12
+ end
13
+ else
14
+ json.set! 'error', 'No data tables request received.'
15
+ end
16
+ json.set! 'appInfo', h(Rails.application.app_info)
@@ -0,0 +1,16 @@
1
+ json.messages do
2
+ json.array! flash.discard do |type,message|
3
+ json.set! 'type', type
4
+ json.set! 'text', message
5
+ end
6
+ end
7
+
8
+ if @<%= singular_table_name %>.errors.any?
9
+ json.api_errors! '<%= singular_table_name %>', @<%= singular_table_name %>.errors
10
+ else
11
+ json.data do
12
+ json.array! [ @<%= singular_table_name %> ] do |<%= singular_table_name %>|
13
+ json.partial! 'details', locals: { <%= singular_table_name %>: <%= singular_table_name %> }
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,128 @@
1
+ <% if namespaced? -%>
2
+ require_dependency "<%= namespaced_path %>/application_controller"
3
+
4
+ <% end -%>
5
+ <% module_namespacing do -%>
6
+ class <%= controller_class_name %>Controller < ApplicationController
7
+ before_action :set_dt_request, only: [ :index, :locate ]
8
+ before_action :set_new_<%= singular_table_name %>, only: [ :new, :create ]
9
+ before_action :set_<%= singular_table_name %>, only: [ :show, :edit, :update, :destroy ]
10
+
11
+ layout :layout_to_use
12
+
13
+ # GET <%= route_url %>
14
+ def index
15
+ end
16
+
17
+ # GET <%= route_url %>/1
18
+ def show
19
+ end
20
+
21
+ # GET <%= route_url %>/new
22
+ def new
23
+ end
24
+
25
+ # GET <%= route_url %>/1/edit
26
+ def edit
27
+ end
28
+
29
+ # POST <%= route_url %>
30
+ def create
31
+ if @<%= orm_instance.save %>
32
+ handle_update_success notice: <%= "'#{human_name} was successfully created.'" %>
33
+ else
34
+ handle_update_failure :new
35
+ end
36
+ end
37
+
38
+ # PATCH/PUT <%= route_url %>/1
39
+ def update
40
+ if @<%= orm_instance.update("#{singular_table_name}_params") %>
41
+ handle_update_success notice: <%= "'#{human_name} was successfully updated.'" %>
42
+ else
43
+ handle_update_failure :edit
44
+ end
45
+ end
46
+
47
+ # DELETE <%= route_url %>/1
48
+ def destroy
49
+ @<%= orm_instance.destroy %>
50
+ handle_update_success notice: <%= "'#{human_name} was successfully destroyed.'" %>
51
+ end
52
+
53
+ # GET/POST <%= route_url %>/api?action=...
54
+ def api
55
+ process_api_action
56
+ end
57
+
58
+ # POST <%= route_url %>/1/locate
59
+ def locate
60
+ render json: { record: @dt_request.record_location }
61
+ end
62
+
63
+ private
64
+
65
+ # Inline requests do not get a layout, otherwise use the default layout.
66
+ def layout_to_use
67
+ inline_request? ? false : nil
68
+ end
69
+
70
+ def handle_update_failure(action)
71
+ if json_request?
72
+ # add a model-level error and render the json response.
73
+ @<%= singular_table_name %>.errors.add(:base, 'failed to save')
74
+ render 'show', formats: [ :json ]
75
+ else
76
+ # render the appropriate action.
77
+ render action
78
+ end
79
+ end
80
+
81
+ def handle_update_success(*messages)
82
+ if inline_request?
83
+ # inline and json requests expect json on success.
84
+ render 'show', formats: [ :json ]
85
+ else
86
+ # otherwise, we redirect.
87
+
88
+ # The default behavior in rails is to redirect to the item that was updated.
89
+ # The default behavior in incline is to redirect to the item collection.
90
+
91
+ # To reinstate the default rails behavior, uncomment the line below.
92
+ # redirect_to @<%= singular_table_name %>, *messages unless @<%= singular_table_name %>.destroyed?
93
+ redirect_to <%= index_helper %>_url, *messages
94
+ end
95
+ end
96
+
97
+ # Only allow a trusted parameter "white list" through.
98
+ def <%= "#{singular_table_name}_params" %>
99
+ if params.include?(:<%= singular_table_name %>)
100
+ <%- if attributes_names.empty? -%>
101
+ params[:<%= singular_table_name %>]
102
+ <%- else -%>
103
+ params.require(:<%= singular_table_name %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
104
+ <%- end -%>
105
+ else
106
+ { }
107
+ end
108
+ end
109
+
110
+ # Assigns the variable used for index and locate actions.
111
+ def set_dt_request
112
+ @dt_request = Incline::DataTablesRequest.new(params) do
113
+ <%= orm_class.all(class_name) %>
114
+ end
115
+ end
116
+
117
+ # Assigns the variable used for new and create actions.
118
+ def set_new_<%= singular_table_name %>
119
+ @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
120
+ end
121
+
122
+ # Assigns the variable used for every other action.
123
+ def set_<%= singular_table_name %>
124
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
125
+ end
126
+
127
+ end
128
+ <% end -%>