Top Level Namespace

Defined Under Namespace

Classes: Datagnan

Instance Method Summary collapse

Instance Method Details

#datagnan(template_file, options = {}, local_vars = {}) ⇒ 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

  • locals (Hash)

    local variables for filling the template



345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# File 'lib/datagnan.rb', line 345

def datagnan(template_file, options = {}, local_vars = {})
	# beginning_time = Time.now
	## default options
	options[:scope] ||= self
	options[:views_dir] = File.realpath(options[:views_dir] || (options[:scope].settings.views if options[:scope].settings) || "./views")
	options[:layout_file] = File.join(options[:views_dir], options[:layout_file] || 'layout.html')
	(options[:local_vars] ||= {}).merge! local_vars

	## prepare template filename
	template_file = File.join(options[:views_dir], template_file.to_s)
	template_file += '.html' unless File.exist? template_file

	## render template
	html = Datagnan.read(template_file, options)
	## debug
	# puts "-- datagnan ( template = #{html} )"
	## check for layout and wrap template if exist
	if File.exist? options[:layout_file]
		options[:local_vars]['template'] = { 'html' => html }
		html = Datagnan.read(options[:layout_file], options)
		## 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'