tramway-core 1.13.1.1 → 1.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +3 -1
  3. data/app/controllers/tramway/core/application_controller.rb +2 -0
  4. data/app/decorators/tramway/core/application_decorated_collection.rb +3 -3
  5. data/app/decorators/tramway/core/application_decorator.rb +15 -14
  6. data/app/decorators/tramway/core/concerns/attributes_decorator_helper.rb +2 -0
  7. data/app/forms/tramway/core/application_form.rb +10 -8
  8. data/app/forms/tramway/core/extendable_form.rb +28 -13
  9. data/app/forms/tramway/core/extended_application_form.rb +7 -5
  10. data/app/forms/tramway/core/form_creator.rb +2 -0
  11. data/app/helpers/tramway/core/title_helper.rb +4 -2
  12. data/app/inputs/date_picker_input.rb +2 -0
  13. data/app/models/tramway/core/application_record.rb +7 -7
  14. data/app/uploaders/application_uploader.rb +2 -0
  15. data/app/uploaders/file_uploader.rb +3 -1
  16. data/app/uploaders/image_defaults.rb +4 -2
  17. data/app/uploaders/photo_uploader.rb +11 -9
  18. data/app/views/tramway/core/shared/_input_extended.html.haml +8 -16
  19. data/app/views/tramway/core/shared/input_extended_types/_checkbox.html.haml +1 -0
  20. data/app/views/tramway/core/shared/input_extended_types/_select.html.haml +16 -0
  21. data/app/views/tramway/core/shared/input_extended_types/_simple.html.haml +4 -0
  22. data/app/views/tramway/core/shared/input_extended_types/_yes_no.html.haml +4 -0
  23. data/config/initializers/assets.rb +3 -1
  24. data/config/initializers/carrierwave.rb +2 -0
  25. data/config/initializers/plurals.rb +9 -7
  26. data/config/routes.rb +2 -0
  27. data/lib/string.rb +5 -3
  28. data/lib/tasks/tramway/core_tasks.rake +2 -0
  29. data/lib/tramway/collection.rb +2 -0
  30. data/lib/tramway/collections/helper.rb +3 -1
  31. data/lib/tramway/core.rb +5 -6
  32. data/lib/tramway/core/application.rb +2 -0
  33. data/lib/tramway/core/engine.rb +2 -0
  34. data/lib/tramway/core/generators/install_generator.rb +3 -1
  35. data/lib/tramway/core/generators/templates/initializers/simple_form.rb +1 -0
  36. data/lib/tramway/core/version.rb +3 -1
  37. data/lib/tramway/error.rb +3 -1
  38. data/lib/tramway/helpers/class_name_helpers.rb +2 -0
  39. data/lib/validators/presence_validator.rb +3 -2
  40. metadata +85 -81
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 98fc3b4eb72607b71692a66f9984842cc63cd135f7c498090b5a89ec22d25648
4
- data.tar.gz: 955159d6eb34fc36e753a3aba3167846a788a7ce37e9e5d3d657fb542c0d6312
3
+ metadata.gz: aff2dd709eb25da798153cd9a21f3bd9f2542eb7386c64897539e9ebb516f45f
4
+ data.tar.gz: e3fb920952051837900f15710c7b2538b30eb99f2edf9d01bda5d04e0b39c4c8
5
5
  SHA512:
6
- metadata.gz: 8901bf8f3c13d43b4bc750dfef901e079bc351eae922674883066ffffaca448c7ba5c3913ef96bf7caed2f52d1872358780295d3dd46c07178f758b6e5ab35b5
7
- data.tar.gz: ceb839ae0aa3d97d75a0e7c98c212bd8502ad21f8f411d20871bce24f608fd7818d67284ed271a0ffa22515d8c47b0403422f9aa0aa559b0b66f9e174c0cf2c5
6
+ metadata.gz: 583b78f563f4ccc605adb76f283ed94f51d44574a4c3e0a67636a8a32f7edef123829463ddf3c8a2af5de630c08c0869c8b4b3181ae81787fcf8f8dff98a5f24
7
+ data.tar.gz: 5ec16b360a0def6d1ad04bfd5e520d28ca40b0915e352ad8bc23da04fbfcd045a303c167dea4562c23baa2e3b09de4ca0ba0a0f0d7771544e1179bb943411d69
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rake'
2
4
  require 'rspec/core/rake_task'
3
-
5
+
4
6
  RSpec::Core::RakeTask.new(:spec) do |t|
5
7
  t.pattern = Dir.glob('spec/**/*_spec.rb')
6
8
  t.rspec_opts = '--format documentation'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Tramway
2
4
  module Core
3
5
  class ApplicationController < ActionController::Base
@@ -1,12 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Tramway::Core::ApplicationDecoratedCollection < Array
2
4
  def initialize(array, original_array)
3
5
  @original_array = original_array
4
6
  super(array)
5
7
  end
6
8
 
7
- def original_array
8
- @original_array
9
- end
9
+ attr_reader :original_array
10
10
 
11
11
  delegate :total_pages, to: :original_array
12
12
  delegate :total_count, to: :original_array
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'tramway/error'
2
4
 
3
5
  class Tramway::Core::ApplicationDecorator
@@ -14,7 +16,7 @@ class Tramway::Core::ApplicationDecorator
14
16
  end
15
17
 
16
18
  def title
