Class: Strelka::CMS::PageFilter::Editorial

Inherits:
Strelka::CMS::PageFilter
  • Object
show all
Defined in:
lib/strelka/cms/pagefilter/editorial.rb

Overview

A class for embedding editorial remarks in a page.

Constant Summary collapse

LinkPI =

PI ::= ‘<?’ PITarget (S (Char* - (Char* ‘?>’ Char*)))? ‘?>’

%r{
		<\?
ed					# Instruction Target
\s+
(\w+?)				# type of editorial mark [$1]
:?					# optional colon
"
	(.*?)           # content that should be edited [$2]
"
\s*
		\?>
}x
TOOLTIP_TEMPLATE =

Tooltip template

%{<div class="tooltip ed %s-ed"><h3>%s</h3><p>%s</p></div>}

Instance Method Summary collapse

Instance Method Details

#generate_mark(current_page, mark_type, content) ⇒ Object

Create an HTML fragment from the parsed LinkPI.



45
46
47
48
49
50
51
52
# File 'lib/strelka/cms/pagefilter/editorial.rb', line 45

def generate_mark( current_page, mark_type, content )
	id = Digest::MD5.hexdigest( content )

	edmark = %{<span class="edmark %s-edmark">(ed.)</span>} % [ mark_type ]
	tooltip = TOOLTIP_TEMPLATE % [ mark_type, mark_type.upcase, content ]

	return edmark + "\n" + tooltip + "\n"
end

#process(source, page) ⇒ Object

Process the given source for <?ed … ?> processing-instructions



33
34
35
36
37
38
39
40
41
# File 'lib/strelka/cms/pagefilter/editorial.rb', line 33

def process( source, page )
	return source.gsub( LinkPI ) do |match|
		# Grab the tag values
		mark_type = $1
		content   = $2

		self.generate_mark( page, mark_type, content )
	end
end