##// END OF EJS Templates
Adds a pseudo format to api template names and overrides ActionController#default_template so that api templates are chosen automatically....
Jean-Philippe Lang -
r4352:224921460a0a
parent child
Show More
@@ -22,7 +22,7 class ApplicationController < ActionController::Base
22 22 include Redmine::I18n
23 23
24 24 layout 'base'
25 exempt_from_layout 'builder', 'apit'
25 exempt_from_layout 'builder', 'rsb'
26 26
27 27 # Remove broken cookie after upgrade from 0.8.x (#4292)
28 28 # See https://rails.lighthouseapp.com/projects/8994/tickets/3360
@@ -426,4 +426,24 class ApplicationController < ActionController::Base
426 426 )
427 427 render options
428 428 end
429
430 # Overrides #default_template so that the api template
431 # is used automatically if it exists
432 def default_template(action_name = self.action_name)
433 if api_request?
434 begin
435 return self.view_paths.find_template(default_template_name(action_name), 'api')
436 rescue ::ActionView::MissingTemplate
437 # the api template was not found
438 # fallback to the default behaviour
439 end
440 end
441 super
442 end
443
444 # Overrides #pick_layout so that #render with no arguments
445 # doesn't use the layout for api requests
446 def pick_layout(*args)
447 api_request? ? nil : super
448 end
429 449 end
@@ -84,7 +84,7 class IssuesController < ApplicationController
84 84
85 85 respond_to do |format|
86 86 format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? }
87 format.api { render :template => 'issues/index.apit' }
87 format.api
88 88 format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
89 89 format.csv { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') }
90 90 format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
@@ -109,7 +109,7 class IssuesController < ApplicationController
109 109 @time_entry = TimeEntry.new
110 110 respond_to do |format|
111 111 format.html { render :template => 'issues/show.rhtml' }
112 format.api { render :template => 'issues/show.apit' }
112 format.api
113 113 format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
114 114 format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
115 115 end
@@ -136,7 +136,7 class IssuesController < ApplicationController
136 136 redirect_to(params[:continue] ? { :action => 'new', :project_id => @project, :issue => {:tracker_id => @issue.tracker, :parent_issue_id => @issue.parent_issue_id}.reject {|k,v| v.nil?} } :
137 137 { :action => 'show', :id => @issue })
138 138 }
139 format.api { render :template => 'issues/show.apit', :status => :created, :location => issue_url(@issue) }
139 format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
140 140 end
141 141 return
142 142 else
@@ -54,7 +54,6 class ProjectsController < ApplicationController
54 54 }
55 55 format.api {
56 56 @projects = Project.visible.find(:all, :order => 'lft')
57 render :template => 'projects/index.apit'
58 57 }
59 58 format.atom {
60 59 projects = Project.visible.find(:all, :order => 'created_on DESC',
@@ -89,7 +88,7 class ProjectsController < ApplicationController
89 88 flash[:notice] = l(:notice_successful_create)
90 89 redirect_to :controller => 'projects', :action => 'settings', :id => @project
91 90 }
92 format.api { render :template => 'projects/show.apit', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) }
91 format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) }
93 92 end
94 93 else
95 94 respond_to do |format|
@@ -165,7 +164,7 class ProjectsController < ApplicationController
165 164
166 165 respond_to do |format|
167 166 format.html
168 format.api { render :template => 'projects/show.apit'}
167 format.api
169 168 end
170 169 end
171 170
@@ -76,8 +76,6 class TimelogController < ApplicationController
76 76 :order => sort_clause,
77 77 :limit => @entry_pages.items_per_page,
78 78 :offset => @entry_pages.current.offset)
79
80 render :template => 'timelog/index.apit'
81 79 }
82 80 format.atom {
83 81 entries = TimeEntry.find(:all,
@@ -103,7 +101,7 class TimelogController < ApplicationController
103 101 respond_to do |format|
104 102 # TODO: Implement html response
105 103 format.html { render :nothing => true, :status => 406 }
106 format.api { render :template => 'timelog/show.apit' }
104 format.api
107 105 end
108 106 end
109 107
@@ -128,7 +126,7 class TimelogController < ApplicationController
128 126 flash[:notice] = l(:notice_successful_update)
129 127 redirect_back_or_default :action => 'index', :project_id => @time_entry.project
130 128 }
131 format.api { render :template => 'timelog/show.apit', :status => :created, :location => time_entry_url(@time_entry) }
129 format.api { render :action => 'show', :status => :created, :location => time_entry_url(@time_entry) }
132 130 end
133 131 else
134 132 respond_to do |format|
@@ -49,7 +49,7 class UsersController < ApplicationController
49 49
50 50 respond_to do |format|
51 51 format.html { render :layout => !request.xhr? }
52 format.api { render :template => 'users/index.apit' }
52 format.api
53 53 end
54 54 end
55 55
@@ -71,7 +71,7 class UsersController < ApplicationController
71 71
72 72 respond_to do |format|
73 73 format.html { render :layout => 'base' }
74 format.api { render :template => 'users/show.apit' }
74 format.api
75 75 end
76 76 rescue ActiveRecord::RecordNotFound
77 77 render_404
@@ -114,7 +114,7 class UsersController < ApplicationController
114 114 {:controller => 'users', :action => 'edit', :id => @user}
115 115 )
116 116 }
117 format.api { render :template => 'users/show.apit', :status => :created, :location => user_url(@user) }
117 format.api { render :action => 'show', :status => :created, :location => user_url(@user) }
118 118 end
119 119 else
120 120 @auth_sources = AuthSource.find(:all)
1 NO CONTENT: file renamed from app/views/issues/index.apit to app/views/issues/index.api.rsb
1 NO CONTENT: file renamed from app/views/issues/show.apit to app/views/issues/show.api.rsb
1 NO CONTENT: file renamed from app/views/projects/index.apit to app/views/projects/index.api.rsb
1 NO CONTENT: file renamed from app/views/projects/show.apit to app/views/projects/show.api.rsb
1 NO CONTENT: file renamed from app/views/timelog/index.apit to app/views/timelog/index.api.rsb
1 NO CONTENT: file renamed from app/views/timelog/show.apit to app/views/timelog/show.api.rsb
1 NO CONTENT: file renamed from app/views/users/index.apit to app/views/users/index.api.rsb
1 NO CONTENT: file renamed from app/views/users/show.apit to app/views/users/show.api.rsb
@@ -230,4 +230,4 Redmine::WikiFormatting.map do |format|
230 230 format.register :textile, Redmine::WikiFormatting::Textile::Formatter, Redmine::WikiFormatting::Textile::Helper
231 231 end
232 232
233 ActionView::Template.register_template_handler :apit, Redmine::Views::ApiTemplateHandler
233 ActionView::Template.register_template_handler :rsb, Redmine::Views::ApiTemplateHandler
General Comments 0
You need to be logged in to leave comments. Login now