17
- error = Tramway::Error.new(plugin: :core, method: :title, message: ("Please, implement `title` method in a #{self.class} or #{object.class}"))
19
+ error = Tramway::Error.new(plugin: :core, method: :title, message: "Please, implement `title` method in a #{self.class} or #{object.class}")
18
20
  raise error.message
19
21
  end
20
22
 
@@ -56,7 +58,7 @@ class Tramway::Core::ApplicationDecorator
56
58
  object.send(association_name).class
57
59
  else
58
60
  unless association.options[:class_name]
59
- error = Tramway::Error.new(plugin: :core, method: :decorate_association, message: ("Please, specify `#{association_name}` association class_name in #{object.class} model. For example: `has_many :#{association_name}, class_name: '#{association_name.to_s.singularize.camelize}'`"))
61
+ error = Tramway::Error.new(plugin: :core, method: :decorate_association, message: "Please, specify `#{association_name}` association class_name in #{object.class} model. For example: `has_many :#{association_name}, class_name: '#{association_name.to_s.singularize.camelize}'`")
60
62
  raise error.message
61
63
  end
62
64
  association.options[:class_name]
@@ -74,7 +76,7 @@ class Tramway::Core::ApplicationDecorator
74
76
  end
75
77
 
76
78
  def model_class
77
- self.to_s.sub(/Decorator$/, '').constantize
79
+ to_s.sub(/Decorator$/, '').constantize
78
80
  end
79
81
 
80
82
  def model_name
@@ -92,7 +94,8 @@ class Tramway::Core::ApplicationDecorator
92
94
  error = Tramway::Error.new(
93
95
  plugin: :core,
94
96
  method: :link,
95
- message: ("Method `link` uses `file` attribute of the decorated object. If decorated object doesn't contain `file`, you shouldn't use `link` method."))
97
+ message: "Method `link` uses `file` attribute of the decorated object. If decorated object doesn't contain `file`, you shouldn't use `link` method."
98
+ )
96
99
  raise error.message
97
100
  end
98
101
  end
@@ -111,7 +114,7 @@ class Tramway::Core::ApplicationDecorator
111
114
 
112
115
  include Tramway::Core::Concerns::AttributesDecoratorHelper
113
116
 
114
- RESERVED_WORDS = [ 'fields' ]
117
+ RESERVED_WORDS = ['fields'].freeze
115
118
 
116
119
  def attributes
117
120
  object.attributes.reduce({}) do |hash, attribute|
@@ -119,13 +122,14 @@ class Tramway::Core::ApplicationDecorator
119
122
  error = Tramway::Error.new(
120
123
  plugin: :core,
121
124
  method: :attributes,
122
- message: ("Method `#{attribute[0]}` is reserved word. Please, create or delegate method in #{self.class.name} with another name."))
125
+ message: "Method `#{attribute[0]}` is reserved word. Please, create or delegate method in #{self.class.name} with another name."
126
+ )
123
127
  raise error.message
124
128
  end
125
129
  value = try(attribute[0]) ? send(attribute[0]) : object.send(attribute[0])
126
130
  if attribute[0].to_s.in? object.class.state_machines.keys.map(&:to_s)
127
131
  hash.merge! attribute[0] => state_machine_view(object, attribute[0])
128
- elsif value.class.in? [ ActiveSupport::TimeWithZone, DateTime, Time ]
132
+ elsif value.class.in? [ActiveSupport::TimeWithZone, DateTime, Time]
129
133
  hash.merge! attribute[0] => datetime_view(attribute[1])
130
134
  elsif value.class.superclass == ApplicationUploader
131
135
  hash.merge! attribute[0] => image_view(object.send(attribute[0]))
@@ -142,11 +146,8 @@ class Tramway::Core::ApplicationDecorator
142
146
  end
143
147
 
144
148
  protected
145
-
146
- def object
147
- @object
148
- end
149
149
 
150
- def association_class_name
151
- end
152
- end
150
+ attr_reader :object
151
+
152
+ def association_class_name; end
153
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Tramway::Core::Concerns::AttributesDecoratorHelper
2
4
  def date_view(value)
3
5
  I18n.l value.to_date if value
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Tramway::Core
2
4
  class ApplicationForm < ::Reform::Form
3
5
  def initialize(object = nil)
4
- object = self.class.model_class.new unless object
6
+ object ||= self.class.model_class.new
5
7
  super(object).tap do
6
8
  @@model_class = object.class
7
9
  @@enumerized_attributes = object.class.try :enumerized_attributes
@@ -27,12 +29,12 @@ module Tramway::Core
27
29
  delegating object
28
30
  end
29
31
  end
30
-
32
+
31
33
  def submit(params)
32
34
  if params
33
35
  save if validate params
34
36
  else
35
- error = Tramway::Error.new(plugin: :core, method: :submit, message: ('ApplicationForm::Params should not be nil'))
37
+ error = Tramway::Error.new(plugin: :core, method: :submit, message: 'ApplicationForm::Params should not be nil')
36
38
  raise error.message
37
39
  end
38
40
  end
@@ -52,7 +54,7 @@ module Tramway::Core
52
54
  def build_errors; end
53
55
 
54
56
  def delegating(object)
55
- methods = [:to_key, :errors]
57
+ methods = %i[to_key errors]
56
58
  methods.each do |method|
57
59
  self.class.send(:define_method, method) do
58
60
  object.send method
@@ -96,7 +98,7 @@ module Tramway::Core
96
98
  def full_class_name_association(association_name)
97
99
  full_class_name_associations[association_name]
98
100
  end
99
-
101
+
100
102
  def enumerized_attributes
