inertia_rails 1.0.0 → 1.0.1

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: 68ba506e9262c9b0ad4d631811f337b4713d103bf2f5c2fc80dce3a8dc688428
4
- data.tar.gz: 8d1dce1b39abbb1c4bcdef67010ead191bfb83dec3ae2327cfe7fcd3e40191b0
3
+ metadata.gz: 5a987e189bffe559a7fd30a5a4af407dd992126196af7f57fe7d496205faefae
4
+ data.tar.gz: dd688cdcb38097978329cacb91db8b76d18db98dd3dc44bf9bddd03e784d6f5d
5
5
  SHA512:
6
- metadata.gz: 013501ef4ce007f27d8f16380fda786be161affaa2b46ba42221b2eb3f5568e29e97f2318e9c39e82f86312b8b55b9fc3c58c8a145467b53edf020bf6ca35bf6
7
- data.tar.gz: 1c20923053db461a39614f988a999fe86272e80f4a89d572bd1419d0b9ddfbdc177c266951c41afacd1033844d81376b6603a8faa80fc0678de80615ca32fe41
6
+ metadata.gz: 2aeccf87d9e621b7617ec111f04bcb2032c4c574793a73f59895985bb73d94546f073c3a091b9ba1d66bd46eac5536e626bbae3892a6e9789fcef5952c20b63f
7
+ data.tar.gz: 8cba5c80ecde60604dc9d93dd1269448bd6fd99411852b0b4f58f20b9e792aa63a0afd9867bdf35ad984d6ca4205734b1f587e206b15dee3e0370587b4ab911e
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [1.0.1] - 2019-10-23
8
+
9
+ ### Fixed
10
+
11
+ * Allow `Intertia.share` within a controller to access controller methods
12
+
13
+ ## [1.0.0] - 2019-10-09
14
+
15
+ * Initial release
@@ -7,8 +7,8 @@ module InertiaRails
7
7
  end
8
8
 
9
9
  # "Getters"
10
- def self.shared_data
11
- shared_plain_data.merge!(evaluated_blocks(shared_blocks))
10
+ def self.shared_data(controller)
11
+ shared_plain_data.merge!(evaluated_blocks(controller, shared_blocks))
12
12
  end
13
13
 
14
14
  def self.version
@@ -39,7 +39,7 @@ module InertiaRails
39
39
  end
40
40
  end
41
41
 
42
- def self.evaluated_blocks(blocks)
43
- blocks.flat_map(&:call).reduce(&:merge) || {}
42
+ def self.evaluated_blocks(controller, blocks)
43
+ blocks.flat_map { |block| controller.instance_exec(&block) }.reduce(&:merge) || {}
44
44
  end
45
45
  end
@@ -4,8 +4,9 @@ module InertiaRails
4
4
  class Renderer
5
5
  attr_reader :component, :view_data
6
6
 
7
- def initialize(component, request, response, render_method, props:, view_data:)
7
+ def initialize(component, controller, request, response, render_method, props:, view_data:)
8
8
  @component = component
9
+ @controller = controller
9
10
  @request = request
10
11
  @response = response
11
12
  @render_method = render_method
@@ -28,13 +29,13 @@ module InertiaRails
28
29
  def props
29
30
  only = (@request.headers['X-Inertia-Partial-Data'] || '').split(',').compact.map(&:to_sym)
30
31
 
31
- _props = ::InertiaRails.shared_data.merge(@props)
32
+ _props = ::InertiaRails.shared_data(@controller).merge(@props)
32
33
 
33
34
  _props = (only.any? && @request.headers['X-Inertia-Partial-Component'] == component) ?
34
35
  _props.select {|key| key.in? only} :
35
36
  _props
36
37
 
37
- deep_transform_values(_props, lambda {|prop| prop.respond_to?(:call) ? prop.call : prop })
38
+ deep_transform_values(_props, lambda {|prop| prop.respond_to?(:call) ? @controller.instance_exec(&prop) : prop })
38
39
  end
39
40
 
40
41
  def page
@@ -1,3 +1,3 @@
1
1
  module InertiaRails
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
data/lib/inertia_rails.rb CHANGED
@@ -4,6 +4,7 @@ require 'inertia_rails/engine'
4
4
  ActionController::Renderers.add :inertia do |component, options|
5
5
  InertiaRails::Renderer.new(
6
6
  component,
7
+ self,
7
8
  request,
8
9
  response,
9
10
  method(:render),
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inertia_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Knoles
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2019-10-09 00:00:00.000000000 Z
13
+ date: 2019-10-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -66,6 +66,7 @@ files:
66
66
  - ".gitignore"
67
67
  - ".rspec"
68
68
  - ".travis.yml"
69
+ - CHANGELOG.md
69
70
  - CODE_OF_CONDUCT.md
70
71
  - Gemfile
71
72
  - LICENSE.txt