Class: Category
- Inherits:
-
Chunk::Abstract
- Object
- Chunk::Abstract
- Category
- Defined in:
- app/models/chunks/category.rb
Overview
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
Constant Summary collapse
- CATEGORY_PATTERN =
/^(:)?category\s*:(.*)$/i
Instance Attribute Summary collapse
-
#hidden ⇒ Object
readonly
Returns the value of attribute hidden.
-
#list ⇒ Object
readonly
Returns the value of attribute list.
Attributes inherited from Chunk::Abstract
#text, #unmask_mode, #unmask_text
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(match_data, content) ⇒ Category
constructor
A new instance of Category.
-
#url(category) ⇒ Object
TODO move presentation of page metadata to controller/view.
Methods inherited from Chunk::Abstract
apply_to, #escaped?, #id, inherited, #mask, mask_re, mask_string, #rendered?, #revert, #unmask
Constructor Details
#initialize(match_data, content) ⇒ Category
Returns a new instance of Category.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/models/chunks/category.rb', line 16 def initialize(match_data, content) super(match_data, content) @hidden = match_data[1] @list = match_data[2].split(',').map { |c| c.strip } @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 |
Instance Attribute Details
#hidden ⇒ Object (readonly)
Returns the value of attribute hidden.
14 15 16 |
# File 'app/models/chunks/category.rb', line 14 def hidden @hidden end |
#list ⇒ Object (readonly)
Returns the value of attribute list.
14 15 16 |
# File 'app/models/chunks/category.rb', line 14 def list @list end |
Class Method Details
.pattern ⇒ Object
12 |
# File 'app/models/chunks/category.rb', line 12 def self.pattern() CATEGORY_PATTERN end |
Instance Method Details
#url(category) ⇒ Object
TODO move presentation of page metadata to controller/view
30 31 32 |
# File 'app/models/chunks/category.rb', line 30 def url(category) %{<a class="category_link" href="../list/?category=#{category}">#{category}</a>} end |