phlex-rails 0.9.0 → 1.0.0

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: 64bd1c0569d8a687689b1eec091acff484e3c3c7db388f80ddc1cb059881c680
4
- data.tar.gz: 282af2d851aaef5e1266519b59ba5ade1360cd13666d629b4109441f16abb6f6
3
+ metadata.gz: 7b847ffd983ba4161668179eb395ccbfd50ee216892ffb7124bdacaa584a9e0a
4
+ data.tar.gz: e34aa3c4e6053b913f09f325ce11e16e6152afed5fecd18857a3ee634a735034
5
5
  SHA512:
6
- metadata.gz: e9f65f079a1ec7372692767beb7f7f1f70dac50f4429f429aa0085bbfefcd40675e2933985d728ed2354fb90983d86a707d1f5432c3333f72f843032086c7924
7
- data.tar.gz: 7e5f5fe2316c5db3ae8757a67517856ffdebf4f5b03467d17a712eb6c571486f402ceeb993cd1ceba31c3a7cfef37aa104ed297123be43fb30cb2af790775530
6
+ metadata.gz: e955615cd2b7ac990742dd35028d524f74f8f05f0799ede53f793435344d1b3c7db6b99c87fb2f3fedef50f016f53d7f3cf32070ab7894be1b86c734b93cca76
7
+ data.tar.gz: 675126fe1bc74b22ee7ec284f0048ca4051a4fb3ea863fe916c8c48c745ca1ea431ed84569fda5d6b9ce046a58fd67f3b11f3e78bab25f4496074fc7e55d8e8a
data/.rubocop.yml CHANGED
@@ -10,3 +10,6 @@ AllCops:
10
10
 
11
11
  Style/MissingRespondToMissing:
12
12
  Enabled: false
13
+
14
+ Style/RescueStandardError:
15
+ Enabled: false
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --private --hide-api private --markup markdown --exclude lib/generators
data/CHANGELOG.md ADDED
@@ -0,0 +1,25 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
4
+
5
+ ## [1.0.0] 2023-04-19
6
+
7
+ ### Added
8
+
9
+ - Added an adapter for the pluralize view helper.
10
+
11
+ ## 0.10.0
12
+
13
+ ### Added
14
+
15
+ - You can now render procs and lambdas and enumerables of renderables.
16
+ - Experimental streaming interface
17
+
18
+ ### Fixed
19
+
20
+ - Escaped ERB captures
21
+ - Use buffered component unless renderin in a template
22
+
23
+ ***
24
+
25
+ Before this changelog was introduced, changes were logged in the [release notes](https://github.com/phlex-ruby/phlex/releases).
data/Gemfile CHANGED
@@ -5,11 +5,12 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5
5
 
6
6
  gemspec
7
7
 
8
- gem "phlex", github: "joeldrapper/phlex"
9
- gem "phlex-testing-capybara", github: "joeldrapper/phlex-testing-capybara"
8
+ gem "phlex", github: "phlex-ruby/phlex"
9
+ gem "phlex-testing-capybara", github: "phlex-ruby/phlex-testing-capybara"
10
10
  gem "rspec-rails"
11
11
  gem "combustion"
12
12
  gem "rubocop"
13
13
  gem "solargraph"
14
14
  gem "view_component"
15
15
  gem "appraisal", github: "excid3/appraisal", branch: "fix-bundle-env"
16
+ gem "yard"
@@ -4,6 +4,7 @@ require "forwardable"
4
4
 
5
5
  module Phlex::Rails
6
6
  # A decorator that buffers all missing method calls and captures the blocks passed to them.
7
+ # @api private
7
8
  class Buffered < BasicObject
8
9
  extend ::Forwardable
9
10
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Phlex::Rails
4
+ # @api private
4
5
  class BufferedCheckboxBuilder < Buffered
5
6
  # @!method object(...)
6
7
  # @!method text(...)
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Phlex::Rails
4
+ # @api private
4
5
  class BufferedFormBuilder < Buffered
5
6
  # @!method field_id(...)
6
7
  # @!method field_name(...)
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Phlex::Rails
4
+ # @api private
4
5
  class BufferedLabelBuilder < Buffered
5
6
  # @!method object(...)
6
7
  # @!method translation(...)
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Phlex::Rails
4
+ # @api private
4
5
  class BufferedRadioButtonBuilder < Buffered
5
6
  # @!method object(...)
6
7
  # @!method text(...)
@@ -4,6 +4,7 @@ require "rails/engine"
4
4
 
5
5
  module Phlex
6
6
  module Rails
7
+ # @api private
7
8
  class Engine < ::Rails::Engine
8
9
  end
9
10
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Phlex
4
4
  module Rails
5
+ # @api private
5
6
  class Form < Phlex::HTML
6
7
  def initialize(model)
7
8
  @model = model
@@ -883,6 +883,14 @@ module Phlex::Rails::Helpers
883
883
  define_output_helper :phone_field_tag
884
884
  end
885
885
 
886
+ module Pluralize
887
+ extend Phlex::Rails::HelperMacros
888
+
889
+ # @!method pluralize(...)
890
+ # @return [String]
891
+ define_value_helper :pluralize
892
+ end
893
+
886
894
  module PreloadLinkTag
887
895
  extend Phlex::Rails::HelperMacros
888
896
 
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # @api private
3
4
  module Phlex::Rails::HTML::Format
4
5
  def format
5
6
  :html
@@ -13,6 +13,7 @@ module Phlex::Rails
13
13
  include Helpers::JavaScriptImportMapTags
14
14
  include Helpers::JavaScriptImportModuleTag
15
15
 
16
+ # @api private
16
17
  module Interface
17
18
  def render(view, _locals, &block)
18
19
  component = new
@@ -34,7 +34,7 @@ module Phlex
34
34
  call(view_context: view_context) do |*args|
35
35
  original_length = @_context.target.length
36
36
 
37
- if args.length == 1 && Phlex::SGML === args[0]
37
+ if args.length == 1 && Phlex::SGML === args[0] && !block.source_location&.[](0)&.end_with?(".rb")
38
38
  output = view_context.capture(
39
39
  args[0].unbuffered, &block
40
40
  )
@@ -60,7 +60,8 @@ module Phlex
60
60
  super&.html_safe
61
61
  end
62
62
 
63
- def plain(content)
63
+ # @api private
64
+ def __text__(content)
64
65
  case content
65
66
  when ActiveSupport::SafeBuffer
66
67
  @_context.target << content
@@ -69,7 +70,19 @@ module Phlex
69
70
  end
70
71
  end
71
72
 
73
+ # @api private
74
+ def await(task)
75
+ if task.is_a?(ActiveRecord::Relation)
76
+ flush unless task.loaded?
77
+
78
+ task
79
+ else
80
+ super
81
+ end
82
+ end
83
+
72
84
  # Trick ViewComponent into thinking we're a ViewComponent to fix rendering output
85
+ # @api private
73
86
  def set_original_view_context(view_context)
74
87
  end
75
88
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ module Phlex::Rails::Streaming
5
+ private
6
+
7
+ def stream(view)
8
+ headers.delete("Content-Length")
9
+
10
+ headers["X-Accel-Buffering"] = "no"
11
+ headers["Cache-Control"] = "no-cache"
12
+ headers["Content-Type"] = "text/html; charset=utf-8"
13
+ headers["Last-Modified"] = Time.zone.now.ctime.to_s
14
+
15
+ response.status = 200
16
+
17
+ self.response_body = Enumerator.new do |buffer|
18
+ view.call(buffer, view_context: view_context)
19
+ rescue => e
20
+ buffer << %('">)
21
+ buffer << view_context.javascript_tag(nonce: true) { %(window.location = "/500.html").html_safe }
22
+
23
+ raise e
24
+ end
25
+ end
26
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # @api private
3
4
  module Phlex::Rails::UnbufferedOverrides
4
5
  def method_missing(name, *args, **kwargs, &block)
5
6
  if @object.respond_to?(name)
@@ -8,7 +9,11 @@ module Phlex::Rails::UnbufferedOverrides
8
9
  @object.capture do
9
10
  if b
10
11
  @object.public_send(name, *a, **k) do |*aa|
11
- @object.helpers.capture(*aa, &b)
12
+ if aa.length == 1 && aa[0].is_a?(Phlex::SGML)
13
+ @object.helpers.capture(aa[0].unbuffered, &b)
14
+ else
15
+ @object.helpers.capture(*aa, &b)
16
+ end
12
17
  end
13
18
  else
14
19
  @object.public_send(name, *a, **k)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Phlex
4
4
  module Rails
5
- VERSION = "0.9.0"
5
+ VERSION = "1.0.0"
6
6
  end
7
7
  end
data/lib/phlex/rails.rb CHANGED
@@ -22,11 +22,13 @@ module Phlex
22
22
  prepend Phlex::Rails::SGML::Overrides
23
23
  end
24
24
 
25
+ # @api private
25
26
  class HTML
26
27
  extend Phlex::Rails::HTML::Format
27
28
  include Phlex::Rails::HTML::Format
28
29
  end
29
30
 
31
+ # @api private
30
32
  class Unbuffered
31
33
  prepend ::Phlex::Rails::UnbufferedOverrides
32
34
  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.9.0
4
+ version: 1.0.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: 2023-03-08 00:00:00.000000000 Z
11
+ date: 2023-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: phlex
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.6'
19
+ version: '1.7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.6'
26
+ version: '1.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -68,7 +68,9 @@ files:
68
68
  - ".editorconfig"
69
69
  - ".rubocop.yml"
70
70
  - ".ruby-version"
71
+ - ".yardopts"
71
72
  - Appraisals
73
+ - CHANGELOG.md
72
74
  - CODE_OF_CONDUCT.md
73
75
  - CONTRIBUTING.md
74
76
  - Gemfile
@@ -113,6 +115,7 @@ files:
113
115
  - lib/phlex/rails/layout.rb
114
116
  - lib/phlex/rails/sgml/class_methods.rb
115
117
  - lib/phlex/rails/sgml/overrides.rb
118
+ - lib/phlex/rails/streaming.rb
116
119
  - lib/phlex/rails/unbuffered_overrides.rb
117
120
  - lib/phlex/rails/version.rb
118
121
  - lib/phlex/testing/rails/view_helper.rb
@@ -122,8 +125,8 @@ licenses:
122
125
  - MIT
123
126
  metadata:
124
127
  homepage_uri: https://www.phlex.fun
125
- source_code_uri: https://github.com/joeldrapper/phlex
126
- changelog_uri: https://github.com/joeldrapper/phlex/releases
128
+ source_code_uri: https://github.com/phlex-ruby/phlex-rails
129
+ changelog_uri: https://github.com/phlex-ruby/phlex-rails/blob/main/CHANGELOG.md
127
130
  funding_uri: https://github.com/sponsors/joeldrapper
128
131
  rubygems_mfa_required: 'true'
129
132
  post_install_message: