Class: StyleSheetAction

Inherits:
ViewAction show all
Includes:
Assert
Defined in:
lib/ribit/action.rb

Constant Summary collapse

MODIFIED =

CSS is not modified (not possible currently, so last modified time is time of start up

Time.new

Constants inherited from ViewAction

ViewAction::ID

Instance Attribute Summary

Attributes inherited from WebAction

#id

Instance Method Summary collapse

Methods included from Assert

assert, #assert, assert_nil, #assert_nil, #assert_not_nil, assert_not_nil, raise_exception

Methods inherited from ViewAction

#decorate_page, #get_cached_page, #get_page_id

Methods inherited from WebAction

#add_headers

Constructor Details

#initialize(ribitData) ⇒ StyleSheetAction

Returns a new instance of StyleSheetAction.



711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
# File 'lib/ribit/action.rb', line 711

def initialize( ribitData )
  assert_not_nil( ribitData, 'RibitData is nil' )
  
  @id = 'stylesheet'
  @ribitData = ribitData
  @logger = RibitLogger.new( StyleSheetAction )
  cssPage = ribitData.get_page_by_full_name( "core::css" )
  
  if ( cssPage != nil )
    @cssPageData = cssPage.data
  else
      # page not found, it is not mandatory
    @logger.warn( 'No CSS page found by name core::css' )
    @cssPageData = '# No CSS page found by name core::css'
  end
end

Instance Method Details

#run(pageRequest, pageResponse) ⇒ Object



729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
# File 'lib/ribit/action.rb', line 729

def run( pageRequest, pageResponse )
  lastModified = pageRequest.get_header_field( 'If-Modified-Since' )
  if ( lastModified != nil )
    @logger.debug( "Found If-Modified-Since field from HTTP headers" )
    time = Time.httpdate( lastModified )
    
    # NOTE: MODIFIED time contains also fraction of seconds but httpdate
    #       doesn't have them => we have to compare full seconds
    if ( ( time.to_i <=> MODIFIED.to_i ) >= 0 )
      @logger.debug( "Cached copy is up to date" )
      pageResponse.status = 304
      return
    end
  end
  
  page = RawPage.new( @cssPageData, 'text/css' )
  page.output_page( pageResponse )
  
  pageResponse.set_header_field( 'Cache-Control', 'public, must-revalidate, proxy-revalidate' )
  pageResponse.set_header_field( 'Last-Modified', MODIFIED.httpdate )
end