lib/i18n/tasks/task_helpers.rb in i18n-tasks-0.0.8 vs lib/i18n/tasks/task_helpers.rb in i18n-tasks-0.1.0
- old
+ new
@@ -9,16 +9,39 @@
out.gets nil
end
# compile prefix matching Regexp from the list of prefixes
def compile_start_with_re(prefixes)
- /^(?:#{prefixes.map{|p| Regexp.escape(p) }.join('|')})/
+ if prefixes.blank?
+ /\Z\A/ # match nothing
+ else
+ /^(?:#{prefixes.map { |p| Regexp.escape(p) }.join('|')})/
+ end
end
# exclude @keys with prefixes matching @patterns
def exclude_patterns(keys, patterns)
pattern_re = compile_start_with_re patterns.select { |p| p.end_with?('.') }
(keys - patterns).reject { |k| k =~ pattern_re }
+ end
+
+ # type: missing, eq_base, unused
+ def ignore_pattern(type, locale = nil)
+ ((@ignore_patterns ||= HashWithIndifferentAccess.new)[type] ||= {})[locale] = begin
+ global = config[:ignore] || []
+ type_ignore = config["ignore_#{type}"] || []
+ if type_ignore.is_a?(Array)
+ compile_start_with_re global + type_ignore
+ elsif type_ignore.is_a?(Hash)
+ p = global + (type_ignore[:all] || [])
+ type_ignore.each { |key, value| p += (value || []) if key.to_s =~ /\b#{locale}\b/ } if locale
+ compile_start_with_re p
+ end
+ end
+ end
+
+ def config
+ I18n::Tasks.config
end
end
end
end