Module: Translatomatic::ResourceFile
- Extended by:
- Util
- Defined in:
- lib/translatomatic/resource_file.rb,
lib/translatomatic/resource_file/xml.rb,
lib/translatomatic/resource_file/html.rb,
lib/translatomatic/resource_file/resw.rb,
lib/translatomatic/resource_file/text.rb,
lib/translatomatic/resource_file/yaml.rb,
lib/translatomatic/resource_file/plist.rb,
lib/translatomatic/resource_file/markdown.rb,
lib/translatomatic/resource_file/properties.rb,
lib/translatomatic/resource_file/xcode_strings.rb
Defined Under Namespace
Classes: Base, HTML, Markdown, Plist, Properties, RESW, Text, XCodeStrings, XML, YAML
Class Method Summary collapse
-
.find(path, options = {}) ⇒ Array<Translatomatic::ResourceFile>
Find all resource files under the given directory.
-
.load(path, locale = nil) ⇒ Translatomatic::ResourceFile::Base
Load a resource file.
-
.modules ⇒ Array<Class>
Find all configured resource file classes.
Methods included from Util
Class Method Details
.find(path, options = {}) ⇒ Array<Translatomatic::ResourceFile>
Find all resource files under the given directory. Follows symlinks.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/translatomatic/resource_file.rb', line 31 def self.find(path, = {}) files = [] include_dot_directories = [:include_dot_directories] path = Pathname.new(path) unless path.kind_of?(Pathname) path.find do |file| if !include_dot_directories && file.basename.to_s[0] == ?. Find.prune else resource = load(file) files << resource if resource end end files end |
.load(path, locale = nil) ⇒ Translatomatic::ResourceFile::Base
Load a resource file. If locale is not specified, the locale of the file will be determined from the filename, or else the current default locale will be used.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/translatomatic/resource_file.rb', line 15 def self.load(path, locale = nil) path = path.kind_of?(Pathname) ? path : Pathname.new(path) modules.each do |mod| # match on entire filename to support extensions containing locales if extension_match(mod, path) log.debug("attempting to load #{path.to_s} using #{mod.name.demodulize}") file = mod.new(path, locale) return file if file.valid? end end nil end |
.modules ⇒ Array<Class>
Find all configured resource file classes
48 49 50 51 52 |
# File 'lib/translatomatic/resource_file.rb', line 48 def self.modules self.constants.map { |c| self.const_get(c) }.select do |klass| klass.is_a?(Class) && klass != Base end end |