Override an existing Blade directive - laravel

I'm building a system that implements an inherited template system using Blade. Depending on where the user is, a different view will be loaded.
The system works well, where I have a default 'theme', which contains all views and components for everything the website uses. I don't use the default view method in my controllers, I instead use my own function which works in the same way as view but instead attempts to load the view in the lowest part of the hierarchy and then works its way up until it lands on the default.
For example, my view structure looks like:
+-- views
| +-- frontend
| +-- default
| +-- home.blade.php
| +-- test.blade.php
| +-- site1
| +-- en-gb
| +-- home.blade.php
| +-- en-de
| +-- home.blade.php
| +-- site2
| +-- en-gb
| +-- home.blade.php
This works well. I can call custom_view('home'); and based on certain circumstances the correct view will be shown. In the above example if I call custom_view('test') my system will check the correct folder for the site and locale, and if the view doesn't exist then the default fallback will be used.
My problem comes when I want to use Laravel directives for loading view partials in my code. The three directives that are troublesome are:
#each(), #include() and #component().
I would like to override these directives and have them look up the file from the appropriate sub-directory in my view structure first.
How can I override Blade directives?

Related

Laravel nWidart/laravel-modules, move an existing module to another folder

I have a bunch of modules in Modules folder. For example "Modules/Customers"
And I need to move everything to "Modules/Core/Customers" keeping all the functionality working. Besides I must will use another subfolder for some modules:
Modules
|___ Core
| |__ Customers
| |__ Products
|
|___ External
|__ Taller
I suppose there might be three possibilities:
1- Lucky one: automatically with an artisan command, but I did not find anything on documentation (https://docs.laravelmodules.com/)
2- Manually changing files and configs, but I suppose that will leave namespaces unchanged, and that is not acceptable I would say.
3- Worst but likely: manually changing namespaces and config files.
I went for the third one as #lk77 suggested and everything was correct if I changed the folder for modules in config file module.php, except that then I cannot add several paths (or I don not find the way as it does not seem to be an array) or a more generic Modules/* as path.
'paths' => [
/*
|--------------------------------------------------------------------------
| Modules path
|--------------------------------------------------------------------------
|
| This path used for save the generated module. This path also will be added
| automatically to list of scanned folders.
|
*/
'modules' => base_path('Modules/Core'),
Thanks a lot!!
Thanks very much
Here is what I finally did. For the existing modules created previously in "Modules":
1- Move files to Modules/Core folder and change manually all references to "Modules/" for "Modules/Core" in folders "app", "bootstrap" and "Modules" (with help of replace all from sublime :-) ). Afterwards it was necessary to manually change references in files "composer.json" and "module.json" of each module.
2- In config/modules.php activate scan:
'scan' => [
'enabled' => true,
'paths' => [
base_path('Modules/Core'),
base_path('Modules/External'),
base_path('vendor/*/*'),
],
],
After doing this old modules seemed to be working properly, but trying to include new ones triggered errors.
In fact the versions that included the feature to add the possibility for managing submodules/subfolders were retired shortly after the release.
So, finally I guess it is better not to use this approach with the package due to the problems.
In the end we are going to use subfolders in Laravel default tree for the core modules and use the package laravel-modules for external and optional custom modules:
app
|
|--- Http
| |
| |--- Controllers
| . |
| . |--- Customers
| |--- Products
|
|--- Models
. |
. |--- Customers
. |--- Products
.
.
Modules
|--- Taller
.
.
.

How to specify Dapr component locations with Sidekick?

I'm trying to get started with Sidekick for Dapr, and am having trouble telling Sidekick where the dapr components are.
By default it's going to %USERPROFILE%.dapr\components, but I'd rather it go to a folder local to the solution.
Looking at the code it appears that adding the following to the appsettings.json should work, but it isn't picked up.
"DaprSidekick": {
"RuntimeDirectory": "dapr",
"ComponentsDirectory": "C:\\Dev\\DaprPOC\\components",
}
However the components folder invariably becomes %USERPROFILE%\.dapr\components
Any help on how I specify the component locations with Sidekick?
When you set "RuntimeDirectory": "dapr" Sidekick will automatically look for component files in the dapr/components subdirectory in your solution. Try removing the ComponentsDirectory entry so it returns to defaults, and try a directory structure like this:
|-- MyProject
| |-- MyProject.csproj
| |-- dapr
| | |-- config.yaml
| | |-- components
| | | |-- my_component.yaml
The Dapr Sidecar should then load my_component.yaml.
You can also manually add the components directory in the dependency injection:
services.AddDaprSidekick(configuration, p => p.Sidecar =
new DaprSidecarOptions() { AppId = "daprservice", ComponentsDirectory = "C:\\Dev\\DaprPOC\\components" });

Package Vue frontend in Go binary

I am trying to serve my frontend using the Gin framework. It is a small project which would make maintenance easier having it as a single binary.
The project structure looks like this:
Project
|
+-- backend
| |
| +-- backend (binary)
|
+-- frontend
| |
| +-- dist
| |
| +-- package.json
|
+-- Procfile
|
+-- .gitlab-ci.yml
Currently I am serving the fronend like this:
r.Use(static.Serve("/", static.LocalFile("../frontend/dist", false)))
For local dev this works fine and I did not have any issues. If I deploy this with my gitlab-ci pipeline it fails as I do not upload the ../frontend/dist directory. I looked at the pkgr library which should help me achieve my goal.
My issue is I can not get it to work with the Gin framework. Current snippet:
test := pkger.Dir("../frontend/dist")
r.Use(static.Serve("/", static.LocalFile("../frontend/dist", false))) <- compiles but does not serve frontend
r.Use(static.Serve("/", static.LocalFile(test, false))) <- Does not compile
Is there an easier way to achieve my goal?
The problem is when you deploy the project to Heroku (I supposed you are using Heroku because of the tag you are using) it compiles the Go to a binary.
The binary is running in the root folder of the project and ../frontend is not in the same path as the development enviroment anymore.
Something like this:
Project
|
+-- backend
| |
| +-- backend (binary)
|
+-- frontend
| |
| +-- dist
| |
| +-- package.json
|
+-- Procfile
|
+-- .gitlab-ci.yml
|
+-- project binary <---- here
So the correct path is ./frontend/ (see one dot)
You can set an environment variable to set the correct path.
As you are using Vue, you can set for the development environment a dev-server with a proxy pointing to backend. Then when building for production you can make Vue compiles to a specific folder that is hardcoded and served by the backend.

Cmake: add_subproject & add_subfolder

I currently want to add some self written classes ("mycode.cpp" and "mycode.hpp") to a big existing C++ project that is configured with Cmake. These classes are located in "myfolder" which is located in the "lib/pointrender" folder of the existing project (see dummy hierarchy below).
|- libs
| |- core
| | |- ...
| |- pointrender
| |- myfolder
| | |- mycode.cpp
| | |- mycode.hpp
| |- existingclasses.cpp
| |- existingclasses.hpp
| |- project.cmake
|- CMakeLists.txt
In the CMakesLists.txt the pointrender folder is declared as a subproject.
declare_subproject(libs/pointrender)
How do I best add my code to the existing cmake configuration? Do I add it as a subfolder in the project.cmake with a seperate CMakeLists.txt in myfolder? Or do I best add it as a subproject with a seperate project.cmake file? What's the difference?
This project.cmake is being include()d be some CMakeLists.txt and get's executed as part of it. Authors of project you are using rolled this out for some reason, so it's probably better to use their infrastructure to add custom code.
The usual way to do this is writing your own CMakeLists.txt and add_subdirectory()ing it from the upper level.
If you wish more details you should update your question with project.cmake contents.

Rails 3.1 asset pipeline vendor/assets folder organization

I'm using the jQuery Tools scrollable library in my Rails 3.1 site with the various assets placed in the vendor/assets folder and it works great.
My question is regarding the best way to organize the various files under vendor/assets. What is the recommended way to organize vendor/assets subfolders? Currently I have this structure:
vendor/assets/
|-- images/
| |-- scrollable/
| <various button/gradient images>
|-- javascripts/
| |-- scrollable/
| jquery.tools.min.js
|-- stylesheets/
| |-- scrollable/
| scrollable-buttons.css
| scrollable-horizontal.css
This is a fairly un-DRY what to do this. I feel that all of the 'scrollable' items should be under one folder.
What is the recommended way to do this without having to manipulate the asset pipeline load paths?
Thanks!
You could organise them this way, which is slightly better in that it keeps stuff related to the plugin in one directory:
vendor/assets/scrollable
|-- images/
| |-- <various button/gradient images>
|-- javascripts/
| |-- jquery.tools.min.js
|-- stylesheets/
| |-- scrollable-buttons.css
| scrollable-horizontal.css
I am pretty sure this will work as rails globs all directories under assets/.

Resources