101
103
  @@enumerized_attributes
102
104
  end
@@ -109,11 +111,11 @@ module Tramway::Core
109
111
  if defined?(@@model_class) && @@model_class
110
112
  @@model_class
111
113
  else
112
- model_class_name ||= self.name.to_s.sub(/Form$/, '')
114
+ model_class_name ||= name.to_s.sub(/Form$/, '')
113
115
  begin
114
116
  @@model_class = model_class_name.constantize
115
- rescue
116
- error = Tramway::Error.new(plugin: :core, method: :model_class, message: ("There is not model class name for #{self.name}. Should be #{model_class_name} or you can use another class to initialize form object or just initialize form with object."))
117
+ rescue StandardError
118
+ error = Tramway::Error.new(plugin: :core, method: :model_class, message: "There is not model class name for #{name}. Should be #{model_class_name} or you can use another class to initialize form object or just initialize form with object.")
117
119
  raise error.message
118
120
  end
119
121
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Tramway::Core::ExtendableForm
2
4
  class << self
3
5
  def new(name, simple_properties: {}, **more_properties)
@@ -9,12 +11,10 @@ class Tramway::Core::ExtendableForm
9
11
 
10
12
  define_method 'submit' do |params|
11
13
  model.values ||= {}
12
- extended_params = params.except(*simple_properties.keys)
14
+ extended_params = params.except(*simple_properties.keys).except(*jsonb_ignored_properties(more_properties))
13
15
  params.each do |key, value|
14
16
  method_name = "#{key}="
15
- if respond_to?(method_name)
16
- send method_name, value
17
- end
17
+ send method_name, value if respond_to?(method_name)
18
18
  end
19
19
  model.values = extended_params.permit!.to_h.reduce(model.values) do |hash, pair|
20
20
  hash.merge! pair[0] => pair[1]
@@ -23,11 +23,8 @@ class Tramway::Core::ExtendableForm
23
23
  end
24
24
 
25
25
  define_method 'properties' do
26
- hash = simple_properties.reduce({}) do |h, property|
27
- unless model.class.state_machines.keys.include?(property[0])
28
- h.merge! property[0] => property[1]
29
- end
30
- h
26
+ hash = simple_properties.each_with_object({}) do |property, h|
27
+ h.merge! property[0] => property[1] unless model.class.state_machines.keys.include?(property[0])
31
28
  end
32
29
  more_properties.reduce(hash) do |h, property|
33
30
  h.merge! property[0] => {
@@ -37,22 +34,40 @@ class Tramway::Core::ExtendableForm
37
34
  end
38
35
 
39
36
  more_properties.each do |property|
40
- define_method property[0] do
37
+ define_method property[0] do
41
38
  model.values[property[0]] if model.values
42
39
  end
43
40
 
44
- if property[1][:validates].present?
41
+ case property[1][:object].field_type
42
+ when 'file'
43
+ field = property[1][:object]
44
+ define_method "#{property[0]}=" do |value|
45
+ file_instance = property[1][:association_model].find_or_create_by "#{model.class.name.underscore}_id" => model.id, "#{field.class.name.underscore}_id" => field.id
46
+ file_instance.file = value
47
+ file_instance.save!
48
+ end
49
+ else
50
+ next unless property[1][:validates].present?
51
+
45
52
  define_method "#{property[0]}=" do |value|
46
53
  property[1][:validates].each do |pair|
47
- validator_object = "#{pair[0].camelize}Validator".constantize.new({ attributes: :not_blank })
54
+ validator_object = "#{pair[0].camelize}Validator".constantize.new(attributes: :not_blank)
48
55
  if pair[1] == 'true' && !validator_object.send(:valid?, value)
49
56
  model.errors.add property[0],
50
- I18n.t("activerecord.errors.models.#{model.class.name.underscore}.attributes.#{property[0]}.#{pair[0]}", { value: value })
57
+ I18n.t("activerecord.errors.models.#{model.class.name.underscore}.attributes.#{property[0]}.#{pair[0]}", value: value)
51
58
  end
52
59
  end
53
60
  end
54
61
  end
55
62
  end
63
+
64
+ define_method :jsonb_ignored_properties do |properties|
65
+ properties.map do |property|
66
+ if property[1][:object].field_type == 'file'
67
+ property[0].to_s
68
+ end
69
+ end.compact
70
+ end
56
71
  end)
57
72
  end
58
73
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Tramway::Core::ExtendedApplicationForm < Tramway::Core::ApplicationForm
2
4
  class << self
3
5
  def properties(*args)
@@ -9,11 +11,11 @@ class Tramway::Core::ExtendedApplicationForm < Tramway::Core::ApplicationForm
9
11
 
10
12
  def initialize(model)
11
13
  @@extendable_properties.each do |prop|
12
- unless model.respond_to? prop
13
- model.class.define_method prop do
14
- end
15
- model.class.define_method "#{prop}=" do |value|
16
- end
14
+ next if model.respond_to? prop
15
+
16
+ model.class.define_method prop do
17
+ end
18
+ model.class.define_method "#{prop}=" do |value|
17
19
  end
18
20
  end
19
21
  super
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Tramway::Core::FormCreator
2
4
  def self.create_form_class
3
5
  raise 'Please, implement `create_form_class` for your class'
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Tramway
2
4
  module Core
3
5
  module TitleHelper
4
6
  def title(page_title = default_title)
5
7
  if @application.present?
