Class: TextPage

Inherits:
XHTMLPage show all
Includes:
Assert
Defined in:
lib/ribit/webpage.rb

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 XHTMLPage

#add_head_element, #get_data, #insert_html_text, #set_message

Methods inherited from WebPage

#get_data, #output_page

Constructor Details

#initialize(ribitData, page, ribitConfig) ⇒ TextPage

Returns a new instance of TextPage.



187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/ribit/webpage.rb', line 187

def initialize( ribitData, page, ribitConfig )
  assert_not_nil( ribitData )
  assert_not_nil( ribitConfig )
  template = ribitData.get_page_by_full_name( "core::pagetemplate" )
  
  super( template.data )
  
  @ribitData = ribitData
  @ribitConfig = ribitConfig
  
  @page = page
  @logger = RibitLogger.new( TextPage )
  
end

Instance Method Details

#get_content_typeObject

Always text/html



203
204
205
# File 'lib/ribit/webpage.rb', line 203

def get_content_type
  return 'text/html'
end

#get_page_dataObject



305
306
307
308
309
310
311
312
313
314
# File 'lib/ribit/webpage.rb', line 305

def get_page_data
  @logger.debug( "Converting data for page ID=#{@page.full_id}, fullName=#{@page.full_name}" )
  
  @logger.debug( "Going to convert following data:\n" + @page.data )
  parser = ContentParser.new(  @ribitData )
  data = parser.parse( @page )
  
  @logger.debug( "Result is:\n" + data )
  return data
end

#handle_category_bar(id, element) ⇒ Object



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/ribit/webpage.rb', line 249

def handle_category_bar( id, element )
  @logger.debug( "Category-bar selected: pageID=#{@page.full_id}" )
  adapters = []
  
  # the current page whose parent categories are searched
  category = @page.category
  
  while ( category != nil )
    mainPageID = category.get_main_page_full_id
    if ( mainPageID != nil )
      adapters.push( ViewActionAdapter.new( mainPageID, category.name ) )
    else
      mainPageID = category.id.to_s + "::empty"
      adapters.push( ViewActionAdapter.new( mainPageID, category.name ) )
    end
    category = category.get_parent_category
  end
  
  actionEle = CategoryBarActionElement.new( id, element )
  actionEle.replace_link_elements( adapters.reverse )
end

#handle_category_bar_next_level(id, element) ⇒ Object



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/ribit/webpage.rb', line 272

def handle_category_bar_next_level( id, element )
  @logger.debug( "Category-bar-next-level selected: pageID=#{@page.full_id}" )
  adapters = []
  
  # the current page whose parent categories are searched
  category = @page.category
  @logger.debug( "childs.size(): " + category.get_child_categories.size().to_s )
  
  # before iterating sort categories
  children = category.get_child_categories
  
  if ( children != nil and children.size() > 0 )
    children = children.sort do |a,b| 
      @logger.debug( "compare: a =" + a.name + ", b =" + b.name )
      a.name<=>b.name
    end
    
    children.each do |childCategory|
      mainPageID = childCategory.get_main_page_full_id
      if ( mainPageID != nil )
        adapters.push( ViewActionAdapter.new( mainPageID, childCategory.name ) )
      else
        mainPageID = childCategory.id + "::empty"
        adapters.push( ViewActionAdapter.new( mainPageID, childCategory.name ) )
      end
    end
  end
  
  actionEle = CategoryBarNextLevelActionElement.new( id, element )
  actionEle.replace_link_elements( adapters )
end

#handle_element(id, element) ⇒ Object



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/ribit/webpage.rb', line 208

def handle_element( id, element )
  case id
  when 'text:title'
    insert_html_text( element, @page.title )
  when "text:body"
    insert_html_text( element, get_page_data )
    
  when 'link:edit'
    if ( element.name != 'a' )
      raise RibitException, "link:edit is not suitable for element #{element.name}", caller
    end
    
    actionEle = LinkActionElement.new( id, element )
    actionEle.url = EditActionAdapter.new( @page.full_id ).get_url()    
    
  when 'link:validator'
    if ( element.name != 'a' )
      raise RibitException, "link:validator is not suitable for element #{element.name}", caller
    end
    
    viewUrl = ViewActionAdapter.new( @page.full_id ).get_url
    baseUrlStr = @ribitConfig.get_base_url
    
    validator = W3CValidatorLinkActionAdapter.new( baseUrlStr + '/' + viewUrl.to_s )
    
    actionEle = LinkActionElement.new( id, element )
    actionEle.url = validator.get_url
    
  when 'link:category-bar'
    handle_category_bar( id, element )
    
  when 'link:category-bar-next-level'
    handle_category_bar_next_level( id, element )    
    
  else
    super( id, element )
  end    
  
end