1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Commit graph

14 commits

Author SHA1 Message Date
Fumiaki MATSUSHIMA
92af4aba25 Support :any variants for FixtureResolver 2019-06-30 02:23:08 +09:00
Prathamesh Sonpatki
6a4bf486c3
Fix deprecation warning about variants and formats
- After https://github.com/rails/rails/pull/35408 and
  https://github.com/rails/rails/pull/35406, the `formats` and
  `variants` methods are deprecated in favor of `format` and `variant`.
2019-04-04 19:29:27 +05:30
Edward Rudd
c5efbbbccb Fix checking for template variants when using the ActionView::FixtureResolver 2019-04-03 18:09:34 -04:00
John Hawthorn
bcd42ae974 Remove query_format argument from resolver 2019-02-26 16:59:04 -08:00
John Hawthorn
c214546217 Create templates with format=nil 2019-02-26 16:59:04 -08:00
Aaron Patterson
ca5e23ed4d
Templates have one format
Templates only have one format.  Before this commit, templates would be
constructed with a single element array that contained the format.  This
commit eliminates the single element array and just implements a
`format` method.  This saves one array allocation per template.
2019-02-25 13:18:44 -08:00
Kir Shatrov
424117281e Use frozen string literal in actionview/ 2017-07-24 11:53:43 +03:00
Matthew Draper
87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590, reversing
changes made to afb66a5a59.
2017-07-02 02:15:17 +09:30
Kir Shatrov
cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
Xavier Noria
411ccbdab2 remove redundant curlies from hash arguments 2016-08-06 19:44:11 +02:00
Xavier Noria
63fff600ac modernizes hash syntax in actionview 2016-08-06 19:36:34 +02:00
Xavier Noria
4b6c68dfb8 applies new string literal convention in actionview/test
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 18:50:17 +02:00
Łukasz Strzałkowski
2d3a6a0cb8 Action Pack Variants
By default, variants in the templates will be picked up if a variant is set
and there's a match. The format will be:

  app/views/projects/show.html.erb
  app/views/projects/show.html+tablet.erb
  app/views/projects/show.html+phone.erb

If request.variant = :tablet is set, we'll automatically be rendering the
html+tablet template.

In the controller, we can also tailer to the variants with this syntax:

  class ProjectsController < ActionController::Base
    def show
      respond_to do |format|
        format.html do |html|
          @stars = @project.stars

          html.tablet { @notifications = @project.notifications }
          html.phone  { @chat_heads    = @project.chat_heads }
        end

        format.js
        format.atom
      end
    end
  end

The variant itself is nil by default, but can be set in before filters, like
so:

  class ApplicationController < ActionController::Base
    before_action do
      if request.user_agent =~ /iPad/
        request.variant = :tablet
      end
    end
  end

This is modeled loosely on custom mime types, but it's specifically not
intended to be used together. If you're going to make a custom mime type,
you don't need a variant. Variants are for variations on a single mime
types.
2013-12-04 00:13:16 +01:00
Piotr Sarnacki
eb23754ebb Move template tests from actionpack to actionview 2013-06-20 17:23:16 +02:00