6
- title_text = "#{page_title} | #{@application.try(:title) || @application.public_name}"
8
+ title_text = "#{page_title} | #{@application.try(:title) || @application.public_name}"
7
9
  content_for(:title) { title_text }
8
10
  else
9
- error = Tramway::Error.new(plugin: :core, method: :title, message: ('You should set Tramway::Core::Application class using `::Tramway::Core.initialize_application model_class: #{model_class_name}` in config/initializers/tramway.rb OR may be you don\'t have any records of application model'))
11
+ error = Tramway::Error.new(plugin: :core, method: :title, message: 'You should set Tramway::Core::Application class using `::Tramway::Core.initialize_application model_class: #{model_class_name}` in config/initializers/tramway.rb OR may be you don\'t have any records of application model')
10
12
  raise error.message
11
13
  end
12
14
  end
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class DatePickerInput < SimpleForm::Inputs::StringInput
2
4
  end
@@ -1,6 +1,6 @@
1
- if defined?(CarrierWave::Mount)
2
- require 'carrierwave/orm/activerecord'
3
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'carrierwave/orm/activerecord' if defined?(CarrierWave::Mount)
4
4
 
5
5
  module Tramway
6
6
  module Core
@@ -22,10 +22,10 @@ module Tramway
22
22
 
23
23
  include ::PgSearch
24
24
 
25
- # FIXME detect inhertited locales
25
+ # FIXME: detect inhertited locales
26
26
  class << self
27
- def human_attribute_name(attribute_name, *args)
28
- excepted_attributes = %w( created_at updated_at state )
27
+ def human_attribute_name(attribute_name, *_args)
28
+ excepted_attributes = %w[created_at updated_at state]
29
29
  if attribute_name.to_s.in? excepted_attributes
30
30
  I18n.t "activerecord.attributes.tramway/core/application_record.#{attribute_name}"
31
31
  else
@@ -38,7 +38,7 @@ module Tramway
38
38
  end
39
39
  end
40
40
 
41
- # FIXME detect inhertited locales
41
+ # FIXME: detect inhertited locales
42
42
  def human_state_name
43
43
  I18n.t "activerecord.state_machines.tramway/core/application_record.state.states.#{state}"
44
44
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'carrierwave'
2
4
 
3
5
  class ApplicationUploader < CarrierWave::Uploader::Base
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class FileUploader < ApplicationUploader
2
4
  def extension_white_list
3
- %w(pdf doc docx xls csv xlsx jpg)
5
+ %w[pdf doc docx xls csv xlsx jpg]
4
6
  end
5
7
  end
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ImageDefaults
2
4
  include CarrierWave::MiniMagick
3
5
 
4
6
  def default_url
5
- "/images/fallback/#{model.class.model_name.to_s.underscore}/" << [mounted_as, version_name].compact.join("_") << ".gif"
7
+ "/images/fallback/#{model.class.model_name.to_s.underscore}/" << [mounted_as, version_name].compact.join('_') << '.gif'
6
8
  end
7
9
 
8
10
  def extension_white_list
9
- %w(jpg jpeg gif png)
11
+ %w[jpg jpeg gif png]
10
12
  end
11
13
  end
@@ -1,37 +1,39 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class PhotoUploader < ApplicationUploader
2
4
  include ImageDefaults
3
5
 
4
6
  def default_url
5
- ActionController::Base.helpers.asset_path("images/default_photo.png")
7
+ ActionController::Base.helpers.asset_path('images/default_photo.png')
6
8
  end
7
9
 
8
10
  def url
9
11
  if file.present? && File.exist?(file.file)
10
- file.file.match(/\/system\/uploads\/.*/).to_s
12
+ file.file.match(%r{/system/uploads/.*}).to_s
11
13
  else
12
- "/assets/tramway/core/mona_lisa_from_prado_square.jpg"
14
+ '/assets/tramway/core/mona_lisa_from_prado_square.jpg'
13
15
  end
14
16
  end
15
17
 
16
18
  version :medium do
17
- process :resize_to_fill => [400, 400]
19
+ process resize_to_fill: [400, 400]
18
20
  end
19
21
 
20
22
  version :small do
21
- process :resize_to_fill => [100, 100]
23
+ process resize_to_fill: [100, 100]
22
24
  end
23
25
 
24
- # FIXME move to tramway-landing uploader
26
+ # FIXME: move to tramway-landing uploader
25
27
  version :card do
26
28
  process resize_to_fill: [400, 400, 'North']
27
29
  end
28
30
 
29
- # FIXME move to tramway-landing uploader
31
+ # FIXME: move to tramway-landing uploader
30
32
  version :horizontal do
31
33
  process resize_to_fill: [800, 350, 'North']
32
34
  end
33
35
 
34
- # FIXME move to tramway-landing uploader
36
+ # FIXME: move to tramway-landing uploader
35
37
  version :mini do
36
38
  process resize_to_limit: [300, nil]
37
39
  end
@@ -43,7 +45,7 @@ class PhotoUploader < ApplicationUploader
43
45
  def capture_size(file)
44
46
  if version_name.blank?
45
47
  if file.path.nil?
46
- img = ::MiniMagick::Image::read(file.file)
48
+ img = ::MiniMagick::Image.read(file.file)
47
49
  @width = img[:width]
48
50
  @height = img[:height]
49
51
  else
@@ -1,22 +1,14 @@
1
1
  - value = defined?(value).present? ? value : ''
2
2
  - case field.field_type
