Skip to content

Commit

Permalink
Remove redundant methods and variables.
Browse files Browse the repository at this point in the history
- Now, calling `write_file` directly without going through `write_bundle`
- Other miscellaneous optimizations
  • Loading branch information
arnavk committed Apr 20, 2015
1 parent 499cbcd commit 72ce192
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
4 changes: 1 addition & 3 deletions lib/twitter_cldr/js/compiler.rb
Expand Up @@ -27,8 +27,7 @@ def compile_bundle(bundle, bundle_elements, bundle_hash, options = {})

contents = ""
bundle_elements.each do |bundle_element|
renderer_const = bundle_hash[bundle_element]
if renderer_const
if renderer_const = bundle_hash[bundle_element]
if bundle[:locale]
contents << renderer_const.new(:locale => bundle[:locale], :prerender => @prerender).render
else
Expand Down Expand Up @@ -60,7 +59,6 @@ def compile_bundle(bundle, bundle_elements, bundle_hash, options = {})

def compile_each(options = {})
@locales.each do |locale|
contents = ""
bundle = TwitterCldr::Js::Renderers::Bundle.new
bundle[:locale] = locale
file = compile_bundle(bundle, @features, implementation_renderers, options)
Expand Down
20 changes: 4 additions & 16 deletions lib/twitter_cldr/js/tasks/tasks.rb
Expand Up @@ -52,7 +52,7 @@ def build(options = {})
options[:files].each_pair do |file_pattern, minify|
compiler.compile_each(:minify => minify) do |bundle, locale|
out_file_path = [output_dir, file_pattern % locale]
write_bundle(out_file_path, bundle.source)
write_file(out_file_path, bundle.source)

if bundle.source_map
ext = File.extname(out_file)
Expand All @@ -63,7 +63,7 @@ def build(options = {})

if options[:render_test_files]
file_contents = compiler.compile_test()
write_bundle([output_dir, 'test_resources.js'], file_contents)
write_file([output_dir, 'test_resources.js'], file_contents)
end

end
Expand All @@ -75,20 +75,8 @@ def build(options = {})
)
end

def write_bundle(file_path, file_contents)
out_file = file_path

if file_path.is_a?(Array)
out_file = File.join(file_path)
end

write_file(out_file, file_contents)
end

def write_file(file_name, file_contents)
File.open(file_name, "w+") do |f|
f.write(file_contents)
end
def write_file(file_path, file_contents)
File.write(File.join(file_path), file_contents)
end

def build_summary(options = {})
Expand Down

0 comments on commit 72ce192

Please sign in to comment.