Skip to content

Instantly share code, notes, and snippets.

@parndt
Last active December 19, 2015 13:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parndt/5962394 to your computer and use it in GitHub Desktop.
Save parndt/5962394 to your computer and use it in GitHub Desktop.
Who wants to make this nicer? :(
def extension_path_for_nested_extension(path, apply_tmp)
if File.exist?(path.gsub(/\.erb$/, ""))
if %r{/(locales/.*\.yml)|((routes|#{gem_name})\.rb\.erb)$} === path
# put new translations into a tmp directory
path = path.split(File::SEPARATOR).insert(-2, "tmp").join(File::SEPARATOR) if apply_tmp
elsif %r{/readme.md$} === path || %r{/#{plural_name}.rb$} === path
path = nil
end
elsif %r{lib\/#{plural_name}.rb$} === path
path = nil
end
path
end
def extension_path_for_nested_extension(path, apply_tmp)
return nil if !File.exist?(path.gsub(/\.erb$/, '')) &&
%r{readme.md|(lib/)?#{plural_name}.rb$} === path
if apply_tmp && %r{(locales/.*\.yml)|((config/routes|#{gem_name})\.rb\.erb)$} === path
return path.split(File::SEPARATOR).insert(-2, "tmp").join(File::SEPARATOR)
end
path
end
@sgerrand
Copy link

You've done a reasonable job with final.rb. 😺

The only change I'd make is to change if !condition && to unless condition || for readability/explicitness. 👴

@parndt
Copy link
Author

parndt commented Jul 10, 2013

@sgerrand thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment