class Object
Public Instance Methods
datagnan(template_files, options = {}, local_vars = {})
click to toggle source
Helper function (for Sinatra, primarily)
@param [String] file_path
path to .html-template file
@param [Hash] options
options for parsing and filling the template
@param [Hash] locals
local variables for filling the template
# File lib/datagnan.rb, line 378 def datagnan(template_files, 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].respond_to? :settings) || "./views") options[:layout_file] = File.join(options[:views_dir], options[:layout_file] || 'layout.html') vars = (options[:local_vars] || {}).merge local_vars html = "" template_files = [template_files] unless template_files.is_a? Array template_files.each do |template_file| ## 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, vars) ## debug # puts "-- datagnan ( template = #{html} )" end ## check for layout and wrap template if exist if File.exist? options[:layout_file] vars['template'] = { 'html' => html } html = Datagnan.read(options[:layout_file], options, vars) ## debug # puts "-- datagnan ( layout = #{html} )" end # end_time = Time.now # puts "Time elapsed for datagnan #{(end_time - beginning_time)*1000} milliseconds" return html end