Skip to content

Instantly share code, notes, and snippets.

@citrus
Created January 4, 2018 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save citrus/147019b9ec5801784dd1713d6c01d359 to your computer and use it in GitHub Desktop.
Save citrus/147019b9ec5801784dd1713d6c01d359 to your computer and use it in GitHub Desktop.
#!/bin/sh
if [ -z "$1" ]
then
echo "You must specify a namespace to flatten" 1>&2
exit 1
else
namespace=$1
fi
# Always use double quotes when rendering
grep -e "render '" -R app/views -l | xargs sed -i "" "s|render '\(.*\)'|render \"\1\"|"
grep -e "render partial: '" -R app/views -l | xargs sed -i "" "s|render partial: '\(.*\)'|render partial: \"\1\"|"
# create new subdirectories
find app/views/$namespace -type d | sed "s/views\/$namespace/views/" | xargs -n1 mkdir -p
# mv files out of namespace
git ls-files | grep "app/views/$namespace" | sed -e "p;s/views\/$namespace/views/" | xargs -n2 mv
# find absolute paths to $namespace views
grep -e "render \"$namespace/" -R app -l | xargs sed -i "" "s|render \"$namespace\/|render \"|"
grep -e "render partial: \"$namespace/" -R app -l | xargs sed -i "" "s|render partial: \"$namespace\/|render partial: \"|"
grep -e "assert_template \"$namespace/" -R test/functional -l | xargs sed -i "" "s|assert_template \"$namespace/|assert_template \"|"
grep -e "assert_template partial: \"$namespace/" -R test/functional -l | xargs sed -i "" "s|assert_template partial: \"$namespace/|assert_template partial: \"|"
# remove $namespace directory
rm -R "app/views/$namespace"
# reset
# git reset --hard; git clean -fd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment