summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2010-12-04 17:43:39 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2010-12-04 17:43:39 +0000
commit224921460a0a3d9c97813e4a64f0903adffff22f (patch)
tree76234577050b11dec0f6b79af2461b8e2359a199 /app
parent915748204965bb7f9704b55554e30f091934138e (diff)
downloadredmine-224921460a0a3d9c97813e4a64f0903adffff22f.tar.gz
redmine-224921460a0a3d9c97813e4a64f0903adffff22f.zip
Adds a pseudo format to api template names and overrides ActionController#default_template so that api templates are chosen automatically.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4466 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application_controller.rb22
-rw-r--r--app/controllers/issues_controller.rb6
-rw-r--r--app/controllers/projects_controller.rb5
-rw-r--r--app/controllers/timelog_controller.rb6
-rw-r--r--app/controllers/users_controller.rb6
-rw-r--r--app/views/issues/index.api.rsb (renamed from app/views/issues/index.apit)0
-rw-r--r--app/views/issues/show.api.rsb (renamed from app/views/issues/show.apit)0
-rw-r--r--app/views/projects/index.api.rsb (renamed from app/views/projects/index.apit)0
-rw-r--r--app/views/projects/show.api.rsb (renamed from app/views/projects/show.apit)0
-rw-r--r--app/views/timelog/index.api.rsb (renamed from app/views/timelog/index.apit)0
-rw-r--r--app/views/timelog/show.api.rsb (renamed from app/views/timelog/show.apit)0
-rw-r--r--app/views/users/index.api.rsb (renamed from app/views/users/index.apit)0
-rw-r--r--app/views/users/show.api.rsb (renamed from app/views/users/show.apit)0
13 files changed, 31 insertions, 14 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index d5241ff89..cb6c1a06f 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -22,7 +22,7 @@ class ApplicationController < ActionController::Base
include Redmine::I18n
layout 'base'
- exempt_from_layout 'builder', 'apit'
+ exempt_from_layout 'builder', 'rsb'
# Remove broken cookie after upgrade from 0.8.x (#4292)
# See https://rails.lighthouseapp.com/projects/8994/tickets/3360
@@ -426,4 +426,24 @@ class ApplicationController < ActionController::Base
)
render options
end
+
+ # Overrides #default_template so that the api template
+ # is used automatically if it exists
+ def default_template(action_name = self.action_name)
+ if api_request?
+ begin
+ return self.view_paths.find_template(default_template_name(action_name), 'api')
+ rescue ::ActionView::MissingTemplate
+ # the api template was not found
+ # fallback to the default behaviour
+ end
+ end
+ super
+ end
+
+ # Overrides #pick_layout so that #render with no arguments
+ # doesn't use the layout for api requests
+ def pick_layout(*args)
+ api_request? ? nil : super
+ end
end
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb
index 79b831ca6..b0c41ff29 100644
--- a/app/controllers/issues_controller.rb
+++ b/app/controllers/issues_controller.rb
@@ -84,7 +84,7 @@ class IssuesController < ApplicationController
respond_to do |format|
format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? }
- format.api { render :template => 'issues/index.apit' }
+ format.api
format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
format.csv { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') }
format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
@@ -109,7 +109,7 @@ class IssuesController < ApplicationController
@time_entry = TimeEntry.new
respond_to do |format|
format.html { render :template => 'issues/show.rhtml' }
- format.api { render :template => 'issues/show.apit' }
+ format.api
format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
format.pdf { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
end
@@ -136,7 +136,7 @@ class IssuesController < ApplicationController
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?} } :
{ :action => 'show', :id => @issue })
}
- format.api { render :template => 'issues/show.apit', :status => :created, :location => issue_url(@issue) }
+ format.api { render :action => 'show', :status => :created, :location => issue_url(@issue) }
end
return
else
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 8ec947258..1c982ac22 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -54,7 +54,6 @@ class ProjectsController < ApplicationController
}
format.api {
@projects = Project.visible.find(:all, :order => 'lft')
- render :template => 'projects/index.apit'
}
format.atom {
projects = Project.visible.find(:all, :order => 'created_on DESC',
@@ -89,7 +88,7 @@ class ProjectsController < ApplicationController
flash[:notice] = l(:notice_successful_create)
redirect_to :controller => 'projects', :action => 'settings', :id => @project
}
- format.api { render :template => 'projects/show.apit', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) }
+ format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) }
end
else
respond_to do |format|
@@ -165,7 +164,7 @@ class ProjectsController < ApplicationController
respond_to do |format|
format.html
- format.api { render :template => 'projects/show.apit'}
+ format.api
end
end
diff --git a/app/controllers/timelog_controller.rb b/app/controllers/timelog_controller.rb
index 78d31490d..300b28f11 100644
--- a/app/controllers/timelog_controller.rb
+++ b/app/controllers/timelog_controller.rb
@@ -76,8 +76,6 @@ class TimelogController < ApplicationController
:order => sort_clause,
:limit => @entry_pages.items_per_page,
:offset => @entry_pages.current.offset)
-
- render :template => 'timelog/index.apit'
}
format.atom {
entries = TimeEntry.find(:all,
@@ -103,7 +101,7 @@ class TimelogController < ApplicationController
respond_to do |format|
# TODO: Implement html response
format.html { render :nothing => true, :status => 406 }
- format.api { render :template => 'timelog/show.apit' }
+ format.api
end
end
@@ -128,7 +126,7 @@ class TimelogController < ApplicationController
flash[:notice] = l(:notice_successful_update)
redirect_back_or_default :action => 'index', :project_id => @time_entry.project
}
- format.api { render :template => 'timelog/show.apit', :status => :created, :location => time_entry_url(@time_entry) }
+ format.api { render :action => 'show', :status => :created, :location => time_entry_url(@time_entry) }
end
else
respond_to do |format|
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 5d80c2937..131e6b12f 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -49,7 +49,7 @@ class UsersController < ApplicationController
respond_to do |format|
format.html { render :layout => !request.xhr? }
- format.api { render :template => 'users/index.apit' }
+ format.api
end
end
@@ -71,7 +71,7 @@ class UsersController < ApplicationController
respond_to do |format|
format.html { render :layout => 'base' }
- format.api { render :template => 'users/show.apit' }
+ format.api
end
rescue ActiveRecord::RecordNotFound
render_404
@@ -114,7 +114,7 @@ class UsersController < ApplicationController
{:controller => 'users', :action => 'edit', :id => @user}
)
}
- format.api { render :template => 'users/show.apit', :status => :created, :location => user_url(@user) }
+ format.api { render :action => 'show', :status => :created, :location => user_url(@user) }
end
else
@auth_sources = AuthSource.find(:all)
diff --git a/app/views/issues/index.apit b/app/views/issues/index.api.rsb
index a63b07a09..a63b07a09 100644
--- a/app/views/issues/index.apit
+++ b/app/views/issues/index.api.rsb
diff --git a/app/views/issues/show.apit b/app/views/issues/show.api.rsb
index 001cabe11..001cabe11 100644
--- a/app/views/issues/show.apit
+++ b/app/views/issues/show.api.rsb
diff --git a/app/views/projects/index.apit b/app/views/projects/index.api.rsb
index e65477a23..e65477a23 100644
--- a/app/views/projects/index.apit
+++ b/app/views/projects/index.api.rsb
diff --git a/app/views/projects/show.apit b/app/views/projects/show.api.rsb
index 4479e500f..4479e500f 100644
--- a/app/views/projects/show.apit
+++ b/app/views/projects/show.api.rsb
diff --git a/app/views/timelog/index.apit b/app/views/timelog/index.api.rsb
index 0367e0666..0367e0666 100644
--- a/app/views/timelog/index.apit
+++ b/app/views/timelog/index.api.rsb
diff --git a/app/views/timelog/show.apit b/app/views/timelog/show.api.rsb
index d5d3c5d26..d5d3c5d26 100644
--- a/app/views/timelog/show.apit
+++ b/app/views/timelog/show.api.rsb
diff --git a/app/views/users/index.apit b/app/views/users/index.api.rsb
index 815abef2b..815abef2b 100644
--- a/app/views/users/index.apit
+++ b/app/views/users/index.api.rsb
diff --git a/app/views/users/show.apit b/app/views/users/show.api.rsb
index 6c3dd9018..6c3dd9018 100644
--- a/app/views/users/show.apit
+++ b/app/views/users/show.api.rsb