Closed xiaohui-zhangxh closed 1 year ago
Hi, I'm curious why nobody asking insert_into_file with between feature? I was get embarrassed many times without any solution to do this:
Here is a simplified webpacker.yml that we just focus on the key point.
# config/webpacker.yml default: &default extract_css: false development: <<: *default test: <<: *default production: <<: *default extract_css: true
I'm going to write a rails template that add extract_css: true to development section with this code:
extract_css: true
development
inject_into_file 'config/webpacker.yml', after: /^development:\n *<<: \*default\n/ do <<~YAML.indent(2) extract_css: true YAML end
unfortunately extract_css: true already exists after production section which also after development section, so inject_into_file will do nothing.
what if inject_into_file support option between or bi-options after + before, it should inserted successfully.
inject_into_file
between
after
before
inject_into_file 'config/webpacker.yml', between: [/^development:\n *<<: \*default\n/, /^production:/] do <<~YAML.indent(2) extract_css: true YAML end
or
inject_into_file 'config/webpacker.yml', after: /^development:\n *<<: \*default\n/, before: /^production:/ do <<~YAML.indent(2) extract_css: true YAML end
My tricky solution is:
inject_into_file 'config/webpacker.yml', after: /^development:\n *<<: \*default\n/ do <<~YAML.indent(2) extract_css: true # this is for dev YAML end
Hi, I'm curious why nobody asking insert_into_file with between feature? I was get embarrassed many times without any solution to do this:
Here is a simplified webpacker.yml that we just focus on the key point.
I'm going to write a rails template that add
extract_css: true
todevelopment
section with this code:unfortunately
extract_css: true
already exists after production section which also after development section, so inject_into_file will do nothing.what if
inject_into_file
support optionbetween
or bi-optionsafter
+before
, it should inserted successfully.or