sablon 0.0.19.beta4 → 0.0.19.beta5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac235d2921b38ea77aa5aef274e73aa34e84ffcf
4
- data.tar.gz: 9ce6a08012f8540e2a1998d35a177a9e6b95a909
3
+ metadata.gz: 938b6732ab4800db8bcfdf4b7cb96b4b8918c391
4
+ data.tar.gz: 1ffa8b58a380a18723abc38b4f037e10512c9446
5
5
  SHA512:
6
- metadata.gz: 219cb0acb4fdbf3eedc347577dc4c42996e78eb792a51394261e60a48d7b8114cd6d3668d91bcd00f0bdeb6406d0e0f3a2fb4ff63f12e12454bb5682cdbe967d
7
- data.tar.gz: 51128d4324f508395837d57cf8330dabed48729ebe8518bacafd18416fa502b0e2a8dfbf4e980ab763a93f5f49c50f5330739dde185780d8f02ac83f66776b59
6
+ metadata.gz: 4d1196ac369f906e38a89850b04943a87e92ebea62e861e6fc9dd983c446462b901910c4ad16c8ced6dcb6c680c90c3d52b4a946207deb9582002c010d125e70
7
+ data.tar.gz: 42c19fda296fbfc9ff1c6163f7dba58b02b96c66ac62cd74a255bb00a89e99e3937443c815eab977deefb5597b264306a28ee549e54dd31a6f36541dfac8332e
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sablon (0.0.19.beta4)
4
+ sablon (0.0.19.beta5)
5
5
  nokogiri (>= 1.6.0)
6
6
  redcarpet (>= 3.2)
7
7
  rubyzip (>= 1.1)
data/README.md CHANGED
@@ -100,7 +100,12 @@ IMPORTANT: This feature is very much *experimental*. Currently, the insertion
100
100
  will replace the containing paragraph. This means that other content in the same
101
101
  paragraph is discarded.
102
102
 
103
- ##### Markdown [experimental]
103
+ ##### Markdown [deprecated]
104
+
105
+ IMPORTANT: Markdown insertion has been deprecated in favor of HTML
106
+ insertion. For now the behavior is still packaged with sablon. Note that the
107
+ implementation of `Sablon::Content::Markdown` is already based on
108
+ `Sablon::Content::HTML`. Markdown insertion will be removed in the future.
104
109
 
105
110
  Similar to WordProcessingML it's possible to use markdown while processing the
106
111
  tempalte. You don't need to modify your templates, a simple insertion operation
