1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionview
Sean Doyle a086418283 Yield translation to FormBuilder#button block
When translating a `<button>` element's contents, it is tedious  to make
the translation text available to a block scope.

For instance, when rendering a `<button type="submit">` with an SVG
element as its child, passing translated label text to that SVG
element's [`<title>`][svg-title] element requires an extra call to
`I18n.translate`.

Prior to this commit, doing so would require a double lookup of the
translation key:

```erb
<%# one time here, implicitly %>
<%= form.button do %>
  <svg>
    <title>
      <!-- one time here, explicitly -->
      <%= translate("helpers.submit.post.create") %>
    </title>
    <!-- ... -->
  </svg>
<% end %>
```

This commit modifies the `ActionView::Helpers::FormBuilder#button` to
check for invocations that are passed a block, and conditionally yield
the contents of `submit_default_value` as the argument.

The new view code might look something like this:

```erb
<%= form.button do |text| %>
  <svg>
    <title><%= text %></title>
    <!-- ... -->
  </svg>
<% end %>
```

Callers of the helper are still free to omit the block parameter.

[svg-title]: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/title
2020-10-30 16:30:56 -04:00
..
app/assets/javascripts Use ES module syntax for application.js.tt and docs 2020-06-16 15:12:12 -04:00
bin
lib Yield translation to FormBuilder#button block 2020-10-30 16:30:56 -04:00
test Yield translation to FormBuilder#button block 2020-10-30 16:30:56 -04:00
.gitignore
actionview.gemspec
blade.yml
CHANGELOG.md Yield translation to FormBuilder#button block 2020-10-30 16:30:56 -04:00
coffeelint.json
MIT-LICENSE
package.json
Rakefile
README.rdoc
RUNNING_UJS_TESTS.rdoc
RUNNING_UNIT_TESTS.rdoc

= Action View

Action View is a framework for handling view template lookup and rendering, and provides
view helpers that assist when building HTML forms, Atom feeds and more.
Template formats that Action View handles are ERB (embedded Ruby, typically
used to inline short Ruby snippets inside HTML), and XML Builder.

You can read more about Action View in the {Action View Overview}[https://edgeguides.rubyonrails.org/action_view_overview.html] guide.

== Download and installation

The latest version of Action View can be installed with RubyGems:

  $ gem install actionview

Source code can be downloaded as part of the Rails project on GitHub:

* https://github.com/rails/rails/tree/master/actionview


== License

Action View is released under the MIT license:

* https://opensource.org/licenses/MIT


== Support

API documentation is at

* https://api.rubyonrails.org

Bug reports for the Ruby on Rails project can be filed here:

* https://github.com/rails/rails/issues

Feature requests should be discussed on the rails-core mailing list here:

* https://discuss.rubyonrails.org/c/rubyonrails-core