Skip to content

Commit 9290f94

Browse files
author
David J. Brenes
committed
Detecting that config/routes.rb already exists and then trying to merge it. Related to the issue GH-1885
1 parent 3b06721 commit 9290f94

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

core/lib/refinery/extension_generation.rb

+10-6
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,12 @@ def extension_path_for(path, extension, apply_tmp = true)
130130

131131
# Detect whether this is a special file that needs to get merged not overwritten.
132132
# This is important only when nesting extensions.
133-
if extension.present? && File.exist?(path)
133+
# Routes and #{gem_name}\.rb have an .erb extension as path points to the generator template
134+
# We have to exclude it when checking if the file already exists and include it in the regexps
135+
if extension.present? && File.exist?(path.gsub(/\.erb$/, ""))
134136
if %r{/locales/.*\.yml$} === path ||
135-
%r{/routes.rb$} === path ||
136-
%r{/#{gem_name}.rb$} === path
137+
%r{/routes\.rb\.erb$} === path ||
138+
%r{/#{gem_name}\.rb\.erb$} === path
137139
# put new translations into a tmp directory
138140
if apply_tmp
139141
path = path.split(File::SEPARATOR).insert(-2, "tmp").
@@ -210,13 +212,15 @@ def merge_locales!
210212
if existing_extension?
211213
# go through all of the temporary files and merge what we need into the current files.
212214
tmp_directories = []
213-
Dir.glob(source_pathname.join("{config/locales/*.yml,config/routes.rb,lib/refinerycms-extension_plural_name.rb}"), File::FNM_DOTMATCH).sort.each do |path|
215+
Dir.glob(source_pathname.join("{config/locales/*.yml,config/routes.rb.erb,lib/refinerycms-extension_plural_name.rb.erb}"), File::FNM_DOTMATCH).sort.each do |path|
214216
# get the path to the current tmp file.
215-
new_file_path = extension_path_for(path, extension_name)
217+
# Both the new and current paths need to strip the .erb portion from the generator template
218+
new_file_path = Pathname.new extension_path_for(path, extension_name).to_s.gsub(/\.erb$/, "")
216219
tmp_directories << Pathname.new(new_file_path.to_s.split(File::SEPARATOR)[0..-2].join(File::SEPARATOR)) # save for later
217220
# get the path to the existing file and perform a deep hash merge.
218-
current_path = extension_path_for(path, extension_name, false)
221+
current_path = Pathname.new extension_path_for(path, extension_name, false).to_s.gsub(/\.erb$/, "")
219222
new_contents = nil
223+
220224
if File.exist?(new_file_path) && %r{.yml$} === new_file_path.to_s
221225
# merge translation files together.
222226
new_contents = YAML::load(new_file_path.read).deep_merge(

0 commit comments

Comments
 (0)