aldous 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.irbrc +3 -0
  4. data/.rspec +3 -0
  5. data/.ruby-version +1 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +591 -0
  9. data/Rakefile +1 -0
  10. data/aldous.gemspec +24 -0
  11. data/examples/basic_todo/.foreman +1 -0
  12. data/examples/basic_todo/.gitignore +16 -0
  13. data/examples/basic_todo/.rspec +3 -0
  14. data/examples/basic_todo/.ruby-version +2 -0
  15. data/examples/basic_todo/Gemfile +52 -0
  16. data/examples/basic_todo/Procfile +1 -0
  17. data/examples/basic_todo/README.rdoc +28 -0
  18. data/examples/basic_todo/Rakefile +6 -0
  19. data/examples/basic_todo/app/assets/images/.keep +0 -0
  20. data/examples/basic_todo/app/assets/javascripts/application.js +13 -0
  21. data/examples/basic_todo/app/assets/stylesheets/application.css +15 -0
  22. data/examples/basic_todo/app/controller_actions/base_action.rb +24 -0
  23. data/examples/basic_todo/app/controller_actions/base_precondition.rb +2 -0
  24. data/examples/basic_todo/app/controller_actions/home_controller/show.rb +8 -0
  25. data/examples/basic_todo/app/controller_actions/shared/ensure_user_not_disabled_precondition.rb +9 -0
  26. data/examples/basic_todo/app/controller_actions/sign_ins_controller/create.rb +24 -0
  27. data/examples/basic_todo/app/controller_actions/sign_ins_controller/destroy.rb +9 -0
  28. data/examples/basic_todo/app/controller_actions/sign_ins_controller/new.rb +7 -0
  29. data/examples/basic_todo/app/controller_actions/sign_ins_controller/user_params.rb +9 -0
  30. data/examples/basic_todo/app/controller_actions/sign_ups_controller/create.rb +23 -0
  31. data/examples/basic_todo/app/controller_actions/sign_ups_controller/new.rb +7 -0
  32. data/examples/basic_todo/app/controller_actions/sign_ups_controller/user_params.rb +9 -0
  33. data/examples/basic_todo/app/controller_actions/todos/all_completed_controller/destroy.rb +17 -0
  34. data/examples/basic_todo/app/controller_actions/todos/completed_controller/create.rb +29 -0
  35. data/examples/basic_todo/app/controller_actions/todos_controller/create.rb +26 -0
  36. data/examples/basic_todo/app/controller_actions/todos_controller/destroy.rb +21 -0
  37. data/examples/basic_todo/app/controller_actions/todos_controller/edit.rb +19 -0
  38. data/examples/basic_todo/app/controller_actions/todos_controller/index.rb +19 -0
  39. data/examples/basic_todo/app/controller_actions/todos_controller/new.rb +17 -0
  40. data/examples/basic_todo/app/controller_actions/todos_controller/todo_params.rb +9 -0
  41. data/examples/basic_todo/app/controller_actions/todos_controller/update.rb +28 -0
  42. data/examples/basic_todo/app/controller_actions/users_controller/index.rb +19 -0
  43. data/examples/basic_todo/app/controllers/application_controller.rb +9 -0
  44. data/examples/basic_todo/app/controllers/home_controller.rb +5 -0
  45. data/examples/basic_todo/app/controllers/sign_ins_controller.rb +5 -0
  46. data/examples/basic_todo/app/controllers/sign_ups_controller.rb +5 -0
  47. data/examples/basic_todo/app/controllers/todos/all_completed_controller.rb +5 -0
  48. data/examples/basic_todo/app/controllers/todos/completed_controller.rb +5 -0
  49. data/examples/basic_todo/app/controllers/todos_controller.rb +5 -0
  50. data/examples/basic_todo/app/controllers/users_controller.rb +5 -0
  51. data/examples/basic_todo/app/helpers/application_helper.rb +2 -0
  52. data/examples/basic_todo/app/mailers/.keep +0 -0
  53. data/examples/basic_todo/app/models/ability.rb +27 -0
  54. data/examples/basic_todo/app/models/role.rb +5 -0
  55. data/examples/basic_todo/app/models/todo.rb +5 -0
  56. data/examples/basic_todo/app/models/user.rb +12 -0
  57. data/examples/basic_todo/app/models/user_role.rb +5 -0
  58. data/examples/basic_todo/app/services/create_user_service.rb +26 -0
  59. data/examples/basic_todo/app/services/find_current_user_service.rb +29 -0
  60. data/examples/basic_todo/app/services/sign_in_service.rb +13 -0
  61. data/examples/basic_todo/app/services/sign_out_service.rb +12 -0
  62. data/examples/basic_todo/app/views/base_view.rb +18 -0
  63. data/examples/basic_todo/app/views/defaults/bad_request.html.slim +12 -0
  64. data/examples/basic_todo/app/views/defaults/bad_request_view.rb +15 -0
  65. data/examples/basic_todo/app/views/defaults/forbidden.html.slim +6 -0
  66. data/examples/basic_todo/app/views/defaults/forbidden_view.rb +14 -0
  67. data/examples/basic_todo/app/views/defaults/server_error.html.slim +12 -0
  68. data/examples/basic_todo/app/views/defaults/server_error_view.rb +14 -0
  69. data/examples/basic_todo/app/views/home/show.html.slim +5 -0
  70. data/examples/basic_todo/app/views/home/show_redirect.rb +5 -0
  71. data/examples/basic_todo/app/views/home/show_view.rb +7 -0
  72. data/examples/basic_todo/app/views/layouts/application.html.slim +18 -0
  73. data/examples/basic_todo/app/views/modules/_header.html.slim +13 -0
  74. data/examples/basic_todo/app/views/modules/header_view.rb +7 -0
  75. data/examples/basic_todo/app/views/sign_ins/new.html.slim +14 -0
  76. data/examples/basic_todo/app/views/sign_ins/new_view.rb +10 -0
  77. data/examples/basic_todo/app/views/sign_ups/new.html.slim +13 -0
  78. data/examples/basic_todo/app/views/sign_ups/new_view.rb +10 -0
  79. data/examples/basic_todo/app/views/todos/edit.html.slim +14 -0
  80. data/examples/basic_todo/app/views/todos/edit_view.rb +10 -0
  81. data/examples/basic_todo/app/views/todos/index.html.slim +12 -0
  82. data/examples/basic_todo/app/views/todos/index_redirect.rb +5 -0
  83. data/examples/basic_todo/app/views/todos/index_view/_todo.html.slim +8 -0
  84. data/examples/basic_todo/app/views/todos/index_view/todo_view.rb +28 -0
  85. data/examples/basic_todo/app/views/todos/index_view.rb +26 -0
  86. data/examples/basic_todo/app/views/todos/new.html.slim +14 -0
  87. data/examples/basic_todo/app/views/todos/new_view.rb +10 -0
  88. data/examples/basic_todo/app/views/todos/not_found.html.slim +6 -0
  89. data/examples/basic_todo/app/views/todos/not_found_view.rb +15 -0
  90. data/examples/basic_todo/app/views/users/index.html.slim +7 -0
  91. data/examples/basic_todo/app/views/users/index_redirect.rb +5 -0
  92. data/examples/basic_todo/app/views/users/index_view/_user.html.slim +2 -0
  93. data/examples/basic_todo/app/views/users/index_view/user_view.rb +22 -0
  94. data/examples/basic_todo/app/views/users/index_view.rb +26 -0
  95. data/examples/basic_todo/bin/bundle +3 -0
  96. data/examples/basic_todo/bin/rails +8 -0
  97. data/examples/basic_todo/bin/rake +8 -0
  98. data/examples/basic_todo/bin/rspec +7 -0
  99. data/examples/basic_todo/bin/spring +15 -0
  100. data/examples/basic_todo/config/application.rb +41 -0
  101. data/examples/basic_todo/config/boot.rb +4 -0
  102. data/examples/basic_todo/config/database.yml +25 -0
  103. data/examples/basic_todo/config/environment.rb +5 -0
  104. data/examples/basic_todo/config/environments/development.rb +37 -0
  105. data/examples/basic_todo/config/environments/production.rb +78 -0
  106. data/examples/basic_todo/config/environments/test.rb +39 -0
  107. data/examples/basic_todo/config/initializers/aldous.rb +3 -0
  108. data/examples/basic_todo/config/initializers/assets.rb +8 -0
  109. data/examples/basic_todo/config/initializers/backtrace_silencers.rb +7 -0
  110. data/examples/basic_todo/config/initializers/cookies_serializer.rb +3 -0
  111. data/examples/basic_todo/config/initializers/filter_parameter_logging.rb +4 -0
  112. data/examples/basic_todo/config/initializers/inflections.rb +16 -0
  113. data/examples/basic_todo/config/initializers/mime_types.rb +4 -0
  114. data/examples/basic_todo/config/initializers/session_store.rb +3 -0
  115. data/examples/basic_todo/config/initializers/wrap_parameters.rb +14 -0
  116. data/examples/basic_todo/config/locales/en.yml +23 -0
  117. data/examples/basic_todo/config/routes.rb +18 -0
  118. data/examples/basic_todo/config/secrets.yml +22 -0
  119. data/examples/basic_todo/config.ru +4 -0
  120. data/examples/basic_todo/db/migrate/20150226035524_create_user.rb +10 -0
  121. data/examples/basic_todo/db/migrate/20150227004411_create_todo.rb +11 -0
  122. data/examples/basic_todo/db/migrate/20150301110126_roles.rb +22 -0
  123. data/examples/basic_todo/db/migrate/20150301121923_add_user_disabled_column.rb +5 -0
  124. data/examples/basic_todo/db/schema.rb +45 -0
  125. data/examples/basic_todo/db/seeds.rb +7 -0
  126. data/examples/basic_todo/lib/assets/.keep +0 -0
  127. data/examples/basic_todo/lib/tasks/.keep +0 -0
  128. data/examples/basic_todo/log/.keep +0 -0
  129. data/examples/basic_todo/public/404.html +67 -0
  130. data/examples/basic_todo/public/422.html +67 -0
  131. data/examples/basic_todo/public/500.html +66 -0
  132. data/examples/basic_todo/public/favicon.ico +0 -0
  133. data/examples/basic_todo/public/robots.txt +5 -0
  134. data/examples/basic_todo/test/controllers/.keep +0 -0
  135. data/examples/basic_todo/test/fixtures/.keep +0 -0
  136. data/examples/basic_todo/test/helpers/.keep +0 -0
  137. data/examples/basic_todo/test/integration/.keep +0 -0
  138. data/examples/basic_todo/test/mailers/.keep +0 -0
  139. data/examples/basic_todo/test/models/.keep +0 -0
  140. data/examples/basic_todo/test/test_helper.rb +10 -0
  141. data/examples/basic_todo/vendor/assets/javascripts/.keep +0 -0
  142. data/examples/basic_todo/vendor/assets/stylesheets/.keep +0 -0
  143. data/lib/aldous/build_respondable_service.rb +23 -0
  144. data/lib/aldous/configuration.rb +18 -0
  145. data/lib/aldous/controller/action/precondition/wrapper.rb +32 -0
  146. data/lib/aldous/controller/action/precondition.rb +52 -0
  147. data/lib/aldous/controller/action/result_execution_service.rb +27 -0
  148. data/lib/aldous/controller/action/wrapper.rb +34 -0
  149. data/lib/aldous/controller/action_execution_service.rb +42 -0
  150. data/lib/aldous/controller/preconditions_execution_service.rb +32 -0
  151. data/lib/aldous/controller.rb +21 -0
  152. data/lib/aldous/controller_action.rb +63 -0
  153. data/lib/aldous/dummy_error_reporter.rb +9 -0
  154. data/lib/aldous/dummy_logger.rb +8 -0
  155. data/lib/aldous/errors/user_error.rb +6 -0
  156. data/lib/aldous/logging_wrapper.rb +16 -0
  157. data/lib/aldous/params.rb +34 -0
  158. data/lib/aldous/respondable/base.rb +32 -0
  159. data/lib/aldous/respondable/headable.rb +30 -0
  160. data/lib/aldous/respondable/redirectable.rb +38 -0
  161. data/lib/aldous/respondable/renderable.rb +50 -0
  162. data/lib/aldous/respondable/request_http_basic_authentication.rb +23 -0
  163. data/lib/aldous/respondable/send_data.rb +36 -0
  164. data/lib/aldous/respondable/shared/flash.rb +24 -0
  165. data/lib/aldous/service/result/base/predicate_methods_for_inheritance.rb +44 -0
  166. data/lib/aldous/service/result/base.rb +13 -0
  167. data/lib/aldous/service/result/failure.rb +11 -0
  168. data/lib/aldous/service/result/success.rb +11 -0
  169. data/lib/aldous/service/wrapper.rb +48 -0
  170. data/lib/aldous/service.rb +34 -0
  171. data/lib/aldous/simple_dto.rb +47 -0
  172. data/lib/aldous/stdout_logger.rb +9 -0
  173. data/lib/aldous/version.rb +3 -0
  174. data/lib/aldous/view/blank/atom_view.rb +12 -0
  175. data/lib/aldous/view/blank/html_view.rb +16 -0
  176. data/lib/aldous/view/blank/json_view.rb +16 -0
  177. data/lib/aldous.rb +40 -0
  178. data/spec/aldous/build_respondable_service_spec.rb +48 -0
  179. data/spec/aldous/configuration_spec.rb +15 -0
  180. data/spec/aldous/controller/action/precondition/wrapper_spec.rb +48 -0
  181. data/spec/aldous/controller/action/precondition_spec.rb +81 -0
  182. data/spec/aldous/controller/action/result_execution_service_spec.rb +43 -0
  183. data/spec/aldous/controller/action/wrapper_spec.rb +46 -0
  184. data/spec/aldous/controller/action_execution_service_spec.rb +79 -0
  185. data/spec/aldous/controller/preconditions_execution_service_spec.rb +45 -0
  186. data/spec/aldous/controller_action_spec.rb +97 -0
  187. data/spec/aldous/controller_spec.rb +25 -0
  188. data/spec/aldous/dummy_error_reporter_spec.rb +10 -0
  189. data/spec/aldous/dummy_logger_spec.rb +7 -0
  190. data/spec/aldous/logging_wrapper_spec.rb +55 -0
  191. data/spec/aldous/params_spec.rb +39 -0
  192. data/spec/aldous/respondable/base_spec.rb +11 -0
  193. data/spec/aldous/respondable/headable/head_action_spec.rb +17 -0
  194. data/spec/aldous/respondable/headable_spec.rb +20 -0
  195. data/spec/aldous/respondable/redirectable/redirect_action_spec.rb +34 -0
  196. data/spec/aldous/respondable/redirectable_spec.rb +26 -0
  197. data/spec/aldous/respondable/renderable/render_action_spec.rb +34 -0
  198. data/spec/aldous/respondable/renderable_spec.rb +46 -0
  199. data/spec/aldous/respondable/request_http_basic_authentication_spec.rb +0 -0
  200. data/spec/aldous/respondable/send_data/send_data_action_spec.rb +15 -0
  201. data/spec/aldous/respondable/send_data_spec.rb +30 -0
  202. data/spec/aldous/respondable/shared/flash_spec.rb +30 -0
  203. data/spec/aldous/service/result/failure_spec.rb +11 -0
  204. data/spec/aldous/service/result/success_spec.rb +11 -0
  205. data/spec/aldous/service/wrapper_spec.rb +110 -0
  206. data/spec/aldous/service_spec.rb +101 -0
  207. data/spec/aldous/simple_dto_spec.rb +40 -0
  208. data/spec/aldous/view/blank/atom_view_spec.rb +15 -0
  209. data/spec/aldous/view/blank/html_view_spec.rb +15 -0
  210. data/spec/aldous/view/blank/json_view_spec.rb +15 -0
  211. data/spec/spec_helper.rb +26 -0
  212. metadata +330 -0
