# encoding: utf-8 require 'spec_helper' describe 'document_link_parser' do before do raw_json = <-2.33387948.877108" end end describe 'image_parser in StructuredText' do before do raw_json = File.read("#{File.dirname(__FILE__)}/responses_mocks/document.json") json = JSON.load(raw_json) @document = Prismic::JsonParser.document_parser(json) @image_st = @document['product.linked_images'] end it 'parses properly with links' do @image_st.blocks[2].link_to.url.should == 'http://google.com/' end it 'parses properly without links' do @image_st.blocks[5].link_to.should be_nil end it 'serializes properly as HTML' do expected = <Here is some introductory text.

The following image is linked.

More important stuff

One more image, this one is not linked:

expected expected.chomp! link_resolver = Prismic.link_resolver("master"){|doc_link| "http://localhost/#{doc_link.id}" } @image_st.as_html(link_resolver).should == expected end end describe 'color_parser' do before do raw_json = <2012_annual.report.pdf" end end describe 'structured_text_parser' do before do raw_json_paragraph = File.read("#{File.dirname(__FILE__)}/responses_mocks/structured_text_paragraph.json") json_paragraph = JSON.load(raw_json_paragraph) @structured_text_paragraph = Prismic::JsonParser.structured_text_parser(json_paragraph) raw_json_heading = File.read("#{File.dirname(__FILE__)}/responses_mocks/structured_text_heading.json") json_heading = JSON.load(raw_json_heading) @structured_text_heading = Prismic::JsonParser.structured_text_parser(json_heading) end describe 'headings parsing' do it "correctly parses headings" do @structured_text_heading.blocks[0].should be_a Prismic::Fragments::StructuredText::Block::Heading @structured_text_heading.blocks[0].text.should == "Salted Caramel Macaron" @structured_text_heading.blocks[0].level.should == 1 end it "correctly parses >h9 heading" do json_heading = JSON.load(<<-JSON) { "type": "StructuredText", "value": [{ "type": "heading10", "text": "Salted Caramel Macaron", "spans": [] }] } JSON @structured_text_heading = Prismic::JsonParser.structured_text_parser(json_heading) @structured_text_heading.blocks[0].should be_a Prismic::Fragments::StructuredText::Block::Heading @structured_text_heading.blocks[0].level.should == 10 end it "parses all the spans" do @structured_text_heading.blocks[0].spans.size.should == 1 end end describe 'paragraphs parsing' do it "correctly parses paragraphs" do @structured_text_paragraph.blocks[0].should be_a Prismic::Fragments::StructuredText::Block::Paragraph @structured_text_paragraph.blocks[0].text.size.should == 224 end end describe 'spans parsing' do it "parses all the spans" do @structured_text_paragraph.blocks[0].spans.size.should == 3 end it "correctly parses the em spans" do @structured_text_paragraph.blocks[0].spans[0].start.should == 103 @structured_text_paragraph.blocks[0].spans[0].end.should == 137 @structured_text_paragraph.blocks[0].spans[0].should be_a Prismic::Fragments::StructuredText::Span::Em end it "correctly parses the strong spans" do @structured_text_paragraph.blocks[0].spans[2].should be_a Prismic::Fragments::StructuredText::Span::Strong end it "correctly parses the hyperlink spans" do @structured_text_paragraph.blocks[0].spans[1].should be_a Prismic::Fragments::StructuredText::Span::Hyperlink @structured_text_paragraph.blocks[0].spans[1].link.should be_a Prismic::Fragments::WebLink end end end describe 'document_parser' do before do raw_json = File.read("#{File.dirname(__FILE__)}/responses_mocks/document.json") json = JSON.load(raw_json) @document = Prismic::JsonParser.document_parser(json) end it "correctly parses Document objects" do @document.id.should == 'UdUkXt_mqZBObPeS' @document.type.should == 'product' @document.href.should == 'doc-url' @document.tags.should == ['Macaron'] @document.slugs.should == ['vanilla-macaron', '南大沢'] end it "correctly parses the document's publication dates" do @document.first_publication_date.should == Time.at(1476845881) @document.last_publication_date.should == Time.at(1476846111) end it "correctly parses the document's fragments" do @document.fragments.size.should == 14 @document.fragments['name'].should be_a Prismic::Fragments::StructuredText end end describe 'response_parser' do it "accepts basic documents response" do @json = JSON.load('{ "page": 1, "results_per_page": 20, "results_size": 20, "total_results_size": 40, "total_pages": 2, "next_page": "https://micro.prismic.io/api/documents/search?ref=UkL0hcuvzYUANCrm&page=2&pageSize=20", "prev_page": null, "results":[]}') @documents = Prismic::JsonParser.response_parser(@json) @documents.results.should == [] @documents.page.should == 1 @documents.results_per_page.should == 20 @documents.results_size.should == 20 @documents.total_results_size.should == 40 @documents.total_pages.should == 2 @documents.next_page.should == "https://micro.prismic.io/api/documents/search?ref=UkL0hcuvzYUANCrm&page=2&pageSize=20" @documents.prev_page.should == nil end end describe 'multiple_parser' do before do raw_json = <2014-06-1\dT\d{2}:30:00\.000[-+]\d{2}:00<\/time>/ end end describe 'unknown_parser' do before do @raw_json = File.read("#{File.dirname(__FILE__)}/responses_mocks/document_with_unknown_fragment.json") @json = JSON.load(@raw_json) end it 'raises the proper error' do Prismic::JsonParser.should_receive(:warn).with("Type blabla is unknown, fragment was skipped; perhaps you should update your prismic.io gem?") Prismic::JsonParser.document_parser(@json).fragments.size.should == 2 end end describe 'structured_text_label_parser' do before do raw_json = File.read("#{File.dirname(__FILE__)}/responses_mocks/structured_text_with_labels.json") json = JSON.load(raw_json) @structured_text = Prismic::JsonParser.structured_text_parser(json) end it 'outputs correctly as HTML' do link_resolver = Prismic.link_resolver("master"){|doc_link| "http://localhost/#{doc_link.id}" } @structured_text.as_html(link_resolver).should == "

