tomify 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +19 -0
  4. data/Rakefile +6 -0
  5. data/app/assets/images/tomify/gifs/basketball.gif +0 -0
  6. data/app/assets/images/tomify/gifs/laughing.gif +0 -0
  7. data/app/assets/images/tomify/gifs/sneer.gif +0 -0
  8. data/app/assets/images/tomify/gifs/wind.gif +0 -0
  9. data/app/assets/images/tomify/gifs/woods.gif +0 -0
  10. data/app/assets/javascripts/tomify/default/array.coffee +4 -0
  11. data/app/assets/javascripts/tomify/default/jquery.patch.coffee +9 -0
  12. data/app/assets/javascripts/tomify/default/object.coffee +4 -0
  13. data/app/assets/javascripts/tomify/default/string.coffee +40 -0
  14. data/app/assets/javascripts/tomify/dynamic/classes/component.coffee +7 -0
  15. data/app/assets/javascripts/tomify/dynamic/classes/field.coffee +24 -0
  16. data/app/assets/javascripts/tomify/dynamic/classes/form.coffee +72 -0
  17. data/app/assets/javascripts/tomify/dynamic/classes/model.coffee +41 -0
  18. data/app/assets/javascripts/tomify/dynamic/classes/namespace.coffee +24 -0
  19. data/app/assets/javascripts/tomify/dynamic/classes/observer.coffee +22 -0
  20. data/app/assets/javascripts/tomify/dynamic/classes/request.coffee +26 -0
  21. data/app/assets/javascripts/tomify/dynamic/classes/store.coffee +37 -0
  22. data/app/assets/javascripts/tomify/dynamic/global.coffee +16 -0
  23. data/app/assets/javascripts/tomify/dynamic/react/components/admin/pages.coffee.erb +30 -0
  24. data/app/assets/javascripts/tomify/dynamic/react/components/admin/settings.coffee +27 -0
  25. data/app/assets/javascripts/tomify/dynamic/react/components/admin/sidebars.coffee +16 -0
  26. data/app/assets/javascripts/tomify/dynamic/react/components/admin/uploads.coffee +13 -0
  27. data/app/assets/javascripts/tomify/dynamic/react/components/admin/users.coffee +18 -0
  28. data/app/assets/javascripts/tomify/dynamic/react/components/edit.coffee +51 -0
  29. data/app/assets/javascripts/tomify/dynamic/react/components/fields/checkbox.coffee +8 -0
  30. data/app/assets/javascripts/tomify/dynamic/react/components/fields/default.coffee +3 -0
  31. data/app/assets/javascripts/tomify/dynamic/react/components/fields/file.coffee +3 -0
  32. data/app/assets/javascripts/tomify/dynamic/react/components/fields/markdown.coffee +9 -0
  33. data/app/assets/javascripts/tomify/dynamic/react/components/fields/select.coffee +8 -0
  34. data/app/assets/javascripts/tomify/dynamic/react/components/fields/textarea.coffee +3 -0
  35. data/app/assets/javascripts/tomify/dynamic/react/components/index.coffee +87 -0
  36. data/app/assets/javascripts/tomify/dynamic/react/components/layout/admin_navbar.coffee +29 -0
  37. data/app/assets/javascripts/tomify/dynamic/react/components/layout/analytics.coffee +34 -0
  38. data/app/assets/javascripts/tomify/dynamic/react/components/layout/footer.coffee +11 -0
  39. data/app/assets/javascripts/tomify/dynamic/react/components/layout/header.coffee +28 -0
  40. data/app/assets/javascripts/tomify/dynamic/react/components/layout/messages.coffee +18 -0
  41. data/app/assets/javascripts/tomify/dynamic/react/components/layout/navbar.coffee +6 -0
  42. data/app/assets/javascripts/tomify/dynamic/react/components/layout/public_navbar.coffee +56 -0
  43. data/app/assets/javascripts/tomify/dynamic/react/components/new.coffee +48 -0
  44. data/app/assets/javascripts/tomify/dynamic/react/components/pagination.coffee +29 -0
  45. data/app/assets/javascripts/tomify/dynamic/react/components/public/passwords/new.coffee +38 -0
  46. data/app/assets/javascripts/tomify/dynamic/react/components/public/sessions/new.coffee +40 -0
  47. data/app/assets/javascripts/tomify/dynamic/react/components/public/sessions/show.coffee +35 -0
  48. data/app/assets/javascripts/tomify/dynamic/react/components/public/users/edit.coffee +42 -0
  49. data/app/assets/javascripts/tomify/dynamic/react/components/public/users/new.coffee +35 -0
  50. data/app/assets/javascripts/tomify/dynamic/react/mixins/follow.coffee +51 -0
  51. data/app/assets/javascripts/tomify/dynamic/react/mixins/will-initialize.coffee +7 -0
  52. data/app/assets/javascripts/tomify/dynamic/react/mount.coffee +9 -0
  53. data/app/assets/javascripts/tomify/turbolinks/compatibility.coffee +29 -0
  54. data/app/assets/javascripts/tomify/turbolinks/react.coffee +5 -0
  55. data/app/assets/javascripts/tomify-dynamic.js +8 -0
  56. data/app/assets/javascripts/tomify.js +1 -0
  57. data/app/assets/stylesheets/_tomify.scss +1 -0
  58. data/app/assets/stylesheets/tomify/_default.scss +26 -0
  59. data/app/assets/stylesheets/tomify/_footer.scss +1 -0
  60. data/app/assets/stylesheets/tomify/_navbar.scss +43 -0
  61. data/app/assets/stylesheets/tomify/_page.scss +31 -0
  62. data/app/assets/stylesheets/tomify/_pagination.scss +5 -0
  63. data/app/assets/stylesheets/tomify/_variables.scss +10 -0
  64. data/app/controllers/tomify/admin/controller.rb +7 -0
  65. data/app/controllers/tomify/admin/pages_controller.rb +2 -0
  66. data/app/controllers/tomify/admin/settings_controller.rb +2 -0
  67. data/app/controllers/tomify/admin/sidebars_controller.rb +2 -0
  68. data/app/controllers/tomify/admin/uploads_controller.rb +2 -0
  69. data/app/controllers/tomify/admin/users_controller.rb +2 -0
  70. data/app/controllers/tomify/api/admin/controller.rb +3 -0
  71. data/app/controllers/tomify/api/admin/pages_controller.rb +2 -0
  72. data/app/controllers/tomify/api/admin/settings_controller.rb +2 -0
  73. data/app/controllers/tomify/api/admin/sidebars_controller.rb +2 -0
  74. data/app/controllers/tomify/api/admin/uploads_controller.rb +2 -0
  75. data/app/controllers/tomify/api/admin/users_controller.rb +7 -0
  76. data/app/controllers/tomify/api/public/controller.rb +3 -0
  77. data/app/controllers/tomify/api/public/passwords_controller.rb +10 -0
  78. data/app/controllers/tomify/api/public/sessions_controller.rb +19 -0
  79. data/app/controllers/tomify/api/public/users_controller.rb +25 -0
  80. data/app/controllers/tomify/concerns/api/admin.rb +9 -0
  81. data/app/controllers/tomify/concerns/api/helpers.rb +57 -0
  82. data/app/controllers/tomify/concerns/api/json.rb +46 -0
  83. data/app/controllers/tomify/concerns/api/public.rb +9 -0
  84. data/app/controllers/tomify/concerns/default/auth_helper.rb +22 -0
  85. data/app/controllers/tomify/concerns/default/env_helper.rb +34 -0
  86. data/app/controllers/tomify/concerns/default/helper.rb +13 -0
  87. data/app/controllers/tomify/concerns/default/react_helper.rb +7 -0
  88. data/app/controllers/tomify/concerns/default.rb +17 -0
  89. data/app/controllers/tomify/public/controller.rb +2 -0
  90. data/app/controllers/tomify/public/pages_controller.rb +22 -0
  91. data/app/controllers/tomify/public/sessions_controller.rb +5 -0
  92. data/app/controllers/tomify/public/users_controller.rb +7 -0
  93. data/app/controllers/tomify_controller.rb +3 -0
  94. data/app/helpers/tomify/carrierwave_helper.rb +17 -0
  95. data/app/helpers/tomify/email_helper.rb +19 -0
  96. data/app/helpers/tomify/render_helper.rb +13 -0
  97. data/app/helpers/tomify/timezone_helper.rb +5 -0
  98. data/app/mailers/tomify/user_mailer.rb +13 -0
  99. data/app/mailers/tomify_mailer.rb +14 -0
  100. data/app/models/tomify/concerns/page.rb +74 -0
  101. data/app/models/tomify/concerns/sidebar.rb +18 -0
  102. data/app/models/tomify/concerns/token.rb +18 -0
  103. data/app/models/tomify/concerns/upload.rb +36 -0
  104. data/app/models/tomify/concerns/user.rb +52 -0
  105. data/app/models/tomify/page.rb +3 -0
  106. data/app/models/tomify/setting/boolean.rb +11 -0
  107. data/app/models/tomify/setting/json.rb +11 -0
  108. data/app/models/tomify/setting/text.rb +3 -0
  109. data/app/models/tomify/setting/uploader.rb +6 -0
  110. data/app/models/tomify/setting.rb +48 -0
  111. data/app/models/tomify/sidebar.rb +3 -0
  112. data/app/models/tomify/token.rb +3 -0
  113. data/app/models/tomify/upload.rb +3 -0
  114. data/app/models/tomify/user.rb +3 -0
  115. data/app/models/tomify_record.rb +33 -0
  116. data/app/uploaders/tomify/file_uploader.rb +5 -0
  117. data/app/uploaders/tomify/setting_uploader.rb +7 -0
  118. data/app/uploaders/tomify_uploader.rb +20 -0
  119. data/app/views/templates/contact.haml +24 -0
  120. data/app/views/templates/default.haml +4 -0
  121. data/app/views/tomify/defaults/_body.haml +8 -0
  122. data/app/views/tomify/defaults/_container.haml +3 -0
  123. data/app/views/tomify/defaults/_env.haml +2 -0
  124. data/app/views/tomify/defaults/_head.haml +14 -0
  125. data/app/views/tomify/defaults/_meta.haml +17 -0
  126. data/app/views/tomify/defaults/_sharing.haml +23 -0
  127. data/app/views/tomify/layouts/application.haml +4 -0
  128. data/app/views/tomify/layouts/mailer.haml +7 -0
  129. data/app/views/tomify/mailers/user_mailer/invite.haml +13 -0
  130. data/app/views/tomify/mailers/user_mailer/reset_password.haml +17 -0
  131. data/config/initializers/assets.rb +7 -0
  132. data/config/initializers/database.rb +3 -0
  133. data/config/initializers/flash_patch.rb +15 -0
  134. data/config/initializers/mailer.rb +4 -0
  135. data/config/initializers/renderers.rb +4 -0
  136. data/config/initializers/settings.rb +5 -0
  137. data/config/routes.rb +38 -0
  138. data/db/migrate/19900000000000_create_users.rb +13 -0
  139. data/db/migrate/19900000000001_create_tokens.rb +10 -0
  140. data/db/migrate/19900000000002_create_settings.rb +13 -0
  141. data/db/migrate/19900000000003_create_uploads.rb +13 -0
  142. data/db/migrate/19900000000004_create_pages.rb +22 -0
  143. data/db/migrate/19900000000005_create_sidebars.rb +12 -0
  144. data/db/seeds.rb +43 -0
  145. data/lib/generators/tomify/bundle/bundle_generator.rb +12 -0
  146. data/lib/generators/tomify/bundle/templates/default.js +2 -0
  147. data/lib/generators/tomify/bundle/templates/react.js +3 -0
  148. data/lib/previews/tomify/user_preview.rb +9 -0
  149. data/lib/previews/tomify_preview.rb +6 -0
  150. data/lib/tasks/package.rake +40 -0
  151. data/lib/tomify/constantly.rb +12 -0
  152. data/lib/tomify/engine.rb +11 -0
  153. data/lib/tomify/version.rb +3 -0
  154. data/lib/tomify.rb +40 -0
  155. data/vendor/tomify/development/react.js +20494 -0
  156. data/vendor/tomify/production/react.js +20352 -0
  157. metadata +219 -0
