ruby2html 1.5.0 → 1.5.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 +4 -4
 - data/app/views/home/form.html.rb +14 -0
 - data/app/views/home/index.html.erb +2 -0
 - data/lib/gem/ruby2html/rails_components/base_component.rb +19 -0
 - data/lib/gem/ruby2html/rails_components/button_to.rb +11 -0
 - data/lib/gem/ruby2html/rails_components/form_with.rb +93 -0
 - data/lib/gem/ruby2html/rails_components/image_tag.rb +11 -0
 - data/lib/gem/ruby2html/rails_components/link_to.rb +11 -0
 - data/lib/gem/ruby2html/render.rb +2 -2
 - data/lib/gem/ruby2html/version.rb +1 -1
 - metadata +7 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 6939967de3aa7a534e6ae8d5736e9b8aada0e7bb8822e8acb2a7be2a072c6f82
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: b872fcd0fa941c7f09bf41a3b3cece4b53d765d060afa9bbde4b88c8ed786ecd
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 7c0e095450fbdb205a1ea30ea67fc2b9a7a84a8336b78b80b2d7426efb05d75cddaa600161e2bc1cf2ee68710cdbc3b2c164555b32e969c01ef80badd2f59e99
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 78e35ea7e89947b3ba9b0e48171539895b2968149ddaabe86b64d87593940ded7cb03e8adac144c2c1d513928c84ccac5739a185ec977a1caadd16d3114f4e01
         
     | 
| 
         @@ -0,0 +1,19 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Ruby2html
         
     | 
| 
      
 4 
     | 
    
         
            +
              module RailsComponents
         
     | 
| 
      
 5 
     | 
    
         
            +
                class BaseComponent
         
     | 
| 
      
 6 
     | 
    
         
            +
                  def initialize(render, context, method, *args, **options)
         
     | 
| 
      
 7 
     | 
    
         
            +
                    @render = render
         
     | 
| 
      
 8 
     | 
    
         
            +
                    @context = context
         
     | 
| 
      
 9 
     | 
    
         
            +
                    @method = method
         
     | 
| 
      
 10 
     | 
    
         
            +
                    @args = args
         
     | 
| 
      
 11 
     | 
    
         
            +
                    @options = options
         
     | 
| 
      
 12 
     | 
    
         
            +
                  end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                  def render(&block)
         
     | 
| 
      
 15 
     | 
    
         
            +
                    raise NotImplementedError
         
     | 
| 
      
 16 
     | 
    
         
            +
                  end
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,93 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Ruby2html
         
     | 
| 
      
 4 
     | 
    
         
            +
              module RailsComponents
         
     | 
| 
      
 5 
     | 
    
         
            +
                class FormWith < BaseComponent
         
     | 
| 
      
 6 
     | 
    
         
            +
                  include ActionView::Helpers::FormHelper
         
     | 
| 
      
 7 
     | 
    
         
            +
                  def render(&block)
         
     | 
| 
      
 8 
     | 
    
         
            +
                    model = @options[:model]
         
     | 
| 
      
 9 
     | 
    
         
            +
                    scope = @options[:scope]
         
     | 
| 
      
 10 
     | 
    
         
            +
                    url = @options[:url]
         
     | 
| 
      
 11 
     | 
    
         
            +
                    method = @options[:method]
         
     | 
| 
      
 12 
     | 
    
         
            +
                    local = @options[:local]
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                    form_options = @options.except(:model, :scope, :url, :method, :local)
         
     | 
| 
      
 15 
     | 
    
         
            +
                    form_options[:action] = determine_url(model, url)
         
     | 
| 
      
 16 
     | 
    
         
            +
                    form_options[:method] = determine_method(model, method)
         
     | 
| 
      
 17 
     | 
    
         
            +
                    form_options['data-remote'] = 'true' unless local
         
     | 
| 
      
 18 
     | 
    
         
            +
                    @model = model
         
     | 
| 
      
 19 
     | 
    
         
            +
                    @scope = determine_scope(model, scope)
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                    @render.form(**form_options) do
         
     | 
| 
      
 22 
     | 
    
         
            +
                      authenticity_token_tag
         
     | 
| 
      
 23 
     | 
    
         
            +
                      utf8_enforcer_tag
         
     | 
| 
      
 24 
     | 
    
         
            +
                      block.call(self)
         
     | 
| 
      
 25 
     | 
    
         
            +
                    end
         
     | 
