props_template 1.0.0.alpha → 1.0.0.alpha.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d2ef9c553bd49fd4d2a66bd8c2fc427e944b696c9eaa75f6224b5fb3627ca5e
4
- data.tar.gz: a717254c4c10d35fb871c50476e72273a25b3ee1ab55ce239b2660633443dbef
3
+ metadata.gz: e576ca76e76fabbf53a61bd1a4151ec9438e0be6024315ff36045e214ff45f3c
4
+ data.tar.gz: af5136ad10bb352e8bbf0c268f61b619431a13f1fdb6707a3a1178dd86aef0e0
5
5
  SHA512:
6
- metadata.gz: 2a4ab324d50d6f14783b10405073e4cef4b80b70bebda2ce9e586927e79c3ea254cc6fd542ac1b5ea195ebb5d106ffde0fa2801a0215a917d10c32425146ec58
7
- data.tar.gz: 2d04b6d02c08da88ac66f5d61c782a8de35e27552f1a49402a39bf14814593b755d8b785f30b42a9dea4197bbe199581f79fcca2b6641293f18d604d48297aa7
6
+ metadata.gz: 3bef324bee977c40a521e92c19d3d36ba7586d75802a06393185a22122b6b6f471c0f4461ccab0b3deff9797cf1d3db513772c7caf38cbcd90dc31b4a3097a8b
7
+ data.tar.gz: c6baaca2c8608dea574adf14a9327910a3cdaca5d48180e05591edc214719e5e62460342609d08cae69257d4c118fc04886a61f30746ca3408f528370dcb0918
data/README.md CHANGED
@@ -640,6 +640,28 @@ json.flash flash.to_h
640
640
  **NOTE** PropsTemplate inverts the usual Rails rendering flow. PropsTemplate
641
641
  will render Layout first, then the template when `yield json` is used.
642
642
 
643
+
644
+ ### Layouts in API-only Rails apps
645
+
646
+ If your controllers inherit from `ActionController::API` (typical in API-only Rails apps),
647
+ the layout feature won’t work out of the box, because `ActionController::API`
648
+ does not include layout support.
649
+
650
+ To enable layout rendering, you can include `ActionView::Layouts` manually,
651
+ then use `layout "your_own_layout"` as usual:
652
+
653
+ ```ruby
654
+ module Api
655
+ class BaseController < ActionController::API
656
+ include ActionView::Layouts
657
+
658
+ layout "api"
659
+ end
660
+ end
661
+ ```
662
+
663
+ Without this, Rails will silently skip the layout, which can be tricky to notice.
664
+
643
665
  ## Change key format
644
666
  By default, keys are not formatted. This is intentional. By being explicit with your keys,
645
667
  it makes your views quicker and more easily diggable when working in JavaScript land.
@@ -111,10 +111,6 @@ module Props
111
111
  nil
112
112
  end
113
113
 
114
- def partial!(**options)
115
- @context.render options
116
- end
117
-
118
114
  # json.id item.id
119
115
  # json.value item.value
120
116
  #
@@ -55,15 +55,16 @@ module Props
55
55
  options = @em.refine_options(options)
56
56
  end
57
57
 
58
- super(key, options, &block)
58
+ super
59
59
  end
60
60
 
61
61
  def handle_set_block(key, options)
62
- @traveled_path.push(key)
63
62
  n = 1
64
63
  if (suffix = options[:path_suffix])
65
64
  n += suffix.length
66
65
  @traveled_path.push(suffix)
66
+ else
67
+ @traveled_path.push(key)
67
68
  end
68
69
 
69
70
  super
@@ -7,18 +7,28 @@ module Props
7
7
  @fragments = fragments
8
8
  end
9
9
 
10
- def handle(options)
10
+ def self.fragment_name_from_options(options)
11
11
  return if !options[:partial]
12
- _partial_name, partial_opts = options[:partial]
12
+
13
+ _, partial_opts = [*options[:partial]]
14
+ return unless partial_opts
15
+
13
16
  fragment = partial_opts[:fragment]
14
17
 
15
18
  if String === fragment || Symbol === fragment
16
- key = fragment.to_s
17
- path = @base.traveled_path.join(".")
18
- @name =key
19
+ fragment.to_s
20
+ end
21
+ end
22
+
23
+ def handle(options)
24
+ fragment_name = self.class.fragment_name_from_options(options)
25
+ path = @base.traveled_path
26
+ .map { |item| item.is_a?(Array) ? item[0] : item }
27
+ .join(".")
19
28
 
