tramway-core 1.18.1.1 → 1.18.3.2
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 +20 -3
- data/app/controllers/tramway/core/application_controller.rb +4 -0
- data/app/decorators/tramway/core/application_decorator.rb +4 -0
- data/app/decorators/tramway/core/associations/class_helper.rb +7 -4
- data/app/decorators/tramway/core/associations/object_helper.rb +9 -1
- data/app/helpers/tramway/core/inputs/associations_helper.rb +2 -1
- data/app/helpers/tramway/core/inputs/polymorphic_associations_helper.rb +2 -1
- data/app/uploaders/ico_uploader.rb +7 -0
- data/lib/tramway/core/version.rb +1 -1
- data/lib/tramway/error.rb +1 -0
- metadata +5 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4642075ecb6eb14dd53a6c0c34da6089ca1e8ffac92baee5e750c8d3ca215c9
|
4
|
+
data.tar.gz: 496474d5bdb285a300f1d8877da45d68743b4527c4a1974915395406a798cd6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d0b406d85678d22316cef99327f517c3d9ee709519458a233ae9bacaac22a8a22afdea28a28379bcc37e2e81d2a841f862aff216531d066272e37612dff9365
|
7
|
+
data.tar.gz: f4fd66bbbecd7bea23b934208fc7b8e721e4bd9054bf5f67946be29eaa17cd854a25d0b303b5f792f388ebd137c70e48e60b5f9a4d00ed24eb9cb1bb5876f81a
|
data/README.md
CHANGED
@@ -46,6 +46,7 @@ Interface: `uploader(attribute_name, uploader_name, **options)`
|
|
46
46
|
* uploader_name - **short** uploader name. You need to connect uploaders which are compatible with Tramway. Available uploaders:
|
47
47
|
* :photo - you can see it [here](https://github.com/Purple-Magic/tramway-core/blob/develop/app/uploaders/photo_uploader.rb)
|
48
48
|
* :file - you can see it [here](https://github.com/Purple-Magic/tramway-core/blob/develop/app/uploaders/file_uploader.rb)
|
49
|
+
* :ico - you can see [here](https://github.com/Purple-Magic/tramway-core/blob/develop/app/uploaders/ico_uploader.rb)
|
49
50
|
* options - you are available to set options for uploaders exactly for this model. Available options:
|
50
51
|
* versions - **only for :photo**. Set needed versions for file to be cropped. If empty - 0 zero versions will be used. All versions you can see [here](https://github.com/Purple-Magic/tramway-core/blob/develop/app/uploaders/photo_uploader.rb)
|
51
52
|
* extensions - whitelist of file extensions. If empty will be used default whitelist from the uploaders (links above)
|
@@ -176,12 +177,28 @@ Something like this:
|
|
176
177
|
copy_to_clipboard "some_id" # some_id is HTML id of element. Content of this element will be copied to the clipboard after pressing the button
|
177
178
|
```
|
178
179
|
|
179
|
-
|
180
|
+
# Every Tramway application need initialized @application object (or if you create Tramway plugin, it should be @application_engine object).
|
181
|
+
|
182
|
+
You don't need to initialize this object yourself, just configurate application with Tramway. You have **2** options of this:
|
183
|
+
|
184
|
+
## Option 1. If you want to change @application object just in the code base.
|
185
|
+
|
186
|
+
```shell
|
187
|
+
rails g tramway:core:application
|
188
|
+
```
|
189
|
+
|
190
|
+
*config/initializers/tramway.rb*
|
191
|
+
|
192
|
+
```ruby
|
193
|
+
Tramway::Core.initialize_application name: :your_application_name
|
194
|
+
```
|
195
|
+
|
196
|
+
## Option 2. If you want to change @application object from admin panel. How to create model that will be an Application Model for the Tramway
|
180
197
|
|
181
198
|
#### 1. Generate model that you to use. We create Organization, for example
|
182
199
|
|
183
200
|
```shell
|
184
|
-
rails g
|
201
|
+
rails g tramway:core:application
|
185
202
|
rails db:migrate
|
186
203
|
```
|
187
204
|
|
@@ -195,7 +212,7 @@ Tramway::Core.initialize_application model_class: Organization
|
|
195
212
|
|
196
213
|
```ruby
|
197
214
|
rails c
|
198
|
-
Organization.create! public_name: 'Tramway', name: :organization, tagline: 'Tramway is not buggy, LOL!'
|
215
|
+
Organization.create! public_name: 'Tramway', name: :organization, tagline: 'Tramway is not buggy, LOL!', main_image: 'https://raw.githubusercontent.com/ulmic/tramway-dev/develop/logo.png'
|
199
216
|
```
|
200
217
|
|
201
218
|
#### 4. Add model to singleton to the `tramway-admin` admin panel to be able to change its data
|
@@ -15,4 +15,8 @@ class Tramway::Core::ApplicationController < ActionController::Base
|
|
15
15
|
def model_class
|
16
16
|
params[:model].constantize
|
17
17
|
end
|
18
|
+
|
19
|
+
def authenticated_user
|
20
|
+
(defined?(current_user) && current_user.try(:model)) || (defined?(current_admin) && current_admin.model)
|
21
|
+
end
|
18
22
|
end
|
@@ -29,14 +29,17 @@ module Tramway::Core::Associations::ClassHelper
|
|
29
29
|
def define_main_association_method(association_name, decorator)
|
30
30
|
define_method association_name do
|
31
31
|
association = object.class.reflect_on_association(association_name)
|
32
|
-
|
32
|
+
type = association_type(association)
|
33
|
+
return if association_has_one_without_object(object, association_name, type)
|
33
34
|
|
34
35
|
check_association object, association_name, association
|
35
36
|
decorator_class_name = decorator || decorator_class_name(class_name(association))
|
36
|
-
|
37
|
-
|
37
|
+
case type
|
38
|
+
when :has_many, :has_and_belongs_to_many
|
39
|
+
associations_collection(object, association_name, decorator_class_name)
|
40
|
+
when :belongs_to, :has_one
|
41
|
+
decorator_class_name.decorate(association_object(object, association_name))
|
38
42
|
end
|
39
|
-
return decorator_class_name.decorate object.send association_name if association_type(association).in? [ :belongs_to, :has_one ]
|
40
43
|
end
|
41
44
|
end
|
42
45
|
end
|
@@ -40,11 +40,19 @@ module Tramway::Core::Associations::ObjectHelper
|
|
40
40
|
|
41
41
|
begin
|
42
42
|
form_class.constantize
|
43
|
-
rescue
|
43
|
+
rescue StandardError
|
44
44
|
Tramway::Error.raise_error(
|
45
45
|
:tramway, :core, :associations, :object_helper, :habtm_add_class_not_defined,
|
46
46
|
class: form_class, association_name: association_name
|
47
47
|
)
|
48
48
|
end
|
49
49
|
end
|
50
|
+
|
51
|
+
def association_has_one_without_object(object, association_name, association_type)
|
52
|
+
association_type == :has_one && object.send(association_name).nil?
|
53
|
+
end
|
54
|
+
|
55
|
+
def association_object(object, association_name)
|
56
|
+
object.send association_name
|
57
|
+
end
|
50
58
|
end
|
@@ -2,9 +2,10 @@
|
|
2
2
|
|
3
3
|
module Tramway::Core::Inputs::AssociationsHelper
|
4
4
|
def build_collection_for_association(form_object, property)
|
5
|
+
user = defined?(current_user) ? current_user : current_admin
|
5
6
|
full_class_name_association = form_object.class.full_class_name_association(property)
|
6
7
|
check_valid_association full_class_name_association
|
7
|
-
full_class_name_association.active.send("#{
|
8
|
+
full_class_name_association.active.send("#{user.role}_scope", user.id).map do |obj|
|
8
9
|
decorator_class(full_class_name_association).decorate obj
|
9
10
|
end.sort_by(&:name)
|
10
11
|
end
|
@@ -2,8 +2,9 @@
|
|
2
2
|
|
3
3
|
module Tramway::Core::Inputs::PolymorphicAssociationsHelper
|
4
4
|
def build_collection_for_polymorphic_association(form_object, property)
|
5
|
+
user = defined?(current_user) ? current_user : current_admin
|
5
6
|
object_names = full_class_names(form_object, property).map do |class_name|
|
6
|
-
class_name.active.send("#{
|
7
|
+
class_name.active.send("#{user.role}_scope", user.id).map do |obj|
|
7
8
|
decorator_class(class_name).decorate obj
|
8
9
|
end
|
9
10
|
end.flatten
|
data/lib/tramway/core/version.rb
CHANGED
data/lib/tramway/error.rb
CHANGED
@@ -22,6 +22,7 @@ class Tramway::Error < RuntimeError
|
|
22
22
|
@errors ||= YAML.load_file("#{Tramway::Core.root}/yaml/errors.yml").with_indifferent_access
|
23
23
|
error = @errors.dig(*coordinates)
|
24
24
|
raise 'Error is not defined in YAML' unless error
|
25
|
+
|
25
26
|
options.each do |pair|
|
26
27
|
error.gsub!("%{#{pair[0]}}", pair[1].to_s)
|
27
28
|
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.18.
|
4
|
+
version: 1.18.3.2
|
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-
|
12
|
+
date: 2020-07-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: audited
|
@@ -119,22 +119,16 @@ dependencies:
|
|
119
119
|
name: haml-rails
|
120
120
|
requirement: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '1.0'
|
125
122
|
- - ">="
|
126
123
|
- !ruby/object:Gem::Version
|
127
|
-
version:
|
124
|
+
version: '0'
|
128
125
|
type: :runtime
|
129
126
|
prerelease: false
|
130
127
|
version_requirements: !ruby/object:Gem::Requirement
|
131
128
|
requirements:
|
132
|
-
- - "~>"
|
133
|
-
- !ruby/object:Gem::Version
|
134
|
-
version: '1.0'
|
135
129
|
- - ">="
|
136
130
|
- !ruby/object:Gem::Version
|
137
|
-
version:
|
131
|
+
version: '0'
|
138
132
|
- !ruby/object:Gem::Dependency
|
139
133
|
name: kaminari
|
140
134
|
requirement: !ruby/object:Gem::Requirement
|
@@ -361,6 +355,7 @@ files:
|
|
361
355
|
- app/models/tramway/core/application_record.rb
|
362
356
|
- app/uploaders/application_uploader.rb
|
363
357
|
- app/uploaders/file_uploader.rb
|
358
|
+
- app/uploaders/ico_uploader.rb
|
364
359
|
- app/uploaders/image_defaults.rb
|
365
360
|
- app/uploaders/photo_uploader.rb
|
366
361
|
- app/views/tramway/core/404.haml
|