Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/openxml_docx_templater/escape_xml.rb
Constant Summary collapse
- CODE_LINE_PATTERN =
/{([^{]*?)%(.+?)%(.*?)}/
- TAG_PATTERN =
/<(.+?)>[\n]?/m
Instance Method Summary collapse
- #convert_newlines ⇒ Object
- #escape_xml ⇒ Object
- #mgsub(key_value_pairs = {}) ⇒ Object
- #refact ⇒ Object
Instance Method Details
#convert_newlines ⇒ Object
11 12 13 |
# File 'lib/openxml_docx_templater/escape_xml.rb', line 11 def convert_newlines gsub("\n", '<w:br/>') end |
#escape_xml ⇒ Object
7 8 9 |
# File 'lib/openxml_docx_templater/escape_xml.rb', line 7 def escape_xml mgsub(/&/ => '&', /</ => '<', />/ => '>') end |
#mgsub(key_value_pairs = {}) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/openxml_docx_templater/escape_xml.rb', line 19 def mgsub(key_value_pairs = {}) regexp_fragments = key_value_pairs.keys gsub(Regexp.union(*regexp_fragments)) do |match| key_value_pairs.detect { |k, _v| k =~ match }[1] end end |
#refact ⇒ Object
15 16 17 |
# File 'lib/openxml_docx_templater/escape_xml.rb', line 15 def refact gsub(CODE_LINE_PATTERN) { |result| result.gsub(TAG_PATTERN, '') } end |