tramway-core 1.17.7.1 → 1.18
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 +4 -4
- data/README.md +1 -1
- data/app/forms/tramway/core/application_form.rb +14 -24
- data/app/forms/tramway/core/application_forms/association_class_helpers.rb +7 -0
- data/app/forms/tramway/core/application_forms/object_helpers.rb +4 -0
- data/app/forms/tramway/core/application_forms/submit_helper.rb +21 -0
- data/app/models/tramway/core/application_record.rb +9 -0
- data/app/uploaders/application_uploader.rb +11 -1
- data/app/uploaders/photo_uploader.rb +14 -17
- data/lib/tramway/core.rb +0 -1
- data/lib/tramway/core/application.rb +2 -1
- data/lib/tramway/core/version.rb +1 -1
- data/lib/yaml/errors.yml +1 -1
- metadata +4 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57bc94fcad00f60e39f4b5eb62b9c959a0739d3063d9ee3017349c9ef8e91c04
|
4
|
+
data.tar.gz: 4b11029d70b3dd9f45bfc7ec4e73fc8fb4b3f9ae60eec90756431ab92d611aa7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6955a32c4a63a19ea949694636d64b7725aa571fc601e213276e67555ac8300bea5bbff4ca3c9337eeba9e8001dcf40b4b9dda4ca6e7bb6f0ab1d2d1d13cb2f5
|
7
|
+
data.tar.gz: cad297b01c90cff4e6a66048cec29e39faba8744ec4148ddf6d1e1fcf80775974bc361414ea8dc05c4788749e87d8cef5ec39832dc150d32e9f80704b8d4d100
|
data/README.md
CHANGED
@@ -157,7 +157,7 @@ copy_to_clipboard "some_id" # some_id is HTML id of element. Content of this ele
|
|
157
157
|
#### 1. Generate model that you to use. We create Organization, for example
|
158
158
|
|
159
159
|
```shell
|
160
|
-
rails g model organization name:text public_name:text tagline:text address:text phone:text coordinates:point, state: text # remember! State field is required, if you use tramway-admin
|
160
|
+
rails g model organization name:text public_name:text tagline:text address:text phone:text coordinates:point, state: text, favicon:text # remember! State field is required, if you use tramway-admin
|
161
161
|
rails db:migrate
|
162
162
|
```
|
163
163
|
|
@@ -1,16 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
class Tramway::Core::ApplicationForm
|
3
|
+
class Tramway::Core::ApplicationForm
|
4
4
|
include Tramway::Core::ApplicationForms::AssociationObjectHelpers
|
5
5
|
include Tramway::Core::ApplicationForms::ConstantObjectActions
|
6
6
|
include Tramway::Core::ApplicationForms::PropertiesObjectHelper
|
7
7
|
include Tramway::Core::ApplicationForms::ObjectHelpers
|
8
|
+
include Tramway::Core::ApplicationForms::SubmitHelper
|
8
9
|
|
9
10
|
attr_accessor :submit_message
|
10
11
|
|
11
12
|
def initialize(object = nil)
|
12
|
-
|
13
|
-
|
13
|
+
tap do
|
14
|
+
@object = object
|
14
15
|
@@model_class = object.class
|
15
16
|
@@enumerized_attributes = object.class.try :enumerized_attributes
|
16
17
|
@@associations ||= []
|
@@ -23,14 +24,6 @@ class Tramway::Core::ApplicationForm < ::Reform::Form
|
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
26
|
-
def submit(params)
|
27
|
-
if params
|
28
|
-
validate(params) ? save : collecting_associations_errors
|
29
|
-
else
|
30
|
-
Tramway::Error.raise_error(:tramway, :core, :application_form, :submit, :params_should_not_be_nil)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
27
|
def model_name
|
35
28
|
@@model_class.model_name
|
36
29
|
end
|
@@ -40,19 +33,25 @@ class Tramway::Core::ApplicationForm < ::Reform::Form
|
|
40
33
|
end
|
41
34
|
|
42
35
|
class << self
|
36
|
+
include Tramway::Core::ApplicationForms::AssociationClassHelpers
|
43
37
|
include Tramway::Core::ApplicationForms::ConstantClassActions
|
44
38
|
|
45
39
|
delegate :defined_enums, to: :model_class
|
46
40
|
|
41
|
+
def properties(*props)
|
42
|
+
@@properties ||= []
|
43
|
+
@@properties += props
|
44
|
+
props.each do |prop|
|
45
|
+
delegate prop, to: :model
|
46
|
+
define_method("#{prop}=") { |value| model.send "#{prop}=", value }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
47
50
|
def association(property)
|
48
51
|
properties property
|
49
52
|
@@associations = ((defined?(@@associations) && @@associations) || []) + [property]
|
50
53
|
end
|
51
54
|
|
52
|
-
def associations(*properties)
|
53
|
-
properties.each { |property| association property }
|
54
|
-
end
|
55
|
-
|
56
55
|
def full_class_name_associations
|
57
56
|
@@associations&.reduce({}) do |hash, association|
|
58
57
|
options = @@model_class.reflect_on_all_associations(:belongs_to).select do |a|
|
@@ -113,13 +112,4 @@ class Tramway::Core::ApplicationForm < ::Reform::Form
|
|
113
112
|
model.send("#{association}=", send(association)) if errors.details[association] == [{ error: :blank }]
|
114
113
|
end
|
115
114
|
end
|
116
|
-
|
117
|
-
def save
|
118
|
-
super
|
119
|
-
rescue ArgumentError => e
|
120
|
-
Tramway::Error.raise_error :tramway, :core, :application_form, :save, :argument_error, message: e.message
|
121
|
-
rescue StandardError => e
|
122
|
-
Tramway::Error.raise_error :tramway, :core, :application_form, :save, :looks_like_you_have_method,
|
123
|
-
method_name: e.name.to_s.gsub('=', ''), model_class: @@model_class, class_name: self.class
|
124
|
-
end
|
125
115
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tramway::Core::ApplicationForms::SubmitHelper
|
4
|
+
def submit(params)
|
5
|
+
if params
|
6
|
+
params.each { |key, value| send("#{key}=", value) }
|
7
|
+
save || collecting_associations_errors
|
8
|
+
else
|
9
|
+
Tramway::Error.raise_error(:tramway, :core, :application_form, :submit, :params_should_not_be_nil)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def save
|
14
|
+
model.save
|
15
|
+
rescue ArgumentError => e
|
16
|
+
Tramway::Error.raise_error :tramway, :core, :application_form, :save, :argument_error, message: e.message
|
17
|
+
rescue StandardError => e
|
18
|
+
Tramway::Error.raise_error :tramway, :core, :application_form, :save, :looks_like_you_have_method,
|
19
|
+
method_name: e.name.to_s.gsub('=', ''), model_class: @@model_class, class_name: self.class
|
20
|
+
end
|
21
|
+
end
|
@@ -42,6 +42,15 @@ class Tramway::Core::ApplicationRecord < ActiveRecord::Base
|
|
42
42
|
def search_by(*attributes, **associations)
|
43
43
|
pg_search_scope :full_text_search, against: attributes, associated_against: associations
|
44
44
|
end
|
45
|
+
|
46
|
+
def uploader(attribute_name, uploader_name, **options)
|
47
|
+
mount_uploader attribute_name, "#{uploader_name.to_s.camelize}Uploader".constantize
|
48
|
+
@versions = options[:versions] if uploader_name == :photo
|
49
|
+
end
|
50
|
+
|
51
|
+
def photo_versions
|
52
|
+
@versions
|
53
|
+
end
|
45
54
|
end
|
46
55
|
|
47
56
|
# FIXME: detect inhertited locales
|
@@ -6,6 +6,16 @@ class ApplicationUploader < CarrierWave::Uploader::Base
|
|
6
6
|
storage :file
|
7
7
|
|
8
8
|
def store_dir
|
9
|
-
"system/uploads/#{model.class.model_name.to_s.underscore}/#{mounted_as}/#{
|
9
|
+
"system/uploads/#{model.class.model_name.to_s.underscore}/#{mounted_as}/#{id_directory}"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def id_directory
|
15
|
+
if model.respond_to?(:uuid)
|
16
|
+
model.reload unless model.uuid.present?
|
17
|
+
else
|
18
|
+
model.id
|
19
|
+
end
|
10
20
|
end
|
11
21
|
end
|
@@ -20,29 +20,14 @@ class PhotoUploader < ApplicationUploader
|
|
20
20
|
super && width.present? && height.present?
|
21
21
|
end
|
22
22
|
|
23
|
-
version :medium do
|
23
|
+
version :medium, if: :medium_version_is_needed? do
|
24
24
|
process resize_to_fill: [400, 400]
|
25
25
|
end
|
26
26
|
|
27
|
-
version :small do
|
27
|
+
version :small, if: :small_version_is_needed? do
|
28
28
|
process resize_to_fill: [100, 100]
|
29
29
|
end
|
30
30
|
|
31
|
-
# FIXME: move to tramway-landing uploader
|
32
|
-
version :card do
|
33
|
-
process resize_to_fill: [400, 400, 'North']
|
34
|
-
end
|
35
|
-
|
36
|
-
# FIXME: move to tramway-landing uploader
|
37
|
-
version :horizontal do
|
38
|
-
process resize_to_fill: [800, 350, 'North']
|
39
|
-
end
|
40
|
-
|
41
|
-
# FIXME: move to tramway-landing uploader
|
42
|
-
version :mini do
|
43
|
-
process resize_to_limit: [300, nil]
|
44
|
-
end
|
45
|
-
|
46
31
|
attr_reader :width, :height
|
47
32
|
|
48
33
|
before :cache, :capture_size
|
@@ -58,4 +43,16 @@ class PhotoUploader < ApplicationUploader
|
|
58
43
|
@width, @height = `identify -format "%wx %h" #{file.path}`.split(/x/).map(&:to_i)
|
59
44
|
end
|
60
45
|
end
|
46
|
+
|
47
|
+
def medium_version_is_needed?(_new_file)
|
48
|
+
version_is_needed? :medium
|
49
|
+
end
|
50
|
+
|
51
|
+
def small_version_is_needed?(_new_file)
|
52
|
+
version_is_needed? :small
|
53
|
+
end
|
54
|
+
|
55
|
+
def version_is_needed?(version)
|
56
|
+
model.class.photo_versions&.include? version
|
57
|
+
end
|
61
58
|
end
|
data/lib/tramway/core.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Tramway::Core::Application
|
4
|
-
attr_accessor :name, :url, :model_class, :title, :tagline, :found_date, :phone, :email, :main_image, :favicon
|
4
|
+
attr_accessor :name, :url, :model_class, :title, :tagline, :found_date, :phone, :email, :main_image, :favicon,
|
5
|
+
:short_description
|
5
6
|
|
6
7
|
def public_name
|
7
8
|
name.to_s.gsub('_', ' ').camelize
|
data/lib/tramway/core/version.rb
CHANGED
data/lib/yaml/errors.yml
CHANGED
@@ -35,6 +35,6 @@ tramway:
|
|
35
35
|
attributes:
|
36
36
|
method_is_reserved_word: "Method `%{attribute_name}` is reserved word. Please, create or delegate method in %{class_name} with another name."
|
37
37
|
title:
|
38
|
-
please_implement_title: "Please, implement `title` method in a %{class_name} or %{object_class}"
|
38
|
+
please_implement_title: "Please, implement `title` method in a %{class_name} or delegate it to %{object_class}"
|
39
39
|
link:
|
40
40
|
method_link_uses_file_attribute: "Method `link` uses `file` attribute of the decorated object. If decorated object doesn't contain `file`, you shouldn't use `link` method."
|
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.
|
4
|
+
version: '1.18'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Kalashnikov
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-04-
|
12
|
+
date: 2020-04-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: audited
|
@@ -197,34 +197,6 @@ dependencies:
|
|
197
197
|
- - ">="
|
198
198
|
- !ruby/object:Gem::Version
|
199
199
|
version: '0'
|
200
|
-
- !ruby/object:Gem::Dependency
|
201
|
-
name: reform
|
202
|
-
requirement: !ruby/object:Gem::Requirement
|
203
|
-
requirements:
|
204
|
-
- - ">="
|
205
|
-
- !ruby/object:Gem::Version
|
206
|
-
version: '0'
|
207
|
-
type: :runtime
|
208
|
-
prerelease: false
|
209
|
-
version_requirements: !ruby/object:Gem::Requirement
|
210
|
-
requirements:
|
211
|
-
- - ">="
|
212
|
-
- !ruby/object:Gem::Version
|
213
|
-
version: '0'
|
214
|
-
- !ruby/object:Gem::Dependency
|
215
|
-
name: reform-rails
|
216
|
-
requirement: !ruby/object:Gem::Requirement
|
217
|
-
requirements:
|
218
|
-
- - '='
|
219
|
-
- !ruby/object:Gem::Version
|
220
|
-
version: 0.1.7
|
221
|
-
type: :runtime
|
222
|
-
prerelease: false
|
223
|
-
version_requirements: !ruby/object:Gem::Requirement
|
224
|
-
requirements:
|
225
|
-
- - '='
|
226
|
-
- !ruby/object:Gem::Version
|
227
|
-
version: 0.1.7
|
228
200
|
- !ruby/object:Gem::Dependency
|
229
201
|
name: rmagick
|
230
202
|
requirement: !ruby/object:Gem::Requirement
|
@@ -362,11 +334,13 @@ files:
|
|
362
334
|
- app/decorators/tramway/core/concerns/attributes_decorator_helper.rb
|
363
335
|
- app/decorators/tramway/core/delegating/class_helper.rb
|
364
336
|
- app/forms/tramway/core/application_form.rb
|
337
|
+
- app/forms/tramway/core/application_forms/association_class_helpers.rb
|
365
338
|
- app/forms/tramway/core/application_forms/association_object_helpers.rb
|
366
339
|
- app/forms/tramway/core/application_forms/constant_class_actions.rb
|
367
340
|
- app/forms/tramway/core/application_forms/constant_object_actions.rb
|
368
341
|
- app/forms/tramway/core/application_forms/object_helpers.rb
|
369
342
|
- app/forms/tramway/core/application_forms/properties_object_helper.rb
|
343
|
+
- app/forms/tramway/core/application_forms/submit_helper.rb
|
370
344
|
- app/forms/tramway/core/extendable_form.rb
|
371
345
|
- app/forms/tramway/core/extendable_forms_helpers/class_builder.rb
|
372
346
|
- app/forms/tramway/core/extendable_forms_helpers/ignored_properties_helper.rb
|