Class: Category

Inherits:
Chunk::Abstract show all
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

Attributes inherited from Chunk::Abstract

#text

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Chunk::Abstract

#post_mask, #pre_mask, #revert

Constructor Details

#initialize(match_data) ⇒ Category

Returns a new instance of Category.



15
16
17
18
19
# File 'app/models/chunks/category.rb', line 15

def initialize(match_data)
  super(match_data)
	@hidden = match_data[1]
  @list = match_data[2].split(',').map { |c| c.strip }
end

Instance Attribute Details

#hiddenObject (readonly)

Returns the value of attribute hidden.



13
14
15
# File 'app/models/chunks/category.rb', line 13

def hidden
  @hidden
end

#listObject (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

.patternObject



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
# 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 ), replacement )
end