para 0.9.3.3 → 0.10.0

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: 8f742ef6484e0ccd595c1a79e219f4cb2a03c72a7fbf9f584990c638412f19e0
4
- data.tar.gz: 8c231925d6c2ecc4d0eb7208c5c4b530410d1a30d8a1276d849f31d3e52f5f76
3
+ metadata.gz: 7dcae0fffaaeae962449f4f7f1849fdcd8817529e9fd16bd2c8a285233dd5a39
4
+ data.tar.gz: f3f52c91b79d7b4d6a2c24dd6f0bf9d4b84bec53c280febc2e7c657b58e3796b
5
5
  SHA512:
6
- metadata.gz: e42df31fcb4d4d490f5b5127939494fbc9e07855ee1123fd720f089c2e36737b4e1f706b347d36699270ed00eeeb4a228ca81050bdc8ae35b84bbde8a7dfd7b6
7
- data.tar.gz: 707696ad2b1f6a2c43f6944f6543ca5dd8dd5a17c3c91942d0d3c38b43e5d2c652d1b76a35409c2de0019c11658f81a6922931d3e4126a6490a77ed189bd8e8a
6
+ metadata.gz: e13111ccd12a242cca031cbf7b24e78e90f5ffbc40ea1c0947db0978b66196a308d4c04e9704fdf29379d9e5b8ef9e90b73c6b55e25c67fe71f42ed449a8b223
7
+ data.tar.gz: d632bd4802a23fe04d80b755c84f0f8250d6158a292326a0133ecac0f4220dd0236b813913d7237871d36f6348ed99e796b85b79c790cf6442fbdeffa2623c3c
@@ -1,4 +1,4 @@
1
- require_dependency "para/application_controller"
1
+ require_dependency 'para/application_controller'
2
2
 
3
3
  module Para
4
4
  module Admin
@@ -37,7 +37,7 @@ module Para
37
37
  end
38
38
 
39
39
  def update
40
- if resource.update_attributes(resource_params)
40
+ if resource.update(resource_params)
41
41
  flash_message(:success, resource)
42
42
  redirect_to after_form_submit_path
43
43
  else
@@ -109,7 +109,7 @@ module Para
109
109
  def resource
110
110
  @resource ||= begin
111
111
  self.class.ensure_resource_name_defined!
112
- instance_variable_get(:"@#{ self.class.resource_name }")
112
+ instance_variable_get(:"@#{self.class.resource_name}")
113
113
  end
114
114
  end
115
115
 
@@ -161,10 +161,10 @@ module Para
161
161
 
162
162
  def self.ensure_resource_name_defined!
163
163
  unless resource_name.presence
164
- raise "Resource not defined in your controller. " \
165
- "You can define the resource of your controller with the " \
166
- "`resource :resource_name` macro when subclassing " \
167
- "Para::Admin::ResourcesController"
164
+ raise 'Resource not defined in your controller. ' \
165
+ 'You can define the resource of your controller with the ' \
166
+ '`resource :resource_name` macro when subclassing ' \
167
+ 'Para::Admin::ResourcesController'
168
168
  end
169
169
  end
170
170
 
@@ -185,8 +185,8 @@ module Para
185
185
 
186
186
  def current_anchor
187
187
  @current_anchor ||= if (current_anchor = params[:_current_anchor]).presence
