tramway-core 1.18.5 → 2.0
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 +67 -51
- data/app/decorators/tramway/core/attributes/view_helper.rb +3 -1
- data/app/decorators/tramway/core/concerns/attributes_decorator_helper.rb +7 -1
- data/app/forms/tramway/core/application_forms/submit_helper.rb +6 -2
- data/app/forms/tramway/core/extendable_forms_helpers/properties_helper.rb +1 -1
- data/app/helpers/tramway/core/title_helper.rb +1 -0
- data/app/models/tramway/core/application_record.rb +11 -5
- data/lib/tramway/core/generators.rb +5 -1
- data/lib/tramway/core/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc709cc658e3bb686e5cf2168db2563d04374053cb83d49b6a0b987971b86271
|
4
|
+
data.tar.gz: 3093efbf62bad2d3e8316dd5f98c0d642c4f384529bd9168b85b6651a31f04ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4b131aa515137b26623ff4e9b894ff7d754532b42952d8c39eb9193c1226e90e6008dd76f43e5e9af80a1ef4fe2fa062c1d9c7c43ac3c272b77776cc79a95ed
|
7
|
+
data.tar.gz: 4832bc73d550dd883c87f561c1227caa6e10d5ffe96a700654248eb58c5eade25ab7aed2814e585ac1c08d3ad2541f9a1251fed8727f6d8a8185e161cb4fc26a
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Tramway::Core   [](https://badge.fury.io/rb/tramway-core)
|
1
|
+
#  Tramway::Core   [](https://badge.fury.io/rb/tramway-core)
|
2
2
|
|
3
3
|
*If you need translation of this Readme, please message us kalashnikov@ulmic.ru. We'll translate for you and post to this page*
|
4
4
|
|
@@ -22,7 +22,7 @@ rails g tramway:core:install
|
|
22
22
|
*config/initializers/tramway.rb*
|
23
23
|
```ruby
|
24
24
|
# Initialize application with name
|
25
|
-
Tramway::Core.initialize_application name:
|
25
|
+
Tramway::Core.initialize_application name: :your_application_name
|
26
26
|
|
27
27
|
# Initialize application name with model_class. Model class must be a singlethon
|
28
28
|
Tramway::Core.initialize_application model_class: ::Tramway::Conference::Unity # example was taken from tramway-conference gem
|
@@ -32,6 +32,64 @@ Tramway::Core.initialize_application model_class: ::Tramway::Conference::Unity #
|
|
32
32
|
```ruby
|
33
33
|
Rails.application.config.assets.precompile += %w( *.jpg *.png *.js )
|
34
34
|
```
|
35
|
+
|
36
|
+
#### Every Tramway application need initialized @application object (or if you create Tramway plugin, it should be @application_engine object).
|
37
|
+
|
38
|
+
You don't need to initialize this object yourself, just configurate application with Tramway. You have **2** options of this:
|
39
|
+
|
40
|
+
## Option 1. If you want to change @application object just in the code base.
|
41
|
+
|
42
|
+
```shell
|
43
|
+
rails g tramway:core:install
|
44
|
+
```
|
45
|
+
|
46
|
+
*config/initializers/tramway.rb*
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
Tramway::Core.initialize_application name: :your_application_name
|
50
|
+
```
|
51
|
+
|
52
|
+
## 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
|
53
|
+
|
54
|
+
#### 1. Generate model that you to use. We create Organization, for example
|
55
|
+
|
56
|
+
```shell
|
57
|
+
rails g tramway:core:application
|
58
|
+
rails db:migrate
|
59
|
+
```
|
60
|
+
|
61
|
+
#### 2. Add model_class to Initializer
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
Tramway::Core.initialize_application model_class: Organization
|
65
|
+
```
|
66
|
+
|
67
|
+
#### 3. Create 1 instance of Organization model
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
rails c
|
71
|
+
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'
|
72
|
+
```
|
73
|
+
|
74
|
+
#### 4. Add model to singleton to the `tramway-admin` admin panel to be able to change its data
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
Tramway::Admin.set_singleton_models Organization, project: :organization # now you should use organization.name here
|
78
|
+
```
|
79
|
+
|
80
|
+
#### 5. Then continue configuration of your model in admin panel with tramway-admin gem [instruction, starting from point 8](https://github.com/ulmic/tramway-dev/tree/develop/tramway-admin#8-configurate-navbar)
|
81
|
+
|
82
|
+
#### 6. Now you are able to change your application main info in admin panel
|
83
|
+
|
84
|
+
## How-to
|
85
|
+
|
86
|
+
### add favicon to your application
|
87
|
+
|
88
|
+
*config/initializers/tramway.rb*
|
89
|
+
```ruby
|
90
|
+
::Tramway::Core.initialize_application attribute1: value, another_attribute: another_value, favicon: `/icon.ico` # icon should be in public folder
|
91
|
+
```
|
92
|
+
|
35
93
|
# Usage
|
36
94
|
|
37
95
|
## Tramway::Core::ApplicationRecord
|
@@ -177,54 +235,6 @@ Something like this:
|
|
177
235
|
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
|
178
236
|
```
|
179
237
|
|
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
|
197
|
-
|
198
|
-
#### 1. Generate model that you to use. We create Organization, for example
|
199
|
-
|
200
|
-
```shell
|
201
|
-
rails g tramway:core:application
|
202
|
-
rails db:migrate
|
203
|
-
```
|
204
|
-
|
205
|
-
#### 2. Add model_class to Initializer
|
206
|
-
|
207
|
-
```ruby
|
208
|
-
Tramway::Core.initialize_application model_class: Organization
|
209
|
-
```
|
210
|
-
|
211
|
-
#### 3. Create 1 instance of Organization model
|
212
|
-
|
213
|
-
```ruby
|
214
|
-
rails c
|
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'
|
216
|
-
```
|
217
|
-
|
218
|
-
#### 4. Add model to singleton to the `tramway-admin` admin panel to be able to change its data
|
219
|
-
|
220
|
-
```ruby
|
221
|
-
Tramway::Admin.set_singleton_models Organization, project: :organization # now you should use organization.name here
|
222
|
-
```
|
223
|
-
|
224
|
-
#### 5. Then continue configuration of your model in admin panel with tramway-admin gem [instruction, starting from point 8](https://github.com/ulmic/tramway-dev/tree/develop/tramway-admin#8-configurate-navbar)
|
225
|
-
|
226
|
-
#### 6. Now you are able to change your application main info in admin panel
|
227
|
-
|
228
238
|
## In Russian
|
229
239
|
|
230
240
|
# Базовые классы
|
@@ -251,7 +261,13 @@ Tramway::Admin.set_singleton_models Organization, project: :organization # now y
|
|
251
261
|
* [Pavel Kalashnikov](https://github.com/kalashnikovisme)
|
252
262
|
* [moshinaan](https://github.com/moshinaan)
|
253
263
|
|
254
|
-
###
|
264
|
+
### Run tests
|
265
|
+
|
266
|
+
```shell
|
267
|
+
make test
|
268
|
+
```
|
269
|
+
|
270
|
+
### Deployment workflow
|
255
271
|
|
256
272
|
#### If you don't have access to push gem to rubygems then
|
257
273
|
|
@@ -9,7 +9,7 @@ module Tramway::Core::Attributes::ViewHelper
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def state_machine?(object, attribute_name)
|
12
|
-
attribute_name.to_s.in? object.class.
|
12
|
+
attribute_name.to_s.in? object.class.state_machines_names.map(&:to_s)
|
13
13
|
end
|
14
14
|
|
15
15
|
def view_by_value(object, value, attribute)
|
@@ -21,6 +21,8 @@ module Tramway::Core::Attributes::ViewHelper
|
|
21
21
|
file_view(object.send(attribute[0]))
|
22
22
|
elsif value.is_a? Enumerize::Value
|
23
23
|
enumerize_view(value)
|
24
|
+
elsif value.is_a? Hash
|
25
|
+
yaml_view(value)
|
24
26
|
else
|
25
27
|
value
|
26
28
|
end
|
@@ -10,7 +10,9 @@ module Tramway::Core::Concerns::AttributesDecoratorHelper
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def state_machine_view(object, attribute_name)
|
13
|
-
object.
|
13
|
+
object.aasm(attribute_name).human_state
|
14
|
+
rescue
|
15
|
+
object.aasm.human_state
|
14
16
|
end
|
15
17
|
|
16
18
|
BASE64_REGEXP = %r{^(?:[a-zA-Z0-9+/]{4})*(?:|(?:[a-zA-Z0-9+/]{3}=)|
|
@@ -40,6 +42,10 @@ module Tramway::Core::Concerns::AttributesDecoratorHelper
|
|
40
42
|
value.text
|
41
43
|
end
|
42
44
|
|
45
|
+
def yaml_view(value)
|
46
|
+
content_tag(:pre) { value.to_yaml }
|
47
|
+
end
|
48
|
+
|
43
49
|
private
|
44
50
|
|
45
51
|
def src_thumb(original, thumb)
|
@@ -18,7 +18,11 @@ module Tramway::Core::ApplicationForms::SubmitHelper
|
|
18
18
|
rescue ArgumentError => e
|
19
19
|
Tramway::Error.raise_error :tramway, :core, :application_form, :save, :argument_error, message: e.message
|
20
20
|
rescue StandardError => e
|
21
|
-
|
22
|
-
|
21
|
+
if e.try :name
|
22
|
+
Tramway::Error.raise_error :tramway, :core, :application_form, :save, :looks_like_you_have_method,
|
23
|
+
method_name: e.name.to_s.gsub('=', ''), model_class: @@model_class, class_name: self.class
|
24
|
+
else
|
25
|
+
raise e
|
26
|
+
end
|
23
27
|
end
|
24
28
|
end
|
@@ -4,7 +4,7 @@ module Tramway::Core::ExtendableFormsHelpers::PropertiesHelper
|
|
4
4
|
def define_properties_method(simple_properties, more_properties)
|
5
5
|
define_method 'properties' do
|
6
6
|
hash = simple_properties.each_with_object({}) do |property, h|
|
7
|
-
h.merge! property[0] => property[1] unless model.class.
|
7
|
+
h.merge! property[0] => property[1] unless model.class.state_machines_names.include?(property[0])
|
8
8
|
end
|
9
9
|
more_properties.reduce(hash) do |h, property|
|
10
10
|
h.merge! property[0] => {
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
module Tramway::Core::TitleHelper
|
4
4
|
def title(page_title = default_title)
|
5
|
+
@application ||= Tramway::Core.application&.model_class&.first || Tramway::Core.application
|
5
6
|
if @application.present?
|
6
7
|
title_text = "#{page_title} | #{@application.try(:title) || @application.public_name}"
|
7
8
|
content_for(:title) { title_text }
|
@@ -6,13 +6,14 @@ class Tramway::Core::ApplicationRecord < ActiveRecord::Base
|
|
6
6
|
self.abstract_class = true
|
7
7
|
audited
|
8
8
|
extend ::Enumerize
|
9
|
+
include ::AASM
|
9
10
|
|
10
|
-
|
11
|
-
state :active
|
11
|
+
aasm column: :state do
|
12
|
+
state :active, initial: true
|
12
13
|
state :removed
|
13
14
|
|
14
15
|
event :remove do
|
15
|
-
|
16
|
+
transitions from: :active, to: :removed
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
@@ -20,12 +21,13 @@ class Tramway::Core::ApplicationRecord < ActiveRecord::Base
|
|
20
21
|
scope :created_by_user, lambda { |user_id|
|
21
22
|
joins(:audits).where('audits.action = \'create\' AND audits.user_id = ?', user_id)
|
22
23
|
}
|
23
|
-
scope :admin_scope, ->(_arg) { all }
|
24
|
+
scope :admin_scope, -> (_arg) { all }
|
24
25
|
|
25
26
|
include ::PgSearch::Model
|
26
27
|
|
27
28
|
def creator
|
28
|
-
audits.where(action: :create).first
|
29
|
+
creation_event = audits.where(action: :create).first
|
30
|
+
creation_event.user if creation_event.user_id.present?
|
29
31
|
end
|
30
32
|
|
31
33
|
# FIXME: detect inhertited locales
|
@@ -56,6 +58,10 @@ class Tramway::Core::ApplicationRecord < ActiveRecord::Base
|
|
56
58
|
def file_extensions
|
57
59
|
@extensions
|
58
60
|
end
|
61
|
+
|
62
|
+
def state_machines_names
|
63
|
+
AASM::StateMachineStore.fetch(self).machine_names
|
64
|
+
end
|
59
65
|
end
|
60
66
|
|
61
67
|
# FIXME: detect inhertited locales
|
data/lib/tramway/core/version.rb
CHANGED
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:
|
4
|
+
version: '2.0'
|
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:
|
12
|
+
date: 2021-02-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: audited
|