From 4d738afb22ad9998b222685d3a66e85276dc9102 Mon Sep 17 00:00:00 2001 From: "Henry J. Wylde" Date: Thu, 28 Nov 2024 16:07:27 +1300 Subject: [PATCH 1/3] actionview: update `label` and `button` signatures to use an optional block --- gems/actionview/6.0/actionview-generated.rbs | 140 ----------------- gems/actionview/6.0/actionview.rbs | 152 +++++++++++++++++++ 2 files changed, 152 insertions(+), 140 deletions(-) diff --git a/gems/actionview/6.0/actionview-generated.rbs b/gems/actionview/6.0/actionview-generated.rbs index 10ae3fe44..52c5d9228 100644 --- a/gems/actionview/6.0/actionview-generated.rbs +++ b/gems/actionview/6.0/actionview-generated.rbs @@ -3605,56 +3605,6 @@ module ActionView # FormOptionsHelper#collection_select and DateHelper#datetime_select. def fields: (?untyped? scope, ?model: untyped? model, **untyped options) { () -> untyped } -> untyped - # Returns a label tag tailored for labelling an input field for a specified attribute (identified by +method+) on an object - # assigned to the template (identified by +object+). The text of label will default to the attribute name unless a translation - # is found in the current I18n locale (through helpers.label..) or you specify it explicitly. - # Additional options on the label tag can be passed as a hash with +options+. These options will be tagged - # onto the HTML as an HTML element attribute as in the example shown, except for the :value option, which is designed to - # target labels for radio_button tags (where the value is used in the ID of the input tag). - # - # ==== Examples - # label(:post, :title) - # # => - # - # You can localize your labels based on model and attribute names. - # For example you can define the following in your locale (e.g. en.yml) - # - # helpers: - # label: - # post: - # body: "Write your entire text here" - # - # Which then will result in - # - # label(:post, :body) - # # => - # - # Localization can also be based purely on the translation of the attribute-name - # (if you are using ActiveRecord): - # - # activerecord: - # attributes: - # post: - # cost: "Total cost" - # - # label(:post, :cost) - # # => - # - # label(:post, :title, "A short title") - # # => - # - # label(:post, :title, "A short title", class: "title_label") - # # => - # - # label(:post, :privacy, "Public Post", value: "public") - # # => - # - # label(:post, :terms) do - # raw('Accept Terms.') - # end - # # => - def label: (untyped object_name, untyped method, ?untyped? content_or_options, ?untyped? options) { () -> untyped } -> untyped - # Returns an input tag of the "text" type tailored for accessing a specified attribute (identified by +method+) on an object # assigned to the template (identified by +object+). Additional options on the input tag can be passed as a # hash with +options+. These options will be tagged onto the HTML as an HTML element attribute as in the example @@ -4351,56 +4301,6 @@ module ActionView # See the docs for the ActionView::FormHelper.fields helper method. def fields: (?untyped? scope, ?model: untyped? model, **untyped options) { () -> untyped } -> untyped - # Returns a label tag tailored for labelling an input field for a specified attribute (identified by +method+) on an object - # assigned to the template (identified by +object+). The text of label will default to the attribute name unless a translation - # is found in the current I18n locale (through helpers.label..) or you specify it explicitly. - # Additional options on the label tag can be passed as a hash with +options+. These options will be tagged - # onto the HTML as an HTML element attribute as in the example shown, except for the :value option, which is designed to - # target labels for radio_button tags (where the value is used in the ID of the input tag). - # - # ==== Examples - # label(:title) - # # => - # - # You can localize your labels based on model and attribute names. - # For example you can define the following in your locale (e.g. en.yml) - # - # helpers: - # label: - # post: - # body: "Write your entire text here" - # - # Which then will result in - # - # label(:body) - # # => - # - # Localization can also be based purely on the translation of the attribute-name - # (if you are using ActiveRecord): - # - # activerecord: - # attributes: - # post: - # cost: "Total cost" - # - # label(:cost) - # # => - # - # label(:title, "A short title") - # # => - # - # label(:title, "A short title", class: "title_label") - # # => - # - # label(:privacy, "Public Post", value: "public") - # # => - # - # label(:terms) do - # raw('Accept Terms.') - # end - # # => - def label: (untyped method, ?untyped? text, ?::Hash[untyped, untyped] options) { () -> untyped } -> untyped - # Returns a checkbox tag tailored for accessing a specified attribute (identified by +method+) on an object # assigned to the template (identified by +object+). This object must be an instance object (@object) and not a local object. # It's intended that +method+ returns an integer and if that integer is above zero, then the checkbox is checked. @@ -4564,46 +4464,6 @@ module ActionView # def submit: (?untyped? value, ?::Hash[untyped, untyped] options) -> untyped - # Add the submit button for the given form. When no value is given, it checks - # if the object is a new resource or not to create the proper label: - # - # <%= form_for @post do |f| %> - # <%= f.button %> - # <% end %> - # - # In the example above, if @post is a new record, it will use "Create Post" as - # button label; otherwise, it uses "Update Post". - # - # Those labels can be customized using I18n under the +helpers.submit+ key - # (the same as submit helper) and using %{model} for translation interpolation: - # - # en: - # helpers: - # submit: - # create: "Create a %{model}" - # update: "Confirm changes to %{model}" - # - # It also searches for a key specific to the given object: - # - # en: - # helpers: - # submit: - # post: - # create: "Add %{model}" - # - # ==== Examples - # button("Create post") - # # => - # - # button do - # content_tag(:strong, 'Ask me!') - # end - # # => - # - def button: (?untyped? value, ?::Hash[untyped, untyped] options) { () -> untyped } -> untyped - def emitted_hidden_id?: () -> untyped private diff --git a/gems/actionview/6.0/actionview.rbs b/gems/actionview/6.0/actionview.rbs index 9dae26c39..23f846064 100644 --- a/gems/actionview/6.0/actionview.rbs +++ b/gems/actionview/6.0/actionview.rbs @@ -1,3 +1,155 @@ +module ActionView + module Helpers + class FormBuilder + # Add the submit button for the given form. When no value is given, it checks + # if the object is a new resource or not to create the proper label: + # + # <%= form_for @post do |f| %> + # <%= f.button %> + # <% end %> + # + # In the example above, if @post is a new record, it will use "Create Post" as + # button label; otherwise, it uses "Update Post". + # + # Those labels can be customized using I18n under the +helpers.submit+ key + # (the same as submit helper) and using %{model} for translation interpolation: + # + # en: + # helpers: + # submit: + # create: "Create a %{model}" + # update: "Confirm changes to %{model}" + # + # It also searches for a key specific to the given object: + # + # en: + # helpers: + # submit: + # post: + # create: "Add %{model}" + # + # ==== Examples + # button("Create post") + # # => + # + # button do + # content_tag(:strong, 'Ask me!') + # end + # # => + # + def button: (?untyped? value, ?::Hash[untyped, untyped] options) ?{ () -> untyped } -> untyped + + # Returns a label tag tailored for labelling an input field for a specified attribute (identified by +method+) on an object + # assigned to the template (identified by +object+). The text of label will default to the attribute name unless a translation + # is found in the current I18n locale (through helpers.label..) or you specify it explicitly. + # Additional options on the label tag can be passed as a hash with +options+. These options will be tagged + # onto the HTML as an HTML element attribute as in the example shown, except for the :value option, which is designed to + # target labels for radio_button tags (where the value is used in the ID of the input tag). + # + # ==== Examples + # label(:title) + # # => + # + # You can localize your labels based on model and attribute names. + # For example you can define the following in your locale (e.g. en.yml) + # + # helpers: + # label: + # post: + # body: "Write your entire text here" + # + # Which then will result in + # + # label(:body) + # # => + # + # Localization can also be based purely on the translation of the attribute-name + # (if you are using ActiveRecord): + # + # activerecord: + # attributes: + # post: + # cost: "Total cost" + # + # label(:cost) + # # => + # + # label(:title, "A short title") + # # => + # + # label(:title, "A short title", class: "title_label") + # # => + # + # label(:privacy, "Public Post", value: "public") + # # => + # + # label(:terms) do + # raw('Accept Terms.') + # end + # # => + def label: (untyped method, ?untyped? text, ?::Hash[untyped, untyped] options) ?{ () -> untyped } -> untyped + end + end +end + +module ActionView + module Helpers + module FormHelper + # Returns a label tag tailored for labelling an input field for a specified attribute (identified by +method+) on an object + # assigned to the template (identified by +object+). The text of label will default to the attribute name unless a translation + # is found in the current I18n locale (through helpers.label..) or you specify it explicitly. + # Additional options on the label tag can be passed as a hash with +options+. These options will be tagged + # onto the HTML as an HTML element attribute as in the example shown, except for the :value option, which is designed to + # target labels for radio_button tags (where the value is used in the ID of the input tag). + # + # ==== Examples + # label(:post, :title) + # # => + # + # You can localize your labels based on model and attribute names. + # For example you can define the following in your locale (e.g. en.yml) + # + # helpers: + # label: + # post: + # body: "Write your entire text here" + # + # Which then will result in + # + # label(:post, :body) + # # => + # + # Localization can also be based purely on the translation of the attribute-name + # (if you are using ActiveRecord): + # + # activerecord: + # attributes: + # post: + # cost: "Total cost" + # + # label(:post, :cost) + # # => + # + # label(:post, :title, "A short title") + # # => + # + # label(:post, :title, "A short title", class: "title_label") + # # => + # + # label(:post, :privacy, "Public Post", value: "public") + # # => + # + # label(:post, :terms) do + # raw('Accept Terms.') + # end + # # => + def label: (untyped object_name, untyped method, ?untyped? content_or_options, ?untyped? options) ?{ () -> untyped } -> untyped + end + end +end + module ActionView module Helpers module UrlHelper From 7492fd906ba3ed1d3ccccbefeaf74c2d33a80263 Mon Sep 17 00:00:00 2001 From: "Henry J. Wylde" Date: Thu, 28 Nov 2024 16:24:19 +1300 Subject: [PATCH 2/3] actionview: update `content_tag` signature to use an optional block --- gems/actionview/6.0/actionview-generated.rbs | 28 ---------------- gems/actionview/6.0/actionview.rbs | 34 ++++++++++++++++++++ 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/gems/actionview/6.0/actionview-generated.rbs b/gems/actionview/6.0/actionview-generated.rbs index 52c5d9228..810fe9c4e 100644 --- a/gems/actionview/6.0/actionview-generated.rbs +++ b/gems/actionview/6.0/actionview-generated.rbs @@ -6843,34 +6843,6 @@ module ActionView # # =>
def tag: (?untyped? name, ?untyped? options, ?bool open, ?bool escape) -> untyped - # Returns an HTML block tag of type +name+ surrounding the +content+. Add - # HTML attributes by passing an attributes hash to +options+. - # Instead of passing the content as an argument, you can also use a block - # in which case, you pass your +options+ as the second parameter. - # Set escape to false to disable attribute value escaping. - # Note: this is legacy syntax, see +tag+ method description for details. - # - # ==== Options - # The +options+ hash can be used with attributes with no value like (disabled and - # readonly), which you can give a value of true in the +options+ hash. You can use - # symbols or strings for the attribute names. - # - # ==== Examples - # content_tag(:p, "Hello world!") - # # =>

