snowsoft / nlktheme
Installs: 97
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/snowsoft/nlktheme
Requires
- php: >=8.3
 - laravel/framework: >=9.0
 - matthiasmullie/minify: *
 - nesbot/carbon: *
 
README
Laravel için kapsamlı bir tema yönetim paketi. Birden fazla tema desteği, component sistemı, cache yönetimi ve daha fazlası.
Özellikler
- ✅ Çoklu tema desteği
 - ✅ Default theme fallback sistemi
 - ✅ Component ve partial sistemi
 - ✅ Section ve Stack yönetimi
 - ✅ Asset yönetimi
 - ✅ Cache yönetimi
 - ✅ Widget sistemi
 - ✅ Event sistemi
 - ✅ Helper fonksiyonları
 - ✅ Güvenlik özellikleri (XSS koruması, CSP, güvenlik header'ları)
 - ✅ Livewire desteği
 - ✅ React + SSR desteği (Vite entegrasyonu)
 - ✅ Inertia.js desteği
 
Kurulum
composer require snowsoft/nlktheme
Temel Kullanım
View Render
// Controller'da use Theme; public function index() { return Theme::view('home'); } // Veya helper ile return theme()->view('home');
Theme Ayarlama
// Belirli tema kullan Theme::uses('tema2')->layout('main')->view('home'); // Helper ile theme('tema2', 'main')->view('home');
Default Theme Fallback
Bir dosya mevcut temada bulunamazsa, otomatik olarak default temadan yüklenir.
Config Ayarları
config/theme.php:
'defaultTheme' => 'default', 'useDefaultThemeFallback' => true, // ✅ true yapın
Örnek Kullanım
// tema2 temasında header.blade.php yoksa // otomatik olarak default temasından yükler Theme::partial('header'); // tema2/views/home.blade.php yoksa // default/views/home.blade.php arar Theme::scope('home');
Partial ve Component
Partial
// Partial render Theme::partial('header', ['title' => 'Welcome']); // Watch partial (önce temada, sonra app'te ara) Theme::watchPartial('footer'); // Helper {!! theme_partial('header') !!}
Component
// Component kaydet theme()->component('card', 'components.card'); // Component render theme()->renderComponent('card', ['title' => 'Card Title', 'body' => 'Content']); // Helper {!! theme_component('card', ['title' => 'Test']) !!}
Blade'de Kullanım
@partial('header') {!! theme_component('card', ['title' => 'Hello']) !!}
Section Sistemi
// Section başlat theme()->startSection('sidebar'); echo "Sidebar content"; theme()->stopSection('sidebar'); // Section içeriğini al $sidebar = theme()->getSection('sidebar'); // Section var mı kontrol et if (theme()->hasSection('sidebar')) { echo theme_section('sidebar'); }
Blade Helper
{!! theme_section('sidebar', 'Default content') !!} @if(has_theme_section('sidebar')) {!! theme_section('sidebar') !!} @endif
Stack Sistemi
Birden fazla yerde içerik toplamak için:
// Stack başlat theme()->startStack('scripts'); echo '<script src="plugin1.js"></script>'; theme()->pushStack('scripts'); // Başka yerde theme()->startStack('scripts'); echo '<script src="plugin2.js"></script>'; theme()->pushStack('scripts'); // Tüm scriptleri al echo theme()->getStack('scripts');
Blade Helper
{!! theme_stack('scripts') !!}
Asset Yönetimi
Helper Fonksiyonları
// Asset URL theme_asset('css/style.css'); // Output: /themes/default/assets/css/style.css // CSS tag theme_css('css/style.css'); // Output: <link rel='stylesheet' type='text/css' href='...' media='all'> // JS tag theme_js('js/app.js'); // Output: <script type='text/javascript' src='...'></script> // Image tag theme_image('images/logo.png', 'Logo', ['class' => 'logo']);
Blade'de Kullanım
<!DOCTYPE html> <html> <head> {!! theme_css('style.css') !!} </head> <body> <img src="{{ theme_asset('images/logo.png') }}"> {!! theme_js('app.js') !!} </body> </html>
Theme Data
Global tema verilerini yönetme:
// Veri set et theme()->setData('user', $user); theme()->setMultipleData(['key1' => 'val1', 'key2' => 'val2']); // Veri al $user = theme()->getData('user'); $allData = theme()->getAllData(); // Helper theme_set('key', 'value'); $value = theme_get('key', 'default');
Cache Yönetimi
// Tüm cache'i temizle theme()->clearCache(); // Belirli temanın cache'ini temizle theme()->clearThemeCache('tema2'); // Temayı yeniden yükle theme()->reload(); // Helper theme_cache_clear(); theme_cache_clear('tema2');
View Kontrolü
// View var mı kontrol et if (theme()->viewExists('home')) { return theme()->view('home'); } // Theme'deki tüm view'ları listele $views = theme()->getThemeViews(); // Helper if (has_theme_view('partial.header')) { {!! theme_partial('partial.header') !!} } // Varsa render et render_if_exists('partial.header', [], 'Default content');
Helper Fonksiyonlar
Metin İşlemleri
// Metin kısaltma theme_truncate('Long text here...', 50); // Output: "Long text here..." // Time ago time_ago('2024-01-01 12:00:00'); // Output: "2 hours ago" // Number format number_format_short(1000); // Output: "1K" number_format_short(1500000); // Output: "1.5M"
Navigation Helper
// Active class active_class('home', 'active'); // Returns: 'active' if current route is 'home' // Blade'de <li class="{{ active_class('home') }}">Home</li>
Widget Sistemi
// Widget render Theme::widget('Menu', ['items' => $menuItems]); // Blade'de @widget('Menu', ['items' => $items])
Region (Alan) Yönetimi
// Region set et theme()->set('meta', '<meta name="keywords" content="...">'); // Region append theme()->append('scripts', '<script>...</script>'); // Region prepend theme()->prepend('styles', '<link>...</link>'); // Region al $meta = theme()->get('meta', 'default'); // Region var mı kontrol et if (theme()->has('meta')) { echo theme()->get('meta'); } // Blade'de @get('meta') @getIfHas('meta')
Event Sistemi
Theme Event'leri
// Theme yükleme öncesi Theme::fire('before', $theme); Theme::fire('asset', $asset); Theme::fire('beforeRenderTheme', $theme); Theme::fire('beforeRenderLayout.main', $theme); Theme::fire('after', $theme);
Config'de Event Tanımlama
themes/tema2/config.php:
return [ 'events' => [ 'before' => function($theme) { $theme->set('title', 'My Site'); }, 'beforeRenderLayout.main' => function($theme) { $theme->set('description', 'Main layout'); }, ], ];
Event Usage Example
// ThemeServiceProvider.php public function boot() { Theme::composer('*', function($view) { $view->with('currentUser', auth()->user()); }); }
Advanced Features
Compile and Cache
$content = theme()->compileAndCache( 'Welcome {{ $name }}', ['name' => 'John'], 'welcome_cache', 3600 // TTL );
String Compilation
$html = theme()->blader('Hello {{ $name }}', ['name' => 'World']);
Get Compiled Path
$compiledPath = theme()->getCompiledPath('theme.tema2.views.home');
Tema Yapısı
themes/
├── default/
│   ├── assets/
│   │   ├── css/
│   │   ├── js/
│   │   └── images/
│   ├── views/
│   │   └── *.blade.php
│   ├── layouts/
│   │   ├── main.blade.php
│   │   └── layout.blade.php
│   ├── partials/
│   │   ├── header.blade.php
│   │   └── footer.blade.php
│   ├── components/
│   │   └── card.blade.php
│   ├── config.php
│   └── theme.json
│
└── tema2/
    ├── assets/
    ├── views/
    ├── layouts/
    └── ...
Config Dosyası
config/theme.php:
return [ 'assetUrl' => '/', 'defaultTheme' => 'default', 'useDefaultThemeFallback' => true, // Default theme fallback 'version' => '1.0.0', 'themeDefault' => 'default', 'layoutDefault' => 'layout', 'themeDir' => 'themes', 'themeURL' => 'themes', 'templateCacheEnabled' => true, 'autoReload' => false, 'defaultEngine' => 'blade', 'minify' => false, 'namespaces' => [ 'widget' => 'App\Widgets' ], 'events' => [ // Global events ], ];
Middleware Kullanımı
// Route'da Route::get('/home', [HomeController::class, 'index']) ->middleware('theme:tema2,main'); // Controller'da public function index() { return theme()->view('home'); }
Helper Listesi
theme($theme, $layout)- Theme instance altheme_asset($path)- Asset URLtheme_css($path, $media)- CSS tagtheme_js($path, $defer)- JS tagtheme_image($path, $alt, $attrs)- Image tagtheme_partial($view, $args)- Partial rendertheme_component($name, $data)- Component rendertheme_section($section, $default)- Section gettheme_stack($name)- Stack getactive_class($path, $active)- Active classtheme_truncate($text, $limit)- Truncatetime_ago($datetime)- Time agonumber_format_short($number)- Short numbertheme_cache_clear($theme)- Clear cachehas_theme_view($view)- Check view existshas_theme_section($section)- Check sectionrender_if_exists($view, $args, $default)- Render if existstheme_set($key, $value)- Set theme datatheme_get($key, $default)- Get theme datatheme_schema($schema)- Generate JSON-LD schematheme_product_schema($data)- Generate Product schematheme_organization_schema($data)- Generate Organization schematheme_breadcrumb_schema($items)- Generate BreadcrumbList schematheme_article_schema($data)- Generate Article schematheme_video_schema($data)- Generate Video schema
Artisan Komutları
Paket, tema yönetimi için çeşitli Artisan komutları sunar:
# Tema oluştur php artisan theme:create mytheme # Temaları listele php artisan theme:list # Temayı kopyala php artisan theme:duplicate default newtheme # Temayı sil php artisan theme:destroy oldtheme # Widget oluştur php artisan theme:widget ProductSlider
Detaylı kullanım için Artisan Komutları Dokümantasyonu dosyasına bakın.
Gelişmiş Özellikler
Paket artık modern frontend framework'leri ve gelişmiş güvenlik özellikleri ile birlikte geliyor:
Güvenlik
- XSS koruması ve HTML sanitization
 - Content Security Policy (CSP) desteği
 - Güvenlik header'ları (X-Frame-Options, X-XSS-Protection, vb.)
 - View path validation
 
Modern Frontend Desteği
- Livewire: Server-side reactive component'ler
 - React + SSR: Vite entegrasyonu ve server-side rendering
 - Inertia.js: SPA deneyimi için tam destek
 
Detaylı dokümantasyon için:
- Hızlı Başlangıç
 - Gelişmiş Özellikler
 - Artisan Komutları
 - Page Builder
 - SEO & Rich Snippets
 - Sorun Giderme
 - Gelecekteki Özellikler
 
License
Support
Sorunlarınız için issue açabilirsiniz.