Module: Idiom::ClassMethods

Included in:
Base
Defined in:
lib/idiom/base.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#find_and_translate_all(options = {}) ⇒ Object



155
156
157
158
159
160
161
162
# File 'lib/idiom/base.rb', line 155

def find_and_translate_all(options={})
  options.stringify_keys!
  
  source_files.each do |path|
    $stdout.puts "Processing #{path}"
    translate_file(path, options)
  end        
end

#source_filesObject



145
146
147
148
149
150
151
152
153
# File 'lib/idiom/base.rb', line 145

def source_files
  if @source =~ /\.(yml|pres)$/
    source_files = Dir[@source]
  else
    dir = File.expand_path(@source)
    source_files = Dir["#{dir}/**/*_en-US.pres"] + Dir["#{dir}/**/*_en-US.yml"]
    source_files.flatten
  end        
end

#translate(options = {}) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
# File 'lib/idiom/base.rb', line 133

def translate(options={})
  options.stringify_keys!
  
  @source = options["source"]
  @destination = options["destination"]
  @use_dirs = options["use_dirs"]
  
  Timer.new.time do
    find_and_translate_all(options)
  end
end

#translate_file(path, options = {}) ⇒ Object



164
165
166
167
168
169
170
171
172
# File 'lib/idiom/base.rb', line 164

def translate_file(path, options={})
  options.stringify_keys!
  if path =~ /\.yml$/i
    Idiom::Yaml.new(options.merge({"source" => path})).generate
  end
  if path =~ /\.pres$/i
    Idiom::Yrb.new(options.merge({"source" => path})).generate
  end        
end