Hello world!

- # content_tag(:div, content_tag(:p, "Hello world!"), class: "strong") - # # =>

Hello world!

- # content_tag(:div, "Hello world!", class: ["strong", "highlight"]) - # # =>
Hello world!
- # content_tag("select", options, multiple: true) - # # => - # - # <%= content_tag :div, class: "strong" do -%> - # Hello world! - # <% end -%> - # # =>
Hello world!
- def content_tag: (untyped name, ?untyped? content_or_options_with_block, ?untyped? options, ?bool escape) { () -> untyped } -> untyped - # Returns a CDATA section with the given +content+. CDATA sections # are used to escape blocks of text containing characters which would # otherwise be recognized as markup. CDATA sections begin with the string diff --git a/gems/actionview/6.0/actionview.rbs b/gems/actionview/6.0/actionview.rbs index 23f846064..3c4cc62f9 100644 --- a/gems/actionview/6.0/actionview.rbs +++ b/gems/actionview/6.0/actionview.rbs @@ -150,6 +150,40 @@ module ActionView end end +module ActionView + module Helpers + module TagHelper + # Returns an HTML block tag of type +name+ surrounding the +content+. Add + # HTML attributes by passing an attributes hash to +options+. + # Instead of passing the content as an argument, you can also use a block + # in which case, you pass your +options+ as the second parameter. + # Set escape to false to disable attribute value escaping. + # Note: this is legacy syntax, see +tag+ method description for details. + # + # ==== Options + # The +options+ hash can be used with attributes with no value like (disabled and + # readonly), which you can give a value of true in the +options+ hash. You can use + # symbols or strings for the attribute names. + # + # ==== Examples + # content_tag(:p, "Hello world!") + # # =>

