Sha256: 393e56b61005427a0d5615bdd0e7521eeb541166e4c34fa4cb657376d068a454

Contents?: true

Size: 1.79 KB

Versions: 22

Compression:

Stored size: 1.79 KB

Contents

require 'helper'

class Nanoc::Filters::HandlebarsTest < Nanoc::TestCase
  def test_filter
    skip_v8_on_ruby24

    if_have 'handlebars' do
      # Create data
      item = Nanoc::Int::Item.new(
        'content',
        { title: 'Max Payne', protagonist: 'Max Payne', location: 'here' },
        '/games/max-payne/',
      )
      layout = Nanoc::Int::Layout.new(
        'layout content',
        { name: 'Max Payne' },
        '/default/',
      )
      config = { animals: 'cats and dogs' }

      # Create filter
      assigns = {
        item: item,
        layout: layout,
        config: config,
        content: 'No Payne No Gayne',
      }
      filter = ::Nanoc::Filters::Handlebars.new(assigns)

      # Run filter
      result = filter.setup_and_run('{{protagonist}} says: {{yield}}.')
      assert_equal('Max Payne says: No Payne No Gayne.', result)
      result = filter.setup_and_run('We can’t stop {{item.location}}! This is the {{layout.name}} layout!')
      assert_equal('We can’t stop here! This is the Max Payne layout!', result)
      result = filter.setup_and_run('It’s raining {{config.animals}} here!')
      assert_equal('It’s raining cats and dogs here!', result)
    end
  end

  def test_filter_without_layout
    skip_v8_on_ruby24

    if_have 'handlebars' do
      # Create data
      item = Nanoc::Int::Item.new(
        'content',
        { title: 'Max Payne', protagonist: 'Max Payne', location: 'here' },
        '/games/max-payne/',
      )

      # Create filter
      assigns = {
        item: item,
        content: 'No Payne No Gayne',
      }
      filter = ::Nanoc::Filters::Handlebars.new(assigns)

      # Run filter
      result = filter.setup_and_run('{{protagonist}} says: {{yield}}.')
      assert_equal('Max Payne says: No Payne No Gayne.', result)
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
nanoc-4.7.9 test/filters/test_handlebars.rb
nanoc-4.7.8 test/filters/test_handlebars.rb
nanoc-4.7.7 test/filters/test_handlebars.rb
nanoc-4.7.6 test/filters/test_handlebars.rb
nanoc-4.7.5 test/filters/test_handlebars.rb
nanoc-4.7.4 test/filters/test_handlebars.rb
nanoc-4.7.3 test/filters/test_handlebars.rb
nanoc-4.7.2 test/filters/test_handlebars.rb
nanoc-4.7.1 test/filters/test_handlebars.rb
nanoc-4.7.0 test/filters/test_handlebars.rb
nanoc-4.6.4 test/filters/test_handlebars.rb
nanoc-4.6.3 test/filters/test_handlebars.rb
nanoc-4.6.2 test/filters/test_handlebars.rb
nanoc-4.6.1 test/filters/test_handlebars.rb
nanoc-4.6.0 test/filters/test_handlebars.rb
nanoc-4.5.4 test/filters/test_handlebars.rb
nanoc-4.5.3 test/filters/test_handlebars.rb
nanoc-4.5.2 test/filters/test_handlebars.rb
nanoc-4.5.1 test/filters/test_handlebars.rb
nanoc-4.5.0 test/filters/test_handlebars.rb