phlex-rails 0.3.2 → 0.4.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: 20f58024a0e5af353aacd2343075de6fbde5b7dd1209ba825c29e752e958987d
4
- data.tar.gz: 5d800097df0cf47570297c6292119b6d38fa6e0d47b48844742b3292a794374d
3
+ metadata.gz: 1c05b7f36804eb576eb2c017a8566e6e15e9dfdc96a80bffe566d6fe1bf90edf
4
+ data.tar.gz: 901dbd435636eb4823cacfef7b42b0281165ad7f4cae0553a070d8592270637b
5
5
  SHA512:
6
- metadata.gz: ce4d38e74e324e60e499e911687d3766e4b45f2cad06936e863ede7e7cbad09d8fa6436f513108cb1b2b44a75356c29260c543c9d76ce7d7d8b0340ec467c157
7
- data.tar.gz: 3c1d9be8acc7ed0627c44efd1bbbf18a7f2e087f63b9b499b9194359a00fa4c88ab4e5e730ae71cfe5b5d3a38e48a159a580affe0d78dc1c5c6b1abc2d2caa6c
6
+ metadata.gz: 58dba0d9f85f66d2b0b8d9a72f211aa685e150bb62646330dcfce230d36fec088f4dd1b81125a23104bf2cfee9d80d1d01e23c240406478df0c15289e3189033
7
+ data.tar.gz: 1ca4bed35a09f31065fb08cf1905942a2f5e6ac468b7a66d5589666957a50361af6269efa2eaf20259fd861efac92884edb2455a111ca83076aa606af1e6f83e
@@ -0,0 +1,14 @@
1
+ <%= render Views::Blog.new do |v| %>
2
+
3
+ hidden
4
+
5
+ <% v.with_post do %><%= link_to "First Post", "/posts/1" %><% end %>
6
+
7
+ content
8
+
9
+ <% v.with_header do %><%= link_to "My blog", "/" %><% end %>
10
+
11
+ here
12
+
13
+ <% v.with_post do %><%= link_to "Last Post", "/posts/2" %><% end %>
14
+ <% end %>
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Views
4
+ class Blog < ApplicationView
5
+ def initialize
6
+ @posts = []
7
+ end
8
+
9
+ def template(&block)
10
+ capture(&block)
11
+
12
+ h3(class: "font-bold") { @header }
13
+
14
+ @posts.each do |post|
15
+ article(class: "drop-shadow p-5 rounded") { post }
16
+ end
17
+ end
18
+
19
+ def with_header(&block)
20
+ @header = capture(&block)
21
+ end
22
+
23
+ def with_post(&block)
24
+ @posts << capture(&block)
25
+ end
26
+ end
27
+ end
@@ -19,7 +19,7 @@ module Phlex
19
19
  def render_in(view_context, &block)
20
20
  if block_given?
21
21
  call(view_context: view_context) do |*args|
22
- view_context.with_output_buffer(OutputBuffer.new(@_target)) do
22
+ view_context.with_output_buffer(self) do
23
23
  original_length = @_target.length
24
24
  output = yield(*args)
25
25
  unchanged = (original_length == @_target.length)
@@ -37,6 +37,34 @@ module Phlex
37
37
  call(view_context: view_context).html_safe
38
38
  end
39
39
  end
40
+
41
+ def safe_append=(value)
42
+ return unless value
43
+
44
+ @_target << case value
45
+ when String then value
46
+ when Symbol then value.name
47
+ else value.to_s
48
+ end
49
+ end
50
+
51
+ def append=(value)
52
+ return unless value
53
+
54
+ if value.html_safe?
55
+ self.safe_append = value
56
+ else
57
+ @_target << case value
58
+ when String then ERB::Util.html_escape(value)
59
+ when Symbol then ERB::Util.html_escape(value.name)
60
+ else ERB::Util.html_escape(value.to_s)
61
+ end
62
+ end
63
+ end
64
+
65
+ def capture
66
+ super.html_safe
67
+ end
40
68
  end
41
69
  end
42
70
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Phlex
4
4
  module Rails
5
- VERSION = "0.3.2"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phlex-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Drapper
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-07 00:00:00.000000000 Z
11
+ date: 2022-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: phlex
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.0.rc1
19
+ version: '1'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '2'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 1.0.0.rc1
29
+ version: '1'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '2'
@@ -89,9 +89,11 @@ files:
89
89
  - fixtures/dummy/app/controllers/articles_controller.rb
90
90
  - fixtures/dummy/app/controllers/comments_controller.rb
91
91
  - fixtures/dummy/app/views/application_view.rb
92
+ - fixtures/dummy/app/views/articles/blog.html.erb
92
93
  - fixtures/dummy/app/views/articles/form.rb
93
94
  - fixtures/dummy/app/views/articles/index.html.erb
94
95
  - fixtures/dummy/app/views/articles/new.html.erb
96
+ - fixtures/dummy/app/views/blog.rb
95
97
  - fixtures/dummy/app/views/card.rb
96
98
  - fixtures/dummy/app/views/comments/comment.rb
97
99
  - fixtures/dummy/app/views/comments/index.html.erb
@@ -136,7 +138,6 @@ files:
136
138
  - lib/phlex/rails/form.rb
137
139
  - lib/phlex/rails/helpers.rb
138
140
  - lib/phlex/rails/layout.rb
139
- - lib/phlex/rails/output_buffer.rb
140
141
  - lib/phlex/rails/renderable.rb
141
142
  - lib/phlex/rails/version.rb
142
143
  - lib/phlex/testing/rails/view_helper.rb
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "cgi"
4
-
5
- module Phlex
6
- module Rails
7
- class OutputBuffer < SimpleDelegator
8
- def safe_append=(value)
9
- return unless value
10
-
11
- self << case value
12
- when String then value
13
- when Symbol then value.name
14
- else value.to_s
15
- end
16
- end
17
-
18
- def append=(value)
19
- return unless value
20
-
21
- if value.html_safe?
22
- self.safe_append = value
23
- else
24
- self << case value
25
- when String then CGI.escape_html(value)
26
- when Symbol then CGI.escape_html(value.name)
27
- else CGI.escape_html(value.to_s)
28
- end
29
- end
30
- end
31
- end
32
- end
33
- end