@@ -0,0 +1,26 @@
1
+ class CreateUserService < Aldous::Service
2
+ attr_reader :user_data_hash
3
+
4
+ def initialize(user_data_hash)
5
+ @user_data_hash = user_data_hash
6
+ end
7
+
8
+ def raisable_error
9
+ Aldous::Errors::UserError
10
+ end
11
+
12
+ def default_result_data
13
+ {user: nil}
14
+ end
15
+
16
+ def perform
17
+ user = User.new(user_data_hash)
18
+ user.roles << Role.where(name: "account_holder").first
19
+
20
+ if user.save
21
+ Result::Success.new(user: user)
22
+ else
23
+ Result::Failure.new
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,29 @@
1
+ class FindCurrentUserService < Aldous::Service
2
+ attr_reader :session
3
+
4
+ def initialize(session)
5
+ @session = session
6
+ end
7
+
8
+ def raisable_error
9
+ Aldous::Errors::UserError
10
+ end
11
+
12
+ def default_result_data
13
+ {user: nil}
14
+ end
15
+
16
+ def perform
17
+ user_id = session[:user_id]
18
+ if user_id
19
+ user = User.where(id: user_id).first
20
+ if user
21
+ Result::Success.new(user: user)
22
+ else
23
+ Result::Failure.new
24
+ end
25
+ else
26
+ Result::Failure.new
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ class SignInService < Aldous::Service
2
+ attr_reader :session, :user
3
+
4
+ def initialize(session, user)
5
+ @session = session
6
+ @user = user
7
+ end
8
+
9
+ def perform
10
+ session[:user_id] = user.id
11
+ Result::Success.new
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ class SignOutService < Aldous::Service
2
+ attr_reader :session
3
+
4
+ def initialize(session)
5
+ @session = session
6
+ end
7
+
8
+ def perform
9
+ session.destroy
10
+ Result::Success.new
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ class BaseView < ::Aldous::Respondable::Renderable
2
+ def default_template_locals
3
+ {
4
+ current_user: current_user,
5
+ header_view: header_view,
6
+ }
7
+ end
8
+
9
+ def current_user
10
+ view_data.current_user
11
+ end
12
+
13
+ private
14
+
15
+ def header_view
16
+ build_view(Modules::HeaderView)
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ - provide :title, "Bad Request"
2
+
3
+ div style="padding: 40px"
4
+ h1= yield(:title)
5
+
6
+ p Boo bad request
7
+
8
+ - if Rails.env.development?
9
+ == ap errors
10
+ - errors.each do |error|
11
+ - if error.respond_to?(:backtrace)
12
+ == ap error.backtrace
@@ -0,0 +1,15 @@
1
+ class Defaults::BadRequestView < BaseView
2
+ def template_data
3
+ {
4
+ template: 'defaults/bad_request',
5
+ locals: {
6
+ errors: view_data.errors,
7
+ }
8
+ }
9
+ end
10
+
11
+ def default_status
12
+ :bad_request
13
+ end
14
+ end
15
+
@@ -0,0 +1,6 @@
1
+ - provide :title, "Forbidden"
2
+
3
+ div style="padding: 40px"
4
+ h1= yield(:title)
5
+
6
+ p= error
@@ -0,0 +1,14 @@
1
+ class Defaults::ForbiddenView < BaseView
2
+ def template_data
3
+ {
4
+ template: 'defaults/forbidden',
5
+ locals: {
6
+ error: view_data.errors.first || "You're not authorized to do this"
7
+ }
8
+ }
9
+ end
10
+
11
+ def default_status
12
+ :forbidden
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ - provide :title, "Internal Server Error"
2
+
3
+ div style="padding: 40px"
4
+ h1= yield(:title)
5
+
6
+ p Boo error
7
+
8
+ - if Rails.env.development?
9
+ == ap errors
10
+ - errors.each do |error|
11
+ - if error.respond_to?(:backtrace)
12
+ == ap error.backtrace
@@ -0,0 +1,14 @@
1
+ class Defaults::ServerErrorView < BaseView
2
+ def template_data
3
+ {
4
+ template: 'defaults/server_error',
5
+ locals: {
6
+ errors: view_data.errors,
7
+ }
8
+ }
9
+ end
10
+
11
+ def default_status
12
+ :internal_server_error
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ - provide :title, "Home"
2
+
3
+ = render header_view.template
4
+
5
+ h1 You must get todos
@@ -0,0 +1,5 @@
1
+ class Home::ShowRedirect < Aldous::Respondable::Redirectable
2
+ def location
3
+ view_context.root_path
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ class Home::ShowView < BaseView
2
+ def template_data
3
+ {
4
+ template: 'home/show'
5
+ }
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ doctype html
2
+ html
3
+ head
4
+ meta charset="utf-8"
5
+
6
+ - if content_for?(:title)
7
+ title= yield(:title)
8
+ - else
9
+ title Todos App
10
+
11
+ meta name="viewport" content="width=device-width, initial-scale=1.0"
12
+
13
+ = stylesheet_link_tag 'application', media: 'all'
14
+ = javascript_include_tag 'application'
15
+ = csrf_meta_tags
16
+
17
+ body
18
+ = yield
@@ -0,0 +1,13 @@
1
+ .header
2
+ .header__container
3
+ = link_to 'Home', root_path, class: 'header__home-link'
4
+ .header__authentication
5
+ - if current_user
6
+ span.header__authenticated-user
7
+ = current_user.email
8
+ ' |
9
+ = button_to 'Sign Out', sign_in_path(current_user), method: :delete, class: 'header__sign-out-link'
10
+ - else
11
+ = link_to 'Sign In', new_sign_in_path, class: 'header__sign-in-link'
12
+ ' |
13
+ = link_to 'Sign Up', new_sign_up_path, class: 'header__sign-up-link'
@@ -0,0 +1,7 @@
1
+ class Modules::HeaderView < BaseView
2
+ def template_data
3
+ {
4
+ partial: 'modules/header'
5
+ }
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ - provide :title, "Sign In"
2
+
3
+ = render header_view.template
4
+
5
+ h1 Sign In
6
+
7
+ div
8
+ = form_for user, url: sign_ins_path(user) do |f|
9
+ = f.label :email
10
+ = f.text_field :email
11
+ = f.label :password
12
+ = f.text_field :password
13
+ = f.submit 'Sign In'
14
+
@@ -0,0 +1,10 @@
1
+ class SignIns::NewView < BaseView
2
+ def template_data
3
+ {
4
+ template: 'sign_ins/new',
5
+ locals: {
6
+ user: User.new,
7
+ }
8
+ }
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ - provide :title, "Sign Up"
2
+
3
+ = render header_view.template
4
+
5
+ h1 Sign Up
6
+
7
+ div
8
+ = form_for user, url: sign_ups_path(user) do |f|
9
+ = f.label :email
10
+ = f.text_field :email
11
+ = f.label :password
12
+ = f.text_field :password
13
+ = f.submit 'Sign Up'
@@ -0,0 +1,10 @@
1
+ class SignUps::NewView < BaseView
2
+ def template_data
3
+ {
4
+ template: 'sign_ups/new',
5
+ locals: {
6
+ user: User.new,
7
+ }
8
+ }
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ - provide :title, "Edit Todo"
2
+
3
+ = render header_view.template
4
+
5
+ h1 Edit Todo
6
+
7
+ div
8
+ = form_for todo, url: todo_path(todo) do |f|
9
+ = f.label :description
10
+ = f.text_field :description
11
+ = f.hidden_field :user_id
12
+ = f.submit 'Update'
13
+
14
+
@@ -0,0 +1,10 @@
1
+ class Todos::EditView < BaseView
2
+ def template_data
3
+ {
4
+ template: 'todos/edit',
5
+ locals: {
6
+ todo: view_data.todo
7
+ }
8
+ }
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ - provide :title, "View Todos"
2
+
3
+ = render header_view.template
4
+
5
+ h1 Your Todos
6
+
7
+ = link_to 'Create New Todo', new_todo_path
8
+ = button_to 'Delete Completed Todos', all_completed_todos_path, method: :delete
9
+
10
+ - todo_views.each do |todo_view|
11
+ = render todo_view.template
12
+
@@ -0,0 +1,5 @@
1
+ class Todos::IndexRedirect < Aldous::Respondable::Redirectable
2
+ def location
3
+ view_context.todos_path
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ div
2
+ span= description
3
+ ' |
4
+ span= done
5
+ span= link_to 'Update', edit_todo_path
6
+ span= button_to 'Delete', delete_todo_path, method: :delete
7
+ span= button_to 'Complete', complete_todo_path, method: :post
8
+ hr
@@ -0,0 +1,28 @@
1
+ class Todos::IndexView::TodoView < BaseView
2
+ def template_data
3
+ {
4
+ partial: 'todos/index_view/todo',
5
+ locals: {
6
+ description: todo.description,
7
+ done: done,
8
+ edit_todo_path: view_context.edit_todo_path(todo),
9
+ delete_todo_path: view_context.todo_path(todo),
10
+ complete_todo_path: view_context.completed_todos_path(todo)
11
+ }
12
+ }
13
+ end
14
+
15
+ private
16
+
17
+ def todo
18
+ view_data.todo
19
+ end
20
+
21
+ def done
22
+ if todo.done
23
+ 'Yes'
24
+ else
25
+ 'No'
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ class Todos::IndexView < BaseView
2
+ def template_data
3
+ {
4
+ template: 'todos/index',
5
+ locals: {
6
+ todo_views: todo_views,
7
+ }
8
+ }
9
+ end
10
+
11
+ private
12
+
13
+ def todos
14
+ view_data.todos
15
+ end
16
+
17
+ def todo_views
18
+ todos.map do |todo|
19
+ todo_view(todo)
20
+ end
21
+ end
22
+
23
+ def todo_view(todo)
24
+ build_view(Todos::IndexView::TodoView, todo: todo)
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ - provide :title, "New Todo"
2
+
3
+ = render header_view.template
4
+
5
+ h1 New Todo
6
+
7
+ div
8
+ = form_for todo, url: todos_path(todo) do |f|
9
+ = f.label :description
10
+ = f.text_field :description
11
+ = f.hidden_field :user_id
12
+ = f.submit 'Create'
13
+
14
+
@@ -0,0 +1,10 @@
1
+ class Todos::NewView < BaseView
2
+ def template_data
3
+ {
4
+ template: 'todos/new',
5
+ locals: {
6
+ todo: view_data.todo
7
+ }
8
+ }
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ - provide :title, "Not Found"
2
+
3
+ div style="padding: 40px"
4
+ h1= yield(:title)
5
+
6
+ p= "No todo with id #{todo_id}, for user #{user_email}"
@@ -0,0 +1,15 @@
1
+ class Todos::NotFoundView < BaseView
2
+ def template_data
3
+ {
4
+ template: 'todos/not_found',
5
+ locals: {
6
+ user_email: current_user.email,
7
+ todo_id: view_data.todo_id,
8
+ }
9
+ }
10
+ end
11
+
12
+ def default_status
13
+ :not_found
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ - provide :title, "Users"
2
+
3
+ = render header_view.template
4
+
5
+ h1 Users
6
+ - user_views.each do |user_view|
7
+ = render user_view
@@ -0,0 +1,5 @@
1
+ class Users::IndexRedirect < Aldous::Respondable::Redirectable
2
+ def location
3
+ view_context.root_path
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ class Users::IndexView::UserView < BaseView
2
+ def template_data
3
+ {
4
+ partial: 'users/index_view/user',
5
+ locals: {
6
+ email: user_email,
7
+ }
8
+ }
9
+ end
10
+
11
+ private
12
+
13
+ def user
14
+ view_data.user
15
+ end
16
+
17
+ def user_email
18
+ if user
19
+ user.email
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,26 @@
1
+ class Users::IndexView < BaseView
2
+ def template
3
+ {
4
+ template: 'users/index',
5
+ locals: {
6
+ user_views: user_views,
7
+ }
8
+ }
9
+ end
10
+
11
+ private
12
+
13
+ def users
14
+ view_data.users
15
+ end
16
+
17
+ def user_views
18
+ users.map do |user|
19
+ user_view(user)
20
+ end
21
+ end
22
+
23
+ def user_view(user)
24
+ build_view(Users::IndexView::UserView, user: user).template
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ load File.expand_path("../spring", __FILE__)
4
+ rescue LoadError
5
+ end
6
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
7
+ require_relative '../config/boot'
8
+ require 'rails/commands'
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ load File.expand_path("../spring", __FILE__)
4
+ rescue LoadError
5
+ end
6
+ require_relative '../config/boot'
7
+ require 'rake'
8
+ Rake.application.run
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ load File.expand_path("../spring", __FILE__)
4
+ rescue LoadError
5
+ end
6
+ require 'bundler/setup'
7
+ load Gem.bin_path('rspec-core', 'rspec')
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # This file loads spring without using Bundler, in order to be fast.
4
+ # It gets overwritten when you run the `spring binstub` command.
5
+
6
+ unless defined?(Spring)
7
+ require "rubygems"
8
+ require "bundler"
9
+
10
+ if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m)
11
+ Gem.paths = { "GEM_PATH" => Bundler.bundle_path.to_s }
12
+ gem "spring", match[1]
13
+ require "spring/binstub"
14
+ end
15
+ end
@@ -0,0 +1,41 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ # Require the gems listed in Gemfile, including any gems
6
+ # you've limited to :test, :development, or :production.
7
+ Bundler.require(*Rails.groups)
8
+
9
+ module BasicTodo
10
+ class Application < Rails::Application
11
+ config.encoding = "utf-8"
12
+
13
+ config.exceptions_app = self.routes
14
+
15
+ config.generators.assets = false
16
+ config.generators.helper = false
17
+
18
+ # Change this to expire all assets
19
+ config.assets.version = '1.0'
20
+
21
+ config.action_controller.include_all_helpers = false
22
+
23
+ config.action_dispatch.default_headers['X-Frame-Options'] = 'SAMEORIGIN'
24
+
25
+ config.autoload_paths += %W(
26
+ #{config.root}/app/views
27
+ #{config.root}/app/services
28
+ #{config.root}/app/controller_services
29
+ #{config.root}/app/controller_actions
30
+ #{config.root}/lib
31
+ )
32
+
33
+ config.eager_load_paths += %W(
34
+ #{config.root}/app/views
35
+ #{config.root}/app/services
36
+ #{config.root}/app/controller_services
37
+ #{config.root}/app/controller_actions
38
+ #{config.root}/lib
39
+ )
40
+ end
41
+ end
@@ -0,0 +1,4 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ #
7
+ default: &default
8
+ adapter: sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ development:
13
+ <<: *default
14
+ database: db/development.sqlite3
15
+
16
+ # Warning: The database defined as "test" will be erased and
17
+ # re-generated from your development database when you run "rake".
18
+ # Do not set this db to the same as development or production.
19
+ test:
20
+ <<: *default
21
+ database: db/test.sqlite3
22
+
23
+ production:
24
+ <<: *default
25
+ database: db/production.sqlite3