Store base URI in Discourse.BaseUri and use it in all places where rootURL was previously used

This commit is contained in:
Wojciech Kocjan 2013-04-04 00:26:47 +02:00
parent bb18b6cb9b
commit a875b1c44a
5 changed files with 9 additions and 25 deletions

View File

@ -22,10 +22,8 @@ Discourse = Ember.Application.createWithMixins({
// The highest seen post number by topic
highestSeenByTopic: {},
rootURL: '/',
getURL: function(url) {
var u = this.get('rootURL');
var u = (Discourse.BaseUri === undefined ? "/" : Discourse.BaseUri);
if (u[u.length-1] === '/') {
u = u.substring(0, u.length-1);
}

View File

@ -13,14 +13,6 @@ Discourse.URL = {
// Used for matching a /more URL
MORE_REGEXP: /\/more$/,
/**
Will be pre-pended to path upon state change
@property rootURL
@default '/'
*/
rootURL: '/',
/**
@private
@ -73,7 +65,8 @@ Discourse.URL = {
If the URL is absolute, remove rootURL
*/
if (path.match(/^\//)) {
var rootURL = this.rootURL.replace(/\/$/, '');
var rootURL = (Discourse.BaseUri === undefined ? "/" : Discourse.BaseUri);
rootURL = rootURL.replace(/\/$/, '');
path = path.replace(rootURL, '');
}

View File

@ -35,14 +35,6 @@ Ember.DiscourseLocation = Ember.Object.extend({
set(this, 'history', window.history);
},
/**
Will be pre-pended to path upon state change
@property rootURL
@default '/'
*/
rootURL: '/',
/**
@private
@ -51,7 +43,7 @@ Ember.DiscourseLocation = Ember.Object.extend({
@method getURL
*/
getURL: function() {
var rootURL = get(this, 'rootURL'),
var rootURL = (Discourse.BaseUri === undefined ? "/" : Discourse.BaseUri),
url = get(this, 'location').pathname;
rootURL = rootURL.replace(/\/$/, '');
@ -154,7 +146,7 @@ Ember.DiscourseLocation = Ember.Object.extend({
var currentState = self.get('currentState');
if (currentState) {
var url = e.state.path,
rootURL = get(self, 'rootURL');
rootURL = (Discourse.BaseUri === undefined ? "/" : Discourse.BaseUri);
rootURL = rootURL.replace(/\/$/, '');
url = url.replace(rootURL, '');
@ -176,7 +168,7 @@ Ember.DiscourseLocation = Ember.Object.extend({
@param url {String}
*/
formatURL: function(url) {
var rootURL = get(this, 'rootURL');
var rootURL = (Discourse.BaseUri === undefined ? "/" : Discourse.BaseUri);
if (url !== '') {
rootURL = rootURL.replace(/\/$/, '');

View File

@ -35,6 +35,7 @@
<script>
Discourse.CDN = '<%= Rails.configuration.action_controller.asset_host %>';
Discourse.BaseUrl = '<%= RailsMultisite::ConnectionManagement.current_hostname %>';
Discourse.BaseUri = '<%= Discourse::base_uri "/" %>';
Discourse.Environment = '<%= Rails.env %>';
Discourse.Router.map(function() {
return Discourse.routeBuilder.call(this);

View File

@ -18,11 +18,11 @@ module Discourse
RailsMultisite::ConnectionManagement.current_hostname
end
def self.base_uri
def self.base_uri default_value=""
if !ActionController::Base.config.relative_url_root.blank?
return ActionController::Base.config.relative_url_root
else
return ""
return default_value
end
end