Sha256: d3cf063b8908baa261f4eb17e6960e5b1324098fd49466cdc10e5e464a457c44

Contents?: true

Size: 903 Bytes

Versions: 8

Compression:

Stored size: 903 Bytes

Contents

# TILT/Sinatra template engine
module Osheet
  class TiltHandler < Tilt::Template

    def self.engine_initialized?
      defined? ::Osheet::Workbook
    end

    def initialize_engine
      require_template_library 'osheet'
    end

    def prepare; end

    def precompiled_preamble(locals)
      "::Osheet::Workbook.new {\n#{super}"
    end

    def precompiled_template(locals)
      data.to_str
    end
    def precompiled_postamble(locals)
      "}.to_data"
    end

  end
end

Tilt.register 'osheet', Osheet::TiltHandler

if defined?(::Sinatra::Base)
  class ::Sinatra::Base

    # use this helper method to render Osheet views in Sinatra
    # => view files should be named: "#{template}.osheet"
    def osheet(template, options={}, locals={})
      options.merge! :layout => false, :default_content_type => ::Osheet::MIME_TYPE
      render :osheet, template, options, locals
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
osheet-0.10.0 lib/osheet/view_handler/tilt.rb
osheet-0.9.2 lib/osheet/view_handler/tilt.rb
osheet-0.9.1 lib/osheet/view_handler/tilt.rb
osheet-0.9.0 lib/osheet/view_handler/tilt.rb
osheet-0.8.0 lib/osheet/view_handler/tilt.rb
osheet-0.7.0 lib/osheet/view_handler/tilt.rb
osheet-0.6.0 lib/osheet/view_handler/tilt.rb
osheet-0.5.0 lib/osheet/template_handler/tilt.rb