Sha256: 0d50f039a01e95f3c280ae4285df69cbee78c79c16384c559f9fe7cd78be4927

Contents?: true

Size: 1.37 KB

Versions: 11

Compression:

Stored size: 1.37 KB

Contents

require 'ruhl'

module Sinatra
  module Templates
    def ruhl(template, options = {}, locals = {})
      require_warn('Ruhl') unless defined?(::Ruhl::Engine)

      render :ruhl, template, options, locals
    end

    private

    def render(engine, template, options={}, locals={})
      # merge app-level options
      options = self.class.send(engine).merge(options) if self.class.respond_to?(engine)

      views = options.delete(:views) || self.class.views || "./views"

      # render template
      data, options[:filename], options[:line] = lookup_template(engine, template, views)

      __send__("render_#{engine}", template, data, options)
    end
    
    def render_ruhl(template, data, options)
      ::Ruhl::Engine.new(data, options).render(self)
    end
  end
end

module Ruhl
  class Engine

    private

    def render_with_layout
      if @layout_source
       data = @layout_source
      else
        views = scope.class.views || "./views"
        data, filename, line = scope.send(:lookup_template, :ruhl, @layout.to_sym, views)
      end

     render_nodes Nokogiri::HTML(data)
    end


    def render_partial
      views = scope.class.views || "./views"

      data, filename, line = scope.send :lookup_template, :ruhl, call_result.to_sym, views

      raise PartialNotFoundError.new(call_result) unless data

      render_nodes Nokogiri::HTML.fragment(data) 
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
ruhl-1.3.6 lib/ruhl/sinatra.rb
ruhl-1.3.5 lib/ruhl/sinatra.rb
ruhl-1.3.4 lib/ruhl/sinatra.rb
ruhl-1.3.3 lib/ruhl/sinatra.rb
ruhl-1.3.2 lib/ruhl/sinatra.rb
ruhl-1.3.1 lib/ruhl/sinatra.rb
ruhl-1.3.0 lib/ruhl/sinatra.rb
ruhl-1.2.0 lib/ruhl/sinatra.rb
ruhl-1.1.1 lib/ruhl/sinatra.rb
ruhl-1.1.0 lib/ruhl/sinatra.rb
ruhl-1.0.0 lib/ruhl/sinatra.rb