Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2022 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require 'redmine/views/builders/json'
  19. require 'redmine/views/builders/xml'
  20. module Redmine
  21. module Views
  22. module Builders
  23. class << self
  24. def for(format, request, response, &block)
  25. builder =
  26. case format
  27. when 'xml', :xml then Builders::Xml.new(request, response)
  28. when 'json', :json then Builders::Json.new(request, response)
  29. else
  30. Rails.logger.error "No builder for format #{format.inspect}"
  31. response.status = 406
  32. return "We couldn't handle your request, sorry. If you were trying to access the API, make sure to append .json or .xml to your request URL.\n"
  33. end
  34. if block_given?
  35. yield(builder)
  36. else
  37. builder
  38. end
  39. end
  40. end
  41. end
  42. end
  43. end