Sha256: 8fbc08f641911591854b48212f390b06e6e9cbe409af8b244e1b64f39c079591

Contents?: true

Size: 970 Bytes

Versions: 4

Compression:

Stored size: 970 Bytes

Contents

require "hmote"

module Tynn::HMote
  include ::HMote::Helpers

  def self.setup(app, options = {}) # :nodoc:
    options = options.dup

    options[:layout] ||= "layout"
    options[:views]  ||= File.expand_path("views", Dir.pwd)

    app.settings[:hmote] ||= options
  end

  module ClassMethods
    def layout(layout)
      settings[:hmote][:layout] = layout
    end
  end

  def render(template, locals = {}, layout = settings[:hmote][:layout])
    res.headers[Rack::CONTENT_TYPE] ||= Syro::Response::DEFAULT

    res.write(view(template, locals, layout))
  end

  def view(template, locals = {}, layout = settings[:hmote][:layout])
    return partial(layout, locals.merge(content: partial(template, locals)))
  end

  def partial(template, locals = {})
    return hmote(template_path(template), locals.merge(app: self), TOPLEVEL_BINDING)
  end

  private

  def template_path(template)
    return File.join(settings[:hmote][:views], "#{ template }.mote")
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tynn-1.0.0.rc1 lib/tynn/hmote.rb
tynn-0.0.4 lib/tynn/hmote.rb
tynn-0.0.3 lib/tynn/hmote.rb
tynn-0.0.2 lib/tynn/hmote.rb