Skip to content

Instantly share code, notes, and snippets.

@thomseddon
Last active December 23, 2015 04:29
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 thomseddon/6580866 to your computer and use it in GitHub Desktop.
Save thomseddon/6580866 to your computer and use it in GitHub Desktop.
Reformat cakephp templates (generated with bake) to bootstrap style using sed
# Remove "actions" divs
find View/ -name "*.ctp" -exec sed -i ':a;N;$!ba;s/<div class="actions">\(.*\)<\/div>//g' '{}' \;
# Add "table" class to tables
find View/ -name "*.ctp" -exec sed -i "s/<table\(.*\)/<table class=\"table table-striped\">/g" '{}' \;
# Add btn classes to buttons
find View/ -name "*.ctp" -exec sed -i "s/view\(.*\))/view\1, array('class' => 'btn btn-default'))/g" '{}' \;
find View/ -name "*.ctp" -exec sed -i "s/edit\(.*\))/edit\1, array('class' => 'btn btn-info'))/g" '{}' \;
find View/ -name "*.ctp" -exec sed -i "s/delete\(.*\), null/delete\1, array('class' => 'btn btn-danger')/g" '{}' \;
# Wrap created/modified with custom date formatter function ("df")
find View/ -name "*.ctp" -exec sed -i "s/h(\(.*\)\(created\|modified\)'])/df(\1\2'])/g" '{}' \;
# Format pagination links
find View/ -name "*.ctp" -exec sed -i "s/div class=\"paging\"/ul class=\"pagination\"/g" '{}' \;
find View/ -name "*.ctp" -exec sed -i "s/Paginator->prev(\(.*\)/Paginator->prev('\&laquo;', array('tag' => 'li', 'escape' => false), '<a href=\"#\">\&laquo;<\/a>', array('class' => 'prev disabled', 'tag' => 'li', 'escape' => false));/g" '{}' \;
find View/ -name "*.ctp" -exec sed -i "s/Paginator->numbers(\(.*\)/Paginator->numbers(array('separator' => '', 'tag' => 'li', 'currentLink' => true, 'currentClass' => 'active'));/g" '{}' \;
find View/ -name "*.ctp" -exec sed -i "s/Paginator->next(\(.*\)/Paginator->next('\&raquo;', array('tag' => 'li', 'escape' => false), '<a href=\"#\">\&raquo;<\/a>', array('class' => 'prev disabled', 'tag' => 'li', 'escape' => false));/g" '{}' \;
# Format form submits
find View/ -name *.ctp -exec sed -i "s/Form->end(__('Submit'))/Form->end(array('value' => __('Submit'), 'class' => 'btn btn-default', 'before' => '<div class="col-md-2"><\/div>'))/g" '{}' \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment