Module: N::Markup

Included in:
BaseContent
Defined in:
lib/nitro/markup.rb

Overview

Markup

Generalised Markup transformations.

The expand methods evaluate (expand) the markup code to produce the final content. The compact methods reverse this process to create the original markup code. Not all markup transformations are reversible.

When this library is included, the default PropertyUtils implementation is overriden to add markup support.

Examples

here comes the #objobj.body # => prints the expanded version.

obj.body = N::Markup.expand(@params)

Class Method Summary collapse

Class Method Details

.clear(str) ⇒ Object

Remove markup code from the input string. NOT IMPLEMENTED.



123
124
# File 'lib/nitro/markup.rb', line 123

def self.clear(str)
end

.compact(str) ⇒ Object

Compact (reverse) the content to the origial markup code. Not all markup transformations are reversible. You should override this method in your application to call your custom markup methods.



111
112
113
114
115
116
117
118
# File 'lib/nitro/markup.rb', line 111

def self.compact(str)
	if str
		xstr = str.dup
		compact_html!(xstr)
		return xstr
	end
	return nil
end

.compact_html!(str) ⇒ Object



83
84
85
86
87
88
89
90
# File 'lib/nitro/markup.rb', line 83

def self.compact_html!(str)
	return unless str
	str.gsub!(/"/, '"')		
	str.gsub!(/'/, "'")
	# gmosx: SOS! double quotes ARE needed for \r\n!!
	str.gsub!(/\s<br \/>/, "\r\n")
	return str
end

.expand(str) ⇒ Object

Expand the markup code to produce the actual content. You should override this method in your application to call your custom markup methods.



97
98
99
100
101
102
103
104
# File 'lib/nitro/markup.rb', line 97

def self.expand(str)
	if str
		xstr = str.dup
		expand_html!(xstr)
		return xstr
	end
	return nil
end

.expand_html!(str) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/nitro/markup.rb', line 75

def self.expand_html!(str)
	return unless str
	str.gsub!(/"/, '&quot;')		
	str.gsub!(/'/, '&#39;')		
	str.gsub!(/\r\n/, ' <br />')
	return str
end