2007-01-22 14:43:50 +01:00
|
|
|
require 'chunks/chunk'
|
2008-05-21 00:02:10 +02:00
|
|
|
require 'stringsupport'
|
2007-01-22 14:43:50 +01:00
|
|
|
|
|
|
|
# The category chunk looks for "category: news" on a line by
|
|
|
|
# itself and parses the terms after the ':' as categories.
|
|
|
|
# Other classes can search for Category chunks within
|
|
|
|
# rendered content to find out what categories this page
|
|
|
|
# should be in.
|
|
|
|
#
|
|
|
|
# Category lines can be hidden using ':category: news', for example
|
|
|
|
class Category < Chunk::Abstract
|
2007-09-06 17:40:48 +02:00
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
CATEGORY_PATTERN = /^(:)?category\s*:(.*)$/i
|
|
|
|
def self.pattern() CATEGORY_PATTERN end
|
|
|
|
|
|
|
|
attr_reader :hidden, :list
|
|
|
|
|
|
|
|
def initialize(match_data, content)
|
|
|
|
super(match_data, content)
|
2010-05-27 07:27:49 +02:00
|
|
|
@content = content
|
2007-01-22 14:43:50 +01:00
|
|
|
@hidden = match_data[1]
|
2009-09-08 03:38:09 +02:00
|
|
|
@list = match_data[2].split(',').map { |c| clean = c.purify.strip.escapeHTML; clean if clean != ''}
|
2007-09-06 17:40:48 +02:00
|
|
|
@list.compact!
|
2007-01-22 14:43:50 +01:00
|
|
|
@unmask_text = ''
|
|
|
|
if @hidden
|
|
|
|
@unmask_text = ''
|
|
|
|
else
|
|
|
|
category_urls = @list.map { |category| url(category) }.join(', ')
|
|
|
|
@unmask_text = '<div class="property"> category: ' + category_urls + '</div>'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# TODO move presentation of page metadata to controller/view
|
|
|
|
def url(category)
|
2010-05-27 07:27:49 +02:00
|
|
|
%{<a class="category_link" href="#{@content.url_generator.url_for :web => @content.web.address,
|
2010-05-27 08:17:24 +02:00
|
|
|
:action => 'list', :only_path => true}/#{CGI.escape(category)}">#{category}</a>}
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
|
|
|
end
|