@@ -158,7 +163,7 @@ To use HTML insertion prepare the context like so:
158
163
  ```ruby
159
164
  html_body = <<-HTML
160
165
  <div>This text can contain <em>additional formatting</em>
161
- according to the <strong>Markdown</strongstrong> specification.</div>
166
+ according to the <strong>HTML</strong> specification.</div>
162
167
  HTML
163
168
  context = {
164
169
  article: { html_body: Sablon.content(:html, html_body) }
@@ -218,6 +223,17 @@ to repeat. Have a look at the
218
223
 
219
224
  It is possible to nest loops and conditionals.
220
225
 
226
+ #### Comments
227
+
228
+ Sometimes it's necessary to include markup in the template that should not be
229
+ visible in the rendered output. For example when defining sample numbering
230
+ styles for HTML insertion.
231
+
232
+ ```
233
+ «comment»
234
+ ... arbitrary document markup ...
235
+ «endComment»
236
+ ```
221
237
 
222
238
  ### Executable
223
239
 
@@ -15,7 +15,6 @@ require "sablon/html/converter"
15
15
  require "sablon/content"
16
16
 
17
17
  require 'redcarpet'
18
- require "sablon/redcarpet/render/word_ml"
19
18
 
20
19
  module Sablon
21
20
  class TemplateError < ArgumentError; end
@@ -83,8 +83,9 @@ module Sablon
83
83
  def self.wraps?(value) false end
84
84
 
85
85
  def initialize(markdown)
86
- redcarpet = ::Redcarpet::Markdown.new(Sablon::Redcarpet::Render::WordML)
87
- word_ml = Sablon.content(:word_ml, redcarpet.render(markdown))
86
+ warn "[DEPRECATION] `Sablon::Content::Markdown` is deprecated. Please use `Sablon::Content::HTML` instead."
87
+ redcarpet = ::Redcarpet::Markdown.new(::Redcarpet::Render::HTML.new)
88
+ word_ml = Sablon.content(:html, redcarpet.render(markdown))
88
89
  super word_ml
89
90
  end
90
91
 
@@ -99,15 +99,17 @@ XML
99
99
  end
100
100
 
101
101
  class TextFormat
102
- def initialize(bold, italic)
102
+ def initialize(bold, italic, underline)
103
103
  @bold = bold
104
104
  @italic = italic
105
+ @underline = underline
105
106
  end
106
107
 
107
108
  def inspect
108
109
  parts = []
109
110
  parts << 'bold' if @bold
110
111
  parts << 'italic' if @italic
112
+ parts << 'underline' if @underline
111
113
  parts.join('|')
112
114
  end
113
115
 
@@ -115,6 +117,7 @@ XML
115
117
  styles = []
116
118
  styles << '<w:b />' if @bold
117
119
  styles << '<w:i />' if @italic
120
+ styles << '<w:u w:val="single"/>' if @underline
118
121
  if styles.any?
119
122
  "<w:rPr>#{styles.join}</w:rPr>"
120
123
  else
@@ -123,15 +126,19 @@ XML
123
126
  end
124
127
 
125
128
  def self.default
126
- @default ||= new(false, false)
129
+ @default ||= new(false, false, false)
127
130
  end
128
131
 
129
132
  def with_bold
130
- TextFormat.new(true, @italic)
133
+ TextFormat.new(true, @italic, @underline)
131
134
  end
132
135
 
133
136
  def with_italic
134
- TextFormat.new(@bold, true)
137
+ TextFormat.new(@bold, true, @underline)
138
+ end
139
+
140
+ def with_underline
141
+ TextFormat.new(@bold, @italic, true)
135
142
  end
136
143
  end
137
144
 
@@ -92,6 +92,9 @@ module Sablon
92
92
  elsif node.name == 'p'
93
93
  @builder.new_layer
94
94
  @builder.emit Paragraph.new('Paragraph', ast_text(node.children))
95
+ elsif node.name =~ /h(\d+)/
96
+ @builder.new_layer
97
+ @builder.emit Paragraph.new("Heading#{$1}", ast_text(node.children))
95
98
  elsif node.name == 'ul'
96
99
  @builder.new_layer ilvl: true
97
100
  unless @builder.nested?
@@ -120,10 +123,12 @@ module Sablon
120
123
  Text.new(node.text, format)
121
124
  elsif node.name == 'br'
122
125
  Newline.new
123
- elsif node.name == 'strong'
126
+ elsif node.name == 'strong' || node.name == 'b'
124
127
  ast_text(node.children, format: format.with_bold).nodes
125
- elsif node.name == 'em'
128
+ elsif node.name == 'em' || node.name == 'i'
126
129
  ast_text(node.children, format: format.with_italic).nodes
130
+ elsif node.name == 'u'
131
+ ast_text(node.children, format: format.with_underline).nodes
127
132
  elsif ['ul', 'ol', 'p', 'div'].include?(node.name)
128
133
  @builder.push(node)
129
134
  nil
@@ -44,6 +44,12 @@ module Sablon
44
44
  end
45
45
  end
46
46
  end
47
+
48
+ class Comment < Struct.new(:block)
49
+ def evaluate(context)
50
+ block.replace []
51
+ end
52
+ end
47
53
  end
48
54
 
49
55
  module Expression
@@ -171,6 +171,9 @@ module Sablon
171
171
  when /([^ ]+):if/
172
172
  block = consume_block("#{$1}:endIf")
173
173
  Statement::Condition.new(Expression.parse($1), block)
174
+ when /comment/
175
+ block = consume_block("endComment")
176
+ Statement::Comment.new(block)
174
177
  end
175
178
  end
176
179
 
@@ -1,3 +1,3 @@
1
1
  module Sablon
2
- VERSION = "0.0.19.beta4"
2
+ VERSION = "0.0.19.beta5"
3
3
  end
@@ -163,6 +163,14 @@ end
163
163
  class ContentMarkdownTest < Sablon::TestCase
164
164
  include ContentTestSetup
165
165
 
166
+ def test_is_deprecated
167
+ previous_stderr, $stderr = $stderr, StringIO.new
168
+ Sablon.content(:markdown, "")
169
+ assert_equal "[DEPRECATION] `Sablon::Content::Markdown` is deprecated. Please use `Sablon::Content::HTML` instead.\n", $stderr.string
170
+ ensure
171
+ $stderr = previous_stderr
172
+ end
173
+
166
174
  def test_blank_markdown
167
175
  Sablon.content(:markdown, "").append_to @paragraph, @node
168
176
 
@@ -0,0 +1,23 @@
1
+ <w:r><w:t xml:space="preserve">Before </w:t></w:r>
2
+ <w:p>
3
+ <w:fldSimple w:instr=" MERGEFIELD comment \* MERGEFORMAT ">
4
+ <w:r>
5
+ <w:rPr><w:noProof/></w:rPr>
6
+ <w:t>«comment»</w:t>
7
+ </w:r>
8
+ </w:fldSimple>
9
+ </w:p>
10
+ <w:p>
11
+ <w:r>
12
+ <w:t>Inside Comment! </w:t>
13
+ </w:r>
14
+ </w:p>
15
+ <w:p>
16
+ <w:fldSimple w:instr=" MERGEFIELD endComment \* MERGEFORMAT ">
17
+ <w:r>
18
+ <w:rPr><w:noProof/></w:rPr>
19
+ <w:t>«endComment»</w:t>
20
+ </w:r>
21
+ </w:fldSimple>
22
+ </w:p>
23
+ <w:r><w:t xml:space="preserve">After</w:t></w:r>
@@ -70,6 +70,22 @@ DOCX
70
70
  assert_equal normalize_wordml(expected_output), @converter.process(input)
71
71
  end
72
72
 
73
+ def test_convert_u_tags_inside_p
74
+ input = '<p>Lorem&nbsp;<u>ipsum dolor</u>&nbsp;sit amet</div>'
75
+ expected_output = <<-DOCX.strip
76
+ <w:p>
77
+ <w:pPr><w:pStyle w:val="Paragraph" /></w:pPr>
78
+ <w:r><w:t xml:space="preserve">Lorem </w:t></w:r>
79
+ <w:r>
80
+ <w:rPr><w:u w:val="single"/></w:rPr>
81
+ <w:t xml:space="preserve">ipsum dolor</w:t>
82
+ </w:r>
83
+ <w:r><w:t xml:space="preserve"> sit amet</w:t></w:r>
84
+ </w:p>
85
+ DOCX
86
+ assert_equal normalize_wordml(expected_output), @converter.process(input)
87
+ end
88
+
73
89
  def test_convert_em_tags_inside_div
74
90
  input = '<div>Lorem&nbsp;<em>ipsum dolor</em>&nbsp;sit amet</div>'
75
91
  expected_output = <<-DOCX.strip
@@ -102,6 +118,17 @@ DOCX
102
118
  assert_equal normalize_wordml(expected_output), @converter.process(input)
103
119
  end
104
120
 
121
+ def test_convert_h1
122
+ input = '<h1>Lorem ipsum dolor</h1>'
123
+ expected_output = <<-DOCX.strip
124
+ <w:p>
125
+ <w:pPr><w:pStyle w:val="Heading1" /></w:pPr>
126
+ <w:r><w:t xml:space="preserve">Lorem ipsum dolor</w:t></w:r>
127
+ </w:p>
128
+ DOCX
129
+ assert_equal normalize_wordml(expected_output), @converter.process(input)
130
+ end
131
+
105
132
  def test_unorderd_lists
106
133
  input = '<ul><li>Lorem</li><li>ipsum</li><li>dolor</li></ul>'
107
134
  expected_output = <<-DOCX.strip
@@ -292,6 +319,18 @@ class HTMLConverterASTTest < Sablon::TestCase
292
319
  assert_equal '<Root: [<Paragraph{Paragraph}: [<Text{}: Lorem ipsum dolor sit amet>]>]>', ast.inspect
293
320
  end
294
321
 
322
+ def test_b
323
+ input = '<p>Lorem <b>ipsum dolor sit amet</b></p>'
324
+ ast = @converter.processed_ast(input)
325
+ assert_equal '<Root: [<Paragraph{Paragraph}: [<Text{}: Lorem >, <Text{bold}: ipsum dolor sit amet>]>]>', ast.inspect
326
+ end
327
+
328
+ def test_i
329
+ input = '<p>Lorem <i>ipsum dolor sit amet</i></p>'
330
+ ast = @converter.processed_ast(input)
331
+ assert_equal '<Root: [<Paragraph{Paragraph}: [<Text{}: Lorem >, <Text{italic}: ipsum dolor sit amet>]>]>', ast.inspect
332
+ end
333
+
295
334
  def test_br_in_strong
296
335
  input = '<div><strong>Lorem<br />ipsum<br />dolor</strong></div>'
297
336
  par = @converter.processed_ast(input).grep(Sablon::HTMLConverter::Paragraph).first
@@ -322,6 +361,18 @@ class HTMLConverterASTTest < Sablon::TestCase
322
361
  assert_equal "[]", par.runs.inspect
323
362
  end
324
363
 
364
+ def test_headings
365
+ input = '<h1>First</h1><h2>Second</h2><h3>Third</h3>'
366
+ ast = @converter.processed_ast(input)
367
+ assert_equal "<Root: [<Paragraph{Heading1}: [<Text{}: First>]>, <Paragraph{Heading2}: [<Text{}: Second>]>, <Paragraph{Heading3}: [<Text{}: Third>]>]>", ast.inspect
368
+ end
369
+
370
+ def test_h_with_formatting
371
+ input = '<h1><strong>Lorem</strong> ipsum dolor <em>sit <u>amet</u></em></h1>'
372
+ ast = @converter.processed_ast(input)
373
+ assert_equal "<Root: [<Paragraph{Heading1}: [<Text{bold}: Lorem>, <Text{}: ipsum dolor >, <Text{italic}: sit >, <Text{italic|underline}: amet>]>]>", ast.inspect
374
+ end
375
+
325
376
  def test_ul
326
377
  input = '<ul><li>Lorem</li><li>ipsum</li></ul>'
327
378
  ast = @converter.processed_ast(input)
@@ -39,7 +39,11 @@ class SablonHTMLTest < Sablon::TestCase
39
39
  private
40
40
  def content
41
41
  <<-HTML
42
- <div>Lorem&nbsp;<strong>ipsum</strong>&nbsp;<em>dolor</em>&nbsp;<strong>sit</strong>&nbsp;<em>amet</em>,&nbsp;<strong>consectetur adipiscing elit</strong>.&nbsp;<em>Suspendisse a tempus turpis</em>. Duis urna justo, vehicula vitae ultricies vel, congue at sem. Fusce turpis turpis, aliquet id pulvinar aliquam, iaculis non elit. Nulla feugiat lectus nulla, in dictum ipsum cursus ac. Quisque at odio neque. Sed ac tortor iaculis, bibendum leo ut, malesuada velit. Donec iaculis sed urna eget pharetra. Praesent ornare fermentum turpis, placerat iaculis urna bibendum vitae. Nunc in quam consequat, tristique tellus in, commodo turpis. Curabitur ullamcorper odio purus, lobortis egestas magna laoreet vitae. Nunc fringilla velit ante, eu aliquam nisi cursus vitae. Suspendisse sit amet dui egestas, volutpat nisi vel, mattis justo. Nullam pellentesque, ipsum eget blandit pharetra, augue elit aliquam mauris, vel mollis nisl augue ut ipsum.</div><ol><li>Vestibulum&nbsp;<ol><li>ante ipsum primis&nbsp;</li></ol></li><li>in faucibus orci luctus&nbsp;<ol><li>et ultrices posuere cubilia Curae;&nbsp;<ol><li>Aliquam vel dolor&nbsp;</li><li>sed sem maximus&nbsp;</li></ol></li><li>fermentum in non odio.&nbsp;<ol><li>Fusce hendrerit ornare mollis.&nbsp;</li></ol></li><li>Nunc scelerisque nibh nec turpis tempor pulvinar.&nbsp;</li></ol></li><li>Donec eros turpis,&nbsp;</li><li>aliquet vel volutpat sit amet,&nbsp;<ol><li>semper eu purus.&nbsp;</li><li>Proin ac erat nec urna efficitur vulputate.&nbsp;<ol><li>Quisque varius convallis ultricies.&nbsp;</li><li>Nullam vel fermentum eros.&nbsp;</li></ol></li></ol></li></ol><div>Pellentesque nulla leo, auctor ornare erat sed, rhoncus congue diam. Duis non porttitor nulla, ut eleifend enim. Pellentesque non tempor sem.</div><div>Mauris auctor egestas arcu,&nbsp;</div><ol><li>id venenatis nibh dignissim id.&nbsp;</li><li>In non placerat metus.&nbsp;</li></ol><ul><li>Nunc sed consequat metus.&nbsp;</li><li>Nulla consectetur lorem consequat,&nbsp;</li><li>malesuada dui at, lacinia lectus.&nbsp;</li></ul><ol><li>Aliquam efficitur&nbsp;</li><li>lorem a mauris feugiat,&nbsp;</li><li>at semper eros pellentesque.&nbsp;</li></ol><div>Nunc lacus diam, consectetur ut odio sit amet, placerat pharetra erat. Sed commodo ut sem id congue. Sed eget neque elit. Curabitur at erat tortor. Maecenas eget sapien vitae est sagittis accumsan et nec orci. Integer luctus at nisl eget venenatis. Nunc nunc eros, consectetur at tortor et, tristique ultrices elit. Nulla in turpis nibh.</div><ul><li>Nam consectetur&nbsp;<ul><li>venenatis tempor.&nbsp;</li></ul></li><li>Aenean&nbsp;<ul><li>blandit<ul><li>porttitor massa,&nbsp;<ul><li>non efficitur&nbsp;<ul><li>metus.&nbsp;</li></ul></li></ul></li></ul></li></ul></li><li>Duis faucibus nunc nec venenatis faucibus.&nbsp;</li><li>Aliquam erat volutpat.&nbsp;</li></ul><div><strong>Quisque non neque ut lacus eleifend volutpat quis sed lacus.<br />Praesent ultrices purus eu quam elementum, sit amet faucibus elit interdum. In lectus orci,<br /> elementum quis dictum ac, porta ac ante. Fusce tempus ac mauris id cursus. Phasellus a erat nulla. <em>Mauris dolor orci</em>, malesuada auctor dignissim non, posuere nec odio. Etiam hendrerit justo nec diam ullamcorper, nec blandit elit sodales.</strong></div>
42
+ <h1>Sablon HTML insertion</h1>
43
+ <h2>Text</h2>
44
+ <div>Lorem&nbsp;<strong>ipsum</strong>&nbsp;<em>dolor</em>&nbsp;<strong>sit</strong>&nbsp;<em>amet</em>,&nbsp;<strong>consectetur adipiscing elit</strong>.&nbsp;<em>Suspendisse a tempus turpis</em>. Duis urna justo, vehicula vitae ultricies vel, congue at sem. Fusce turpis turpis, aliquet id pulvinar aliquam, iaculis non elit. Nulla feugiat lectus nulla, in dictum ipsum cursus ac. Quisque at odio neque. Sed ac tortor iaculis, bibendum leo ut, malesuada velit. Donec iaculis sed urna eget pharetra. <u>Praesent ornare fermentum turpis</u>, placerat iaculis urna bibendum vitae. Nunc in quam consequat, tristique tellus in, commodo turpis. Curabitur ullamcorper odio purus, lobortis egestas magna laoreet vitae. Nunc fringilla velit ante, eu aliquam nisi cursus vitae. Suspendisse sit amet dui egestas, volutpat nisi vel, mattis justo. Nullam pellentesque, ipsum eget blandit pharetra, augue elit aliquam mauris, vel mollis nisl augue ut ipsum.</div>
45
+ <h2>Lists</h2>
46
+ <ol><li>Vestibulum&nbsp;<ol><li>ante ipsum primis&nbsp;</li></ol></li><li>in faucibus orci luctus&nbsp;<ol><li>et ultrices posuere cubilia Curae;&nbsp;<ol><li>Aliquam vel dolor&nbsp;</li><li>sed sem maximus&nbsp;</li></ol></li><li>fermentum in non odio.&nbsp;<ol><li>Fusce hendrerit ornare mollis.&nbsp;</li></ol></li><li>Nunc scelerisque nibh nec turpis tempor pulvinar.&nbsp;</li></ol></li><li>Donec eros turpis,&nbsp;</li><li>aliquet vel volutpat sit amet,&nbsp;<ol><li>semper eu purus.&nbsp;</li><li>Proin ac erat nec urna efficitur vulputate.&nbsp;<ol><li>Quisque varius convallis ultricies.&nbsp;</li><li>Nullam vel fermentum eros.&nbsp;</li></ol></li></ol></li></ol><div>Pellentesque nulla leo, auctor ornare erat sed, rhoncus congue diam. Duis non porttitor nulla, ut eleifend enim. Pellentesque non tempor sem.</div><div>Mauris auctor egestas arcu,&nbsp;</div><ol><li>id venenatis nibh dignissim id.&nbsp;</li><li>In non placerat metus.&nbsp;</li></ol><ul><li>Nunc sed consequat metus.&nbsp;</li><li>Nulla consectetur lorem consequat,&nbsp;</li><li>malesuada dui at, lacinia lectus.&nbsp;</li></ul><ol><li>Aliquam efficitur&nbsp;</li><li>lorem a mauris feugiat,&nbsp;</li><li>at semper eros pellentesque.&nbsp;</li></ol><div>Nunc lacus diam, consectetur ut odio sit amet, placerat pharetra erat. Sed commodo ut sem id congue. Sed eget neque elit. Curabitur at erat tortor. Maecenas eget sapien vitae est sagittis accumsan et nec orci. Integer luctus at nisl eget venenatis. Nunc nunc eros, consectetur at tortor et, tristique ultrices elit. Nulla in turpis nibh.</div><ul><li>Nam consectetur&nbsp;<ul><li>venenatis tempor.&nbsp;</li></ul></li><li>Aenean&nbsp;<ul><li>blandit<ul><li>porttitor massa,&nbsp;<ul><li>non efficitur&nbsp;<ul><li>metus.&nbsp;</li></ul></li></ul></li></ul></li></ul></li><li>Duis faucibus nunc nec venenatis faucibus.&nbsp;</li><li>Aliquam erat volutpat.&nbsp;</li></ul><div><strong>Quisque non neque ut lacus eleifend volutpat quis sed lacus.<br />Praesent ultrices purus eu quam elementum, sit amet faucibus elit interdum. In lectus orci,<br /> elementum quis dictum ac, porta ac ante. Fusce tempus ac mauris id cursus. Phasellus a erat nulla. <em>Mauris dolor orci</em>, malesuada auctor dignissim non, <u>posuere nec odio</u>. Etiam hendrerit justo nec diam ullamcorper, nec blandit elit sodales.</strong></div>
43
47
  HTML
44
48
  end
45
49
  end
@@ -0,0 +1,81 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "test_helper"
3
+ require "support/xml_snippets"
4
+
5
+ class SablonMarkdownTest < Sablon::TestCase
6
+ include Sablon::Test::Assertions
7
+
8
+ def setup
9
+ super
10
+ @base_path = Pathname.new(File.expand_path("../", __FILE__))
11
+
12
+ @sample_path = @base_path + "fixtures/markdown_sample.docx"
13
+ end
14
+
15
+ def test_generate_document_from_template_with_styles_and_markdown
16
+ template_path = @base_path + "fixtures/insertion_template.docx"
17
+ output_path = @base_path + "sandbox/markdown.docx"
18
+ template = Sablon.template template_path
19
+ context = {'markdown:content' => content}
20
+ template.render_to_file output_path, context
21
+
22
+ assert_docx_equal @sample_path, output_path
23
+ end
24
+
25
+ private
26
+ def content
27
+ <<-MARKDOWN
28
+ # Sablon Markdown insertion
29
+
30
+ ## Text
31
+
32
+ **_Lorem ipsum_ dolor sit amet, consectetur adipiscing elit. Suspendisse at libero at elit posuere convallis ac vitae augue. Morbi pretium diam et leo pulvinar, sit amet placerat mauris scelerisque.** Vivamus sollicitudin ante ligula, non egestas diam molestie at.
33
+
34
+ Nunc tincidunt massa id libero mollis bibendum.
35
+ Sed vel arcu blandit, scelerisque ex ut, semper justo.
36
+ Nunc tempor velit a tortor lacinia, vel mattis diam sollicitudin.
37
+ Etiam eget faucibus enim.
38
+
39
+ Curabitur rutrum vestibulum nisi, vel posuere ligula commodo a. Sed nibh odio, convallis vitae orci a, cursus venenatis tellus. Duis consequat auctor elementum. Quisque blandit augue id faucibus dignissim. Aenean malesuada placerat turpis. Mauris tincidunt lorem sit amet est ultricies, eu tristique arcu dapibus. Nam ultrices vulputate tellus, quis feugiat ante faucibus non. Donec lectus est, suscipit in arcu molestie, pharetra cursus massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
40
+
41
+ ## Lists
42
+
43
+ * Etiam vulputate elementum mi, at porta est malesuada sit amet.
44
+ * Praesent porttitor arcu id justo dignissim, vitae dignissim lectus pharetra.
45
+ * Curabitur efficitur mauris ac justo porta dignissim. Integer sed dui justo.
46
+
47
+ Donec finibus lectus a erat pharetra dapibus.
48
+
49
+ 1. Nulla facilisis aliquet ex.
50
+ 1. Mauris eget ante sed purus dictum tempus eu non dolor.
51
+ 1. Aliquam finibus, leo at rutrum euismod, urna quam scelerisque ante, eu finibus dolor lectus vel ipsum.
52
+
53
+ Ut id condimentum ante, eget convallis justo. Quisque accumsan porta interdum. Integer sit amet luctus felis.
54
+
55
+ Nunc imperdiet, massa id ultricies porttitor, felis magna tincidunt augue, a egestas orci neque sed odio.
56
+
57
+ 1. Suspendisse
58
+ 1. tempor
59
+ 1. turpis
60
+ 1. turpis
61
+ 1. vitae
62
+ 1. tristique
63
+ 1. nulla
64
+ 1. pulvinar
65
+ 1. nec.
66
+
67
+ * Suspendisse
68
+ * potenti
69
+ * In condimentum
70
+ * enim ut nibh cursus imperdiet.
71
+ * Aliquam
72
+ * lacinia
73
+ * scelerisque
74
+ * tristique.
75
+
76
+ Phasellus consectetur placerat ornare. Nulla facilisi. Morbi fringilla est vitae pulvinar dictum. Praesent quis malesuada ex. Pellentesque posuere facilisis molestie.
77
+
78
+ Maecenas pretium erat vitae neque convallis consectetur. Cras ultricies mi nec mauris consectetur, eu blandit purus mattis. Quisque ante nulla, sagittis sed interdum non, eleifend quis augue. Curabitur vestibulum quam sed blandit rhoncus. Morbi eget vestibulum felis. Nulla vitae molestie elit. Etiam sagittis lorem elit, sit amet rhoncus eros dapibus non. Praesent nec dignissim dui. Quisque quis vehicula turpis, sit amet aliquet leo. Ut urna magna, malesuada eget fringilla ut, laoreet sed diam. Maecenas a ipsum varius, efficitur eros quis, vulputate mauris.
79
+ MARKDOWN
80
+ end
81
+ end
@@ -374,6 +374,11 @@ class ProcessorDocumentTest < Sablon::TestCase
374
374
  assert_equal "", text(result)
375
375
  end
376
376
 
377
+ def test_comment
378
+ result = process(snippet("comment"), {})
379
+ assert_equal "Before After", text(result)
380
+ end
381
+
377
382
  private
378
383
  def process(document, context)
379
384
  @processor.process(wrap(document), context).to_xml
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sablon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19.beta4
4
+ version: 0.0.19.beta5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yves Senn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-07 00:00:00.000000000 Z
11
+ date: 2016-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -138,7 +138,6 @@ files:
138
138
  - lib/sablon/processor/document.rb
139
139
  - lib/sablon/processor/numbering.rb
140
140
  - lib/sablon/processor/section_properties.rb
141
- - lib/sablon/redcarpet/render/word_ml.rb
142
141
  - lib/sablon/template.rb
143
142
  - lib/sablon/test.rb
144
143
  - lib/sablon/test/assertions.rb
@@ -159,9 +158,11 @@ files:
159
158
  - test/fixtures/html_sample.docx
160
159
  - test/fixtures/insertion_template.docx
161
160
  - test/fixtures/insertion_template_no_styles.docx
161
+ - test/fixtures/markdown_sample.docx
162
162
  - test/fixtures/recipe_context.json
163
163
  - test/fixtures/recipe_sample.docx
164
164
  - test/fixtures/recipe_template.docx
165
+ - test/fixtures/xml/comment.xml
165
166
  - test/fixtures/xml/complex_field.xml
166
167
  - test/fixtures/xml/complex_field_inline_conditional.xml
167
168
  - test/fixtures/xml/conditional.xml
@@ -180,8 +181,8 @@ files:
180
181
  - test/html/converter_test.rb
181
182
  - test/html_test.rb
182
183
  - test/mail_merge_parser_test.rb
184
+ - test/markdown_test.rb
183
185
  - test/processor/document_test.rb
184
- - test/redcarpet_render_word_ml_test.rb
185
186
  - test/sablon_test.rb
186
187
  - test/sandbox/.gitkeep
187
188
  - test/section_properties_test.rb
@@ -224,9 +225,11 @@ test_files:
224
225
  - test/fixtures/html_sample.docx
225
226
  - test/fixtures/insertion_template.docx
226
227
  - test/fixtures/insertion_template_no_styles.docx
228
+ - test/fixtures/markdown_sample.docx
227
229
  - test/fixtures/recipe_context.json
228
230
  - test/fixtures/recipe_sample.docx
229
231
  - test/fixtures/recipe_template.docx
232
+ - test/fixtures/xml/comment.xml
230
233
  - test/fixtures/xml/complex_field.xml
231
234
  - test/fixtures/xml/complex_field_inline_conditional.xml
232
235
  - test/fixtures/xml/conditional.xml
@@ -245,8 +248,8 @@ test_files:
245
248
  - test/html/converter_test.rb
246
249
  - test/html_test.rb
247
250
  - test/mail_merge_parser_test.rb
251
+ - test/markdown_test.rb
248
252
  - test/processor/document_test.rb
249
- - test/redcarpet_render_word_ml_test.rb
250
253
  - test/sablon_test.rb
251
254
  - test/sandbox/.gitkeep
252
255
  - test/section_properties_test.rb
@@ -1,57 +0,0 @@
1
- module Sablon
2
- module Redcarpet
3
- module Render
4
- class WordML < ::Redcarpet::Render::Base
5
- PARAGRAPH_PATTERN = <<-XML.gsub("\n", "")
6
- <w:p>
7
- <w:pPr>
8
- <w:pStyle w:val="%s" />
9
- </w:pPr>
10
- %s
11
- </w:p>
12
- XML
13
-
14
- def linebreak
15
- "<w:r><w:br/></w:r>"
16
- end
17
-
18
- def header(title, level)
19
- heading_style = "Heading#{level}"
20
- PARAGRAPH_PATTERN % [heading_style, title]
21
- end
22
-
23
- def paragraph(text)
24
- PARAGRAPH_PATTERN % ["Paragraph", text]
25
- end
26
-
27
- def normal_text(text)
28
- @raw_text = text
29
- return '' if text.nil? || text == '' || text == "\n"
30
- "<w:r><w:t xml:space=\"preserve\">#{text}</w:t></w:r>"
31
- end
32
-
33
- def emphasis(text)
34
- "<w:r><w:rPr><w:i /></w:rPr><w:t xml:space=\"preserve\">#{@raw_text}</w:t></w:r>"
35
- end
36
-
37
- def double_emphasis(text)
38
- "<w:r><w:rPr><w:b /></w:rPr><w:t xml:space=\"preserve\">#{@raw_text}</w:t></w:r>"
39
- end
40
-
41
- def list(content, list_type)
42
- content
43
- end
44
-
45
- LIST_STYLE_MAPPING = {
46
- ordered: "ListNumber",
47
- unordered: "ListBullet"
48
- }
49
-
50
- def list_item(content, list_type)
51
- list_style = LIST_STYLE_MAPPING[list_type]
52
- PARAGRAPH_PATTERN % [list_style, content]
53
- end
54
- end
55
- end
56
- end
57
- end
@@ -1,107 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require "test_helper"
3
-
4
- class RedcarpetRenderWordMLTest < Sablon::TestCase
5
- def setup
6
- @redcarpet = ::Redcarpet::Markdown.new(Sablon::Redcarpet::Render::WordML)
7
- end
8
-
9
- def test_normal_text
10
- word_ml = <<-XML.gsub("\n", "")
11
- <w:p>
12
- <w:pPr><w:pStyle w:val=\"Paragraph\" /></w:pPr>
13
- <w:r><w:t xml:space=\"preserve\">normal</w:t></w:r>
14
- </w:p>
15
- XML
16
- assert_equal word_ml, @redcarpet.render("normal")
17
- end
18
-
19
- def test_empty_string
20
- assert_equal "", @redcarpet.render("")
21
- end
22
-
23
- def test_blank_string_with_newline
24
- assert_equal "", @redcarpet.render("\n")
25
- end
26
-
27
- def test_newline_in_a_paragraph_starts_new_paragraph
28
- word_ml = <<-XML.gsub("\n", "")
29
- <w:p>
30
- <w:pPr><w:pStyle w:val=\"Paragraph\" /></w:pPr>
31
- <w:r><w:t xml:space=\"preserve\">some </w:t></w:r>
32
- <w:r><w:br/></w:r>
33
- <w:r><w:t xml:space=\"preserve\">text</w:t></w:r>
34
- </w:p>
35
- XML
36
- assert_equal word_ml, @redcarpet.render("some \ntext")
37
- end
38
-
39
- def test_bold_text
40
- word_ml = <<-XML.gsub("\n", "")
41
- <w:p>
42
- <w:pPr><w:pStyle w:val=\"Paragraph\" /></w:pPr>
43
- <w:r>
44
- <w:rPr><w:b /></w:rPr>
45
- <w:t xml:space="preserve">bold</w:t>
46
- </w:r>
47
- </w:p>
48
- XML
49
- assert_equal word_ml, @redcarpet.render("**bold**")
50
- end
51
-
52
- def test_italic_text
53
- word_ml = <<-XML.gsub("\n", "")
54
- <w:p>
55
- <w:pPr><w:pStyle w:val=\"Paragraph\" /></w:pPr>
56
- <w:r>
57
- <w:rPr><w:i /></w:rPr>
58
- <w:t xml:space="preserve">italic</w:t>
59
- </w:r>
60
- </w:p>
61
- XML
62
- assert_equal word_ml, @redcarpet.render("*italic*")
63
- end
64
-
65
- def test_single_line_mixed_text
66
- word_ml = <<-XML.gsub("\n", "")
67
- <w:p>
68
- <w:pPr><w:pStyle w:val=\"Paragraph\" /></w:pPr>
69
-
70
- <w:r><w:t xml:space="preserve">some </w:t></w:r>
71
-
72
- <w:r>
73
- <w:rPr><w:i /></w:rPr>
74
- <w:t xml:space="preserve">random</w:t>
75
- </w:r>
76
-
77
- <w:r><w:t xml:space="preserve"> </w:t></w:r>
78
- <w:r>
79
- <w:rPr><w:b /></w:rPr>
80
- <w:t xml:space="preserve">text</w:t>
81
- </w:r>
82
- </w:p>
83
- XML
84
- assert_equal word_ml, @redcarpet.render("some *random* **text**")
85
- end
86
-
87
- def test_unordered_lists
88
- word_ml = <<-XML.gsub("\n", "")
89
- <w:p>
90
- <w:pPr><w:pStyle w:val="ListBullet" /></w:pPr>
91
- <w:r><w:t xml:space="preserve">first</w:t></w:r>
92
- </w:p>
93
-
94
- <w:p>
95
- <w:pPr><w:pStyle w:val="ListBullet" /></w:pPr>
96
- <w:r><w:t xml:space="preserve">second</w:t></w:r>
97
- </w:p>
98
-
99
- <w:p>
100
- <w:pPr><w:pStyle w:val="ListBullet" /></w:pPr>
101
- <w:r><w:t xml:space="preserve">third</w:t></w:r>
102
- </w:p>
103
- XML
104
-
105
- assert_equal word_ml, @redcarpet.render("- first\n- second\n- third")
106
- end
107
- end