diff --git a/Gemfile.lock b/Gemfile.lock index e7714984..d41bcf30 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,19 +3,19 @@ PATH specs: sablon (0.0.19) nokogiri (>= 1.6.0) - redcarpet (>= 3.2) rubyzip (>= 1.1) GEM remote: https://rubygems.org/ specs: - mini_portile2 (2.0.0) + mini_portile2 (2.1.0) minitest (5.8.0) - nokogiri (1.6.7.1) - mini_portile2 (~> 2.0.0.rc2) + nokogiri (1.6.8) + mini_portile2 (~> 2.1.0) + pkg-config (~> 1.1.7) + pkg-config (1.1.7) rake (10.4.2) - redcarpet (3.3.3) - rubyzip (1.1.7) + rubyzip (1.2.0) xml-simple (1.1.5) PLATFORMS @@ -29,4 +29,4 @@ DEPENDENCIES xml-simple BUNDLED WITH - 1.10.6 + 1.12.5 diff --git a/README.md b/README.md index f1a8f38f..8843982e 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ require "sablon" template = Sablon.template(File.expand_path("~/Desktop/template.docx")) context = { title: "Fabulous Document", - technologies: ["Ruby", "Markdown", "ODF"] + technologies: ["Ruby", "HTML", "ODF"] } template.render_to_file File.expand_path("~/Desktop/output.docx"), context ``` @@ -100,54 +100,6 @@ IMPORTANT: This feature is very much *experimental*. Currently, the insertion will replace the containing paragraph. This means that other content in the same paragraph is discarded. -##### Markdown [deprecated] - -IMPORTANT: Markdown insertion has been deprecated in favor of HTML - insertion. For now the behavior is still packaged with sablon. Note that the - implementation of `Sablon::Content::Markdown` is already based on - `Sablon::Content::HTML`. Markdown insertion will be removed in the future. - -Similar to WordProcessingML it's possible to use markdown while processing the -tempalte. You don't need to modify your templates, a simple insertion operation -is sufficient: - -``` -«=article.body» -``` - -To use Markdown insertion prepare the context like so: - -```ruby -markdown_body = <<-MD -This text can contain *additional formatting* -according to the **Markdown** specification. -MD -context = { - article: { body: Sablon.content(:markdown, markdown_body) } -} -template.render_to_file File.expand_path("~/Desktop/output.docx"), context -``` - -Markdown insertion has built-in support for: - -* [Headers](http://spec.commonmark.org/0.17/#atx-header) -* [Paragraphs](http://spec.commonmark.org/0.17/#paragraphs) -* [Emphasis and strong emphasis](http://spec.commonmark.org/0.17/#emphasis-and-strong-emphasis) -* [Hard line breaks](http://spec.commonmark.org/0.17/#hard-line-breaks) -* [Lists](http://spec.commonmark.org/0.17/#lists) - -For headings and lists to function properly it is necessary that the template -defines specific styles. Headings use styles called `Heading1`, `Heading2`, -etc. according to the header level. Ordered lists will use the style -`ListNumber` and unordered lists use `ListBullet`. Nested lists are not -supported. Normal text paragraphs use the style `Paragraph`. It's not necessary -to have that style in the template. Word will fall back to using the `Normal` style. - -IMPORTANT: This feature is very much *experimental*. Currently, the insertion - will replace the containing paragraph. This means that other content in the same - paragraph is discarded. In the near future this feature will most likely be - implemented on top of HTML insertion. - ##### HTML [experimental] Similar to WordProcessingML it's possible to use html as input while processing the diff --git a/lib/sablon.rb b/lib/sablon.rb index e3f8f04b..d9ac1abd 100644 --- a/lib/sablon.rb +++ b/lib/sablon.rb @@ -14,8 +14,6 @@ require "sablon/html/converter" require "sablon/content" -require 'redcarpet' - module Sablon class TemplateError < ArgumentError; end class ContextError < ArgumentError; end diff --git a/lib/sablon/content.rb b/lib/sablon/content.rb index fc344452..8df41fc2 100644 --- a/lib/sablon/content.rb +++ b/lib/sablon/content.rb @@ -77,23 +77,6 @@ def append_to(paragraph, display_node) end end - class Markdown < Struct.new(:word_ml) - include Sablon::Content - def self.id; :markdown end - def self.wraps?(value) false end - - def initialize(markdown) - warn "[DEPRECATION] `Sablon::Content::Markdown` is deprecated. Please use `Sablon::Content::HTML` instead." - redcarpet = ::Redcarpet::Markdown.new(::Redcarpet::Render::HTML.new) - word_ml = Sablon.content(:html, redcarpet.render(markdown)) - super word_ml - end - - def append_to(*args) - word_ml.append_to(*args) - end - end - class HTML < Struct.new(:word_ml) include Sablon::Content def self.id; :html end @@ -112,7 +95,6 @@ def append_to(*args) register Sablon::Content::String register Sablon::Content::WordML - register Sablon::Content::Markdown register Sablon::Content::HTML end end diff --git a/sablon.gemspec b/sablon.gemspec index 5530b019..b5fc8532 100644 --- a/sablon.gemspec +++ b/sablon.gemspec @@ -21,7 +21,6 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency 'nokogiri', ">= 1.6.0" spec.add_runtime_dependency 'rubyzip', ">= 1.1" - spec.add_runtime_dependency 'redcarpet', ">= 3.2" spec.add_development_dependency "bundler", ">= 1.6" spec.add_development_dependency "rake", "~> 10.0" diff --git a/test/content_test.rb b/test/content_test.rb index b022bc83..66f5be1d 100644 --- a/test/content_test.rb +++ b/test/content_test.rb @@ -158,47 +158,3 @@ def test_inserting_word_ml_multiple_times_into_same_paragraph skip "Content::WordML currently removes the paragraph..." end end - - -class ContentMarkdownTest < Sablon::TestCase - include ContentTestSetup - - def test_is_deprecated - previous_stderr, $stderr = $stderr, StringIO.new - Sablon.content(:markdown, "") - assert_equal "[DEPRECATION] `Sablon::Content::Markdown` is deprecated. Please use `Sablon::Content::HTML` instead.\n", $stderr.string - ensure - $stderr = previous_stderr - end - - def test_blank_markdown - Sablon.content(:markdown, "").append_to @paragraph, @node - - assert_xml_equal "AFTER", @document - end - - def test_inserts_markdown - Sablon.content(:markdown, "yay **bold** text").append_to @paragraph, @node - - output = <<-XML.strip.gsub("\n", "") - - -yay - - -bold - - - text - - -AFTER - XML - - assert_xml_equal output, @document - end - - def test_inserting_markdown_multiple_times_into_same_paragraph - skip "Content::Markdown currently removes the paragraph..." - end -end diff --git a/test/context_test.rb b/test/context_test.rb index f327e78f..60552726 100644 --- a/test/context_test.rb +++ b/test/context_test.rb @@ -13,14 +13,14 @@ def test_recognizes_wordml_keys "otherkey"=>""}, transformed) end - def test_recognizes_markdown_keys - transformed = Sablon::Context.transform({"markdown:mykey" => "**yay**", "otherkey" => ""}) - assert_equal({ "mykey"=>Sablon.content(:markdown, "**yay**"), + def test_recognizes_html_keys + transformed = Sablon::Context.transform({"html:mykey" => "**yay**", "otherkey" => ""}) + assert_equal({ "mykey"=>Sablon.content(:html, "**yay**"), "otherkey"=>""}, transformed) end - def test_does_not_wrap_markdown_and_wordml_with_nil_value - transformed = Sablon::Context.transform({"markdown:mykey" => nil, "word_ml:otherkey" => nil, "normalkey" => nil}) + def test_does_not_wrap_html_and_wordml_with_nil_value + transformed = Sablon::Context.transform({"html:mykey" => nil, "word_ml:otherkey" => nil, "normalkey" => nil}) assert_equal({ "mykey" => nil, "otherkey" => nil, "normalkey" => nil}, transformed) diff --git a/test/fixtures/recipe_context.json b/test/fixtures/recipe_context.json index fabec54b..b8319578 100644 --- a/test/fixtures/recipe_context.json +++ b/test/fixtures/recipe_context.json @@ -13,7 +13,7 @@ }, "title": "Bruschetta", "word_ml:intro": "Bruschetta (Italian pronunciation: [bruˈsketta]) is an antipasto (starter dish) from Italy consisting of grilled bread rubbed with garlic and topped with tomatoes, olive oil, salt and pepper. Variations may include toppings of tomato, vegetables, beans, cured meat, or cheese, a popular dish is Bruschetta pomodoro; the most popular recipe outside of Italy involves basil, fresh tomato, garlic and onion or mozzarella. Bruschetta is usually served as a snack or appetizer. In some countries, a topping of chopped tomato, olive oil and herbs is marketed under the bruschetta name.", - "markdown:preparation": "## How to make Baby's Bruschetta\n\n### Preparation\nMake the bruschetta mixture one day before the event and let it sit in the fridge overnight to absorb all the flavours(be aware your fridge will smell entirely like the *tomatoes* and *garlic*\n\nI find it works best to slice the *baguette* on an angle to create more space. Put the broiler on the oven on to toast the bread. Line them up on a baking sheet and make a small mixture of chopped garlic and olive oil to lightly spread on the slices of *baguette*, then place into the oven.\n\nOnce Half toasted remove bread and place bruschetta mixture on top (after draining off the majority of fluid). Then sprinkle the grated cheese on top and place back into the oven to broil/toast to your desired effect. ~ Please note that if you prefer to not have your *cheese* melted you can skip this step and just toast the bread fully, add the mixture and *cheese* and serve.\n\nOnce melted, remove and place directly on a serving platter and let rest for one minute while adding fresh chopped *basil* for garnish, and **ENJOY!**\n\n### Variations\n\n1. Use fresh oregano instead of basil.\n1. Other possible toppings: prosciutto, salami, bean spreads\n\n### Notes\n- In **Italy**, bruschetta is often prepared using a brustolina grill. In the Abruzzo region of Italy a variation of bruschetta made with a salame called *ventricina* is served.\n- In **Tuscany** it is called *fettunta* and it is usually served without toppings, \nespecially in November, to taste the very first oil of the season.\n- The chinese translation of 'Bruschetta' is '大蒜麵包' (Google Translator)", + "html:preparation": "