| 
      
 26 
     | 
    
         
            +
                  end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                  def label(method, text = nil, options = {})
         
     | 
| 
      
 29 
     | 
    
         
            +
                    @render.label(**options.merge(for: field_id(method))) do
         
     | 
| 
      
 30 
     | 
    
         
            +
                      text || method.to_s.humanize
         
     | 
| 
      
 31 
     | 
    
         
            +
                    end
         
     | 
| 
      
 32 
     | 
    
         
            +
                  end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                  def text_field(method, options = {})
         
     | 
| 
      
 35 
     | 
    
         
            +
                    @render.input(**options.merge(type: 'text', name: field_name(method), id: field_id(method), value: object_value_for(method)))
         
     | 
| 
      
 36 
     | 
    
         
            +
                  end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                  def hidden_field(method, options = {})
         
     | 
| 
      
 39 
     | 
    
         
            +
                    @render.input(**options.merge(type: 'hidden', name: field_name(method), id: field_id(method), value: object_value_for(method)))
         
     | 
| 
      
 40 
     | 
    
         
            +
                  end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                  def password_field(method, options = {})
         
     | 
| 
      
 43 
     | 
    
         
            +
                    @render.input(**options.merge(type: 'password', name: field_name(method), id: field_id(method)))
         
     | 
| 
      
 44 
     | 
    
         
            +
                  end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                  def file_field(method, options = {})
         
     | 
| 
      
 47 
     | 
    
         
            +
                    @render.input(**options.merge(type: 'file', name: field_name(method), id: field_id(method)))
         
     | 
| 
      
 48 
     | 
    
         
            +
                  end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                  def submit(value = nil, options = {})
         
     | 
| 
      
 51 
     | 
    
         
            +
                    @render.input(**options.merge(type: 'submit', value: value || submit_default_value))
         
     | 
| 
      
 52 
     | 
    
         
            +
                  end
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                  private
         
     | 
| 
      
 55 
     | 
    
         
            +
                    def determine_url(model, url)
         
     | 
| 
      
 56 
     | 
    
         
            +
                      return url if url
         
     | 
| 
      
 57 
     | 
    
         
            +
                      return polymorphic_path(model) if model && model.respond_to?(:persisted?)
         
     | 
| 
      
 58 
     | 
    
         
            +
                      nil
         
     | 
| 
      
 59 
     | 
    
         
            +
                    end
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
                    def determine_method(model, method)
         
     | 
| 
      
 62 
     | 
    
         
            +
                      return method if method
         
     | 
| 
      
 63 
     | 
    
         
            +
                      return 'post' unless model
         
     | 
| 
      
 64 
     | 
    
         
            +
                      model.respond_to?(:persisted?) && model.persisted? ? 'patch' : 'post'
         
     | 
| 
      
 65 
     | 
    
         
            +
                    end
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                    def determine_scope(model, scope)
         
     | 
| 
      
 68 
     | 
    
         
            +
                      return scope if scope
         
     | 
| 
      
 69 
     | 
    
         
            +
                      model.model_name.param_key if model.respond_to?(:model_name)
         
     | 
| 
      
 70 
     | 
    
         
            +
                    end
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                    def authenticity_token_tag
         
     | 
| 
      
 73 
     | 
    
         
            +
                      @render.input(type: 'hidden', name: 'authenticity_token', value: @context.session[:_csrf_token])
         
     | 
| 
      
 74 
     | 
    
         
            +
                    end
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                    def utf8_enforcer_tag
         
     | 
| 
      
 77 
     | 
    
         
            +
                      @render.input(type: 'hidden', name: 'utf8', value: '✓')
         
     | 
| 
      
 78 
     | 
    
         
            +
                    end
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                    def field_name(method)
         
     | 
| 
      
 81 
     | 
    
         
            +
                      @scope ? "#{@scope}[#{method}]" : method.to_s
         
     | 
| 
      
 82 
     | 
    
         
            +
                    end
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
                    def field_id(method)
         
     | 
| 
      
 85 
     | 
    
         
            +
                      @scope ? "#{@scope}_#{method}" : method.to_s
         
     | 
| 
      
 86 
     | 
    
         
            +
                    end
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
                    def object_value_for(method)
         
     | 
| 
      
 89 
     | 
    
         
            +
                      @model&.public_send(method) if @model
         
     | 
| 
      
 90 
     | 
    
         
            +
                    end
         
     | 
| 
      
 91 
     | 
    
         
            +
                end
         
     | 
| 
      
 92 
     | 
    
         
            +
              end
         
     | 
| 
      
 93 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/gem/ruby2html/render.rb
    CHANGED
    
    | 
         @@ -12,7 +12,7 @@ module Ruby2html 
     | 
|
| 
       12 
12 
     | 
    
         
             
                  kbd label legend li link main map mark meta meter nav noscript object ol optgroup option
         
     | 
| 
       13 
13 
     | 
    
         
             
                  output p param picture pre progress q rp rt ruby s samp script section select small source
         
     | 
| 
       14 
14 
     | 
    
         
             
                  span strong style sub summary sup table tbody td template textarea tfoot th thead time title
         
     | 
| 
       15 
     | 
    
         
            -
                  tr track u ul var video wbr
         
     | 
| 
      
 15 
     | 
    
         
            +
                  tr track u ul var video wbr turbo-frame
         
     | 
| 
       16 
16 
     | 
    
         
             
                ].freeze
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
                VOID_ELEMENTS = %w[area base br col embed hr img input link meta param source track wbr].freeze
         
     | 
| 
         @@ -53,7 +53,7 @@ module Ruby2html 
     | 
|
| 
       53 
53 
     | 
    
         
             
                end
         
     | 
| 
       54 
54 
     | 
    
         | 
| 
       55 
55 
     | 
    
         
             
                HTML5_TAGS.each do |tag|
         
     | 
| 
       56 
     | 
    
         
            -
                  define_method(tag) do |*args, **options, &block|
         
     | 
| 
      
 56 
     | 
    
         
            +
                  define_method(tag.tr('-', '_')) do |*args, **options, &block|
         
     | 
| 
       57 
57 
     | 
    
         
             
                    html!(tag, *args, **options, &block)
         
     | 
| 
       58 
58 
     | 
    
         
             
                  end
         
     | 
| 
       59 
59 
     | 
    
         
             
                end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: ruby2html
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1.5. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.5.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - sebi
         
     | 
| 
         @@ -63,6 +63,7 @@ files: 
     | 
|
| 
       63 
63 
     | 
    
         
             
            - app/models/concerns/.keep
         
     | 
| 
       64 
64 
     | 
    
         
             
            - app/views/benchmark/normal_html.html.erb
         
     | 
| 
       65 
65 
     | 
    
         
             
            - app/views/benchmark/ruby_2html.html.rb
         
     | 
| 
      
 66 
     | 
    
         
            +
            - app/views/home/form.html.rb
         
     | 
| 
       66 
67 
     | 
    
         
             
            - app/views/home/index.html.erb
         
     | 
| 
       67 
68 
     | 
    
         
             
            - app/views/home/rb_files.html.rb
         
     | 
| 
       68 
69 
     | 
    
         
             
            - app/views/layouts/application.html.erb
         
     | 
| 
         @@ -97,6 +98,11 @@ files: 
     | 
|
| 
       97 
98 
     | 
    
         
             
            - lib/gem/ruby2html.rb
         
     | 
| 
       98 
99 
     | 
    
         
             
            - lib/gem/ruby2html/component_helper.rb
         
     | 
| 
       99 
100 
     | 
    
         
             
            - lib/gem/ruby2html/html_beautifier_middleware.rb
         
     | 
| 
      
 101 
     | 
    
         
            +
            - lib/gem/ruby2html/rails_components/base_component.rb
         
     | 
| 
      
 102 
     | 
    
         
            +
            - lib/gem/ruby2html/rails_components/button_to.rb
         
     | 
| 
      
 103 
     | 
    
         
            +
            - lib/gem/ruby2html/rails_components/form_with.rb
         
     | 
| 
      
 104 
     | 
    
         
            +
            - lib/gem/ruby2html/rails_components/image_tag.rb
         
     | 
| 
      
 105 
     | 
    
         
            +
            - lib/gem/ruby2html/rails_components/link_to.rb
         
     | 
| 
       100 
106 
     | 
    
         
             
            - lib/gem/ruby2html/rails_helper.rb
         
     | 
| 
       101 
107 
     | 
    
         
             
            - lib/gem/ruby2html/railtie.rb
         
     | 
| 
       102 
108 
     | 
    
         
             
            - lib/gem/ruby2html/render.rb
         
     |