Sha256: 59701e2aed670867ff79955bedbb8772f0dfe5943bd5120a20980e8bdb426aaa

Contents?: true

Size: 988 Bytes

Versions: 36

Compression:

Stored size: 988 Bytes

Contents

require 'sinatra/base'
require 'markaby'

module Sinatra
  module Markaby
    # Generate html file using Markaby.
    # Takes the name of a template to render as a Symbol and returns a String with the rendered output.
    #
    # Options for markaby may be specified in Sinatra using set :markaby, { ... }
    # TODO: the options aren't actually used yet
    def markaby(template=nil, options={}, locals = {}, &block)
      options, template = template, nil if template.is_a?(Hash)
      template = lambda { block } if template.nil?
      render :mab, template, options, locals
    end

  protected
    def render_mab(template, data, options, locals, &block)
      filename = options.delete(:filename) || '<MARKABY>'
      line = options.delete(:line) || 1
      mab = ::Markaby::Builder.new(locals)
      if data.respond_to?(:to_str)
        eval(data.to_str, binding, filename, line)
      elsif data.kind_of?(Proc)
        data.call(mab)
      end
    end
  end

  helpers Markaby
end

Version data entries

36 entries across 36 versions & 3 rubygems

Version Path
sbfaulkner-sinatra-markaby-0.9.2.1 lib/sinatra/markaby.rb
sbfaulkner-sinatra-markaby-0.9.2.2 lib/sinatra/markaby.rb
sbfaulkner-sinatra-markaby-0.9.2 lib/sinatra/markaby.rb
tdreyno-middleman-0.2.4 vendor/sinatra-markaby/lib/sinatra/markaby.rb
tdreyno-middleman-0.2.5 vendor/sinatra-markaby/lib/sinatra/markaby.rb
tdreyno-middleman-0.2.6 vendor/sinatra-markaby/lib/sinatra/markaby.rb
tdreyno-middleman-0.2.7 vendor/sinatra-markaby/lib/sinatra/markaby.rb
tdreyno-middleman-0.2.8 vendor/sinatra-markaby/lib/sinatra/markaby.rb
tdreyno-middleman-0.2.9 vendor/sinatra-markaby/lib/sinatra/markaby.rb
tdreyno-middleman-0.3.0 vendor/sinatra-markaby/lib/sinatra/markaby.rb
tdreyno-middleman-0.3.1 vendor/sinatra-markaby/lib/sinatra/markaby.rb
tdreyno-middleman-0.3.10 vendor/sinatra-markaby/lib/sinatra/markaby.rb
tdreyno-middleman-0.3.2 vendor/sinatra-markaby/lib/sinatra/markaby.rb
tdreyno-middleman-0.3.3 vendor/sinatra-markaby/lib/sinatra/markaby.rb
tdreyno-middleman-0.3.4 vendor/sinatra-markaby/lib/sinatra/markaby.rb
tdreyno-middleman-0.3.7 vendor/sinatra-markaby/lib/sinatra/markaby.rb
tdreyno-middleman-0.3.8 vendor/sinatra-markaby/lib/sinatra/markaby.rb
middleman-0.3.6 vendor/sinatra-markaby/lib/sinatra/markaby.rb
middleman-0.3.7 vendor/sinatra-markaby/lib/sinatra/markaby.rb
middleman-0.3.8 vendor/sinatra-markaby/lib/sinatra/markaby.rb