Sha256: 202cc309ea28f75327015e5f14b399787a93f26442c75ca865e6c67f142f8bc1

Contents?: true

Size: 1.3 KB

Versions: 5

Compression:

Stored size: 1.3 KB

Contents

require 'diecut/template'
require 'diecut/mustache'

describe Diecut::Template do
  let :tmpl do
    tmpl = Diecut::Template.new("somewhere", <<EOT)
I am a {{thing}} with {{ very.deep.values }}.
{{#sometimes}}I tell secrets {{#lengthy}}at length {{/lengthy}}- also {{sometime}}
{{/sometimes}}
{{^sometimes}}I am an open book{{/sometimes}}{{! this is silly }}
Oh: something else: {{< apartial}}
This too: {{#nested}}{{< apartial}}{{/nested}}
EOT
    tmpl
  end

  let :prtl do
    Diecut::Template.new("apartial", <<EOT)
I'm {{status}}
EOT
  end

  let :renderer do
    renderer = Diecut::Mustache.new
    renderer.partials_hash = {
      :somewhere => tmpl,
      :apartial => prtl
    }
    renderer
  end

  before :each do
    tmpl.partial_context(prtl)

    tmpl.context.from_hash(
      thing: "template",
      very: { deep: { values: "strongly held beliefs" }},
      sometimes: [
        { sometime: "stories", lengthy: false },
        { sometime: "lies", lengthy: true }
      ],
      status: "green",
      nested: { status: "yellow" }
    )
  end

  it "renders a string based on config" do

    expect(tmpl.render(renderer)).to eq(<<EOS)
I am a template with strongly held beliefs.
I tell secrets - also stories
I tell secrets at length - also lies

Oh: something else: I'm green

This too: I'm yellow

EOS
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
diecut-0.0.5 spec/template_spec.rb
diecut-0.0.4 spec/template_spec.rb
diecut-0.0.3 spec/template_spec.rb
diecut-0.0.2 spec/template_spec.rb
diecut-0.0.1 spec/template_spec.rb