Skip to content

Instantly share code, notes, and snippets.

@BeFiveINFO
Created March 28, 2017 23:51
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 BeFiveINFO/91648cae116dcb1383873f2184f544fd to your computer and use it in GitHub Desktop.
Save BeFiveINFO/91648cae116dcb1383873f2184f544fd to your computer and use it in GitHub Desktop.
File list and template replacement example
#!/bin/bash
sectionTemplate="$(cat ../section_template.php)"
i=0
while read line
do
array[ $i ]="$line"
(( i++ ))
done < <(ls)
for item in ${array[@]}; do
fileName=$(basename "$item")
fileName="${fileName%.*}"
# if [[ $fileName =~ ^(.*?)-(.*)$ ]]; then
if [[ $fileName =~ ^([^\-]*)\-(.*)$ ]]; then
sectionSlug=${BASH_REMATCH[1]}
styleSlug=${BASH_REMATCH[2]}
fi
styleName=${styleSlug//-/ }
styleName=`echo $styleName | perl -pe 's/(\w+)/\u$1/g'`
sectionName=`echo $sectionSlug | perl -pe 's/(\w+)/\u$1/g'`
# $fileName
sectionTemplateCopy="${sectionTemplate/\{fileName\}/$fileName}"
# $sectionName
sectionTemplateCopy="${sectionTemplateCopy/\{sectionName\}/$sectionName}"
# $sectionSlug
sectionTemplateCopy="${sectionTemplateCopy/\{sectionSlug\}/$sectionSlug}"
# $styleSlug
sectionTemplateCopy="${sectionTemplateCopy/\{styleSlug\}/$styleSlug}"
# $styleName
sectionTemplateCopy="${sectionTemplateCopy/\{styleName\}/$styleName}"
# write a file
echo "$sectionTemplateCopy" > "$fileName.php"
done
<?php
$data = array();
$data['name'] = __( '{sectionName} {styleName}', 'themeMountain' );
$data['weight'] = 0;
$data['custom_class'] = 'tm-section tm-tmp_{fileName} tm-tmp-category_{sectionSlug}';
$data['content'] = <<<CONTENT
[vc_row][vc_column width="1/3"][tm_textblock]loremipsum[/tm_textblock][/vc_column][/vc_row]
CONTENT;
vc_add_default_templates( $data );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment