tramway 0.1.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +12 -893
- data/Rakefile +8 -8
- data/app/components/tailwind_component.html.haml +0 -0
- data/app/components/tailwind_component.rb +6 -0
- data/app/components/tailwinds/navbar/button_component.html.haml +1 -0
- data/app/components/tailwinds/navbar/button_component.rb +14 -0
- data/config/routes.rb +0 -9
- data/lib/tasks/tramway_tasks.rake +5 -0
- data/lib/tramway/engine.rb +5 -10
- data/lib/tramway/version.rb +1 -1
- data/lib/tramway.rb +5 -140
- metadata +17 -554
- data/app/assets/config/tramway_core_manifest.js +0 -2
- data/app/assets/images/tramway/mona_lisa_from_prado.jpg +0 -0
- data/app/assets/images/tramway/mona_lisa_from_prado_square.jpg +0 -0
- data/app/assets/javascripts/bootstrap-datepicker-1.8.0.js +0 -2035
- data/app/assets/javascripts/bootstrap-datepicker-1.8.0.ru.min.js +0 -64
- data/app/assets/javascripts/ckeditor/config.js +0 -30
- data/app/assets/javascripts/ckeditor/plugins/image/dialogs/image.js +0 -1259
- data/app/assets/javascripts/ckeditor/plugins/image/icons/hidpi/image.png +0 -0
- data/app/assets/javascripts/ckeditor/plugins/image/icons/image.png +0 -0
- data/app/assets/javascripts/ckeditor/plugins/image/images/noimage.png +0 -0
- data/app/assets/javascripts/ckeditor/plugins/image/lang/en.js +0 -25
- data/app/assets/javascripts/ckeditor/plugins/image/lang/ru.js +0 -25
- data/app/assets/javascripts/ckeditor/plugins/image/plugin.js +0 -184
- data/app/assets/javascripts/ckeditor/plugins/youtube/images/icon-hdpi.png +0 -0
- data/app/assets/javascripts/ckeditor/plugins/youtube/images/icon.png +0 -0
- data/app/assets/javascripts/ckeditor/plugins/youtube/lang/en.js +0 -25
- data/app/assets/javascripts/ckeditor/plugins/youtube/lang/ru.js +0 -25
- data/app/assets/javascripts/ckeditor/plugins/youtube/plugin.js +0 -449
- data/app/assets/javascripts/tramway/application.js +0 -60
- data/app/assets/stylesheets/tramway/application.sass +0 -60
- data/app/assets/stylesheets/tramway/bootstrap-datepicker-1.8.0.css +0 -477
- data/app/controllers/concerns/auth_management.rb +0 -26
- data/app/controllers/concerns/filtering.rb +0 -43
- data/app/controllers/tramway/application_controller.rb +0 -142
- data/app/controllers/tramway/export/application_controller.rb +0 -5
- data/app/controllers/tramway/has_and_belongs_to_many_records_controller.rb +0 -26
- data/app/controllers/tramway/records_controller.rb +0 -86
- data/app/controllers/tramway/sessions_controller.rb +0 -49
- data/app/controllers/tramway/singletons_controller.rb +0 -48
- data/app/controllers/tramway/welcome_controller.rb +0 -17
- data/app/decorators/tramway/application_decorated_collection.rb +0 -15
- data/app/decorators/tramway/application_decorator.rb +0 -124
- data/app/decorators/tramway/associations/class_helper.rb +0 -45
- data/app/decorators/tramway/associations/object_helper.rb +0 -58
- data/app/decorators/tramway/attributes/view_helper.rb +0 -30
- data/app/decorators/tramway/concerns/attributes_decorator_helper.rb +0 -97
- data/app/decorators/tramway/concerns/table_builder.rb +0 -33
- data/app/decorators/tramway/default/values_helper.rb +0 -23
- data/app/decorators/tramway/delegating/class_helper.rb +0 -9
- data/app/decorators/tramway/user_decorator.rb +0 -49
- data/app/forms/admin/tramway/user_form.rb +0 -24
- data/app/forms/tramway/application_form.rb +0 -124
- data/app/forms/tramway/application_forms/association_class_helpers.rb +0 -7
- data/app/forms/tramway/application_forms/association_object_helpers.rb +0 -36
- data/app/forms/tramway/application_forms/constant_class_actions.rb +0 -7
- data/app/forms/tramway/application_forms/constant_object_actions.rb +0 -20
- data/app/forms/tramway/application_forms/frontend.rb +0 -12
- data/app/forms/tramway/application_forms/object_helpers.rb +0 -15
- data/app/forms/tramway/application_forms/properties_object_helper.rb +0 -16
- data/app/forms/tramway/application_forms/submit_helper.rb +0 -26
- data/app/forms/tramway/extendable_form.rb +0 -15
- data/app/forms/tramway/extendable_forms_helpers/class_builder.rb +0 -34
- data/app/forms/tramway/extendable_forms_helpers/ignored_properties_helper.rb +0 -11
- data/app/forms/tramway/extendable_forms_helpers/more_properties_helper.rb +0 -31
- data/app/forms/tramway/extendable_forms_helpers/properties_helper.rb +0 -16
- data/app/forms/tramway/extendable_forms_helpers/submit/class_helpers.rb +0 -18
- data/app/forms/tramway/extendable_forms_helpers/submit/object_helpers.rb +0 -21
- data/app/forms/tramway/extendable_forms_helpers/validators.rb +0 -40
- data/app/forms/tramway/extended_application_form.rb +0 -23
- data/app/forms/tramway/form_creator.rb +0 -7
- data/app/forms/tramway/session_form.rb +0 -26
- data/app/helpers/tramway/actions_helper.rb +0 -45
- data/app/helpers/tramway/additional_buttons_builder.rb +0 -12
- data/app/helpers/tramway/application_helper.rb +0 -27
- data/app/helpers/tramway/cases_helper.rb +0 -13
- data/app/helpers/tramway/copy_to_clipboard_helper.rb +0 -11
- data/app/helpers/tramway/focus_generator_helper.rb +0 -10
- data/app/helpers/tramway/frontend_helper.rb +0 -26
- data/app/helpers/tramway/inputs/associations_helper.rb +0 -30
- data/app/helpers/tramway/inputs/polymorphic_associations_helper.rb +0 -24
- data/app/helpers/tramway/inputs_helper.rb +0 -96
- data/app/helpers/tramway/model_helper.rb +0 -7
- data/app/helpers/tramway/navbar_helper.rb +0 -11
- data/app/helpers/tramway/records_helper.rb +0 -120
- data/app/helpers/tramway/russian_cases_helper.rb +0 -26
- data/app/helpers/tramway/singleton_helper.rb +0 -12
- data/app/helpers/tramway/state_machine_buttons_helper.rb +0 -61
- data/app/helpers/tramway/title_helper.rb +0 -25
- data/app/inputs/date_picker_input.rb +0 -4
- data/app/inputs/multiple_file_input.rb +0 -7
- data/app/models/tramway/application_record.rb +0 -60
- data/app/models/tramway/user.rb +0 -23
- data/app/uploaders/application_uploader.rb +0 -22
- data/app/uploaders/file_uploader.rb +0 -4
- data/app/uploaders/ico_uploader.rb +0 -7
- data/app/uploaders/image_defaults.rb +0 -14
- data/app/uploaders/photo_uploader.rb +0 -54
- data/app/views/layouts/tramway/application.html.haml +0 -32
- data/app/views/layouts/tramway/shared/_navbar.html.haml +0 -46
- data/app/views/tramway/404.haml +0 -1
- data/app/views/tramway/records/_form.html.haml +0 -22
- data/app/views/tramway/records/_list.html.haml +0 -38
- data/app/views/tramway/records/_search.html.haml +0 -34
- data/app/views/tramway/records/edit.html.haml +0 -1
- data/app/views/tramway/records/index.html.haml +0 -31
- data/app/views/tramway/records/new.html.haml +0 -1
- data/app/views/tramway/records/show.html.haml +0 -1
- data/app/views/tramway/sessions/new.html.haml +0 -9
- data/app/views/tramway/shared/_input.html.haml +0 -34
- data/app/views/tramway/shared/_input_extended.html.haml +0 -14
- data/app/views/tramway/shared/_messages.html.haml +0 -10
- data/app/views/tramway/shared/_show.html.haml +0 -35
- data/app/views/tramway/shared/errors/server_error.html.haml +0 -12
- data/app/views/tramway/shared/input_extended_types/_checkbox.html.haml +0 -1
- data/app/views/tramway/shared/input_extended_types/_select.html.haml +0 -16
- data/app/views/tramway/shared/input_extended_types/_simple.html.haml +0 -4
- data/app/views/tramway/shared/input_extended_types/_yes_no.html.haml +0 -4
- data/app/views/tramway/shared/show/_attribute_tr.html.haml +0 -9
- data/app/views/tramway/shared/show/associations/_habtm_row.html.haml +0 -14
- data/app/views/tramway/shared/show/associations/_list.html.haml +0 -21
- data/app/views/tramway/shared/show/associations/_row.html.haml +0 -19
- data/app/views/tramway/shared/show/associations/_table_row.html.haml +0 -21
- data/app/views/tramway/singletons/_form.html.haml +0 -15
- data/app/views/tramway/singletons/edit.html.haml +0 -1
- data/app/views/tramway/singletons/new.html.haml +0 -1
- data/app/views/tramway/singletons/show.html.haml +0 -1
- data/app/views/tramway/welcome/index.html.haml +0 -4
- data/config/initializers/assets.rb +0 -7
- data/config/initializers/carrierwave.rb +0 -5
- data/config/initializers/ckeditor.rb +0 -9
- data/config/initializers/plurals.rb +0 -25
- data/config/locales/en/collections.yml +0 -4
- data/config/locales/en/date.yml +0 -16
- data/config/locales/en/dates.yml +0 -10
- data/config/locales/en/helpers.yml +0 -26
- data/config/locales/en/locale.yml +0 -11
- data/config/locales/en/messages.yml +0 -7
- data/config/locales/en/models.yml +0 -9
- data/config/locales/en/simple_form_extension.yml +0 -8
- data/config/locales/en/state_machines.yml +0 -8
- data/config/locales/ru/collections.yml +0 -4
- data/config/locales/ru/date.yml +0 -16
- data/config/locales/ru/dates.yml +0 -10
- data/config/locales/ru/helpers.yml +0 -30
- data/config/locales/ru/locale.yml +0 -6
- data/config/locales/ru/messages.yml +0 -7
- data/config/locales/ru/models.yml +0 -21
- data/config/locales/ru/simple_form_extension.yml +0 -8
- data/config/locales/ru/state_machines.yml +0 -8
- data/lib/string.rb +0 -18
- data/lib/tramway/application.rb +0 -10
- data/lib/tramway/class_name_helpers.rb +0 -15
- data/lib/tramway/collection.rb +0 -9
- data/lib/tramway/collections/helper.rb +0 -21
- data/lib/tramway/collections.rb +0 -4
- data/lib/tramway/error.rb +0 -32
- data/lib/tramway/forms.rb +0 -5
- data/lib/tramway/generators/install_generator.rb +0 -49
- data/lib/tramway/generators/model_generator.rb +0 -105
- data/lib/tramway/generators/templates/create_tramway_users.rb +0 -18
- data/lib/tramway/generators/templates/decorator.rb.erb +0 -56
- data/lib/tramway/generators/templates/form.rb.erb +0 -22
- data/lib/tramway/generators/templates/initializers/simple_form.rb +0 -23
- data/lib/tramway/generators/templates/initializers/simple_form_bootstrap.rb +0 -133
- data/lib/tramway/generators.rb +0 -6
- data/lib/tramway/navbar.rb +0 -44
- data/lib/tramway/notifications.rb +0 -12
- data/lib/tramway/record_routes_helper.rb +0 -23
- data/lib/tramway/records_models.rb +0 -52
- data/lib/tramway/singleton_models.rb +0 -32
- data/lib/tramway/spec/helpers/navbar_helper.rb +0 -7
- data/lib/tramway/spec/helpers/tramway_helpers.rb +0 -47
- data/lib/tramway/welcome_page_actions.rb +0 -5
- data/lib/tramway/yaml/errors.yml +0 -49
- data/lib/validators/presence_validator.rb +0 -9
data/config/locales/en/date.yml
DELETED
@@ -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
|
-
|
data/config/locales/en/dates.yml
DELETED
@@ -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
|
data/config/locales/ru/date.yml
DELETED
@@ -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
|
-
|
data/config/locales/ru/dates.yml
DELETED
@@ -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,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: пользователя
|
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
|
data/lib/tramway/application.rb
DELETED
@@ -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
|
data/lib/tramway/collection.rb
DELETED
@@ -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
|
data/lib/tramway/collections.rb
DELETED
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
|
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,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 'audited:install'
|
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
|