diff --git a/build.js b/build.js index eafbb91..17007ec 100755 --- a/build.js +++ b/build.js @@ -20,7 +20,7 @@ class buildGenerator extends Generator { type: "list", name: "platform", message: "Choose Platform", - choices: ['WordPress', 'Hubspot', 'Hubspot Email', 'JavaScript', 'PHP'], + choices: ['WordPress', 'WordPress Block', 'Hubspot', 'Hubspot Email', 'JavaScript', 'PHP'], default: 'WordPress' } ]) @@ -46,6 +46,10 @@ class buildGenerator extends Generator { if (this.data.platform === 'WordPress') { return buildWordPress(); } + + if (this.data.platform === 'WordPress Block') { + return buildWordPress(true); + } }); } else if (this.data.platform === 'Hubspot Email') { diff --git a/platforms/wordpress/templates/Template_Basic_Component.php b/platforms/wordpress/templates/Template_Basic_Component.php new file mode 100644 index 0000000..3a381c3 --- /dev/null +++ b/platforms/wordpress/templates/Template_Basic_Component.php @@ -0,0 +1,31 @@ +_Component { + + public function __construct() { + add_action( 'wp_enqueue_scripts', [ $this, 'register_assets' ] ); + } + + function register_assets(): void { + wp_enqueue_style( '<%= blockFilename %>', + get_template_directory_uri() . '/components/partials/<%= blockFilename %>/templates/styles/<%= blockFilename %>.min.css', + [ 'style-wp' ], + Global_Functions::get_current_version_number() + ); + + wp_enqueue_script( '<%= blockFilename %>', + get_template_directory_uri() . '/components/partials/<%= blockFilename %>/templates/scripts/<%= blockFilename %>.min.js', + [ 'jquery', 'swiper' ], + Global_Functions::get_current_version_number(), + true + ); + } + + public function render( $args = [] ): void { + $output = ( include( __DIR__ . '/templates/<%= blockFilename %>.template.php' ) )( array_merge( [], $args ), self::class ); + echo apply_filters( 'the_content', wpautop( $output ) ); + } + +} diff --git a/platforms/wordpress/wordpress-adapter.js b/platforms/wordpress/wordpress-adapter.js index bcbcb45..4da2718 100644 --- a/platforms/wordpress/wordpress-adapter.js +++ b/platforms/wordpress/wordpress-adapter.js @@ -6,9 +6,9 @@ import {fileURLToPath} from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); -const {projectPath, modulesPath} = getConfigs(); +const {projectPath} = getConfigs(); -export async function buildWordPress(blockName) { +export async function buildWordPress(isBlock = false) { const distPath = path.join(projectPath, 'exports', 'wordpress'); await mkdir(distPath, {recursive: true}) @@ -37,27 +37,37 @@ export async function buildWordPress(blockName) { include_elementor_widget: false, }); - await createFiles(data, [{ - from: `templates/Template_Component.php`, - to: `${data.blockClassModel}_Component.php`, - }], { - pathDist: distPath, - generatorsPath: path.join(__dirname) - }); + if (isBlock) { + await createFiles(data, [{ + from: `templates/Template_Component.php`, + to: `${data.blockClassModel}_Component.php`, + }], { + pathDist: distPath, + generatorsPath: path.join(__dirname) + }); - await createFiles(data, [{ - from: `templates/helpers/Template_API.php`, - to: `helpers/${data.blockClassModel}_API.php`, - }], { - pathDist: distPath, - generatorsPath: path.join(__dirname) - }); + await createFiles(data, [{ + from: `templates/helpers/Template_API.php`, + to: `helpers/${data.blockClassModel}_API.php`, + }], { + pathDist: distPath, + generatorsPath: path.join(__dirname) + }); - await createFiles(data, [{ - from: `templates/helpers/Template_Defaults.php`, - to: `helpers/${data.blockClassModel}_Defaults.php`, - }], { - pathDist: distPath, - generatorsPath: path.join(__dirname) - }); + await createFiles(data, [{ + from: `templates/helpers/Template_Defaults.php`, + to: `helpers/${data.blockClassModel}_Defaults.php`, + }], { + pathDist: distPath, + generatorsPath: path.join(__dirname) + }); + } else { + await createFiles(data, [{ + from: `templates/Template_Basic_Component.php`, + to: `${data.blockClassModel}_Component.php`, + }], { + pathDist: distPath, + generatorsPath: path.join(__dirname) + }); + } }