From 8ee1dbea762857a1b1f85358bbc65949854dc028 Mon Sep 17 00:00:00 2001 From: Rajab Natshah <rajabn@gmail.com> Date: Mon, 29 Jan 2018 19:17:07 +0200 Subject: [PATCH] Issue #2939408: Managed optional configs for [Varbase Theme - Material Design] theme, and Added a create-new-vartheme_material.sh generator bash script file. --- composer.json | 3 +- .../config/optional/block.block.copyright.yml | 1 - scripts/create-new-vartheme.sh | 1 + scripts/create-new-vartheme_material.sh | 260 ++++++++++++++++++ ...lock.block.VARTHEME_SUBTHEME_copyright.yml | 28 ++ ...oslider_media_varbase_heroslider_media.yml | 33 +++ .../block.block.vartheme_copyright.yml | 7 +- ...oslider_media_varbase_heroslider_media.yml | 33 +++ 8 files changed, 360 insertions(+), 6 deletions(-) create mode 100644 scripts/create-new-vartheme_material.sh create mode 100644 themes/vartheme/VARTHEME_SUBTHEME/config/optional/block.block.VARTHEME_SUBTHEME_copyright.yml create mode 100644 themes/vartheme/VARTHEME_SUBTHEME/config/optional/block.block.views_block__varbase_heroslider_media_varbase_heroslider_media.yml rename modules/varbase_features/varbase_default_content/config/optional/block.block.copyright_material.yml => themes/vartheme/config/optional/block.block.vartheme_copyright.yml (89%) create mode 100644 themes/vartheme/config/optional/block.block.views_block__varbase_heroslider_media_varbase_heroslider_media.yml diff --git a/composer.json b/composer.json index 85f8b277..2878f43d 100644 --- a/composer.json +++ b/composer.json @@ -197,7 +197,8 @@ "./bin/phing push" ], "post-drupal-scaffold-cmd": ["Varbase\\composer\\ScriptHandler::postDrupalScaffoldProcedure"], - "create-new-vartheme": "scripts/create-new-vartheme.sh" + "create-new-vartheme": "scripts/create-new-vartheme.sh", + "create-new-vartheme_material": "scripts/create-new-vartheme_material.sh" }, "extra": { "branch-alias": { diff --git a/modules/varbase_features/varbase_default_content/config/optional/block.block.copyright.yml b/modules/varbase_features/varbase_default_content/config/optional/block.block.copyright.yml index 31563702..70813b10 100644 --- a/modules/varbase_features/varbase_default_content/config/optional/block.block.copyright.yml +++ b/modules/varbase_features/varbase_default_content/config/optional/block.block.copyright.yml @@ -26,4 +26,3 @@ settings: info: '' view_mode: full visibility: { } - diff --git a/scripts/create-new-vartheme.sh b/scripts/create-new-vartheme.sh index c95a0728..bbcc804e 100644 --- a/scripts/create-new-vartheme.sh +++ b/scripts/create-new-vartheme.sh @@ -183,6 +183,7 @@ if [[ ! -d "$theme_path/$theme_name" ]]; then mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_SUBTHEME_branding.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_branding.yml mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_SUBTHEME_breadcrumbs.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_breadcrumbs.yml mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_SUBTHEME_content.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_content.yml + mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_SUBTHEME_copyright.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_copyright.yml mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_SUBTHEME_footer.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_footer.yml mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_SUBTHEME_help.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_help.yml mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_SUBTHEME_local_actions.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_local_actions.yml diff --git a/scripts/create-new-vartheme_material.sh b/scripts/create-new-vartheme_material.sh new file mode 100644 index 00000000..4cf87367 --- /dev/null +++ b/scripts/create-new-vartheme_material.sh @@ -0,0 +1,260 @@ +#!//bin/bash +################################################################################ +## Create new vartheme Material subtheme. +################################################################################ +## +## Quick tip on how to use this script command file. +## +## Create new Vartheme Material sub theme for a project. +## By Composer: +## ----------------------------------------------------------------------------- +## cd PROJECT_DIR_NAME/docroot/profiles/varbase +## composer create-new-vartheme_material "THEME_NAME" "ltr" "sites/default/themes/custom" +## ----------------------------------------------------------------------------- +## By Bash: +## ----------------------------------------------------------------------------- +## cd PROJECT_DIR_NAME/docroot/profiles/varbase/scripts +## bash ./create-new-vartheme_material.sh "THEME_NAME" "ltr" "sites/default/themes/custom" +##------------------------------------------------------------------------------ +## +## For right to left themes. +## By Composer: +## ----------------------------------------------------------------------------- +## cd PROJECT_DIR_NAME/docroot/profiles/varbase +## composer create-new-vartheme_material "THEME_NAME" "rtl" "sites/default/themes/custom" +## ----------------------------------------------------------------------------- +## By Bash: +## ----------------------------------------------------------------------------- +## cd PROJECT_DIR_NAME/docroot/profiles/varbase/scripts +## bash ./create-new-vartheme_material.sh "THEME_NAME" "rtl" "sites/default/themes/custom" +## ----------------------------------------------------------------------------- +## +## To create a new theme in the themes/custom +## By Composer: +## ----------------------------------------------------------------------------- +## cd PROJECT_DIR_NAME/docroot/profiles/varbase +## composer create-new-vartheme_material "THEME_NAME" "ltr" +## ----------------------------------------------------------------------------- +## By Bash: +## ----------------------------------------------------------------------------- +## cd PROJECT_DIR_NAME/docroot/profiles/varbase/scripts +## bash ./create-new-vartheme_material.sh "THEME_NAME" "ltr" +## ----------------------------------------------------------------------------- +## +################################################################################ + +# Basic yaml parser. +parse_yaml() { + local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034') + sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \ + -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 | + awk -F$fs '{ + indent = length($1)/2; + vname[indent] = $2; + for (i in vname) {if (i > indent) {delete vname[i]}} + if (length($3) > 0) { + vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")} + printf("%s%s%s=\"%s\"\n", "",vn, $2, $3); + } + }' +} + +current_path=$(pwd); +drupal_root="$current_path"; + +if [[ "${drupal_root: -1}" == "/" ]]; then + drupal_root="${drupal_root::-1}"; +fi + +if [[ "${drupal_root: -24}" == "profiles/varbase/scripts" ]]; then + drupal_root="${drupal_root::-24}"; +fi + +if [[ "${drupal_root: -16}" == "profiles/varbase" ]]; then + drupal_root="${drupal_root::-16}"; +fi + +if [[ "${drupal_root: -8}" == "profiles" ]]; then + drupal_root="${drupal_root::-8}"; +fi + +if [[ "${drupal_root: -1}" == "/" ]]; then + drupal_root="${drupal_root::-1}"; +fi + +echo "Current path: $current_path"; +echo "Drupal root: $drupal_root"; + +# Read scripts.settings.yml file +eval $(parse_yaml $drupal_root/profiles/varbase/scripts/scripts.settings.yml); + +# Default theme name. +theme_name=$default_theme_name; + +# Grape the theme name argument. +if [ ! -z "$1" ]; then + arg1="$1"; + if [[ $arg1 =~ ^[A-Za-z][A-Za-z0-9_]*$ ]]; then + theme_name="$arg1"; + else + echo "---------------------------------------------------------------------------"; + echo " Theme name is not a valid theme name! "; + echo "---------------------------------------------------------------------------"; + exit 1; + fi +else + echo "---------------------------------------------------------------------------"; + echo " Please add the name of your theme! "; + echo "---------------------------------------------------------------------------"; + exit 1; +fi + +# Default direction. +direction=$default_direction; + +# Grape the direction argument. only if we have arg #2. +if [ ! -z "$2" ]; then + arg2="$2"; + if [[ "$arg2" == "rtl" || "$arg2" == "RTL" ]]; then + direction=$arg2; + elif [[ "$arg2" == "ltr" || "$arg2" == "LTR" ]]; then + direction=$arg2; + else + echo "---------------------------------------------------------------------------"; + echo " Direction of language is not valid! "; + echo " ltr - for (left to right) languages. "; + echo " rtl - for (right to left) languages. "; + echo "---------------------------------------------------------------------------"; + exit 1; + fi +fi + +# Default themes creation path. +theme_path=$drupal_root/$default_themes_creation_path; + +# Grape the theme path argument. only if we have arg #3. +if [ ! -z "$3" ]; then + arg3=$3; + if [[ $arg3 =~ ^[A-Za-z][A-Za-z0-9_-/]*$ ]]; then + if [[ "${arg3: -1}" == "/" ]]; then + arg3="${arg3::-1}"; + fi + + if [[ ! -d "$arg3" ]]; then + theme_path=$arg3; + mkdir -p $theme_path; + fi + else + echo "---------------------------------------------------------------------------"; + echo " Theme path must be in the right format! "; + echo "---------------------------------------------------------------------------"; + exit 1; + fi +else + if [[ ! -d "$theme_path" ]]; then + mkdir -p $theme_path; + fi +fi + + +# Create the new Vartheme material subtheme if we do not have a folder with that name yet. +if [[ ! -d "$theme_path/$theme_name" ]]; then + + # 1. Copy the VARTHEME_MATERIAL_SUBTHEME folder to your custom theme location. + cp -r ${drupal_root}/themes/contrib/vartheme_material/VARTHEME_MATERIAL_SUBTHEME ${theme_path}/${theme_name}; + + # 2. Rename VARTHEME_MATERIAL_SUBTHEME.starterkit.yml your_subtheme_name.info.yml + mv ${theme_path}/${theme_name}/VARTHEME_MATERIAL_SUBTHEME.starterkit.yml ${theme_path}/${theme_name}/VARTHEME_SUBTHEME.info.yml ; + mv ${theme_path}/${theme_name}/VARTHEME_MATERIAL_SUBTHEME.info.yml ${theme_path}/${theme_name}/${theme_name}.info.yml ; + + # 3. Rename VARTHEME_MATERIAL_SUBTHEME.libraries.yml your_subtheme_name.libraries.yml + mv ${theme_path}/${theme_name}/VARTHEME_MATERIAL_SUBTHEME.libraries.yml ${theme_path}/${theme_name}/${theme_name}.libraries.yml ; + + # 4. Rename VARTHEME_MATERIAL_SUBTHEME.theme your_subtheme_name.theme + mv ${theme_path}/${theme_name}/VARTHEME_MATERIAL_SUBTHEME.theme ${theme_path}/${theme_name}/${theme_name}.theme ; + + # 5. Rename VARTHEME_MATERIAL_SUBTHEME.settings.yml + mv ${theme_path}/${theme_name}/config/install/VARTHEME_MATERIAL_SUBTHEME.settings.yml ${theme_path}/${theme_name}/config/install/${theme_name}.settings.yml ; + + # 6. Rename VARTHEME_MATERIAL_SUBTHEME.schema.yml + mv ${theme_path}/${theme_name}/config/schema/VARTHEME_MATERIAL_SUBTHEME.schema.yml ${theme_path}/${theme_name}/config/schema/${theme_name}.schema.yml ; + + # 7. Rename VARTHEME_MATERIAL_SUBTHEME optional blocks. + mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_MATERIAL_SUBTHEME_branding.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_branding.yml + mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_MATERIAL_SUBTHEME_breadcrumbs.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_breadcrumbs.yml + mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_MATERIAL_SUBTHEME_content.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_content.yml + mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_MATERIAL_SUBTHEME_copyright.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_copyright.yml + mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_MATERIAL_SUBTHEME_footer.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_footer.yml + mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_MATERIAL_SUBTHEME_help.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_help.yml + mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_MATERIAL_SUBTHEME_local_actions.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_local_actions.yml + mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_MATERIAL_SUBTHEME_local_tasks.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_local_tasks.yml + mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_MATERIAL_SUBTHEME_main_menu.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_main_menu.yml + mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_MATERIAL_SUBTHEME_messages.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_messages.yml + mv ${theme_path}/${theme_name}/config/optional/block.block.VARTHEME_MATERIAL_SUBTHEME_page_title.yml ${theme_path}/${theme_name}/config/optional/block.block.${theme_name}_page_title.yml + + # 8. Rename VARTHEME_MATERIAL_SUBTHEME.base.css files. + mv ${theme_path}/${theme_name}/css/base/VARTHEME_SUBTHEME.base.css ${theme_path}/${theme_name}/css/base/${theme_name}.base.css + mv ${theme_path}/${theme_name}/css/base/VARTHEME_SUBTHEME.base.css.map ${theme_path}/${theme_name}/css/base/${theme_name}.base.css.map + + # 9. Rename VARTHEME_MATERIAL_SUBTHEME-rtl.base.css files. + mv ${theme_path}/${theme_name}/css/rtl/base/VARTHEME_SUBTHEME-rtl.base.css ${theme_path}/${theme_name}/css/rtl/base/${theme_name}-rtl.base.css + mv ${theme_path}/${theme_name}/css/rtl/base/VARTHEME_SUBTHEME-rtl.base.css.map ${theme_path}/${theme_name}/css/rtl/base/${theme_name}-rtl.base.css.map + + # 10. Rename VARTHEME_MATERIAL_SUBTHEME.base.less file. + mv ${theme_path}/${theme_name}/less/base/VARTHEME_SUBTHEME.base.less ${theme_path}/${theme_name}/less/base/${theme_name}.base.less + + # 11. Rename VARTHEME_MATERIAL_SUBTHEME-rtl.base.less file. + mv ${theme_path}/${theme_name}/less/rtl/base/VARTHEME_SUBTHEME-rtl.base.less ${theme_path}/${theme_name}/less/rtl/base/${theme_name}-rtl.base.less + + # 12. Replace all VARTHEME_MATERIAL_SUBTHEME with the machine name of your theme. + grep -rl 'VARTHEME_MATERIAL_SUBTHEME' ${theme_path}/${theme_name} | xargs sed -i "s/VARTHEME_MATERIAL_SUBTHEME/${theme_name}/g" ; + + # 13. Replace the name: 'Vartheme Material Sub-Theme (LESS)' to the name of your theme. + grep -rl 'Vartheme Material Sub-Theme (LESS)' ${theme_path}/${theme_name} | xargs sed -i "s/Vartheme Material Sub-Theme (LESS)/${theme_name}/g" ; + + + # 14. If we want to use the RTL (right to left) bootstrap. + # 15.1 Delete the template folder bootstrap. + rm -rf ${theme_path}/${theme_name}/bootstrap ; + + # 15.2 Download the bootstrap library. change the version as you need. + wget -P ${theme_path}/${theme_name} https://github.com/twbs/bootstrap/archive/v${bootstrap_library_version}.tar.gz -vvv + + # 15.3 Extract the bootstrap library. + mkdir ${theme_path}/${theme_name}/bootstrap + tar -xzvf ${theme_path}/${theme_name}/v${bootstrap_library_version}.tar.gz --strip-components=1 -C ${theme_path}/${theme_name}/bootstrap -vvv + + # 15.4 Delete the archived bootstrap library. + rm ${theme_path}/${theme_name}/v${bootstrap_library_version}.tar.gz + + # 16. If we want to use the RTL (right to left) bootstrap. + if [[ $direction == "rtl" || $direction == "RTL" ]]; then + # 16.1. Delete the template folder bootstrap-rtl. + rm -rf ${theme_path}/${theme_name}/bootstrap-rtl ; + + # 16.2. Download the bootstrap library. change the version as you need. + wget -P ${theme_path}/${theme_name} https://github.com/morteza/bootstrap-rtl/archive/v${bootstrap_rtl_library_version}.tar.gz -vvv + + # 16.3. Extract the bootstrap library. + mkdir ${theme_path}/${theme_name}/bootstrap-rtl + tar -xzvf ${theme_path}/${theme_name}/v${bootstrap_rtl_library_version}.tar.gz --strip-components=1 -C ${theme_path}/${theme_name}/bootstrap-rtl -vvv + + # 16.4. Delete the archived bootstrap library. + rm ${theme_path}/${theme_name}/v${bootstrap_rtl_library_version}.tar.gz + fi + + generated_datetime="$(date '+%Y/%m/%d - %H:%M:%S')"; + generated_log=" Generated by -- composer create-new-vartheme_material ${theme_name} ${direction} ${theme_path} -- on ${generated_datetime}"; + echo "${generated_log}" >> ${theme_path}/${theme_name}/README.md; + + echo "---------------------------------------------------------------------------"; + echo " The new Vartheme Material subtheme were created at \"${theme_path}/${theme_name} :)\" "; + echo "---------------------------------------------------------------------------"; + exit 0; + +else + echo "---------------------------------------------------------------------------"; + echo " The folder \"${theme_path}/${theme_name}\" is already in the site!"; + echo "---------------------------------------------------------------------------"; + exit 1; +fi diff --git a/themes/vartheme/VARTHEME_SUBTHEME/config/optional/block.block.VARTHEME_SUBTHEME_copyright.yml b/themes/vartheme/VARTHEME_SUBTHEME/config/optional/block.block.VARTHEME_SUBTHEME_copyright.yml new file mode 100644 index 00000000..d71d6552 --- /dev/null +++ b/themes/vartheme/VARTHEME_SUBTHEME/config/optional/block.block.VARTHEME_SUBTHEME_copyright.yml @@ -0,0 +1,28 @@ +langcode: en +status: true +dependencies: + content: + - 'block_content:basic:b858d97d-eaa5-4cfe-af6f-b92c21bbca95' + module: + - block_class + - block_content + theme: + - VARTHEME_SUBTHEME +third_party_settings: + block_class: + classes: '' +id: VARTHEME_SUBTHEME_copyright +theme: VARTHEME_SUBTHEME +region: footer +weight: -5 +provider: null +plugin: 'block_content:b858d97d-eaa5-4cfe-af6f-b92c21bbca95' +settings: + id: 'block_content:b858d97d-eaa5-4cfe-af6f-b92c21bbca95' + label: Copyright + provider: block_content + label_display: '0' + status: true + info: '' + view_mode: full +visibility: { } diff --git a/themes/vartheme/VARTHEME_SUBTHEME/config/optional/block.block.views_block__varbase_heroslider_media_varbase_heroslider_media.yml b/themes/vartheme/VARTHEME_SUBTHEME/config/optional/block.block.views_block__varbase_heroslider_media_varbase_heroslider_media.yml new file mode 100644 index 00000000..830c2044 --- /dev/null +++ b/themes/vartheme/VARTHEME_SUBTHEME/config/optional/block.block.views_block__varbase_heroslider_media_varbase_heroslider_media.yml @@ -0,0 +1,33 @@ +langcode: en +status: true +dependencies: + config: + - views.view.varbase_heroslider_media + module: + - block_class + - system + - views + theme: + - VARTHEME_SUBTHEME +third_party_settings: + block_class: + classes: '' +id: views_block__varbase_heroslider_media_varbase_heroslider_media +theme: VARTHEME_SUBTHEME +region: hero_slider +weight: 0 +provider: null +plugin: 'views_block:varbase_heroslider_media-varbase_heroslider_media' +settings: + id: 'views_block:varbase_heroslider_media-varbase_heroslider_media' + label: '' + provider: views + label_display: '0' + views_label: '' + items_per_page: none +visibility: + request_path: + id: request_path + pages: '<front>' + negate: false + context_mapping: { } diff --git a/modules/varbase_features/varbase_default_content/config/optional/block.block.copyright_material.yml b/themes/vartheme/config/optional/block.block.vartheme_copyright.yml similarity index 89% rename from modules/varbase_features/varbase_default_content/config/optional/block.block.copyright_material.yml rename to themes/vartheme/config/optional/block.block.vartheme_copyright.yml index 6279cea7..5bbb5f7d 100644 --- a/modules/varbase_features/varbase_default_content/config/optional/block.block.copyright_material.yml +++ b/themes/vartheme/config/optional/block.block.vartheme_copyright.yml @@ -7,12 +7,12 @@ dependencies: - block_class - block_content theme: - - vartheme_material + - vartheme third_party_settings: block_class: classes: '' -id: copyright -theme: vartheme_material +id: vartheme_copyright +theme: vartheme region: footer weight: -5 provider: null @@ -26,4 +26,3 @@ settings: info: '' view_mode: full visibility: { } - diff --git a/themes/vartheme/config/optional/block.block.views_block__varbase_heroslider_media_varbase_heroslider_media.yml b/themes/vartheme/config/optional/block.block.views_block__varbase_heroslider_media_varbase_heroslider_media.yml new file mode 100644 index 00000000..c335df80 --- /dev/null +++ b/themes/vartheme/config/optional/block.block.views_block__varbase_heroslider_media_varbase_heroslider_media.yml @@ -0,0 +1,33 @@ +langcode: en +status: true +dependencies: + config: + - views.view.varbase_heroslider_media + module: + - block_class + - system + - views + theme: + - vartheme +third_party_settings: + block_class: + classes: '' +id: views_block__varbase_heroslider_media_varbase_heroslider_media +theme: vartheme +region: hero_slider +weight: 0 +provider: null +plugin: 'views_block:varbase_heroslider_media-varbase_heroslider_media' +settings: + id: 'views_block:varbase_heroslider_media-varbase_heroslider_media' + label: '' + provider: views + label_display: '0' + views_label: '' + items_per_page: none +visibility: + request_path: + id: request_path + pages: '<front>' + negate: false + context_mapping: { } -- GitLab