Sha256: cad1284ee13ad59913a64999f26767fa234f46738ca338fb789fabf24f465917

Contents?: true

Size: 1.85 KB

Versions: 3

Compression:

Stored size: 1.85 KB

Contents

#= require joosy/joosy
#= require joosy/widget
#= require joosy/layout
#= require joosy/modules/page/scrolling
#= require joosy/modules/page/title

#
# Base class for Joosy Pages.
#
# @example Sample application page
#   class @RumbaPage extends Joosy.Page
#     @view 'rumba'
#
# @include Joosy.Modules.Page_Scrolling
# @extend  Joosy.Modules.Page_Title
#
class Joosy.Page extends Joosy.Widget
  #
  # Sets layout for current page
  #
  # @param [Class] layoutClass      Layout to use
  #
  @layout: (layoutClass) ->
    @::__layoutClass = layoutClass

  @include Joosy.Modules.Page_Scrolling
  @extend  Joosy.Modules.Page_Title

  #
  # @param [Hash] params             Route params
  # @param [Joosy.Page] previous     Previous page to unload
  #
  constructor: (@params, @previous) ->
    @layoutShouldChange = @previous?.__layoutClass != @__layoutClass

    @halted = !@__runBeforeLoads()
    @layout = switch
      when @layoutShouldChange && @__layoutClass
        new @__layoutClass(params, @previous?.layout)
      when !@layoutShouldChange
        @previous?.layout

    # If the page has no layout defined while the previous had one
    # we should declare ourselves as a relpacement to the layout, not the page
    @previous = @previous.layout if @layoutShouldChange && !@layout

  ######
  ###### Widget extensions
  ######

  #
  # This is required by {Joosy.Modules.Renderer}
  # Sets the base template dir to app_name/templates/pages
  #
  __renderSection: ->
    'pages'

  #
  # Unlike widget that injects straightforwardly into given container
  # page injects itself into the content of Layout and uses given container
  # as a fallback for cases when no Layout has been set
  #
  __bootstrapDefault: (applicationContainer) ->
    @__bootstrap @__nestingMap(), @layout?.content() || applicationContainer

# AMD wrapper
if define?.amd?
  define 'joosy/page', -> Joosy.Page

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
joosy-1.2.0.alpha.57 source/joosy/page.coffee
joosy-1.2.0.alpha.56 source/joosy/page.coffee
joosy-1.2.0.alpha.55 source/joosy/page.coffee