tramway-core 1.15.1 → 1.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ff76332aa909eb5a15e3e5bec7ac91800b7d8b3f739a9408e39ed1a03727486
4
- data.tar.gz: b95e3167b3a5686559707b88d0959abc09d7165e6ef0d41987bbc8d1f1cee1b4
3
+ metadata.gz: b65406e59a86c298559e164d9e16a55b62f83b20ecba159b86b682aa9af037bc
4
+ data.tar.gz: 7a4177835f457e7b5c48f59c0980965c3c05052d75d3f52b2c1f7a9a4f270ca9
5
5
  SHA512:
6
- metadata.gz: 32ff27f78222c1373369fd055aa40334e881caab6da886d763dfaaab90d0b841d9fd24eb4360203e6e28fb368bbb8bd29f0de0f8978add292487447656fd680a
7
- data.tar.gz: a79db87f481d08debcd1ac67aaa2f0b3b044d74acac333836e313dfe76ae48990d638d508ee80bdfb2772bfcecd7ed346916863ca61e5b7a151583c3d27c9f10
6
+ metadata.gz: 480f307ce1de6c9202e5a9d42539df4f34b8374037c5d643ab61592374f592fddeb63890eb094e61ee6c667660088121feb0158bf7b374c605d3a3236ac4bf77
7
+ data.tar.gz: 5e96737dabbb4aace66cc0123ea1d59c0b7cd11aad65ce544153213394c359accd6544d6f3515dbbd4a98b5ec7d5639e4a2c208b79d3f452639630b5591ac919
data/README.md CHANGED
@@ -31,6 +31,55 @@ Tramway::Core.initialize_application model_class: ::Tramway::Conference::Unity #
31
31
  ```ruby
32
32
  Rails.application.config.assets.precompile += %w( *.jpg *.png *.js )
33
33
  ```