29
+ if fragment_name
20
30
  @fragments.push(
21
- {id: key, path: path}
31
+ {id: fragment_name, path: path}
22
32
  )
23
33
  end
24
34
  end
@@ -11,6 +11,7 @@ module Props
11
11
  @builder = builder
12
12
  @traveled_path = []
13
13
  @partialer = Partialer.new(self, context, builder)
14
+ @fragment_name = nil
14
15
  end
15
16
 
16
17
  def deferred!
@@ -24,12 +25,19 @@ module Props
24
25
  def found!
25
26
  pass_opts = @found_options.clone || {}
26
27
  pass_opts.delete(:defer)
27
- traveled_path = @traveled_path[1..] || []
28
+ traveled_path = @traveled_path || []
28
29
  if !traveled_path.empty?
29
30
  pass_opts[:path_suffix] = traveled_path
30
31
  end
31
32
 
32
- [@found_block, pass_opts]
33
+ fragment_name = Fragment.fragment_name_from_options(pass_opts)
34
+ if fragment_name
35
+ @fragment_name = fragment_name
36
+ @traveled_path = []
37
+ end
38
+
39
+ fragment_context = @fragment_name
40
+ [@found_block, @traveled_path, pass_opts, fragment_context]
33
41
  end
34
42
 
35
43
  def set_block_content!(*args)
@@ -50,6 +58,12 @@ module Props
50
58
 
51
59
  @depth += 1
52
60
  if options[:partial]
61
+ fragment_name = Fragment.fragment_name_from_options(options)
62
+ if fragment_name
63
+ @fragment_name = fragment_name
64
+ @traveled_path = []
65
+ end
66
+
53
67
  @partialer.handle(options)
54
68
  else
55
69
  yield
@@ -94,6 +108,11 @@ module Props
94
108
 
95
109
  @depth += 1
96
110
  if pass_opts[:partial]
111
+ fragment_name = Fragment.fragment_name_from_options(pass_opts)
112
+ if fragment_name
113
+ @fragment_name = fragment_name
114
+ @traveled_path = []
115
+ end
97
116
  # todo: what happens when cached: true is passed?
98
117
  # would there be any problems with not using the collection_rende?
99
118
  @partialer.handle(pass_opts)
@@ -105,7 +124,7 @@ module Props
105
124
  end
106
125
  end
107
126
 
108
- def child!(options={}, &block)
127
+ def child!(options = {}, &block)
109
128
  return if @found_block
110
129
 
111
130
  child_index = @child_index || -1
@@ -128,7 +147,7 @@ module Props
128
147
  @depth -= 1
129
148
  end
130
149
 
131
- @child_index = child_index
150
+ @child_index = child_index
132
151
  end
133
152
  end
134
153
  end
@@ -1,3 +1,3 @@
1
1
  module Props
2
- VERSION = "1.0.0.alpha".freeze
2
+ VERSION = "1.0.0.alpha.2".freeze
3
3
  end
@@ -30,11 +30,14 @@ module Props
30
30
  :disable_deferments!,
31
31
  :set_block_content!,
32
32
  :traveled_path!,
33
+ :fragment_context!,
33
34
  to: :builder!
34
35
 
35
36
  def initialize(context = nil, options = {})
36
37
  @builder = BaseWithExtensions.new(self, context, options)
37
38
  @context = context
39
+ @fragment_context = nil
40
+ @found_path = []
38
41
  end
39
42
 
40
43
  def set!(key, options = {}, &block)
@@ -48,7 +51,9 @@ module Props
48
51
  options.delete(:dig)
49
52
 
50
53
  @builder.set!(key, options, &block)
51
- found_block, found_options = @builder.found!
54
+ found_block, found_path, found_options, fragment_context = @builder.found!
55
+ @found_path = found_path || []
56
+ @fragment_context = fragment_context
52
57
  @builder = prev_builder
53
58
 
54
59
  if found_block
@@ -59,6 +64,18 @@ module Props
59
64
  end
60
65
  end
61
66
 
67
+ def partial!(**options)
68
+ @context.render options
69
+ end
70
+
71
+ def found_path!
72
+ @found_path.join(".")
73
+ end
74
+
75
+ def fragment_context!
76
+ @fragment_context
77
+ end
78
+
62
79
  def builder!
63
80
  @builder
64
81
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: props_template
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.alpha
4
+ version: 1.0.0.alpha.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johny Ho
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-07-13 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activesupport
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
108
  requirements: []
109
- rubygems_version: 3.6.2
109
+ rubygems_version: 3.6.9
110
110
  specification_version: 4
111
111
  summary: A fast JSON builder
112
112
  test_files: []