phlex-rails 0.8.1 → 0.10.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 +4 -4
 - data/.rubocop.yml +3 -0
 - data/CHANGELOG.md +19 -0
 - data/Gemfile +2 -2
 - data/lib/phlex/rails/sgml/overrides.rb +22 -7
 - data/lib/phlex/rails/streaming.rb +24 -0
 - data/lib/phlex/rails/version.rb +1 -1
 - metadata +8 -6
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 555800cbdaf17b6f8b17c861a26a3d3db5d189dc85ac2bb8e4a91ee01a3451a5
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: e6f95ee6e6ed074cb90ed8b5761fca2e5885879a6237e53287c9d19a0f7c3dc5
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 5ebedcdc21e1b898181068e2d71b15c8679c00cb66fc3f923fac36151a37fce36ad2486d7e561e6d9af8de82ea1c975d37e72b40bb01ac00a51a2e3ed2a770f1
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: d3f0a529298f5ae7ce3c1b1628488b076a596bef03225a158baa54a80fd28282072c8d88344d5c0c21ff3071d7023d9765a3545dace66bce7f7ca4c54d8f7624
         
     | 
    
        data/.rubocop.yml
    CHANGED
    
    
    
        data/CHANGELOG.md
    ADDED
    
    | 
         @@ -0,0 +1,19 @@ 
     | 
|
| 
      
 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 
     | 
    
         
            +
            ## 0.10.0
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            Added
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            - You can now render procs and lambdas and enumerables of renderables.
         
     | 
| 
      
 10 
     | 
    
         
            +
            - Experimental streaming interface
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            Fixed
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            - Escaped ERB captures
         
     | 
| 
      
 15 
     | 
    
         
            +
            - Use buffered component unless renderin in a template
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            ***
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
            Before this changelog was introduced, changes were logged in the [release notes](https://github.com/phlex-ruby/phlex/releases).
         
     | 
    
        data/Gemfile
    CHANGED
    
    | 
         @@ -5,8 +5,8 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } 
     | 
|
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            gemspec
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
            gem "phlex", github: " 
     | 
| 
       9 
     | 
    
         
            -
            gem "phlex-testing-capybara", github: " 
     | 
| 
      
 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"
         
     | 
| 
         @@ -12,12 +12,16 @@ module Phlex 
     | 
|
| 
       12 
12 
     | 
    
         
             
            					end
         
     | 
| 
       13 
13 
     | 
    
         
             
            				end
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
            				def render( 
     | 
| 
       16 
     | 
    
         
            -
            					 
     | 
| 
       17 
     | 
    
         
            -
            					return super if renderable.is_a?(Class) && renderable < Phlex::SGML
         
     | 
| 
      
 15 
     | 
    
         
            +
            				def render(*args, **kwargs, &block)
         
     | 
| 
      
 16 
     | 
    
         
            +
            					renderable = args[0]
         
     | 
| 
       18 
17 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
            					 
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
      
 18 
     | 
    
         
            +
            					case renderable
         
     | 
| 
      
 19 
     | 
    
         
            +
            					when Phlex::SGML, Proc
         
     | 
| 
      
 20 
     | 
    
         
            +
            						return super
         
     | 
| 
      
 21 
     | 
    
         
            +
            					when Class
         
     | 
| 
      
 22 
     | 
    
         
            +
            						return super if renderable < Phlex::SGML
         
     | 
| 
      
 23 
     | 
    
         
            +
            					when Enumerable
         
     | 
| 
      
 24 
     | 
    
         
            +
            						return super unless renderable.is_a?(ActiveRecord::Relation)
         
     | 
| 
       21 
25 
     | 
    
         
             
            					else
         
     | 
| 
       22 
26 
     | 
    
         
             
            						@_context.target << @_view_context.render(*args, **kwargs, &block)
         
     | 
| 
       23 
27 
     | 
    
         
             
            					end
         
     | 
| 
         @@ -30,7 +34,7 @@ module Phlex 
     | 
|
| 
       30 
34 
     | 
    
         
             
            						call(view_context: view_context) do |*args|
         
     | 
| 
       31 
35 
     | 
    
         
             
            							original_length = @_context.target.length
         
     | 
| 
       32 
36 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
            							if args.length == 1 && Phlex::SGML === args[0]
         
     | 
| 
      
 37 
     | 
    
         
            +
            							if args.length == 1 && Phlex::SGML === args[0] && !block.source_location&.[](0)&.end_with?(".rb")
         
     | 
| 
       34 
38 
     | 
    
         
             
            								output = view_context.capture(
         
     | 
| 
       35 
39 
     | 
    
         
             
            									args[0].unbuffered, &block
         
     | 
| 
       36 
40 
     | 
    
         
             
            								)
         
     | 
| 
         @@ -56,7 +60,7 @@ module Phlex 
     | 
|
| 
       56 
60 
     | 
    
         
             
            					super&.html_safe
         
     | 
| 
       57 
61 
     | 
    
         
             
            				end
         
     | 
| 
       58 
62 
     | 
    
         | 
| 
       59 
     | 
    
         
            -
            				def  
     | 
| 
      
 63 
     | 
    
         
            +
            				def __text__(content)
         
     | 
| 
       60 
64 
     | 
    
         
             
            					case content
         
     | 
| 
       61 
65 
     | 
    
         
             
            					when ActiveSupport::SafeBuffer
         
     | 
| 
       62 
66 
     | 
    
         
             
            						@_context.target << content
         
     | 
| 
         @@ -65,6 +69,17 @@ module Phlex 
     | 
|
| 
       65 
69 
     | 
    
         
             
            					end
         
     | 
| 
       66 
70 
     | 
    
         
             
            				end
         
     | 
| 
       67 
71 
     | 
    
         | 
| 
      
 72 
     | 
    
         
            +
            				# @api experimental
         
     | 
| 
      
 73 
     | 
    
         
            +
            				def await(task)
         
     | 
| 
      
 74 
     | 
    
         
            +
            					if task.is_a?(ActiveRecord::Relation)
         
     | 
| 
      
 75 
     | 
    
         
            +
            						flush unless task.loaded?
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
            						task
         
     | 
| 
      
 78 
     | 
    
         
            +
            					else
         
     | 
| 
      
 79 
     | 
    
         
            +
            						super
         
     | 
| 
      
 80 
     | 
    
         
            +
            					end
         
     | 
| 
      
 81 
     | 
    
         
            +
            				end
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
       68 
83 
     | 
    
         
             
            				# Trick ViewComponent into thinking we're a ViewComponent to fix rendering output
         
     | 
| 
       69 
84 
     | 
    
         
             
            				def set_original_view_context(view_context)
         
     | 
| 
       70 
85 
     | 
    
         
             
            				end
         
     | 
| 
         @@ -0,0 +1,24 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            # @api experimental
         
     | 
| 
      
 4 
     | 
    
         
            +
            module Phlex::Rails::Streaming
         
     | 
| 
      
 5 
     | 
    
         
            +
            	private def stream(view)
         
     | 
| 
      
 6 
     | 
    
         
            +
            		headers.delete("Content-Length")
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            		headers["X-Accel-Buffering"] = "no"
         
     | 
| 
      
 9 
     | 
    
         
            +
            		headers["Cache-Control"] = "no-cache"
         
     | 
| 
      
 10 
     | 
    
         
            +
            		headers["Content-Type"] = "text/html; charset=utf-8"
         
     | 
| 
      
 11 
     | 
    
         
            +
            		headers["Last-Modified"] = Time.zone.now.ctime.to_s
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            		response.status = 200
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            		self.response_body = Enumerator.new do |buffer|
         
     | 
| 
      
 16 
     | 
    
         
            +
            			view.call(buffer, view_context: view_context)
         
     | 
| 
      
 17 
     | 
    
         
            +
            		rescue => e
         
     | 
| 
      
 18 
     | 
    
         
            +
            			buffer << %('">)
         
     | 
| 
      
 19 
     | 
    
         
            +
            			buffer << view_context.javascript_tag(nonce: true) { %(window.location = "/500.html").html_safe }
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            			raise e
         
     | 
| 
      
 22 
     | 
    
         
            +
            		end
         
     | 
| 
      
 23 
     | 
    
         
            +
            	end
         
     | 
| 
      
 24 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/phlex/rails/version.rb
    CHANGED
    
    
    
        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. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.10.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- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2023-04-18 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:  
     | 
| 
      
 19 
     | 
    
         
            +
                    version: 1.7.0
         
     | 
| 
       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:  
     | 
| 
      
 26 
     | 
    
         
            +
                    version: 1.7.0
         
     | 
| 
       27 
27 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       28 
28 
     | 
    
         
             
              name: rails
         
     | 
| 
       29 
29 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -69,6 +69,7 @@ files: 
     | 
|
| 
       69 
69 
     | 
    
         
             
            - ".rubocop.yml"
         
     | 
| 
       70 
70 
     | 
    
         
             
            - ".ruby-version"
         
     | 
| 
       71 
71 
     | 
    
         
             
            - Appraisals
         
     | 
| 
      
 72 
     | 
    
         
            +
            - CHANGELOG.md
         
     | 
| 
       72 
73 
     | 
    
         
             
            - CODE_OF_CONDUCT.md
         
     | 
| 
       73 
74 
     | 
    
         
             
            - CONTRIBUTING.md
         
     | 
| 
       74 
75 
     | 
    
         
             
            - Gemfile
         
     | 
| 
         @@ -113,6 +114,7 @@ files: 
     | 
|
| 
       113 
114 
     | 
    
         
             
            - lib/phlex/rails/layout.rb
         
     | 
| 
       114 
115 
     | 
    
         
             
            - lib/phlex/rails/sgml/class_methods.rb
         
     | 
| 
       115 
116 
     | 
    
         
             
            - lib/phlex/rails/sgml/overrides.rb
         
     | 
| 
      
 117 
     | 
    
         
            +
            - lib/phlex/rails/streaming.rb
         
     | 
| 
       116 
118 
     | 
    
         
             
            - lib/phlex/rails/unbuffered_overrides.rb
         
     | 
| 
       117 
119 
     | 
    
         
             
            - lib/phlex/rails/version.rb
         
     | 
| 
       118 
120 
     | 
    
         
             
            - lib/phlex/testing/rails/view_helper.rb
         
     | 
| 
         @@ -122,8 +124,8 @@ licenses: 
     | 
|
| 
       122 
124 
     | 
    
         
             
            - MIT
         
     | 
| 
       123 
125 
     | 
    
         
             
            metadata:
         
     | 
| 
       124 
126 
     | 
    
         
             
              homepage_uri: https://www.phlex.fun
         
     | 
| 
       125 
     | 
    
         
            -
              source_code_uri: https://github.com/ 
     | 
| 
       126 
     | 
    
         
            -
              changelog_uri: https://github.com/ 
     | 
| 
      
 127 
     | 
    
         
            +
              source_code_uri: https://github.com/phlex-ruby/phlex-rails
         
     | 
| 
      
 128 
     | 
    
         
            +
              changelog_uri: https://github.com/phlex-ruby/phlex-rails/blob/main/CHANGELOG.md
         
     | 
| 
       127 
129 
     | 
    
         
             
              funding_uri: https://github.com/sponsors/joeldrapper
         
     | 
| 
       128 
130 
     | 
    
         
             
              rubygems_mfa_required: 'true'
         
     | 
| 
       129 
131 
     | 
    
         
             
            post_install_message:
         
     |