188
- current_anchor.gsub(/^\#/, '')
189
- end
188
+ current_anchor.gsub(/^\#/, '')
189
+ end
190
190
  end
191
191
  end
192
192
  end
@@ -23,8 +23,8 @@ module Para
23
23
  end
24
24
  end
25
25
 
26
- def find_relation_name_for(relation, partial, options = {})
27
- return relation if partial_exists?(relation, partial, options)
26
+ def find_relation_name_for(relation, partial, **options)
27
+ return relation if partial_exists?(relation, partial, **options)
28
28
  return nil unless options[:relation_class]
29
29
 
30
30
  relation = options[:relation_class].ancestors.find do |ancestor|
@@ -32,7 +32,7 @@ module Para
32
32
  break if ancestor == ActiveRecord::Base
33
33
 
34
34
  ancestor_name = plural_file_path_for(ancestor.name)
35
- partial_exists?(ancestor_name, partial, options)
35
+ partial_exists?(ancestor_name, partial, **options)
36
36
  end
37
37
 
38
38
  plural_file_path_for(relation) if relation
@@ -9,7 +9,7 @@ module Para
9
9
  association_name = parent_resource.association(attribute_name).options[:inverse_of]
10
10
  return resource unless association_name
11
11
 
12
- resource.association(association_name).replace(parent_resource)
12
+ resource.association(association_name).send(:replace, parent_resource)
13
13
  end
14
14
  end
15
15
  end
@@ -19,7 +19,7 @@ module Para
19
19
  defaults << options.delete(:default) if options[:default]
20
20
  options[:default] = defaults
21
21
 
22
- I18n.translate(defaults.shift, options)
22
+ ::I18n.translate(defaults.shift, **options)
23
23
  end
24
24
  end
25
25
  end
@@ -4,13 +4,15 @@ module Para
4
4
  class ApplicationRecord < ActiveRecord::Base
5
5
  self.abstract_class = true
6
6
 
7
- private
8
-
9
7
  # Adds the `optional: true` option to the belongs_to calls inside the provided block,
10
8
  # but only for Rails 5.1+
11
9
  #
12
10
  def self.with_belongs_to_optional_option_if_needed(&block)
13
- if ActiveRecord::Associations::Builder::BelongsTo.valid_options({}).include?(:optional)
11
+ belongs_to_accepts_optional = ActiveRecord::Associations::Builder::BelongsTo
12
+ .send(:valid_options, {})
13
+ .include?(:optional)
14
+
15
+ if belongs_to_accepts_optional
14
16
  with_options(optional: true, &block)
15
17
  else
16
18
  block.call
@@ -10,7 +10,7 @@ module Para
10
10
  Para::Component.registered_components[name] = component
11
11
  end
12
12
 
13
- def self.configurable_on(key, options = {})
13
+ def self.configurable_on(key, _options = {})
14
14
  store_accessor(:configuration, key)
15
15
  end
16
16
 
@@ -22,8 +22,8 @@ module Para
22
22
  end
23
23
 
24
24
  has_many :child_components, -> { ordered },
25
- class_name: 'Para::Component::Base',
26
- foreign_key: 'parent_component_id'
25
+ class_name: 'Para::Component::Base',
26
+ foreign_key: 'parent_component_id'
27
27
 
28
28
  validates :identifier, :type, presence: true
29
29
 
@@ -33,14 +33,14 @@ module Para
33
33
 
34
34
  def name
35
35
  read_attribute(:name) || ::I18n.t(
36
- "components.component.#{ identifier }",
36
+ "components.component.#{identifier}",
37
37
  default: identifier.humanize
38
38
  )
39
39
  end
40
40
 
41
41
  def main_navigation_name
42
42
  ::I18n.t(
43
- "components.main_navigation.#{ identifier }",
43
+ "components.main_navigation.#{identifier}",
44
44
  default: name
45
45
  )
46
46
  end
@@ -62,7 +62,7 @@ module Para
62
62
  end
63
63
 
64
64
  def default_form_actions
65
- [:submit, :submit_and_edit, :submit_and_add_another, :cancel]
65
+ %i[submit submit_and_edit submit_and_add_another cancel]
66
66
  end
67
67
 
68
68
  def to_param
@@ -1,8 +1,8 @@
1
1
  module Para
2
2
  class ComponentSection < Para::ApplicationRecord
3
3
  has_many :components, -> { ordered }, class_name: 'Para::Component::Base',
4
- autosave: true, foreign_key: :component_section_id,
5
- dependent: :destroy
4
+ autosave: true, foreign_key: :component_section_id,
5
+ dependent: :destroy
6
6
 
7
7
  scope :ordered, -> { order(position: :asc) }
8
8
 
@@ -10,7 +10,7 @@ module Para
10
10
 
11
11
  def name
12
12
  read_attribute(:name) || ::I18n.t(
13
- "components.section.#{ identifier }",
13
+ "components.section.#{identifier}",
14
14
  default: identifier.humanize
15
15
  )
16
16
  end
@@ -11,10 +11,10 @@ module Para
11
11
  def attachment_path
12
12
  return unless attachment.attached?
13
13
 
14
- attachment.service_url
14
+ attachment.url
15
15
  end
16
16
 
17
- alias_method :attachment_url, :attachment_path
17
+ alias attachment_url attachment_path
18
18
 
19
19
  def attachment_ext
20
20
  ::File.extname(attachment.filename.to_s) if attachment.attached?
@@ -14,7 +14,6 @@ module Para
14
14
  end
15
15
 
16
16
  class << self
17
-
18
17
  # This method is a shortcut to create a has_one through relation
19
18
  def section_resource(*args, &block)
20
19
  _ensure_section_resource_relation
@@ -47,10 +46,10 @@ module Para
47
46
  return if @section_resources_already_initialized
48
47
 
49
48
  has_many :section_resources, -> { ordered },
50
- foreign_key: 'section_id',
51
- class_name: '::Para::Page::SectionResource',
52
- inverse_of: :section,
53
- dependent: :destroy
49
+ foreign_key: 'section_id',
50
+ class_name: '::Para::Page::SectionResource',
51
+ inverse_of: :section,
52
+ dependent: :destroy
54
53
 
55
54
  accepts_nested_attributes_for :section_resources, allow_destroy: true
56
55
 
@@ -74,7 +73,7 @@ module Para
74
73
  source_type: target_class_name
75
74
  )
76
75
 
77
- has_one(*args, options, &block)
76
+ has_one(*args, **options, &block)
78
77
  end
79
78
 
80
79
  def _create_section_resource_has_many_relation_for(*args, &block)
@@ -94,7 +93,7 @@ module Para
94
93
  source_type: target_class_name
95
94
  )
96
95
 
97
- has_many(*args, options, &block)
96
+ has_many(*args, **options, &block)
98
97
  end
99
98
  end
100
99
  end
@@ -1 +1 @@
1
- = render file: template_path_lookup('admin/dashboard', 'para/admin/dashboard')
1
+ = render template: template_path_lookup('admin/dashboard', 'para/admin/dashboard')
@@ -11,7 +11,7 @@
11
11
 
12
12
  = form.remove_association_button
13
13
 
14
- .panel-collapse.form-inputs.collapse{ id: form.nested_resource_dom_id, class: ('in' if uncollapsed && form.object.persisted?), data: { rendered: render_partial, render_path: @component.path(remote_partial_params), id: form.object.id, :"object-name" => form.object_name, :"model-name" => model.name } }
14
+ .panel-collapse.form-inputs.collapse{ id: form.nested_resource_dom_id, class: ('in' if uncollapsed && form.object.persisted?), data: { rendered: render_partial, render_path: @component.path(**remote_partial_params), id: form.object.id, :"object-name" => form.object_name, :"model-name" => model.name } }
15
15
  .panel-body{ data: { :"nested-form-container" => true } }
16
16
  - if render_partial
17
17
  = render partial: find_partial_for(model, form.nested_fields_partial_name), locals: { form: form }.merge(nested_locals)
@@ -1,23 +1,29 @@
1
1
  module Para
2
2
  class ActiveStorageDownloader
3
- if defined?(ActiveStorage)
4
- include ActiveStorage::Downloading
5
- end
3
+ include ActiveStorage::Downloading if defined?(ActiveStorage::Downloading)
6
4
 
7
5
  attr_reader :attachment
8
-
6
+
9
7
  delegate :blob, to: :attachment
10
8
 
11
9
  def initialize(attachment)
12
10
  @attachment = attachment
13
11
  end
14
12
 
15
- if defined?(ActiveStorage)
13
+ if defined?(ActiveStorage::Downloading)
16
14
  public :download_blob_to_tempfile
15
+ elsif defined?(ActiveStorage)
16
+ # For versions of ActiveStorage that don't have an ActiveStorage::Downloading
17
+ # module, we define the method ourselves, as defined in the ActiveStorage::Analyzer
18
+ # and ActiveStorage::Previewer classes, which is simple enough to be copied here.
19
+ #
20
+ def download_blob_to_tempfile(&block)
21
+ blob.open tmpdir: Dir.tmpdir, &block
22
+ end
17
23
  else
18
24
  define_method(:download_blob_to_tempfile) do
19
- raise NoMethodError, "ActiveStorage is not included in your application"
25
+ raise NoMethodError, 'ActiveStorage is not included in your application'
20
26
  end
21
27
  end
22
28
  end
23
- end
29
+ end
@@ -2,6 +2,7 @@ module Para
2
2
  module Breadcrumbs
3
3
  module Controller
4
4
  extend ActiveSupport::Concern
5
+ include ActionController::Helpers
5
6
 
6
7
  included do
7
8
  class_attribute :_class_level_breadcrumbs
@@ -44,19 +44,20 @@ module Para
44
44
  Para::ActiveStorageDownloader.new(original_attachment).download_blob_to_tempfile do |tempfile|
45
45
  attachment_target = clone.send(association_name)
46
46
 