@@ -0,0 +1,8 @@
1
+ //= require tomify
2
+ //= require tomify/dynamic/classes/namespace
3
+ //= require tomify/dynamic/classes/observer
4
+ //= require react
5
+ //= require_tree ./tomify/dynamic/react/mixins
6
+ //= require_tree ./tomify/dynamic/classes
7
+ //= require tomify/dynamic/global
8
+ //= require_tree ./tomify/dynamic
@@ -0,0 +1 @@
1
+ //= require_tree ./tomify/default
@@ -0,0 +1 @@
1
+ @import "tomify/*";
@@ -0,0 +1,26 @@
1
+ @import "bootstrap";
2
+ @import "variables";
3
+ @import "font-awesome";
4
+ @import url(https://fonts.googleapis.com/css?family=Raleway:300,400,700|Dosis:400,700);
5
+
6
+ html, body {
7
+ margin: 0;
8
+ padding: 0;
9
+ height: 100%;
10
+ }
11
+ body {
12
+ color: $black;
13
+ font-family: "Raleway", sans-serif;
14
+ }
15
+ a {
16
+ color: $brand;
17
+ &:active, &:focus, &:hover { color: $blue; }
18
+ }
19
+ em { font-size: 24px; }
20
+
21
+ .panel-heading {
22
+ h4 {
23
+ display: inline-block;
24
+ a { margin-left: 10px; }
25
+ }
26
+ }
@@ -0,0 +1 @@
1
+ footer { padding-top: 40px; }
@@ -0,0 +1,43 @@
1
+ .admin-navbar {
2
+ margin-bottom: 0;
3
+ border-radius: 0;
4
+ border-color: $brand;
5
+ background-color: $brand;
6
+ .navbar-brand, .navbar-nav > li > a { color: $white; }
7
+ .navbar-toggle .icon-bar { background-color: $white; }
8
+ }
9
+
10
+ .navbar.center {
11
+ text-align: center;
12
+
13
+ .navbar-brand img { height: 100%; }
14
+ }
15
+
16
+ .navbar, .alert {
17
+ margin-bottom: 0;
18
+
19
+ .container-fluid {
20
+ margin-top: 0;
21
+ }
22
+ }
23
+
24
+ .brand-navbar {
25
+ margin-bottom: 0;
26
+ border-radius: 0;
27
+ border-color: $brand;
28
+ background-color: $brand;
29
+ .navbar-brand, .navbar-nav > li > a { color: $white; }
30
+ .navbar-toggle .icon-bar { background-color: $white; }
31
+ }
32
+
33
+ .container-fluid {
34
+ margin-top: 20px;
35
+ }
36
+
37
+ @media screen and (min-width: $screen-sm) {
38
+ .navbar.center .nav {
39
+ display: inline-block;
40
+ float: none;
41
+ vertical-align: top;
42
+ }
43
+ }
@@ -0,0 +1,31 @@
1
+ .page {
2
+ h1 { color: $brand; }
3
+ h2, h3 { font-style: italic; }
4
+ h2 { font-size: 1.5em; }
5
+ h3 { font-size: 1.25em; }
6
+ h2, h3, table, p, li { text-align: left; }
7
+ table { width: 100%; }
8
+ > ul > li {
9
+ margin-top: 10px;
10
+ font-size: 24px;
11
+ &:before { top: -1px; }
12
+ :not(p) { font-size: 14px; }
13
+ }
14
+ ul {
15
+ list-style-type: none;
16
+ padding-left: 0;
17
+ }
18
+ li {
19
+ position: relative;
20
+ padding-left: 25px;
21
+ &:before {
22
+ position: absolute;
23
+ top: 0;
24
+ left: 0;
25
+ font-family: "FontAwesome";
26
+ content: "\f058";
27
+ color: $brand;
28
+ }
29
+ ul li:before { content: "\f055"; }
30
+ }
31
+ }
@@ -0,0 +1,5 @@
1
+ .pagination {
2
+ float: right;
3
+ margin-top: 2px;
4
+ margin-bottom: 10px;
5
+ }
@@ -0,0 +1,10 @@
1
+ $white: white !default;
2
+ $black: black !default;
3
+ $blue: #4D90FE !default;
4
+ $green: #42B755 !default;
5
+
6
+ $brand: $green !default;
7
+ $brand-primary: $blue !default;
8
+ $brand-success: $green !default;
9
+
10
+ @import "bootstrap/variables";
@@ -0,0 +1,7 @@
1
+ class Tomify::Admin::Controller < Tomify.controllers.base
2
+ before_action :require_user!, :require_admin!
3
+
4
+ def index
5
+ render component: "Admin.#{controller_name.capitalize}.Index.Container"
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ class Tomify::Admin::PagesController < Tomify.controllers.admin
2
+ end
@@ -0,0 +1,2 @@
1
+ class Tomify::Admin::SettingsController < Tomify.controllers.admin
2
+ end
@@ -0,0 +1,2 @@
1
+ class Tomify::Admin::SidebarsController < Tomify.controllers.admin
2
+ end
@@ -0,0 +1,2 @@
1
+ class Tomify::Admin::UploadsController < Tomify.controllers.admin
2
+ end
@@ -0,0 +1,2 @@
1
+ class Tomify::Admin::UsersController < Tomify.controllers.admin
2
+ end
@@ -0,0 +1,3 @@
1
+ class Tomify::Api::Admin::Controller < Tomify.controllers.admin
2
+ include Tomify::Concerns::Api::Admin
3
+ end
@@ -0,0 +1,2 @@
1
+ class Tomify::Api::Admin::PagesController < Tomify.controllers.admin_api
2
+ end
@@ -0,0 +1,2 @@
1
+ class Tomify::Api::Admin::SettingsController < Tomify.controllers.admin_api
2
+ end
@@ -0,0 +1,2 @@
1
+ class Tomify::Api::Admin::SidebarsController < Tomify.controllers.admin_api
2
+ end
@@ -0,0 +1,2 @@
1
+ class Tomify::Api::Admin::UploadsController < Tomify.controllers.admin_api
2
+ end
@@ -0,0 +1,7 @@
1
+ class Tomify::Api::Admin::UsersController < Tomify.controllers.admin_api
2
+ def destroy
3
+ @record = model.find(params[:id])
4
+ return super unless @record.email == "tom@tomify.me" || @record.id == current_user.id
5
+ render json: { type: :danger, message: "You shall not pass" }
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ class Tomify::Api::Public::Controller < Tomify.controllers.public
2
+ include Tomify::Concerns::Api::Public
3
+ end
@@ -0,0 +1,10 @@
1
+ class Tomify::Api::Public::PasswordsController < Tomify.controllers.public_api
2
+ def create
3
+ if user = Tomify.models.user.find_by(email: params[:password][:email])
4
+ Tomify.mailers.user.reset_password(user).deliver_now
5
+ render json: { type: :success, message: "Email Sent" }
6
+ else
7
+ render json: { type: :warning, message: "Email could not be found" }
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ class Tomify::Api::Public::SessionsController < Tomify.controllers.public_api
2
+ def create
3
+ email = params[:session][:email].strip.downcase
4
+ user = Tomify.models.user.find_by(email: email)
5
+ if user && user.password_digest && user.authenticate(params[:session][:password])
6
+ session[:current_user_id] = user.id
7
+ flash[:success] = "Welcome #{current_user.name}!"
8
+ render json: { type: :success }
9
+ else
10
+ render json: { type: :warning, message: "Invalid Credentials" }
11
+ end
12
+ end
13
+
14
+ def destroy
15
+ flash[:success] = "Goodbye #{current_user.name}" if current_user
16
+ session[:current_user_id] = nil
17
+ render json: { type: :success }
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ class Tomify::Api::Public::UsersController < Tomify.controllers.public_api
2
+ before_action :require_user!, only: [:show, :update]
3
+ before_action :set_record, only: [:show, :update]
4
+ before_action :not_found, only: :create, unless: "setting(:allow_signup)"
5
+
6
+ def create
7
+ session[:current_user_id] = Tomify.models.user.create!(record_params).id
8
+ flash[:success] = "Welcome #{current_user.name}!"
9
+ render json: { type: :success, message: "Welcome #{current_user.name}!" }
10
+ rescue ActiveRecord::RecordInvalid => e
11
+ render json: { type: :warning, message: e.record.errors.full_messages.join(", ") }
12
+ end
13
+
14
+ def update
15
+ current_user.update!(record_params)
16
+ render json: { type: :success, message: "Profile Updated" }
17
+ rescue ActiveRecord::RecordInvalid => e
18
+ render json: { type: :warning, message: e.record.errors.full_messages.join(", ") }
19
+ end
20
+
21
+ private
22
+ def set_record
23
+ @record = current_user
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ module Tomify::Concerns::Api::Admin
2
+ extend ActiveSupport::Concern
3
+
4
+ include Tomify::Concerns::Api::JSON
5
+
6
+ def record_params
7
+ params.require(model_param).permit(model.admin_params)
8
+ end
9
+ end
@@ -0,0 +1,57 @@
1
+ module Tomify::Concerns::Api::Helpers
2
+ def find_records
3
+ @records ||= model.where(search_params)
4
+ end
5
+
6
+ def find_record
7
+ @record ||= model.find(params[:id])
8
+ end
9
+
10
+ def create_record
11
+ @record ||= model.create!(record_params)
12
+ end
13
+
14
+ def update_record
15
+ @record.update!(record_params)
16
+ end
17
+
18
+ def destroy_record
19
+ @record.destroy!
20
+ end
21
+
22
+ def record_params
23
+ params.require(model_param).permit(model.default_params)
24
+ end
25
+
26
+ def search_params
27
+ @search_params = {}
28
+ @search_params[:created_at] = date_range(params[:created_at]) if params[:created_at]
29
+ @search_params[:updated_at] = date_range(params[:updated_at]) if params[:updated_at]
30
+ @search_params
31
+ end
32
+
33
+ def model
34
+ @model ||= controller_name.chomp("s").titleize.constantize
35
+ end
36
+
37
+ def model
38
+ return @model if @model
39
+ @model = model_name.constantize if Object.const_defined? model_name
40
+ @model ||= "Tomify::#{model_name}".constantize
41
+ end
42
+
43
+ def model_name
44
+ @model_name ||= controller_name.chomp("s").titleize
45
+ end
46
+
47
+ def model_param
48
+ @model_param ||= controller_name.chomp("s")
49
+ end
50
+
51
+ def date_range(start_date, end_date = nil)
52
+ start_date = DateTime.strptime(start_date, "%D")
53
+ end_date = end_date ? DateTime.strptime(end_date, "%D") : DateTime.now
54
+
55
+ (start_date.beginning_of_day)..(end_date.end_of_day)
56
+ end
57
+ end
@@ -0,0 +1,46 @@
1
+ module Tomify::Concerns::Api::JSON
2
+ extend ActiveSupport::Concern
3
+
4
+ include Tomify::Concerns::Api::Helpers
5
+
6
+ included do
7
+ rescue_from "ActiveRecord::RecordInvalid" do |e|
8
+ render json: {
9
+ type: :warning,
10
+ data: e.record,
11
+ message: e.record.errors.full_messages.join(", ")
12
+ }
13
+ end
14
+
15
+ rescue_from "ActiveRecord::RecordNotDestroyed" do |e|
16
+ render json: { type: :warning, message: "#{model_name} could not be deleted" }
17
+ end
18
+ end
19
+
20
+ def index
21
+ find_records
22
+ render json: { type: :success, data: @records }
23
+ end
24
+
25
+ def show
26
+ find_record
27
+ render json: { type: :success, data: @record }
28
+ end
29
+
30
+ def create
31
+ create_record
32
+ render json: { type: :success, data: @record, message: "#{model_name} Created" }
33
+ end
34
+
35
+ def update
36
+ find_record
37
+ update_record
38
+ render json: { type: :success, data: @record, message: "#{model_name} Updated" }
39
+ end
40
+
41
+ def destroy
42
+ find_record
43
+ destroy_record
44
+ render json: { type: :danger, message: "#{model_name} Deleted" }
45
+ end
46
+ end
@@ -0,0 +1,9 @@
1
+ module Tomify::Concerns::Api::Public
2
+ extend ActiveSupport::Concern
3
+
4
+ include Tomify::Concerns::Api::JSON
5
+
6
+ def record_params
7
+ params.require(model_param).permit(model.public_params)
8
+ end
9
+ end
@@ -0,0 +1,22 @@
1
+ module Tomify::Concerns::Default::AuthHelper
2
+ def not_found
3
+ raise ActionController::RoutingError.new("Not Found")
4
+ end
5
+
6
+ def current_user
7
+ @current_user ||= Tomify.models.user.find_by(id: session[:current_user_id])
8
+ end
9
+
10
+ def require_user!
11
+ not_found unless current_user
12
+ end
13
+
14
+ def require_admin!
15
+ redirect_to root_path unless current_user.admin
16
+ end
17
+
18
+ def check_token
19
+ return unless params[:token] && user = Tomify.models.user.joins(:tokens).find_by(tokens: { uuid: params[:token] })
20
+ session[:current_user_id] = user.id
21
+ end
22
+ end
@@ -0,0 +1,34 @@
1
+ module Tomify::Concerns::Default::EnvHelper
2
+ def js_env
3
+ {
4
+ messages: flash.collect { |key, value| { type: key, text: value }},
5
+ navbar: {
6
+ admin: admin_pages,
7
+ public: public_pages
8
+ },
9
+ settings: public_settings,
10
+ user: current_user
11
+ }
12
+ end
13
+
14
+ def admin_pages
15
+ [
16
+ { name: "App", path: "admin/settings" },
17
+ { name: "Pages", path: "admin/pages" },
18
+ { name: "Sidebars", path: "admin/sidebars" },
19
+ { name: "Uploads", path: "admin/uploads" },
20
+ { name: "Users", path: "admin/users" }
21
+ ]
22
+ end
23
+
24
+ def public_pages
25
+ Tomify.models.page.where(parent_id: nil).as_json(
26
+ only: [:active, :name, :path, :root],
27
+ include: [children: { only: [:active, :name, :path] }]
28
+ )
29
+ end
30
+
31
+ def public_settings
32
+ Tomify.models.setting.public.as_json(only: [:name, :value])
33
+ end
34
+ end
@@ -0,0 +1,13 @@
1
+ module Tomify::Concerns::Default::Helper
2
+ def setting(name)
3
+ Tomify.setting(name)
4
+ end
5
+
6
+ def root_page
7
+ Tomify.models.page.root
8
+ end
9
+
10
+ def page
11
+ @page || root_page
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ include ActionView::Helpers::TagHelper
2
+
3
+ module Tomify::Concerns::Default::ReactHelper
4
+ def react_component(name, props = {})
5
+ content_tag :div, "", class: "react-component", data: { react: { component: name, props: props.to_json }}
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ module Tomify::Concerns::Default
2
+ extend ActiveSupport::Concern
3
+
4
+ include Tomify::Concerns::Default::Helper
5
+ include Tomify::Concerns::Default::AuthHelper
6
+ include Tomify::Concerns::Default::EnvHelper
7
+ include Tomify::Concerns::Default::ReactHelper
8
+
9
+ included do
10
+ protect_from_forgery with: :exception
11
+ add_flash_types :success, :info, :warning, :danger
12
+ layout "tomify/layouts/application"
13
+ helper_method :js_env, :page, :root_page, :setting
14
+ helper_method :current_user, :react_component
15
+ before_action :check_token
16
+ end
17
+ end
@@ -0,0 +1,2 @@
1
+ class Tomify::Public::Controller < Tomify.controllers.base
2
+ end
@@ -0,0 +1,22 @@
1
+ class Tomify::Public::PagesController < Tomify.controllers.public
2
+ def show
3
+ @page = Tomify.models.page.find_by(path: params[:path]) || not_found
4
+
5
+ render_template
6
+ end
7
+
8
+ def root
9
+ @page = root_page
10
+
11
+ render_template
12
+ end
13
+
14
+ private
15
+ def render_template
16
+ case template = @page.template
17
+ when "default"
18
+ end
19
+
20
+ render "templates/#{template}", layout: true
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ class Tomify::Public::SessionsController < Tomify.controllers.public
2
+ def show
3
+ render component: "Public.Sessions.Show"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ class Tomify::Public::UsersController < Tomify.controllers.public
2
+ before_action :require_user!
3
+
4
+ def edit
5
+ render component: "Public.Users.Edit"
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ class TomifyController < ActionController::Base
2
+ include Tomify::Concerns::Default
3
+ end
@@ -0,0 +1,17 @@
1
+ module Tomify::CarrierwaveHelper
2
+ def self.load_config
3
+ return unless defined? Carrierwave
4
+ return unless settings = Tomify.setting(:aws)
5
+
6
+ CarrierWave.configure do |config|
7
+ config.fog_provider = "fog/aws"
8
+ config.storage = :fog
9
+ config.fog_credentials = {
10
+ provider: "AWS",
11
+ aws_access_key_id: settings["access_key"],
12
+ aws_secret_access_key: settings["secret_key"]
13
+ }
14
+ config.fog_directory = settings["bucket"]
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ module Tomify::EmailHelper
2
+ def self.load_config
3
+ return unless settings = Tomify.setting(:email)
4
+
5
+ config = {
6
+ authentication: "plain",
7
+ enable_starttls_auto: true,
8
+ user_name: settings["username"],
9
+ password: settings["password"]
10
+ }
11
+ config[:address] = settings["address"] || "email-smtp.us-east-1.amazonaws.com"
12
+ config[:domain] = settings["domain"] || "tomify.me"
13
+ config[:port] = settings["port"] || "587"
14
+
15
+ Rails.application.config.action_mailer.asset_host = settings["base_url"]
16
+ Rails.application.config.action_mailer.default_url_options = { host: settings["base_url"].split("//").last }
17
+ Rails.application.config.action_mailer.smtp_settings = config
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ module Tomify::RenderHelper
2
+ def tomify_render_for(name, context = nil)
3
+ override = "#{name}_partial".to_sym
4
+ partial = content_for?(override) ? content_for(override) : name
5
+ if lookup_context.exists?(partial, [], true)
6
+ render partial: partial
7
+ elsif lookup_context.exists?(partial, ["tomify/defaults"], true)
8
+ render partial: "tomify/defaults/#{partial}"
9
+ else
10
+ react_component [context, name].compact.collect { |x| x.to_s.camelize }.join(".")
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module Tomify::TimezoneHelper
2
+ def self.load_config
3
+ Rails.application.config.time_zone = Tomify.setting(:timezone)
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ class Tomify::UserMailer < Tomify.mailers.base
2
+ def invite(user)
3
+ @user = user
4
+
5
+ mail to: @user.email, subject: "You're Invited!"
6
+ end
7
+
8
+ def reset_password(user)
9
+ @user = user
10
+
11
+ mail to: @user.email, subject: "Reset Password"
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ class TomifyMailer < ActionMailer::Base
2
+ include Tomify::Concerns::Default::Helper
3
+
4
+ prepend_view_path Tomify.root.join("app", "views", "tomify", "mailers")
5
+ prepend_view_path Rails.root.join("app", "views", "mailers")
6
+
7
+ default from: "Tomify <notify@tomify.me>"
8
+ layout "tomify/layouts/mailer"
9
+ helper_method :setting
10
+
11
+ def self.mailer_name
12
+ super.split("/").last
13
+ end
14
+ end