tramway-core 1.18.5.1 → 2.0.0.1

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: d6cfb3174c3fd183a2fed510756d21cf1057704a37d0321972e6a22efe6c5520
4
- data.tar.gz: 5b198f9d8033d27f17eba26c260b1c3b0300067d44f1bc621f251f65d054c84b
3
+ metadata.gz: 00bb04a9c6afb2c0803e4b0d8ee009ce9af3b511564793933c1e21862345fe16
4
+ data.tar.gz: f2b70d7ee88943a6e134764fc582830d46fbcc78eda2712e6974c5887432bfe6
5
5
  SHA512:
6
- metadata.gz: dad0b1593ae99e4428b1e35bfb55089203035290bfd3b328a2e339d9a6be1e1ed3af7ad8cc3626931ea2154a300b48eafb431e559aade167366ce30bdefb1ef6
7
- data.tar.gz: 41d2def3e83a4676d87dd1792a4a749586889fd716f02aeb75c6a909c2423d12733a984622896e31f64898e08e718c24b8f118f3674f773548188d0d627d5c8c
6
+ metadata.gz: 49ec7b81fa82bf40b32f32d2a716f5affbbb7428b2934506697d6f3a79c9f34b2a849570e9f90b09da27af79738422748ec98ca5a576c71295b64dfe1415f93f
7
+ data.tar.gz: e623ac3c3a5e189459d5144a3227807ea4229eb6b5a54c49b65177c0da5d4c60d463e545c19f9459c3f25c1f22d0acef25ca8011171f84ce616d1e54ce155d5b
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Tramway::Core ![Ruby](https://github.com/Purple-Magic/tramway-core/workflows/Tests/badge.svg) ![Ruby](https://github.com/Purple-Magic/tramway-core/workflows/Rubocop/badge.svg) [![Gem Version](https://badge.fury.io/rb/tramway-core.svg)](https://badge.fury.io/rb/tramway-core)
1
+ # ![tramway-ico](https://raw.githubusercontent.com/kalashnikovisme/kalashnikovisme/master/%D1%82%D1%80%D1%8D%D0%BC%D0%B2%D1%8D%D0%B9%D0%B1%D0%B5%D0%B7%D1%84%D0%BE%D0%BD%D0%B0-min.png) Tramway::Core ![Ruby](https://github.com/Purple-Magic/tramway-core/workflows/Tests/badge.svg) ![Ruby](https://github.com/Purple-Magic/tramway-core/workflows/Rubocop/badge.svg) [![Gem Version](https://badge.fury.io/rb/tramway-core.svg)](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: "Your application's 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
- ### Workflow
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.state_machines.keys.map(&:to_s)
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.send "human_#{attribute_name}_name"
13
+ I18n.t("state_machines.#{object.class.model_name.to_s.underscore}.#{attribute_name}.states.#{object.send(attribute_name)}")
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
- Tramway::Error.raise_error :tramway, :core, :application_form, :save, :looks_like_you_have_method,
22
- method_name: e.name.to_s.gsub('=', ''), model_class: @@model_class, class_name: self.class
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.state_machines.keys.include?(property[0])
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
- state_machine :state, initial: :active do
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
- transition active: :removed
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.user
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tramway
4
4
  module Core
5
- VERSION = '1.18.5.1'
5
+ VERSION = '2.0.0.1'
6
6
  end
7
7
  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.5.1
4
+ version: 2.0.0.1
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-09-17 00:00:00.000000000 Z
12
+ date: 2021-02-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: audited