47
- attachment_target.attach({
48
- io: tempfile,
47
+ cloned_blob = ActiveStorage::Blob.create_and_upload!(
48
+ io: tempfile,
49
49
  filename: original_blob.filename,
50
50
  content_type: original_blob.content_type
51
- })
51
+ )
52
52
 
53
+ attachment_target.attach(cloned_blob)
53
54
  cloned_attachment = find_cloned_attachment(attachment_target, original_blob)
54
55
 
55
56
  # Store the cloned attachment and blob into the deep_cloneable dictionary used
56
57
  # by the `deep_clone` method to ensure that, if needed during the cloning
57
58
  # operation, they won't be cloned once more and are accessible for processing
58
59
  store_cloned(original_attachment, cloned_attachment)
59
- store_cloned(original_blob, cloned_attachment.blob)
60
+ store_cloned(original_blob, cloned_blob)
60
61
  end
61
62
  end
62
63
 
@@ -21,10 +21,3 @@ require 'para/component/exportable'
21
21
  require 'para/component/importable'
22
22
  require 'para/component/subclassable'
23
23
  require 'para/component/history'
24
-
25
- # Require models
26
- require 'para/component/base'
27
- require 'para/component/resource'
28
- require 'para/component/crud'
29
- require 'para/component/form'
30
- require 'para/component/settings'
@@ -1,17 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Para
2
4
  class ComponentsCleaner
3
5
  # Hide class instanciation
4
- def self.run; new.run; end
6
+ def self.run
7
+ new.run
8
+ end
5
9
 
6
10
  def run
7
11
  components.each do |component|
8
- unless component == Para.components.component_for(component.identifier)
12
+ if component.id != Para.components.components_ids_hash[component.identifier]
9
13
  component.destroy
10
14
  end
11
15
  end
12
16
 
13
17
  Para::ComponentSection.find_each do |section|
14
- unless Para.components.section_for(section.identifier)
18
+ unless Para.components.sections_ids_hash[section.identifier]
15
19
  section.destroy
16
20
  end
17
21
  end
@@ -5,6 +5,7 @@ module Para
5
5
 
6
6
  def draw(&block)
7
7
  return unless components_installed?
8
+
8
9
  Para::LogConfig.with_log_level(:fatal) do
9
10
  log_level = Rails.logger.level
10
11
  Rails.logger.level = :fatal
@@ -36,10 +37,10 @@ module Para
36
37
  section
37
38
  else
38
39
  sections_cache[identifier] = if (section_id = sections_ids_hash[identifier])
39
- Para::ComponentSection.find(section_id)
40
- else
41
- Para::ComponentSection.find_by(identifier: identifier)
42
- end
40
+ Para::ComponentSection.find(section_id)
41
+ else
42
+ Para::ComponentSection.find_by(identifier: identifier)
43
+ end
43
44
  end
44
45
  end
45
46
 
@@ -48,10 +49,10 @@ module Para
48
49
  component
49
50
  else
50
51
  components_cache[identifier] = if (component_id = components_ids_hash[identifier])
51
- Para::Component::Base.find(component_id)
52
- else
53
- Para::Component::Base.find_by(identifier: identifier)
54
- end
52
+ Para::Component::Base.find(component_id)
53
+ else
54
+ Para::Component::Base.find_by(identifier: identifier)
55
+ end
55
56
  end
56
57
  end
57
58
 
@@ -64,9 +65,7 @@ module Para
64
65
  else
65
66
  component.child_components.each do |child_component|
66
67
  # If one of the component children has the searched identifier return it
67
- if child_component.identifier.to_s == identifier.to_s
68
- return child_component
69
- end
68
+ return child_component if child_component.identifier.to_s == identifier.to_s
70
69
  end
71
70
  end
72
71
  end
@@ -76,6 +75,14 @@ module Para
76
75
  nil
77
76
  end
78
77
 
78
+ def sections_ids_hash
79
+ @sections_ids_hash ||= {}.with_indifferent_access
80
+ end
81
+
82
+ def components_ids_hash
83
+ @components_ids_hash ||= {}.with_indifferent_access
84
+ end
85
+
79
86
  private
80
87
 
81
88
  def build
@@ -93,14 +100,6 @@ module Para
93
100
  end
94
101
  end
95
102
 
96
- def sections_ids_hash
97
- @sections_ids_hash ||= {}.with_indifferent_access
98
- end
99
-
100
- def components_ids_hash
101
- @components_ids_hash ||= {}.with_indifferent_access
102
- end
103
-
104
103
  # Only store sections cache for the request duration to avoid expired
