tramway 0.1.2 → 0.1.3

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 (177) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +12 -893
  4. data/Rakefile +8 -8
  5. data/app/components/tailwind_component.html.haml +0 -0
  6. data/app/components/tailwind_component.rb +6 -0
  7. data/app/components/tailwinds/navbar/button_component.html.haml +1 -0
  8. data/app/components/tailwinds/navbar/button_component.rb +14 -0
  9. data/config/routes.rb +0 -9
  10. data/lib/tasks/tramway_tasks.rake +5 -0
  11. data/lib/tramway/engine.rb +5 -10
  12. data/lib/tramway/version.rb +1 -1
  13. data/lib/tramway.rb +5 -140
  14. metadata +16 -545
  15. data/app/assets/config/tramway_core_manifest.js +0 -2
  16. data/app/assets/images/tramway/mona_lisa_from_prado.jpg +0 -0
  17. data/app/assets/images/tramway/mona_lisa_from_prado_square.jpg +0 -0
  18. data/app/assets/javascripts/bootstrap-datepicker-1.8.0.js +0 -2035
  19. data/app/assets/javascripts/bootstrap-datepicker-1.8.0.ru.min.js +0 -64
  20. data/app/assets/javascripts/ckeditor/config.js +0 -30
  21. data/app/assets/javascripts/ckeditor/plugins/image/dialogs/image.js +0 -1259
  22. data/app/assets/javascripts/ckeditor/plugins/image/icons/hidpi/image.png +0 -0
  23. data/app/assets/javascripts/ckeditor/plugins/image/icons/image.png +0 -0
  24. data/app/assets/javascripts/ckeditor/plugins/image/images/noimage.png +0 -0
  25. data/app/assets/javascripts/ckeditor/plugins/image/lang/en.js +0 -25
  26. data/app/assets/javascripts/ckeditor/plugins/image/lang/ru.js +0 -25
  27. data/app/assets/javascripts/ckeditor/plugins/image/plugin.js +0 -184
  28. data/app/assets/javascripts/ckeditor/plugins/youtube/images/icon-hdpi.png +0 -0
  29. data/app/assets/javascripts/ckeditor/plugins/youtube/images/icon.png +0 -0
  30. data/app/assets/javascripts/ckeditor/plugins/youtube/lang/en.js +0 -25
  31. data/app/assets/javascripts/ckeditor/plugins/youtube/lang/ru.js +0 -25
  32. data/app/assets/javascripts/ckeditor/plugins/youtube/plugin.js +0 -449
  33. data/app/assets/javascripts/tramway/application.js +0 -61
  34. data/app/assets/stylesheets/tramway/application.sass +0 -59
  35. data/app/controllers/tramway/application_controller.rb +0 -142
  36. data/app/controllers/tramway/concerns/auth_management.rb +0 -26
  37. data/app/controllers/tramway/concerns/filtering.rb +0 -43
  38. data/app/controllers/tramway/export/application_controller.rb +0 -5
  39. data/app/controllers/tramway/has_and_belongs_to_many_records_controller.rb +0 -26
  40. data/app/controllers/tramway/records_controller.rb +0 -86
  41. data/app/controllers/tramway/sessions_controller.rb +0 -49
  42. data/app/controllers/tramway/singletons_controller.rb +0 -48
  43. data/app/controllers/tramway/welcome_controller.rb +0 -17
  44. data/app/decorators/tramway/application_decorated_collection.rb +0 -15
  45. data/app/decorators/tramway/application_decorator.rb +0 -124
  46. data/app/decorators/tramway/associations/class_helper.rb +0 -45
  47. data/app/decorators/tramway/associations/object_helper.rb +0 -58
  48. data/app/decorators/tramway/attributes/view_helper.rb +0 -30
  49. data/app/decorators/tramway/concerns/attributes_decorator_helper.rb +0 -97
  50. data/app/decorators/tramway/concerns/table_builder.rb +0 -33
  51. data/app/decorators/tramway/default/values_helper.rb +0 -23
  52. data/app/decorators/tramway/delegating/class_helper.rb +0 -9
  53. data/app/decorators/tramway/user_decorator.rb +0 -49
  54. data/app/forms/admin/tramway/user_form.rb +0 -24
  55. data/app/forms/tramway/application_form.rb +0 -124
  56. data/app/forms/tramway/application_forms/association_class_helpers.rb +0 -7
  57. data/app/forms/tramway/application_forms/association_object_helpers.rb +0 -36
  58. data/app/forms/tramway/application_forms/constant_class_actions.rb +0 -7
  59. data/app/forms/tramway/application_forms/constant_object_actions.rb +0 -20
  60. data/app/forms/tramway/application_forms/frontend.rb +0 -12
  61. data/app/forms/tramway/application_forms/object_helpers.rb +0 -15
  62. data/app/forms/tramway/application_forms/properties_object_helper.rb +0 -16
  63. data/app/forms/tramway/application_forms/submit_helper.rb +0 -26
  64. data/app/forms/tramway/extendable_form.rb +0 -15
  65. data/app/forms/tramway/extendable_forms_helpers/class_builder.rb +0 -34
  66. data/app/forms/tramway/extendable_forms_helpers/ignored_properties_helper.rb +0 -11
  67. data/app/forms/tramway/extendable_forms_helpers/more_properties_helper.rb +0 -31
  68. data/app/forms/tramway/extendable_forms_helpers/properties_helper.rb +0 -16
  69. data/app/forms/tramway/extendable_forms_helpers/submit/class_helpers.rb +0 -18
  70. data/app/forms/tramway/extendable_forms_helpers/submit/object_helpers.rb +0 -21
  71. data/app/forms/tramway/extendable_forms_helpers/validators.rb +0 -40
  72. data/app/forms/tramway/extended_application_form.rb +0 -23
  73. data/app/forms/tramway/form_creator.rb +0 -7
  74. data/app/forms/tramway/session_form.rb +0 -26
  75. data/app/helpers/tramway/actions_helper.rb +0 -45
  76. data/app/helpers/tramway/additional_buttons_builder.rb +0 -12
  77. data/app/helpers/tramway/application_helper.rb +0 -27
  78. data/app/helpers/tramway/cases_helper.rb +0 -13
  79. data/app/helpers/tramway/copy_to_clipboard_helper.rb +0 -11
  80. data/app/helpers/tramway/focus_generator_helper.rb +0 -10
  81. data/app/helpers/tramway/frontend_helper.rb +0 -26
  82. data/app/helpers/tramway/inputs/associations_helper.rb +0 -30
  83. data/app/helpers/tramway/inputs/polymorphic_associations_helper.rb +0 -24
  84. data/app/helpers/tramway/inputs_helper.rb +0 -96
  85. data/app/helpers/tramway/model_helper.rb +0 -7
  86. data/app/helpers/tramway/navbar_helper.rb +0 -11
  87. data/app/helpers/tramway/records_helper.rb +0 -120
  88. data/app/helpers/tramway/russian_cases_helper.rb +0 -26
  89. data/app/helpers/tramway/singleton_helper.rb +0 -12
  90. data/app/helpers/tramway/state_machine_buttons_helper.rb +0 -61
  91. data/app/helpers/tramway/title_helper.rb +0 -25
  92. data/app/inputs/date_picker_input.rb +0 -4
  93. data/app/inputs/multiple_file_input.rb +0 -7
  94. data/app/models/tramway/application_record.rb +0 -62
  95. data/app/models/tramway/user.rb +0 -18
  96. data/app/uploaders/application_uploader.rb +0 -22
  97. data/app/uploaders/file_uploader.rb +0 -4
  98. data/app/uploaders/ico_uploader.rb +0 -7
  99. data/app/uploaders/image_defaults.rb +0 -14
  100. data/app/uploaders/photo_uploader.rb +0 -54
  101. data/app/views/layouts/tramway/application.html.haml +0 -32
  102. data/app/views/layouts/tramway/shared/_navbar.html.haml +0 -46
  103. data/app/views/tramway/404.haml +0 -1
  104. data/app/views/tramway/records/_form.html.haml +0 -22
  105. data/app/views/tramway/records/_list.html.haml +0 -38
  106. data/app/views/tramway/records/_search.html.haml +0 -34
  107. data/app/views/tramway/records/edit.html.haml +0 -1
  108. data/app/views/tramway/records/index.html.haml +0 -31
  109. data/app/views/tramway/records/new.html.haml +0 -1
  110. data/app/views/tramway/records/show.html.haml +0 -1
  111. data/app/views/tramway/sessions/new.html.haml +0 -9
  112. data/app/views/tramway/shared/_input.html.haml +0 -34
  113. data/app/views/tramway/shared/_input_extended.html.haml +0 -14
  114. data/app/views/tramway/shared/_messages.html.haml +0 -10
  115. data/app/views/tramway/shared/_show.html.haml +0 -35
  116. data/app/views/tramway/shared/errors/server_error.html.haml +0 -12
  117. data/app/views/tramway/shared/input_extended_types/_checkbox.html.haml +0 -1
  118. data/app/views/tramway/shared/input_extended_types/_select.html.haml +0 -16
  119. data/app/views/tramway/shared/input_extended_types/_simple.html.haml +0 -4
  120. data/app/views/tramway/shared/input_extended_types/_yes_no.html.haml +0 -4
  121. data/app/views/tramway/shared/show/_attribute_tr.html.haml +0 -9
  122. data/app/views/tramway/shared/show/associations/_habtm_row.html.haml +0 -14
  123. data/app/views/tramway/shared/show/associations/_list.html.haml +0 -21
  124. data/app/views/tramway/shared/show/associations/_row.html.haml +0 -19
  125. data/app/views/tramway/shared/show/associations/_table_row.html.haml +0 -21
  126. data/app/views/tramway/singletons/_form.html.haml +0 -15
  127. data/app/views/tramway/singletons/edit.html.haml +0 -1
  128. data/app/views/tramway/singletons/new.html.haml +0 -1
  129. data/app/views/tramway/singletons/show.html.haml +0 -1
  130. data/app/views/tramway/welcome/index.html.haml +0 -4
  131. data/config/initializers/assets.rb +0 -7
  132. data/config/initializers/ckeditor.rb +0 -9
  133. data/config/initializers/plurals.rb +0 -25
  134. data/config/locales/en/collections.yml +0 -4
  135. data/config/locales/en/date.yml +0 -16
  136. data/config/locales/en/dates.yml +0 -10
  137. data/config/locales/en/helpers.yml +0 -26
  138. data/config/locales/en/locale.yml +0 -11
  139. data/config/locales/en/messages.yml +0 -7
  140. data/config/locales/en/models.yml +0 -9
  141. data/config/locales/en/simple_form_extension.yml +0 -8
  142. data/config/locales/en/state_machines.yml +0 -8
  143. data/config/locales/ru/collections.yml +0 -4
  144. data/config/locales/ru/date.yml +0 -16
  145. data/config/locales/ru/dates.yml +0 -10
  146. data/config/locales/ru/helpers.yml +0 -30
  147. data/config/locales/ru/locale.yml +0 -6
  148. data/config/locales/ru/messages.yml +0 -7
  149. data/config/locales/ru/models.yml +0 -21
  150. data/config/locales/ru/simple_form_extension.yml +0 -8
  151. data/config/locales/ru/state_machines.yml +0 -8
  152. data/lib/string.rb +0 -18
  153. data/lib/tramway/application.rb +0 -10
  154. data/lib/tramway/class_name_helpers.rb +0 -15
  155. data/lib/tramway/collection.rb +0 -9
  156. data/lib/tramway/collections/helper.rb +0 -21
  157. data/lib/tramway/collections.rb +0 -4
  158. data/lib/tramway/error.rb +0 -32
  159. data/lib/tramway/forms.rb +0 -5
  160. data/lib/tramway/generators/install_generator.rb +0 -49
  161. data/lib/tramway/generators/model_generator.rb +0 -105
  162. data/lib/tramway/generators/templates/create_tramway_users.rb +0 -18
  163. data/lib/tramway/generators/templates/decorator.rb.erb +0 -56
  164. data/lib/tramway/generators/templates/form.rb.erb +0 -22
  165. data/lib/tramway/generators/templates/initializers/simple_form.rb +0 -23
  166. data/lib/tramway/generators/templates/initializers/simple_form_bootstrap.rb +0 -133
  167. data/lib/tramway/generators.rb +0 -6
  168. data/lib/tramway/navbar.rb +0 -44
  169. data/lib/tramway/notifications.rb +0 -12
  170. data/lib/tramway/record_routes_helper.rb +0 -23
  171. data/lib/tramway/records_models.rb +0 -60
  172. data/lib/tramway/singleton_models.rb +0 -32
  173. data/lib/tramway/spec/helpers/navbar_helper.rb +0 -7
  174. data/lib/tramway/spec/helpers/tramway_helpers.rb +0 -47
  175. data/lib/tramway/welcome_page_actions.rb +0 -5
  176. data/lib/tramway/yaml/errors.yml +0 -50
  177. data/lib/validators/presence_validator.rb +0 -9
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- {
4
- ru: {
5
- i18n: {
6
- plural: {
7
- keys: %i[zero one few many],
8
- rule: lambda do |n|
9
- if n.zero?
10
- :zero
11
- elsif n % 10 == 1 && n % 100 != 11
12
- # 1, 21, 31, 41, 51, 61...
13
- :one
14
- elsif [2, 3, 4].include?(n % 10) && ![12, 13, 14].include?(n % 100)
15
- # 2-4, 22-24, 32-34...
16
- :few
17
- elsif n % 10.zero? || ![5, 6, 7, 8, 9].include?(n % 10) || ![11, 12, 13, 14].include?(n % 100)
18
- # 0, 5-20, 25-30, 35-40...
19
- :many
20
- end
21
- end
22
- }
23
- }
24
- }
25
- }
@@ -1,4 +0,0 @@
1
- en:
2
- default:
3
- collections:
4
- all: All
@@ -1,16 +0,0 @@
1
- en:
2
- defaults: &defaults
3
- month_names:
4
- [~, January, February, March, April, May, June, July, August, September, October, November, December]
5
- formats:
6
- default: "%B %d %Y"
7
- short: "%m/%d/%Y"
8
- date:
9
- <<: *defaults
10
- order:
11
- - :day
12
- - :month
13
- - :year
14
- time:
15
- <<: *defaults
16
-
@@ -1,10 +0,0 @@
1
- en:
2
- date:
3
- from: from
4
- to: to
5
- formats:
6
- default: "%m/%d/%Y"
7
- month_names: [~, January, February, March, April, May, June, July, August, September, October, November, December]
8
- time:
9
- formats:
10
- default: "%m/%d/%Y %H:%M"
@@ -1,26 +0,0 @@
1
- en:
2
- helpers:
3
- links:
4
- enter: Sign In
5
- save: Save
6
- back: Back
7
- sign_out: Sign Out
8
- actions: Actions
9
- open: Open
10
- actions:
11
- create: Create
12
- update: Update
13
- search: Search
14
- reset: Reset
15
- download: Download
16
- add: Add
17
- scope:
18
- found: Found
19
- "yes": yes
20
- "no": no
21
- tramway:
22
- auth:
23
- web:
24
- sessions:
25
- new:
26
- title: Sign In
@@ -1,11 +0,0 @@
1
- en:
2
- tramway:
3
- admin:
4
- welcome:
5
- index:
6
- title: Admin panel
7
- auth:
8
- web:
9
- sessions:
10
- new:
11
- title: Sign In
@@ -1,7 +0,0 @@
1
- en:
2
- tramway:
3
- shared:
4
- messages:
5
- some_errors_was_found: There are errors
6
- errors:
7
- wrong_email_or_password: Wrong email or password
@@ -1,9 +0,0 @@
1
- en:
2
- activerecord:
3
- attributes:
4
- tramway/application_record:
5
- created_at: Created at
6
- updated_at: Updated at
7
- state: State
8
- errors:
9
- wrong_email_or_password: Wrong email or password
@@ -1,8 +0,0 @@
1
- en:
2
- simple_form:
3
- extension:
4
- selectize:
5
- add: Add
6
- file:
7
- select: Select file
8
- change: Change file
@@ -1,8 +0,0 @@
1
- en:
2
- activerecord:
3
- state_machines:
4
- tramway/application_record:
5
- state:
6
- states:
7
- active: Active
8
- removed: Removed
@@ -1,4 +0,0 @@
1
- ru:
2
- default:
3
- collections:
4
- all: Все
@@ -1,16 +0,0 @@
1
- ru:
2
- defaults: &defaults
3
- month_names:
4
- [~, Январь, Февраль, Март, Апрель, Май, Июнь, Июль, Август, Сентябрь, Октябрь, Ноябрь, Декабрь]
5
- formats:
6
- default: "%d. %B %Y"
7
- short: "%d.%m.%Y"
8
- date:
9
- <<: *defaults
10
- order:
11
- - :day
12
- - :month
13
- - :year
14
- time:
15
- <<: *defaults
16
-
@@ -1,10 +0,0 @@
1
- ru:
2
- date:
3
- from: с
4
- to: по
5
- formats:
6
- default: "%d.%m.%Y"
7
- month_names: [~, января, февраля, марта, апреля, мая, июня, июля, августа, сентября, октября, ноября, декабря]
8
- time:
9
- formats:
10
- default: "%d.%m.%Y %H:%M"
@@ -1,30 +0,0 @@
1
- ru:
2
- helpers:
3
- links:
4
- enter: Войти
5
- save: Сохранить
6
- back: Назад
7
- sign_out: Выйти
8
- actions: Действия
9
- open: Открыть
10
- actions:
11
- create: Создать
12
- update: Редактировать
13
- search: Искать
14
- reset: Сбросить
15
- download: Скачать
16
- add: Добавить
17
- scope:
18
- found: Найденные
19
- "yes": Да
20
- "no": Нет
21
- tramway:
22
- admin:
23
- welcome:
24
- index:
25
- title: Админка
26
- auth:
27
- web:
28
- sessions:
29
- new:
30
- title: Авторизация
@@ -1,6 +0,0 @@
1
- ru:
2
- tramway:
3
- admin:
4
- welcome:
5
- index:
6
- title: Админка
@@ -1,7 +0,0 @@
1
- ru:
2
- tramway:
3
- shared:
4
- messages:
5
- some_errors_was_found: Найдены ошибки
6
- errors:
7
- wrong_email_or_password: Неверный логин или пароль
@@ -1,21 +0,0 @@
1
- ru:
2
- activerecord:
3
- models:
4
- tramway/user/user: Пользователь
5
- attributes:
6
- tramway/application_record:
7
- created_at: Создан
8
- updated_at: Обновлён
9
- state: Статус
10
- tramway/user:
11
- password: Пароль
12
- errors:
13
- models:
14
- tramway/user/user:
15
- attributes:
16
- email:
17
- email: имеет неверный формат
18
- cases:
19
- tramway/user:
20
- plural: пользователи
21
- genitive: пользователя
@@ -1,8 +0,0 @@
1
- ru:
2
- simple_form:
3
- extension:
4
- selectize:
5
- add: Добавить
6
- file:
7
- select: Выбрать файл
8
- change: Изменить файл
@@ -1,8 +0,0 @@
1
- ru:
2
- activerecord:
3
- state_machines:
4
- tramway/application_record:
5
- state:
6
- states:
7
- active: Активный
8
- removed: Удалённый
data/lib/string.rb DELETED
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'active_support/inflector/methods'
4
-
5
- class String
6
- def pluralize(count = nil, locale = :en)
7
- case locale
8
- when :ru
9
- case count
10
- when :many
11
- I18n.t('cases.')
12
- end
13
- else
14
- locale = count if count.is_a? Symbol
15
- count == 1 ? dup : ActiveSupport::Inflector.pluralize(self, locale)
16
- end
17
- end
18
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Tramway::Application
4
- attr_accessor :name, :url, :model_class, :title, :tagline, :found_date, :phone, :email, :main_image, :favicon,
5
- :short_description
6
-
7
- def public_name
8
- name.to_s.gsub('_', ' ').camelize
9
- end
10
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Tramway::ClassNameHelpers
4
- def model_class_name(class_name)
5
- class_name.constantize
6
- end
7
-
8
- def decorator_class_name(class_name = -> { model_class }.call)
9
- "#{class_name}Decorator".constantize
10
- end
11
-
12
- def form_class_name(class_name = -> { model_class }.call)
13
- "#{class_name}Form".constantize
14
- end
15
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Tramway::Collection
4
- class << self
5
- def list
6
- raise 'Please add collection to list method'
7
- end
8
- end
9
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'tramway/collections'
4
-
5
- module Tramway::Collections::Helper
6
- def collection_list_by(name:)
7
- begin
8
- require name # needed to load class name with collection
9
- rescue LoadError
10
- raise "No such file #{name}. You should create file in the `lib/#{name}.rb` or elsewhere you want"
11
- end
12
- unless ::Tramway::Collection.descendants.map(&:to_s).include?(name.camelize)
13
- ::Tramway::Error.raise_error(
14
- :tramway, :collections, :helper, :collection_list_by, :there_no_such_collection,
15
- name_camelize: name.camelize
16
- )
17
- end
18
-
19
- name.camelize.constantize.list
20
- end
21
- end
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Tramway::Collections
4
- end
data/lib/tramway/error.rb DELETED
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Tramway::Error < RuntimeError
4
- def initialize(*args, plugin: nil, method: nil, message: nil)
5
- @properties = {}
6
- @properties[:plugin] = plugin
7
- @properties[:method] = method
8
- @properties[:message] = message
9
- super(*args)
10
- end
11
-
12
- def message
13
- "Plugin: #{@properties[:plugin]}; Method: #{@properties[:method]}; Message: #{@properties[:message]}"
14
- end
15
-
16
- def properties
17
- @properties ||= {}
18
- end
19
-
20
- class << self
21
- def raise_error(*coordinates, **options)
22
- @errors ||= YAML.load_file("#{Tramway.root}/lib/tramway/yaml/errors.yml").with_indifferent_access[:tramway]
23
- error = @errors.dig(*coordinates)
24
- raise 'Error is not defined in YAML' unless error
25
-
26
- options.each do |pair|
27
- error.gsub!("%{#{pair[0]}}", pair[1].to_s)
28
- end
29
- raise error
30
- end
31
- end
32
- end
data/lib/tramway/forms.rb DELETED
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Tramway::Forms
4
- attr_accessor :forms
5
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails/generators'
4
- require 'tramway/generators'
5
- require 'tramway/generators/model_generator'
6
-
7
- class Tramway::Generators::InstallGenerator < ::Rails::Generators::Base
8
- source_root File.expand_path('templates', __dir__)
9
- class_option :user_role, type: :string, default: 'admin'
10
- include Rails::Generators::Migration
11
-
12
- def run_other_generators
13
- generate 'paper_trail:install --with-changes'
14
- end
15
-
16
- def self.next_migration_number(path)
17
- next_migration_number = current_migration_number(path) + 1
18
- ActiveRecord::Migration.next_migration_number next_migration_number
19
- end
20
-
21
- def copy_initializer
22
- simple_form_files = %w[simple_form simple_form_bootstrap]
23
- simple_form_files.each do |file|
24
- copy_file(
25
- "/#{File.dirname __dir__}/generators/templates/initializers/#{file}.rb",
26
- "config/initializers/#{file}.rb"
27
- )
28
- end
29
- end
30
-
31
- def copy_migrations
32
- migrations = %i[
33
- create_tramway_users
34
- ]
35
-
36
- migrations.each do |migration|
37
- migration_template "#{migration}.rb", "db/migrate/#{migration}.rb"
38
- end
39
- end
40
-
41
- def run_decorator_generators
42
- Tramway::Error.raise_error(:tramway, :generators, :install) unless Tramway.application.present?
43
-
44
- project = Tramway.application.name
45
- Tramway.available_models_for(project).map do |model|
46
- generate 'tramway:model', model.to_s, "--user-role=#{options[:user_role]}"
47
- end
48
- end
49
- end
@@ -1,105 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails/generators/named_base'
4
-
5
- class Tramway::Generators::ModelGenerator < ::Rails::Generators::NamedBase
6
- source_root File.expand_path('templates', __dir__)
7
- class_option :user_role, type: :string, default: 'admin'
8
-
9
- COLLECTION_ATTRIBUTE_LIMIT = 4 # limiting columns in #index table
10
- ATTRIBUTE_TYPE_MAPPING = {
11
- date: :date_picker,
12
- datetime: :date_picker,
13
- time: :date_picker,
14
- text: :text,
15
- string: :string,
16
- uuid: :string,
17
- float: :float,
18
- integer: :integer,
19
- boolean: :boolean
20
- }.freeze
21
- DEFAULT_FIELD_TYPE = :string
22
- READ_ONLY_ATTRIBUTES = %w[id uuid created_at updated_at].freeze
23
-
24
- def run_decorator_generator
25
- template(
26
- 'decorator.rb.erb',
27
- Rails.root.join("app/decorators/#{file_path}_decorator.rb")
28
- )
29
- end
30
-
31
- def run_forms_generator
32
- template(
33
- 'form.rb.erb',
34
- Rails.root.join("app/forms/#{user_role}/#{file_path}_form.rb")
35
- )
36
- end
37
-
38
- private
39
-
40
- def user_role
41
- options[:user_role]
42
- end
43
-
44
- def attributes
45
- # TODO: this for model associations, but they probably should be handled differently
46
- # klass.reflections.keys +
47
-
48
- klass.columns.map(&:name) -
49
- redundant_attributes
50
- end
51
-
52
- def form_attributes
53
- attributes - READ_ONLY_ATTRIBUTES
54
- end
55
-
56
- def form_type(attribute)
57
- type = column_type_for_attribute(attribute.to_s)
58
-
59
- if type
60
- ATTRIBUTE_TYPE_MAPPING.fetch(type, DEFAULT_FIELD_TYPE)
61
- # else
62
- # association_type(attribute)
63
- end
64
- end
65
-
66
- def redundant_attributes
67
- klass.reflections.keys.flat_map do |relationship|
68
- redundant_attributes_for(relationship)
69
- end.compact
70
- end
71
-
72
- def redundant_attributes_for(relationship)
73
- case association_type(relationship)
74
- when :polymorphic
75
- ["#{relationship}_id", "#{relationship}_type"]
76
- when :belongs_to
77
- "#{relationship}_id"
78
- end
79
- end
80
-
81
- def association_type(attribute)
82
- relationship = klass.reflections[attribute.to_s]
83
- if relationship.has_one?
84
- :has_one
85
- elsif relationship.collection?
86
- :has_many
87
- elsif relationship.polymorphic?
88
- :polymorphic
89
- else
90
- :belongs_to
91
- end
92
- end
93
-
94
- def column_type_for_attribute(attr)
95
- column_types(attr)
96
- end
97
-
98
- def column_types(attr)
99
- klass.columns.find { |column| column.name == attr }.try(:type)
100
- end
101
-
102
- def klass
103
- @klass ||= Object.const_get(class_name)
104
- end
105
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class CreateTramwayUsers < ActiveRecord::Migration[5.1]
4
- def change
5
- create_table :tramway_users do |t|
6
- t.text :email
7
- t.text :password_digest
8
- t.text :first_name
9
- t.text :last_name
10
- t.text :avatar
11
- t.text :role
12
- t.text :phone
13
- t.datetime :deleted_at
14
-
15
- t.timestamps null: false
16
- end
17
- end
18
- end
@@ -1,56 +0,0 @@
1
- class <%= class_name %>Decorator < Tramway::ApplicationDecorator
2
- # Associations you want to show in admin dashboard
3
- # decorate_associations :messages, :posts
4
-
5
- delegate_attributes(
6
- <% attributes.each do |attr| -%>
7
- :<%= attr %>,
8
- <% end -%>
9
- )
10
-
11
- class << self
12
- def collections
13
- # [ :all, :scope1, :scope2 ]
14
- [ :all ]
15
- end
16
-
17
- def list_attributes
18
- [
19
- <% attributes.first(COLLECTION_ATTRIBUTE_LIMIT).each do |attr| -%>
20
- :<%= attr %>,
21
- <% end -%>
22
- ]
23
- end
24
-
25
- def show_attributes
26
- [
27
- <% attributes.each do |attr| -%>
28
- :<%= attr %>,
29
- <% end -%>
30
- ]
31
- end
32
-
33
- def show_associations
34
- # Associations you want to show in admin dashboard
35
- # [ :messages ]
36
- end
37
-
38
- def list_filters
39
- # {
40
- # filter_name: {
41
- # type: :select,
42
- # select_collection: filter_collection,
43
- # query: lambda do |list, value|
44
- # list.where some_attribute: value
45
- # end
46
- # },
47
- # date_filter_name: {
48
- # type: :dates,
49
- # query: lambda do |list, begin_date, end_date|
50
- # list.where 'created_at > ? AND created_at < ?', begin_date, end_date
51
- # end
52
- # }
53
- # }
54
- end
55
- end
56
- end
@@ -1,22 +0,0 @@
1
- class <%= user_role.capitalize %>::<%= class_name %>Form < Tramway::ApplicationForm
2
- properties <%= form_attributes.map{ |a| ":#{a}" }.join(', ') %>
3
-
4
- def initialize(object)
5
- super(object).tap do
6
- # Here is the mapping from model attributes to simple_form inputs.
7
- # form_properties title: :string,
8
- # logo: :file,
9
- # description: :ckeditor,
10
- # games: :association,
11
- # date: :date_picker,
12
- # text: :text,
13
- # birth_date: {
14
- # type: :default,
15
- # input_options: {
16
- # hint: 'It should be more than 18'
17
- # }
18
- # }
19
- form_properties <%= form_attributes.map{ |attr| "#{attr}: :#{form_type(attr)}"}.join(",\n ") %>
20
- end
21
- end
22
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- SimpleForm.setup do |config|
4
- config.wrappers :default, class: :input,
5
- hint_class: :field_with_hint, error_class: :field_with_errors do |b|
6
- b.use :html5
7
- b.use :placeholder
8
- b.optional :maxlength
9
- b.optional :pattern
10
- b.optional :min_max
11
- b.optional :readonly
12
- b.use :label_input
13
- b.use :hint, wrap_with: { tag: :span, class: :hint }
14
- b.use :error, wrap_with: { tag: :span, class: :error }
15
- end
16
- config.default_wrapper = :default
17
- config.boolean_style = :nested
18
- config.button_class = 'btn'
19
- config.error_notification_tag = :div
20
- config.error_notification_class = 'error_notification'
21
- config.browser_validations = false
22
- config.boolean_label_class = 'checkbox'
23
- end