3
- - when 'text', 'string', 'numeric', 'date_picker'
4
- - if value.present?
5
- = f.input field.title.to_sym, as: field.field_type, input_html: { class: class_name, id: "#{class_name}_#{field.title}", name: "#{class_name}[#{field.title}]", value: value }
6
- - else
7
- = f.input field.title.to_sym, as: field.field_type, input_html: { class: class_name, id: "#{class_name}_#{field.title}", name: "#{class_name}[#{field.title}]" }
3
+ - when 'text', 'string', 'numeric', 'date_picker', 'file'
4
+ = render 'tramway/core/shared/input_extended_types/simple', value: value, field: field, class_name: class_name, f: f
8
5
  - when 'select'
9
- - parsed_json = field.options.is_a?(Hash) ? field.options : (JSON.parse(field.options) unless field.options == '')
10
- - if parsed_json&.dig('collection', 'name')
11
- - if value.present?
12
- = f.input field.title.to_sym, as: :select, collection: collection_list_by(name: parsed_json['collection']['name']), input_html: { class: class_name, id: "#{class_name}_#{field.title}", name: "#{class_name}[#{field.title}]" }, selected: value
13
- - else
14
- = f.input field.title.to_sym, as: :select, collection: collection_list_by(name: parsed_json['collection']['name']), input_html: { class: class_name, id: "#{class_name}_#{field.title}", name: "#{class_name}[#{field.title}]" }
15
- - else
16
- - if value.present?
17
- = f.input field.title.to_sym, as: :select, input_html: { class: class_name, id: "#{class_name}_#{field.title}", name: "#{class_name}[#{field.title}]" }, selected: value
18
- - else
19
- = f.input field.title.to_sym, as: :select, input_html: { class: class_name, id: "#{class_name}_#{field.title}", name: "#{class_name}[#{field.title}]" }
6
+ = render 'tramway/core/shared/input_extended_types/select', value: value, field: field, class_name: class_name, f: f
7
+ - when 'yes_no'
8
+ = render 'tramway/core/shared/input_extended_types/yes_no', value: value, field: field, class_name: class_name, f: f
9
+ - when 'checkbox'
10
+ = render 'tramway/core/shared/input_extended_types/checkbox', value: value, field: field, class_name: class_name, f: f
11
+
20
12
  - if params[:errors].present? && params[:errors][field.title]&.first
21
13
  .alert.alert-danger
22
14
  = params[:errors][field.title]&.first
