Created
March 28, 2017 23:51
-
-
Save BeFiveINFO/91648cae116dcb1383873f2184f544fd to your computer and use it in GitHub Desktop.
File list and template replacement example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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