Top Level Namespace

Defined Under Namespace

Classes: Datagnan

Instance Method Summary collapse

Instance Method Details

#datagnan(template_file, options = {}, locals = {}) ⇒ Object

Helper function (for Sinatra, primarily)

Parameters:

  • file_path (String)

    path to .html-template file

  • options (Hash) (defaults to: {})

    options for parsing and filling the template @option options [Object] :scope (self) Scope for variables @option options [String] :views (scope.settings.views || “./views”) Path to views directory @option options [Hash] :locals (locals || {}) Local variables for filling the template

  • locals (Hash) (defaults to: {})

    local variables for filling the template



314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/datagnan.rb', line 314

def datagnan(template_file, options = {}, locals = {})
	# beginning_time = Time.now
	## default options
	scope = options.delete(:scope) || self
	views = File.realpath(options.delete(:views) || scope.settings.views || "./views")
	locals = options.delete(:locals) || locals || {}

	html = Datagnan.read(File.join(views, template_file.to_s+'.html'), :scope => scope, :locals => locals)
	## debug
	# puts "-- datagnan ( template = #{html} )"
	if File.exist? File.join(views, 'layout.html')
		locals['template'] = {'html' => html}
		html = Datagnan.read(File.join(views, 'layout.html'), :scope => scope, :locals => locals)
		## debug
		# puts "-- datagnan ( layout = #{html} )"
	end

	# end_time = Time.now
	# puts "Time elapsed for datagnan #{(end_time - beginning_time)*1000} milliseconds"

	return html
end

#ogaObject

Oga for HTML parsing (Yeah, no Nokogiri!)



2
# File 'lib/datagnan.rb', line 2

require 'oga'