Skip to content

Commit

Permalink
feat(app generator): add logic to determine the appBaseUrl
Browse files Browse the repository at this point in the history
Often, the `document` and the app will share the same base url, but not necessarily so.
This determines and registers the app's base url so resources can know their origin.
  • Loading branch information
cueedee committed Aug 26, 2016
1 parent 48e1b1b commit 49eb4d8
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions generators/app/templates/src/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,25 @@ settings = require( 'madlib-settings' )
##
## https://github.com/Qwerios/madlib-hostmapping#readme
##
<% if ( i18n ) { %>


###*
# The app's base url, so that resources can know what their origin is.
#
# Often the `document` and this app will share the same base url, but not necessarily so.
#
# @property appBaseUrl
#
# @type String
# @final
###

## Leverage `document.currentScript` or a fallback (for IE <=11).
##
appBaseUrl = ( document.currentScript ? Array::slice.call( document.scripts, -1 )[0] ).src.match( /^.*\// )[0]

settings.init( 'appBaseUrl', appBaseUrl )<% if ( i18n ) { %>


## Setup localeManager
##
Expand All @@ -235,10 +253,10 @@ initialized = Q.all(
##
new Q.Promise( ( resolve ) -> $( resolve ); return; )<% if ( i18n ) { %>

## Initialize locale passing Handlebars runtime and default locale.
## Initialize locale passing Handlebars runtime, default locale and base url for locale files.
## Wait until it's been loaded.
##
locale.initialize( Handlebars, 'en-GB' )<% } %>
locale.initialize( Handlebars, 'en-GB', "#{ appBaseUrl }i18n" )<% } %>
]
)

Expand Down

0 comments on commit 49eb4d8

Please sign in to comment.