105
104
  # references to AR objects between requests
106
105
  #
@@ -116,14 +115,14 @@ module Para
116
115
  end
117
116
 
118
117
  def components_installed?
119
- tables_exist = %w(component/base component_section).all? do |name|
118
+ tables_exist = %w[component/base component_section].all? do |name|
120
119
  Para.const_get(name.camelize).table_exists?
121
120
  end
122
121
 
123
122
  unless tables_exist
124
123
  Rails.logger.warn(
125
124
  "Para migrations are not installed.\n" \
126
- "Skipping components definition until next app reload."
125
+ 'Skipping components definition until next app reload.'
127
126
  )
128
127
  end
129
128
 
@@ -140,7 +139,7 @@ module Para
140
139
  #
141
140
  def eager_load_components!
142
141
  $LOAD_PATH.each do |path|
143
- next unless path.match(/\/components$/)
142
+ next unless path.match(%r{/components$})
144
143
 
145
144
  glob = File.join(path, '**', '*_component.rb')
146
145
 
@@ -158,8 +157,8 @@ module Para
158
157
  instance_eval(&block)
159
158
  end
160
159
 
161
- def component(*args, &block)
162
- components << Component.new(*args, &block)
160
+ def component(*args, **options, &block)
161
+ components << Component.new(*args, **options, &block)
163
162
  end
164
163
 
165
164
  def components
@@ -191,19 +190,15 @@ module Para
191
190
  instance_eval(&block) if block
192
191
 
193
192
  unless type
194
- raise UndefinedComponentTypeError.new(
195
- "Undefined Para component : #{ type_identifier }. " +
196
- "Please ensure that your app or gems define this component type."
197
- )
193
+ raise UndefinedComponentTypeError, "Undefined Para component : #{type_identifier}. " +
194
+ 'Please ensure that your app or gems define this component type.'
198
195
  end
199
196
  end
200
197
 
201
198
  def component(*args, **child_options, &block)
202
199
  # Do not allow nesting components more than one level as the display of illimited
203
200
  # child nesting deepness is not implemented
204
- if parent
205
- raise ComponentTooDeepError, "Cannot nest components more than one level"
206
- end
201
+ raise ComponentTooDeepError, 'Cannot nest components more than one level' if parent
207
202
 
208
203
  child_component_options = child_options.merge(parent: self)
209
204
  child_components << Component.new(*args, **child_component_options, &block)
@@ -88,6 +88,8 @@ module Para
88
88
  join_resources.find do |res|
89
89
  res.send(attribute_field.through_relation_source_foreign_key) == resource.id
90
90
  end
91
+ else
92
+ resource
91
93
  end
92
94
 
93
95
  existing_resource.position
@@ -17,11 +17,11 @@ module Para
17
17
  # Build association without trying to save the new record
18
18
  resource = case association
19
19
  when ActiveRecord::Associations::HasOneThroughAssociation
20
- association.replace(model.new)
20
+ association.send(:replace, model.new)
21
21
  when ActiveRecord::Associations::HasOneAssociation
22
- association.replace(model.new, false)
22
+ association.send(:replace, model.new, false)
23
23
  else
24
- association.replace(model.new)
24
+ association.send(:replace, model.new)
25
25
  end
26
26
  end
27
27
 
data/lib/para/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Para
4
- VERSION = '0.9.3.3'
4
+ VERSION = '0.10.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: para
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3.3
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valentin Ballestrino
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-02 00:00:00.000000000 Z
11
+ date: 2023-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '4.0'
20
20
  - - "<="
21
21
  - !ruby/object:Gem::Version
22
- version: '7.0'
22
+ version: '8.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '4.0'
30
30
  - - "<="
31
31
  - !ruby/object:Gem::Version
32
- version: '7.0'
32
+ version: '8.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rails-i18n
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -852,7 +852,7 @@ homepage: http://github.com/glyph-fr/para
852
852
  licenses:
853
853
  - MIT
854
854
  metadata: {}
855
- post_install_message:
855
+ post_install_message:
856
856
  rdoc_options: []
857
857
  require_paths:
858
858
  - lib
@@ -867,8 +867,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
867
867
  - !ruby/object:Gem::Version
868
868
  version: '0'
869
869
  requirements: []
870
- rubygems_version: 3.1.4
871
- signing_key:
870
+ rubygems_version: 3.3.7
871
+ signing_key:
872
872
  specification_version: 4
873
873
  summary: Rails admin engine
874
874
  test_files: []