Tips to dress a pastry

\n\n" + "

\"\"

\n\n" + "

Our Pastry Dressers (yes, it is a full-time job in Les Bonnes Choses!) have it somewhat different from our other pastry artists: while the others keep their main focus on the taste, smell, and potentially touch of your pastries, the Pastry Dressers are mainly focused on their looks.

\n\n" + "

It sometimes makes them feem like they're doing a job that is reasonably different from plain old pastry, and to make the most of your pastry dressings, perhaps so should you!

\n\n" + "

Step by step

\n\n" + "

From bottom to top, the steps towards a great dressing are pretty clear, and change rarely.

\n\n" + "

Pastry Dresser, or speleologist?

\n\n" + "

One of the first handy phases of dressing your pastry will be about carving to get to a desired shape and size to build upon. This is very precise work, as you will need to clean the object without breaking it, to remove pieces of it while keeping intact the meaningful bits. Now you're ready to iterate upon it!

\n\n" + "

Pastry Dresser, or clay sculptor?

\n\n

" + "Then, you will need to shape your piece of art into the design you have in mind, by adding the right materials to just the right places. Ganache is your friend in such moments, such as any shape-free material. You'll have to master them, so they obey to the shapes you have in mind.

\n\n" + "

Pastry Dresser, or hairdresser?

\n\n" + "

The top of the pastry is a priority zone for finalization. This is where your "last touch" goes, and it's tremendously important, as it gives the pastry most of its character. You will have to play with the details, to keep the top of your piece on the... top of your priorities!

\n\n

Before starting

\n\n

" + "Finishing by the beginning: what did we have to consider, before running towards the aforementioned steps?

\n\n" + "

\"\"

\n\n" + "

Pastry Dresser, or illustrator?

\n\n" + "

We didn't mention color, but it's a very important component of the piece. Just like an illustrator will pick colors that add to the shape in a matching way to keep a perfect meaning, the colors must be perfect to be consistent with the taste of the piece (do not use green-colored sugar for a strawberry-flavored pastry, if you don't want to gross people out!)

\n\n" + "

Pastry Dresser, or designer?

\n\n

And even before the illustration and colors, you really need to take the time to think about your destination, to make sure it's nothing short of perfect. This may imply taking the time to sit down for a few minutes with a paper and a pen. The first skill of an imaginative Pastry Dresser is a drawing skill, just like a fashion stylist.

" end end