Hello world!

+ # content_tag(:div, content_tag(:p, "Hello world!"), class: "strong") + # # =>

Hello world!

+ # content_tag(:div, "Hello world!", class: ["strong", "highlight"]) + # # =>
Hello world!
+ # content_tag("select", options, multiple: true) + # # => + # + # <%= content_tag :div, class: "strong" do -%> + # Hello world! + # <% end -%> + # # =>
Hello world!
+ def content_tag: (untyped name, ?untyped? content_or_options_with_block, ?untyped? options, ?bool escape) ?{ () -> untyped } -> untyped + end + end +end + module ActionView module Helpers module UrlHelper From 7948b04a28d0e422e07b14ad083639924ef1b07b Mon Sep 17 00:00:00 2001 From: "Henry J. Wylde" Date: Thu, 28 Nov 2024 16:35:57 +1300 Subject: [PATCH 3/3] actionview: update `render` signature to use an optional block --- gems/actionview/6.0/actionview-generated.rbs | 18 --------------- gems/actionview/6.0/actionview.rbs | 24 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/gems/actionview/6.0/actionview-generated.rbs b/gems/actionview/6.0/actionview-generated.rbs index 810fe9c4e..9205dccac 100644 --- a/gems/actionview/6.0/actionview-generated.rbs +++ b/gems/actionview/6.0/actionview-generated.rbs @@ -6444,24 +6444,6 @@ module ActionView # In order to use this module, all you need is to implement # view_renderer that returns an ActionView::Renderer object. module RenderingHelper - # Returns the result of a render that's dictated by the options hash. The primary options are: - # - # * :partial - See ActionView::PartialRenderer. - # * :file - Renders an explicit template file (this used to be the old default), add :locals to pass in those. - # * :inline - Renders an inline template similar to how it's done in the controller. - # * :plain - Renders the text passed in out. Setting the content - # type as text/plain. - # * :html - Renders the HTML safe string passed in out, otherwise - # performs HTML escape on the string first. Setting the content type as - # text/html. - # * :body - Renders the text passed in, and inherits the content - # type of text/plain from ActionDispatch::Response - # object. - # - # If no options hash is passed or :update specified, the default is to render a partial and use the second parameter - # as the locals hash. - def render: (?::Hash[untyped, untyped] options, ?::Hash[untyped, untyped] locals) { () -> untyped } -> untyped - # Overwrites _layout_for in the context object so it supports the case a block is # passed to a partial. Returns the contents that are yielded to a layout, given a # name or a block. diff --git a/gems/actionview/6.0/actionview.rbs b/gems/actionview/6.0/actionview.rbs index 3c4cc62f9..8bce08cc4 100644 --- a/gems/actionview/6.0/actionview.rbs +++ b/gems/actionview/6.0/actionview.rbs @@ -150,6 +150,30 @@ module ActionView end end +module ActionView + module Helpers + module RenderingHelper + # Returns the result of a render that's dictated by the options hash. The primary options are: + # + # * :partial - See ActionView::PartialRenderer. + # * :file - Renders an explicit template file (this used to be the old default), add :locals to pass in those. + # * :inline - Renders an inline template similar to how it's done in the controller. + # * :plain - Renders the text passed in out. Setting the content + # type as text/plain. + # * :html - Renders the HTML safe string passed in out, otherwise + # performs HTML escape on the string first. Setting the content type as + # text/html. + # * :body - Renders the text passed in, and inherits the content + # type of text/plain from ActionDispatch::Response + # object. + # + # If no options hash is passed or :update specified, the default is to render a partial and use the second parameter + # as the locals hash. + def render: (?::Hash[untyped, untyped] options, ?::Hash[untyped, untyped] locals) ?{ () -> untyped } -> untyped + end + end +end + module ActionView module Helpers module TagHelper