Sha256: 8760c19fa9cfe39fd734f1fdd707a60beebe1a11f389e97b2af21ec4cb477a33

Contents?: true

Size: 881 Bytes

Versions: 1

Compression:

Stored size: 881 Bytes

Contents

require 'tilt'

class BatchIt
  VERSION = File.read(File.join(File.dirname(__FILE__),"..","VERSION")).freeze

  attr_reader :corpus
  def initialize(corpus)
    @corpus = corpus
    @erb_template, @markdown_template = Tilt.templates_for("corpus.markdown.erb")
  end

  def result(data)
    enumerate_over_bindings(data) do |bind|
      markdown_result(erb_result(corpus, bind))
    end
  end

  private
  def enumerate_over_bindings(input)
    case input
    when Array
      input.map do |item|
        yield(item)
      end
    else
      yield(input)
    end
  end

  def markdown_template(corpus)
    @markdown_template.new{corpus}
  end

  def markdown_result(corpus)
    markdown_template(corpus).render
  end

  def erb_result(corpus, data)
    erb(corpus).render(data)
  end

  def erb(corpus)
    @erb ||= @erb_template.new("corpus.erb", trim: false) { corpus }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
batch_it-0.1.0 lib/batch_it.rb