Sha256: 89b1208c5110206f7aabb1b2f88c371af28fa5f51273439324017b09401bd4b6

Contents?: true

Size: 1.28 KB

Versions: 6

Compression:

Stored size: 1.28 KB

Contents

#!/usr/bin/env ruby

require 'digest/md5'

require 'strelka/cms/pagefilter' unless defined?( Strelka::CMS::PageFilter )

# A class for embedding editorial remarks in a page.
class Strelka::CMS::PageFilter::Editorial < Strelka::CMS::PageFilter

	# PI	   ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
	LinkPI = %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>}


	######
	public
	######

	### Process the given +source+ for <?ed ... ?> processing-instructions
	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


	### Create an HTML fragment from the parsed LinkPI.
	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


end # class Strelka::CMS::Page::EditorialFilter

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
strelka-cms-0.3.0 lib/strelka/cms/pagefilter/editorial.rb
strelka-cms-0.2.0 lib/strelka/cms/pagefilter/editorial.rb
strelka-cms-0.1.0 lib/strelka/cms/pagefilter/editorial.rb
strelka-cms-0.0.1 lib/strelka/cms/pagefilter/editorial.rb
strelka-cms-0.0.1.pre.19 lib/strelka/cms/pagefilter/editorial.rb
strelka-cms-0.0.1.pre.15 lib/strelka/cms/pagefilter/editorial.rb