How to make Baby's Bruschetta

\n

Preparation

Make the bruschetta mixture one day before the event and let it sit in the fridge overnight to absorb all the flavours(be aware your fridge will smell entirely like the tomatoes and garlic

I find it works best to slice the baguette on an angle to create more space. Put the broiler on the oven on to toast the bread. Line them up on a baking sheet and make a small mixture of chopped garlic and olive oil to lightly spread on the slices of baguette, then place into the oven.

Once Half toasted remove bread and place bruschetta mixture on top (after draining off the majority of fluid). Then sprinkle the grated cheese on top and place back into the oven to broil/toast to your desired effect. ~ Please note that if you prefer to not have your cheese melted you can skip this step and just toast the bread fully, add the mixture and cheese and serve.

Once melted, remove and place directly on a serving platter and let rest for one minute while adding fresh chopped *basil* for garnish, and ENJOY!

Variations

  1. Use fresh oregano instead of basil.
  2. Other possible toppings: prosciutto, salami, bean spreads

Notes

  • In Italy, bruschetta is often prepared using a brustolina grill. In the Abruzzo region of Italy a variation of bruschetta made with a salame called ventricina is served.
  • In Tuscany it is called fettunta and it is usually served without toppings, especially in November, to taste the very first oil of the season.
  • The chinese translation of 'Bruschetta' is '大蒜麵包' (Google Translator)
", "ingredients": [ {"name": "Ripened, chopped, medium sized tomatoes ", "amount": "6"}, {"name": "medium sized red (Spanish) onion", "amount": "1"}, diff --git a/test/fixtures/recipe_sample.docx b/test/fixtures/recipe_sample.docx index 7d642a81..fb2b41db 100644 Binary files a/test/fixtures/recipe_sample.docx and b/test/fixtures/recipe_sample.docx differ diff --git a/test/markdown_test.rb b/test/markdown_test.rb deleted file mode 100644 index 6dc7377b..00000000 --- a/test/markdown_test.rb +++ /dev/null @@ -1,81 +0,0 @@ -# -*- coding: utf-8 -*- -require "test_helper" -require "support/xml_snippets" - -class SablonMarkdownTest < Sablon::TestCase - include Sablon::Test::Assertions - - def setup - super - @base_path = Pathname.new(File.expand_path("../", __FILE__)) - - @sample_path = @base_path + "fixtures/markdown_sample.docx" - end - - def test_generate_document_from_template_with_styles_and_markdown - template_path = @base_path + "fixtures/insertion_template.docx" - output_path = @base_path + "sandbox/markdown.docx" - template = Sablon.template template_path - context = {'markdown:content' => content} - template.render_to_file output_path, context - - assert_docx_equal @sample_path, output_path - end - - private - def content - <<-MARKDOWN -# Sablon Markdown insertion - -## Text - -**_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. - -Nunc tincidunt massa id libero mollis bibendum. -Sed vel arcu blandit, scelerisque ex ut, semper justo. -Nunc tempor velit a tortor lacinia, vel mattis diam sollicitudin. -Etiam eget faucibus enim. - -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. - -## Lists - -* Etiam vulputate elementum mi, at porta est malesuada sit amet. -* Praesent porttitor arcu id justo dignissim, vitae dignissim lectus pharetra. -* Curabitur efficitur mauris ac justo porta dignissim. Integer sed dui justo. - -Donec finibus lectus a erat pharetra dapibus. - -1. Nulla facilisis aliquet ex. -1. Mauris eget ante sed purus dictum tempus eu non dolor. -1. Aliquam finibus, leo at rutrum euismod, urna quam scelerisque ante, eu finibus dolor lectus vel ipsum. - -Ut id condimentum ante, eget convallis justo. Quisque accumsan porta interdum. Integer sit amet luctus felis. - -Nunc imperdiet, massa id ultricies porttitor, felis magna tincidunt augue, a egestas orci neque sed odio. - -1. Suspendisse - 1. tempor - 1. turpis - 1. turpis - 1. vitae - 1. tristique - 1. nulla - 1. pulvinar -1. nec. - -* Suspendisse - * potenti - * In condimentum - * enim ut nibh cursus imperdiet. - * Aliquam - * lacinia - * scelerisque -* tristique. - -Phasellus consectetur placerat ornare. Nulla facilisi. Morbi fringilla est vitae pulvinar dictum. Praesent quis malesuada ex. Pellentesque posuere facilisis molestie. - -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. -MARKDOWN - end -end diff --git a/test/sablon_test.rb b/test/sablon_test.rb index 8f04a406..c38f2d19 100644 --- a/test/sablon_test.rb +++ b/test/sablon_test.rb @@ -65,7 +65,7 @@ def test_generate_document_from_template language.new("German", "fluent"), language.new("French", "basics"), ], - about_me: Sablon.content(:markdown, "I am fond of writing *short stories* and *poems* in my spare time, \nand have won several literary contests in pursuit of my **passion**."), + about_me: Sablon.content(:html, "I am fond of writing short stories and poems in my spare time,
and have won several literary contests in pursuit of my passion."), activities: ["Writing", "Photography", "Traveling"], referees: [ referee.new("Mary P. Larsen", "Strongbod",