tramway-core 1.5.5.2 → 1.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e8703832cc6c58c0f12a36a5d54ca98d3a720678c2808c8c72726a2d148e1b2
4
- data.tar.gz: dbeaae9bd58c6279c3ad4579696452ba1f643b469810a81151a866390e5cdfff
3
+ metadata.gz: a7e6b600208a0aac1aac49df14d744385891acb532898ecf27dbac1cab935c40
4
+ data.tar.gz: cbe160a3e54769372c33a1c890e79cd47335cc245715648688f3b9ea8a6f6210
5
5
  SHA512:
6
- metadata.gz: c321c73b6818ca94ceded5f3a27196684b33b74e0d864bdd98222210f87e0a2ccbb35d9e2f8f6c4f26228dab1c2a7e3ada6b6be1f255b46a996cdee6fdd9fa23
7
- data.tar.gz: 17da4f4e51a4219c955daa841686c302762867aa03e1786afe4beb514d25a5c09253b44381d29cbb712c9c302592983e1368a342efbbc1b065a1f6a05d01dfc5
6
+ metadata.gz: c8619069ed2f4b3f01aad7a0521e1f1c8d8aa6f657da86520e875eeb06f7bf517e15e6d371cc06397f7dd40002e6ed03e95fea6707e61379c7b6b7f532df2212
7
+ data.tar.gz: a14f0760eccb8d942547e3e35028537c314f474c15944d1f1bf4d201d7dcf429156de1cf5f30206f2f7629b376f8ee189866cdc2ca97c0a40c480b3180742d84
@@ -2,6 +2,9 @@ module Tramway::Core
2
2
  class ApplicationForm < ::Reform::Form
3
3
  def initialize(object)
4
4
  super(object).tap do
5
+ @@model_class = object.class
6
+ @@enumerized_attributes = object.class.enumerized_attributes
7
+
5
8
  @@associations&.each do |association|
6
9
  options = object.class.reflect_on_all_associations(:belongs_to).select do |a|
7
10
  a.name == association.to_sym
@@ -26,7 +29,7 @@ module Tramway::Core
26
29
  end
27
30
 
28
31
  def properties
29
- @form_properties
32
+ @form_properties || []
30
33
  end
31
34
 
32
35
  class << self
@@ -35,6 +38,14 @@ module Tramway::Core
35
38
  @@associations ||= []
36
39
  @@associations << property
37
40
  end
41
+
42
+ def enumerized_attributes
43
+ @@enumerized_attributes
44
+ end
45
+
46
+ def reflect_on_association(*args)
47
+ @@model_class.reflect_on_association(*args)
48
+ end
38
49
  end
39
50
  end
40
51
  end
@@ -1,6 +1,6 @@
1
1
  class Tramway::Core::ExtendableForm
2
2
  class << self
3
- def new(name, *more_properties)
3
+ def new(name, **more_properties)
4
4
  if Object.const_defined? name
5
5
  name.constantize
6
6
  else
@@ -13,9 +13,17 @@ class Tramway::Core::ExtendableForm
13
13
  super params
14
14
  end
15
15
 
16
+ define_method 'properties' do
17
+ more_properties.reduce({}) do |hash, property|
18
+ hash.merge! property[0] => {
19
+ extended_form_property: property[1]
20
+ }
21
+ end
22
+ end
23
+
16
24
  more_properties.each do |property|
17
- define_method property do
18
- model.values[property] if model.values
25
+ define_method property[0] do
26
+ model.values[property[0]] if model.values
19
27
  end
20
28
  end
21
29
  end)
@@ -0,0 +1,5 @@
1
+ class Tramway::Core::FormCreator
2
+ def self.create_form_class
3
+ raise 'Please, implement `create_form_class` for your class'
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ - value = defined?(value).present? ? value : ''
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}]" }
8
+ - when 'select'
9
+ - parsed_json = JSON.parse(field.options) unless field.options == ''
10
+ - if parsed_json && parsed_json['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}]" }
@@ -1,5 +1,5 @@
1
1
  module Tramway
2
2
  module Core
3
- VERSION = '1.5.5.2'
3
+ VERSION = '1.6'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tramway-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.5.2
4
+ version: '1.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov
@@ -227,12 +227,14 @@ files:
227
227
  - app/decorators/tramway/core/application_decorator.rb
228
228
  - app/forms/tramway/core/application_form.rb
229
229
  - app/forms/tramway/core/extendable_form.rb
230
+ - app/forms/tramway/core/form_creator.rb
230
231
  - app/inputs/date_picker_input.rb
231
232
  - app/models/tramway/core/application_record.rb
232
233
  - app/uploaders/application_uploader.rb
233
234
  - app/uploaders/file_uploader.rb
234
235
  - app/uploaders/image_defaults.rb
235
236
  - app/uploaders/photo_uploader.rb
237
+ - app/views/tramway/core/shared/_input_extended.html.haml
236
238
  - app/views/tramway/core/shared/_messages.html.haml
237
239
  - config/initializers/assets.rb
238
240
  - config/locales/ru/dates.yml
@@ -250,7 +252,6 @@ files:
250
252
  - lib/tramway/core/generators/templates/initializers/simple_form.rb
251
253
  - lib/tramway/core/generators/templates/initializers/simple_form_bootstrap.rb
252
254
  - lib/tramway/core/version.rb
253
- - lib/tramway/generators/install_generator.rb
254
255
  homepage: https://github.com/kalashnikovisme/tramway-core
255
256
  licenses:
256
257
  - MIT
@@ -1,25 +0,0 @@
1
- require 'rails/generators'
2
-
3
- module Tramway
4
- module Core
5
- module Generators
6
- class InstallGenerator < ::Rails::Generators::Base
7
- source_root File.expand_path('../templates', __FILE__)
8
-
9
- def run_other_generators
10
- generate 'audited:install'
11
- end
12
-
13
- def self.next_migration_number(path)
14
- next_migration_number = current_migration_number(path) + 1
15
- ActiveRecord::Migration.next_migration_number next_migration_number
16
- end
17
-
18
- def copy_initializer
19
- copy_file "/#{File.dirname __dir__}/generators/templates/initializers/simple_form.rb", 'config/initializers/simple_form.rb'
20
- copy_file "/#{File.dirname __dir__}/generators/templates/initializers/simple_form_bootstrap.rb", 'config/initializers/simple_form_bootstrap.rb'
21
- end
22
- end
23
- end
24
- end
25
- end