@@ -0,0 +1 @@
1
+ = f.input field.title.to_sym, as: :boolean, input_html: { class: class_name, id: "#{class_name}_#{field.title.to_sym}", name: "#{class_name}[#{field.title}]" }, checked_value: value == field.title.to_sym
@@ -0,0 +1,16 @@
1
+ - parsed_json = field.options.is_a?(Hash) ? field.options : (JSON.parse(field.options) unless field.options == '')
2
+ - if parsed_json&.dig('collection', 'name')
3
+ - if value.present?
4
+ = f.input field.title.to_sym, as: :select, collection: collection_list_by(name: parsed_json['collection']['name']), input_html: { class: class_name, id: "#{class_name}_#{field.title}", name: "#{class_name}[#{field.title}]" }, selected: value
5
+ - else
6
+ = f.input field.title.to_sym, as: :select, collection: collection_list_by(name: parsed_json['collection']['name']), input_html: { class: class_name, id: "#{class_name}_#{field.title}", name: "#{class_name}[#{field.title}]" }
7
+ - elsif parsed_json&.dig('collection', 'array')
8
+ - if value.present?
9
+ = f.input field.title.to_sym, as: :select, collection: parsed_json.dig('collection', 'array'), input_html: { class: class_name, id: "#{class_name}_#{field.title}", name: "#{class_name}[#{field.title}]" }, selected: value
10
+ - else
11
+ = f.input field.title.to_sym, as: :select, collection: parsed_json.dig('collection', 'array'), input_html: { class: class_name, id: "#{class_name}_#{field.title}", name: "#{class_name}[#{field.title}]" }
12
+ - else
13
+ - if value.present?
14
+ = f.input field.title.to_sym, as: :select, input_html: { class: class_name, id: "#{class_name}_#{field.title}", name: "#{class_name}[#{field.title}]" }, selected: value
15
+ - else
16
+ = f.input field.title.to_sym, as: :select, input_html: { class: class_name, id: "#{class_name}_#{field.title}", name: "#{class_name}[#{field.title}]" }
@@ -0,0 +1,4 @@
1
+ - if value.present?
2
+ = f.input field.title.to_sym, as: field.field_type, input_html: { class: class_name, id: "#{class_name}_#{field.title}", name: "#{class_name}[#{field.title}]", value: value }
3
+ - else
4
+ = f.input field.title.to_sym, as: field.field_type, input_html: { class: class_name, id: "#{class_name}_#{field.title}", name: "#{class_name}[#{field.title}]" }
@@ -0,0 +1,4 @@
1
+ - if value.present?
2
+ = f.input field.title.to_sym, as: :select, input_html: { class: class_name, id: "#{class_name}_#{field.title}", name: "#{class_name}[#{field.title}]" }, selected: value
3
+ - else
4
+ = f.input field.title.to_sym, as: :select, input_html: { class: class_name, id: "#{class_name}_#{field.title}", name: "#{class_name}[#{field.title}]" }
@@ -1 +1,3 @@
1
- Rails.application.config.assets.precompile += %w( vendor/assets/javascripts/* vendor/assets/stylesheets/* )
1
+ # frozen_string_literal: true
2
+
3
+ Rails.application.config.assets.precompile += %w[vendor/assets/javascripts/* vendor/assets/stylesheets/*]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ActiveSupport.on_load :active_record do
2
4
  require 'audited'
3
5
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  {
2
- ru: {
4
+ ru: {
3
5
  i18n: {
4
6
  plural: {
5
- keys: [:zero, :one, :few, :many],
6
- rule: lambda do |n|
7
+ keys: %i[zero one few many],
8
+ rule: lambda do |n|
7
9
  if n == 0
8
10
  :zero
9
11
  elsif n % 10 == 1 && n % 100 != 11
@@ -16,8 +18,8 @@
16
18
  # 0, 5-20, 25-30, 35-40...
17
19
  :many
18
20
  end
19
- end
20
- }
21
- }
22
- }
21
+ end
22
+ }
23
+ }
24
+ }
23
25
  }
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Tramway::Core::Engine.routes.draw do
2
4
  end
@@ -1,12 +1,14 @@
1
- require "active_support/inflector/methods"
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/inflector/methods'
2
4
 
3
5
  class String
4
6
  def pluralize(count = nil, locale = :en)
5
7
  if locale == :ru
6
8
  case count
7
9
  when :many
8
- I18n.t("cases.#{}")
9
- end
10
+ I18n.t('cases.')
11
+ end
10
12
  else
11
13
  locale = count if count.is_a? Symbol
12
14
  count == 1 ? dup : ActiveSupport::Inflector.pluralize(self, locale)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # desc "Explaining what the task does"
2
4
  # task :tramway_core do
3
5
  # # Task goes here
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Tramway
2
4
  class Collection
3
5
  class << self
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Tramway
2
4
  module Collections
3
5
  module Helper
4
6
  def collection_list_by(name:)
5
7
  require name # needed to load class name with collection
6
8
  unless ::Tramway::Collection.descendants.map(&:to_s).include?(name.camelize)
7
- raise "There no such collection named #{name.camelize}. Please create class with self method `list` and extended of `Tramway::Collection`"
9
+ raise "There no such collection named #{name.camelize}. Please create class with self method `list` and extended of `Tramway::Collection`"
8
10
  end
9
11
 
10
12
  name.camelize.constantize.list
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'tramway/core/engine'
2
4
  require 'tramway/collection'
3
5
  require 'tramway/collections/helper'
@@ -17,18 +19,15 @@ module Tramway
17
19
  end
18
20
  end
19
21
 
20
- def application
21
- @application
22
- end
22
+ attr_reader :application
23
23
  end
24
24
  end
25
25
  end
26
26
 
27
- # HACK FIXME
27
+ # HACK: FIXME
28
28
 
29
29
  module ActiveModel
30
30
  class Errors
31
- def merge!(*args)
32
- end
31
+ def merge!(*args); end
33
32
  end
34
33
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Tramway::Core::Application
2
4
  attr_accessor :name, :url, :model_class, :title, :tagline, :found_date
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'tramway/core/generators/install_generator'
2
4
  require 'tramway/core/application'
3
5
  require 'simple_form'
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails/generators'
2
4
 
3
5
  module Tramway
4
6
  module Core
5
7
  module Generators
6
8
  class InstallGenerator < ::Rails::Generators::Base
7
- source_root File.expand_path('../templates', __FILE__)
9
+ source_root File.expand_path('templates', __dir__)
8
10
 
9
11
  def run_other_generators
10
12
  generate 'audited:install'
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  SimpleForm.setup do |config|
3
4
  config.wrappers :default, class: :input,
4
5
  hint_class: :field_with_hint, error_class: :field_with_errors do |b|
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Tramway
2
4
  module Core
3
- VERSION = '1.13.1.1'
5
+ VERSION = '1.14'
4
6
  end
5
7
  end
@@ -1,4 +1,6 @@
1
- class Tramway::Error < Exception
1
+ # frozen_string_literal: true
2
+
3
+ class Tramway::Error < RuntimeError
2
4
  def initialize(*args, plugin: nil, method: nil, message: nil)
3
5
  @properties ||= {}
4
6
  @properties[:plugin] = plugin
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Tramway::ClassNameHelpers
2
4
  def model_class_name(class_name)
3
5
  class_name.constantize
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class PresenceValidator
2
- def initialize(attributes)
3
- end
4
+ def initialize(attributes); end
4
5
 
5
6
  def valid?(value)
6
7
  value.present?
metadata CHANGED
@@ -1,157 +1,125 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tramway-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.13.1.1
4
+ version: '1.14'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-09 00:00:00.000000000 Z
11
+ date: 2019-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: reform-rails
14
+ name: audited
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.7
19
+ version: 4.8.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.7
26
+ version: 4.8.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: enumerize
28
+ name: bootstrap
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '2.1'
34
31
  - - ">="
35
32
  - !ruby/object:Gem::Version
36
- version: 2.1.2
33
+ version: 4.1.2
37
34
  type: :runtime
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
- - - "~>"
42
- - !ruby/object:Gem::Version
43
- version: '2.1'
44
38
  - - ">="
45
39
  - !ruby/object:Gem::Version
46
- version: 2.1.2
40
+ version: 4.1.2
47
41
  - !ruby/object:Gem::Dependency
48
- name: simple_form
42
+ name: carrierwave
49
43
  requirement: !ruby/object:Gem::Requirement
50
44
  requirements:
51
45
  - - ">="
52
46
  - !ruby/object:Gem::Version
53
- version: 3.5.0
54
- - - "~>"
55
- - !ruby/object:Gem::Version
56
- version: '3.5'
47
+ version: '0'
57
48
  type: :runtime
58
49
  prerelease: false
59
50
  version_requirements: !ruby/object:Gem::Requirement
60
51
  requirements:
61
52
  - - ">="
62
53
  - !ruby/object:Gem::Version
63
- version: 3.5.0
64
- - - "~>"
65
- - !ruby/object:Gem::Version
66
- version: '3.5'
54
+ version: '0'
67
55
  - !ruby/object:Gem::Dependency
68
- name: sass-rails
56
+ name: enumerize
69
57
  requirement: !ruby/object:Gem::Requirement
70
58
  requirements:
71
59
  - - "~>"
72
60
  - !ruby/object:Gem::Version
73
- version: '5.0'
61
+ version: '2.1'
74
62
  - - ">="
75
63
  - !ruby/object:Gem::Version
76
- version: 5.0.7
64
+ version: 2.1.2
77
65
  type: :runtime
78
66
  prerelease: false
79
67
  version_requirements: !ruby/object:Gem::Requirement
80
68
  requirements:
81
69
  - - "~>"
82
70
  - !ruby/object:Gem::Version
83
- version: '5.0'
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- version: 5.0.7
87
- - !ruby/object:Gem::Dependency
88
- name: bootstrap
89
- requirement: !ruby/object:Gem::Requirement
90
- requirements:
91
- - - ">="
92
- - !ruby/object:Gem::Version
93
- version: 4.1.2
94
- type: :runtime
95
- prerelease: false
96
- version_requirements: !ruby/object:Gem::Requirement
97
- requirements:
71
+ version: '2.1'
98
72
  - - ">="
99
73
  - !ruby/object:Gem::Version
100
- version: 4.1.2
74
+ version: 2.1.2
101
75
  - !ruby/object:Gem::Dependency
102
- name: audited
76
+ name: font_awesome5_rails
103
77
  requirement: !ruby/object:Gem::Requirement
104
78
  requirements:
105
79
  - - ">="
106
80
  - !ruby/object:Gem::Version
107
- version: 4.8.0
81
+ version: '0'
108
82
  type: :runtime
109
83
  prerelease: false
110
84
  version_requirements: !ruby/object:Gem::Requirement
111
85
  requirements:
112
86
  - - ">="
113
87
  - !ruby/object:Gem::Version
114
- version: 4.8.0
88
+ version: '0'
115
89
  - !ruby/object:Gem::Dependency
116
- name: mini_magick
90
+ name: haml-rails
117
91
  requirement: !ruby/object:Gem::Requirement
118
92
  requirements:
119
93
  - - ">="
120
94
  - !ruby/object:Gem::Version
121
- version: 4.8.0
95
+ version: 1.0.0
122
96
  - - "~>"
123
97
  - !ruby/object:Gem::Version
124
- version: '4.8'
98
+ version: '1.0'
125
99
  type: :runtime
126
100
  prerelease: false
127
101
  version_requirements: !ruby/object:Gem::Requirement
128
102
  requirements:
129
103
  - - ">="
130
104
  - !ruby/object:Gem::Version
131
- version: 4.8.0
105
+ version: 1.0.0
132
106
  - - "~>"
133
107
  - !ruby/object:Gem::Version
134
- version: '4.8'
108
+ version: '1.0'
135
109
  - !ruby/object:Gem::Dependency
136
- name: rmagick
110
+ name: kaminari
137
111
  requirement: !ruby/object:Gem::Requirement
138
112
  requirements:
139
113
  - - ">="
140
114
  - !ruby/object:Gem::Version
141
- version: 2.16.0
142
- - - "~>"
143
- - !ruby/object:Gem::Version
144
- version: '2.16'
115
+ version: '0'
145
116
  type: :runtime
146
117
  prerelease: false
147
118
  version_requirements: !ruby/object:Gem::Requirement
148
119
  requirements:
149
120
  - - ">="
150
121
  - !ruby/object:Gem::Version
151
- version: 2.16.0
152
- - - "~>"
153
- - !ruby/object:Gem::Version
154
- version: '2.16'
122
+ version: '0'
155
123
  - !ruby/object:Gem::Dependency
156
124
  name: loofah
157
125
  requirement: !ruby/object:Gem::Requirement
@@ -173,27 +141,27 @@ dependencies:
173
141
  - !ruby/object:Gem::Version
174
142
  version: 2.2.1
175
143
  - !ruby/object:Gem::Dependency
176
- name: haml-rails
144
+ name: mini_magick
177
145
  requirement: !ruby/object:Gem::Requirement
178
146
  requirements:
179
147
  - - ">="
180
148
  - !ruby/object:Gem::Version
181
- version: 1.0.0
149
+ version: 4.8.0
182
150
  - - "~>"
183
151
  - !ruby/object:Gem::Version
184
- version: '1.0'
152
+ version: '4.8'
185
153
  type: :runtime
186
154
  prerelease: false
187
155
  version_requirements: !ruby/object:Gem::Requirement
188
156
  requirements:
189
157
  - - ">="
190
158
  - !ruby/object:Gem::Version
191
- version: 1.0.0
159
+ version: 4.8.0
192
160
  - - "~>"
193
161
  - !ruby/object:Gem::Version
194
- version: '1.0'
162
+ version: '4.8'
195
163
  - !ruby/object:Gem::Dependency
196
- name: font_awesome5_rails
164
+ name: pg_search
197
165
  requirement: !ruby/object:Gem::Requirement
198
166
  requirements:
199
167
  - - ">="
@@ -207,7 +175,7 @@ dependencies:
207
175
  - !ruby/object:Gem::Version
208
176
  version: '0'
209
177
  - !ruby/object:Gem::Dependency
210
- name: carrierwave
178
+ name: reform
211
179
  requirement: !ruby/object:Gem::Requirement
212
180
  requirements:
213
181
  - - ">="
@@ -221,49 +189,81 @@ dependencies:
221
189
  - !ruby/object:Gem::Version
222
190
  version: '0'
223
191
  - !ruby/object:Gem::Dependency
224
- name: kaminari
192
+ name: reform-rails
193
+ requirement: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - '='
196
+ - !ruby/object:Gem::Version
197
+ version: 0.1.7
198
+ type: :runtime
199
+ prerelease: false
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - '='
203
+ - !ruby/object:Gem::Version
204
+ version: 0.1.7
205
+ - !ruby/object:Gem::Dependency
206
+ name: rmagick
225
207
  requirement: !ruby/object:Gem::Requirement
226
208
  requirements:
227
209
  - - ">="
228
210
  - !ruby/object:Gem::Version
229
- version: '0'
211
+ version: 2.16.0
212
+ - - "~>"
213
+ - !ruby/object:Gem::Version
214
+ version: '2.16'
230
215
  type: :runtime
231
216
  prerelease: false
232
217
  version_requirements: !ruby/object:Gem::Requirement
233
218
  requirements:
234
219
  - - ">="
235
220
  - !ruby/object:Gem::Version
236
- version: '0'
221
+ version: 2.16.0
222
+ - - "~>"
223
+ - !ruby/object:Gem::Version
224
+ version: '2.16'
237
225
  - !ruby/object:Gem::Dependency
238
- name: reform
226
+ name: sass-rails
239
227
  requirement: !ruby/object:Gem::Requirement
240
228
  requirements:
229
+ - - "~>"
230
+ - !ruby/object:Gem::Version
231
+ version: '5.0'
241
232
  - - ">="
242
233
  - !ruby/object:Gem::Version
243
- version: '0'
234
+ version: 5.0.7
244
235
  type: :runtime
245
236
  prerelease: false
246
237
  version_requirements: !ruby/object:Gem::Requirement
247
238
  requirements:
239
+ - - "~>"
240
+ - !ruby/object:Gem::Version
241
+ version: '5.0'
248
242
  - - ">="
249
243
  - !ruby/object:Gem::Version
250
- version: '0'
244
+ version: 5.0.7
251
245
  - !ruby/object:Gem::Dependency
252
- name: pg_search
246
+ name: simple_form
253
247
  requirement: !ruby/object:Gem::Requirement
254
248
  requirements:
255
249
  - - ">="
256
250
  - !ruby/object:Gem::Version
257
- version: '0'
251
+ version: 3.5.0
252
+ - - "~>"
253
+ - !ruby/object:Gem::Version
254
+ version: '3.5'
258
255
  type: :runtime
259
256
  prerelease: false
260
257
  version_requirements: !ruby/object:Gem::Requirement
261
258
  requirements:
262
259
  - - ">="
263
260
  - !ruby/object:Gem::Version
264
- version: '0'
261
+ version: 3.5.0
262
+ - - "~>"
263
+ - !ruby/object:Gem::Version
264
+ version: '3.5'
265
265
  - !ruby/object:Gem::Dependency
266
- name: rspec-rails
266
+ name: factory_bot_rails
267
267
  requirement: !ruby/object:Gem::Requirement
268
268
  requirements:
269
269
  - - ">="
@@ -277,7 +277,7 @@ dependencies:
277
277
  - !ruby/object:Gem::Version
278
278
  version: '0'
279
279
  - !ruby/object:Gem::Dependency
280
- name: pry
280
+ name: pg
281
281
  requirement: !ruby/object:Gem::Requirement
282
282
  requirements:
283
283
  - - ">="
@@ -291,7 +291,7 @@ dependencies:
291
291
  - !ruby/object:Gem::Version
292
292
  version: '0'
293
293
  - !ruby/object:Gem::Dependency
294
- name: pg
294
+ name: pry
295
295
  requirement: !ruby/object:Gem::Requirement
296
296
  requirements:
297
297
  - - ">="
@@ -305,7 +305,7 @@ dependencies:
305
305
  - !ruby/object:Gem::Version
306
306
  version: '0'
307
307
  - !ruby/object:Gem::Dependency
308
- name: factory_bot_rails
308
+ name: rspec-rails
309
309
  requirement: !ruby/object:Gem::Requirement
310
310
  requirements:
311
311
  - - ">="
@@ -353,6 +353,10 @@ files:
353
353
  - app/uploaders/photo_uploader.rb
354
354
  - app/views/tramway/core/shared/_input_extended.html.haml
355
355
  - app/views/tramway/core/shared/_messages.html.haml
356
+ - app/views/tramway/core/shared/input_extended_types/_checkbox.html.haml
357
+ - app/views/tramway/core/shared/input_extended_types/_select.html.haml
358
+ - app/views/tramway/core/shared/input_extended_types/_simple.html.haml
359
+ - app/views/tramway/core/shared/input_extended_types/_yes_no.html.haml
356
360
  - config/initializers/assets.rb
357
361
  - config/initializers/carrierwave.rb
358
362
  - config/initializers/plurals.rb