34
+ # Usage
35
+ ## Decorators
36
+ ### Helper methods
37
+
38
+ #### date_view
39
+ Returns a date in the format depending on localization
40
+
41
+ *app/decorators/\*_decorator.rb*
42
+ ```ruby
43
+ def created_at
44
+ date_view object.created_at
45
+ end
46
+ ```
47
+ #### datetime_view
48
+ Returns a date and time in the format depending on localization
49
+
50
+ *app/decorators/*_decorator.rb*
51
+ ```ruby
52
+ def created_at
53
+ datetime_view object.created_at
54
+ end
55
+ ```
56
+ #### state_machine_view
57
+ Returns the state of an object according to a state machine
58
+
59
+ *app/decorators/*_decorator.rb*
60
+ ```ruby
61
+ def state
62
+ state_machine_view object, :state
63
+ end
64
+ ```
65
+ #### image_view
66
+ Returns an image in a particular format depending on the parameters of the original image file
67
+
68
+ *app/decorators/\*_decorator.rb*
69
+ ```ruby
70
+ def avatar
71
+ image_view object.avatar
72
+ end
73
+ ```
74
+ #### enumerize_view
75
+ Returns object enumerations as text
76
+
77
+ *app/decorators/\*_decorator.rb*
78
+ ```ruby
79
+ def field_type
80
+ enumerize_view object.field_type
81
+ end
82
+ ```
34
83
 
35
84
  # Базовые классы
36
85
 
@@ -48,7 +48,7 @@ class Tramway::Core::ApplicationDecorator
48
48
  end
49
49
  end
50
50
 
51
- def decorate_association(association_name, decorator: nil)
51
+ def decorate_association(association_name, decorator: nil, as: nil)
52
52
  @@decorated_associations ||= []
53
53
  @@decorated_associations << association_name
54
54
 
@@ -77,6 +77,10 @@ class Tramway::Core::ApplicationDecorator
77
77
  return decorator_class_name.decorate object.send association_name
78
78
  end
79
79
  end
80
+
81
+ define_method "#{association_name}_as" do
82
+ as
83
+ end
80
84
  end
81
85
 
82
86
  def model_class
@@ -35,10 +35,10 @@ module Tramway::Core
35
35
  if validate params
36
36
  begin
37
37
  save.tap do
38
- #self.class.remove_validations_from_model!
38
+ # self.class.remove_validations_from_model!
39
39
  end
40
40
  rescue StandardError => e
41
- #self.class.remove_validations_from_model!
41
+ # self.class.remove_validations_from_model!
42
42
  error = Tramway::Error.new(plugin: :core, method: :submit, message: "Looks like you have method `#{e.name.to_s.gsub('=', '')}` in #{@@model_class}. You should rename it or rename property in #{self.class}")
43
43
  raise error.message
44
44
  end
@@ -51,11 +51,11 @@ module Tramway::Core
51
51
  end
52
52
  end
53
53
  (association_error && save).tap do
54
- #self.class.remove_validations_from_model!
54
+ # self.class.remove_validations_from_model!
55
55
  end
56
56
  end
57
57
  else
58
- #self.class.remove_validations_from_model!
58
+ # self.class.remove_validations_from_model!
59
59
  error = Tramway::Error.new(plugin: :core, method: :submit, message: 'ApplicationForm::Params should not be nil')
60
60
  raise error.message
61
61
  end
@@ -75,6 +75,7 @@ module Tramway::Core
75
75
 
76
76
  def properties
77
77
  return @form_properties if @form_properties
78
+
78
79
  yaml_config_file_path = Rails.root.join('app', 'forms', "#{self.class.name.underscore}.yml")
79
80
  if File.exist? yaml_config_file_path
80
81
  @form_properties = YAML.load_file(yaml_config_file_path).deep_symbolize_keys
@@ -165,17 +166,17 @@ module Tramway::Core
165
166
 
166
167
  def validates(attribute, **options)
167
168
  if !defined?(@@model_class) || @@model_class.nil?
168
- error = Tramway::Error.new(plugin: :core, method: :validates, message: "You need to set `model_class` name while using validations. Just write `self.model_class = YOUR_MODEL_NAME` in the class area.")
169
+ error = Tramway::Error.new(plugin: :core, method: :validates, message: 'You need to set `model_class` name while using validations. Just write `self.model_class = YOUR_MODEL_NAME` in the class area.')
169
170
  raise error.message
170
171
  end
171
172
  @@model_class.validates attribute, **options
172
- # @@validations ||= {}
173
- # @@validations.deep_merge! attribute => options
173
+ # @@validations ||= {}
174
+ # @@validations.deep_merge! attribute => options
174
175
  end
175
-
176
+
176
177
  # FIXME: Removes all validations in a field. We must implement own validations
177
-
178
- #def remove_validations_from_model!
178
+
179
+ # def remove_validations_from_model!
179
180
  # return unless defined? @@validations
180
181
  # @@validations&.each do |validation|
181
182
  # @@model_class.class_eval do
@@ -187,7 +188,7 @@ module Tramway::Core
187
188
  # end
188
189
  # end
189
190
  # end
190
- #end
191
+ # end
191
192
  end
192
193
  end
193
194
  end
@@ -40,7 +40,7 @@ class Tramway::Core::ExtendableForm
40
40
 
41
41
  case property[1][:object].field_type
42
42
  when 'file'
43
- field = property[1][:object]
43
+ field = property[1][:object]
44
44
  define_method "#{property[0]}=" do |value|
45
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
46
  file_instance.file = value
@@ -63,9 +63,7 @@ class Tramway::Core::ExtendableForm
63
63
 
64
64
  define_method :jsonb_ignored_properties do |properties|
65
65
  properties.map do |property|
66
- if property[1][:object].field_type == 'file'
67
- property[0].to_s
68
- end
66
+ property[0].to_s if property[1][:object].field_type == 'file'
69
67
  end.compact
70
68
  end
71
69
  end)
@@ -0,0 +1 @@
1
+ != @message
@@ -13,6 +13,7 @@ ru:
13
13
  search: Искать
14
14
  reset: Сбросить
15
15
  download: Скачать
16
+ add: Добавить
16
17
  scope:
17
18
  found: Найденные
18
19
  "yes": Да
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tramway
4
4
  module Core
5
- VERSION = '1.15.1'
5
+ VERSION = '1.16'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tramway-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.15.1
4
+ version: '1.16'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-20 00:00:00.000000000 Z
11
+ date: 2020-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: audited
@@ -353,6 +353,7 @@ files:
353
353
  - app/uploaders/file_uploader.rb
354
354
  - app/uploaders/image_defaults.rb
355
355
  - app/uploaders/photo_uploader.rb
356
+ - app/views/tramway/core/404.haml
356
357
  - app/views/tramway/core/shared/_input_extended.html.haml
357
358
  - app/views/tramway/core/shared/_messages.html.haml
358
359
  - app/views/tramway/core/shared/input_extended_types/_checkbox.html.haml