lib/jetel/helpers/general_helper.rb in jetel-0.0.6 vs lib/jetel/helpers/general_helper.rb in jetel-0.0.7

- old
+ new

@@ -1,19 +1,22 @@ # encoding: utf-8 require_relative '../config/config' +require_relative '../helpers/helpers' require_relative '../loaders/loaders' +require 'erb' require 'i18n' +require 'ostruct' module Jetel module Helper class << self def target_dir(modul, dir, source) - klass = I18n.transliterate(modul.class.name.split('::').last).gsub(/[^0-9a-z_\-]/i, '_') - source_name = I18n.transliterate(source[:name]).gsub(/[^0-9a-z_\-]/i, '_') + klass = modul.class.name.split('::').last + source_name = Helper.sanitize(source[:name]) File.join(dir || Config[:DATA_DIRECTORY], klass, source_name) end def get_loader(uri) loaders = Loaders.loaders @@ -21,9 +24,22 @@ res = loaders.find do |loader| loader[:class_name].downcase === loader_schema end res[:klass].new(uri) + end + + def erb(template, vars) + ERB.new(template).result(OpenStruct.new(vars).instance_eval { binding }) + end + + def erb_template(file, vars) + template = File.open(file, 'r').read + ERB.new(template).result(OpenStruct.new(vars).instance_eval { binding }) + end + + def sanitize(str) + I18n.transliterate(str).gsub(/[^0-9a-z_\-]/i, '_') end end end end