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
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
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(match_data, revision) ⇒ Category
constructor
A new instance of Category.
-
#mask(content) ⇒ Object
Mark this chunk’s start and end points but allow the terms after the ‘:’ to be marked up.
-
#unmask(content) ⇒ Object
If the chunk is hidden, erase the mask and return this chunk otherwise, surround it with a ‘div’ block.
Methods inherited from Chunk::Abstract
#post_mask, #pre_mask, #revert
Constructor Details
#initialize(match_data, revision) ⇒ Category
Returns a new instance of Category.
15 16 17 18 19 |
# File 'app/models/chunks/category.rb', line 15 def initialize(match_data, revision) super(match_data, revision) @hidden = match_data[1] @list = match_data[2].split(',').map { |c| c.strip } end |
Instance Attribute Details
#hidden ⇒ Object (readonly)
Returns the value of attribute hidden.
13 14 15 |
# File 'app/models/chunks/category.rb', line 13 def hidden @hidden end |
#list ⇒ Object (readonly)
Returns the value of attribute list.
13 14 15 |
# File 'app/models/chunks/category.rb', line 13 def list @list end |
Class Method Details
.pattern ⇒ Object
11 |
# File 'app/models/chunks/category.rb', line 11 def self.pattern() return /^(:)?category\s*:(.*)$/i end |
Instance Method Details
#mask(content) ⇒ Object
Mark this chunk’s start and end points but allow the terms after the ‘:’ to be marked up.
23 |
# File 'app/models/chunks/category.rb', line 23 def mask(content) pre_mask + list.join(', ') + post_mask end |
#unmask(content) ⇒ Object
If the chunk is hidden, erase the mask and return this chunk otherwise, surround it with a ‘div’ block.
27 28 29 30 31 32 |
# File 'app/models/chunks/category.rb', line 27 def unmask(content) #replacement = ( hidden ? '' : '<div class="property">category:\1</div>' ) self if content.sub!( Regexp.new( pre_mask+'(.*)?'+post_mask ) ) { "<div class='property' #{'style="display: none"' if hidden}>category:#{$1.split(',').map { |c| c.strip!; "<a href='../list/?category=#{c}'>#{c}</a> " }}</div>" } end |