lib/flapjack/utility.rb in flapjack-1.3.0 vs lib/flapjack/utility.rb in flapjack-1.4.0rc1

- old
+ new

@@ -79,9 +79,23 @@ (text.rindex(options[:separator], length_with_room_for_omission) || length_with_room_for_omission) : length_with_room_for_omission (text.length > length ? text[0...stop] + options[:omission] : text).to_s end + def load_template(template_config, message_type, message_filetype, + default_template_path) + template_file = if template_config.nil? || !template_config.has_key?("#{message_type}.#{message_filetype}") + # we ship UTF-8 templates with the gem + template_path = File.join(default_template_path, "#{message_type}.#{message_filetype}.erb") + File.open(template_path, "r:UTF-8", &:read) + else + # respects Encoding.default_external (UTF-8 or ENV['LANG']) + template_path = template_config["#{message_type}.#{message_filetype}"] + File.read(template_path) + end + [ERB.new(template_file, nil, '-'), template_file] + end + private def plural_s(value) (value == 1) ? '' : 's' end