Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
8a6af1c6
Commit
8a6af1c6
authored
Nov 28, 2014
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Plain Diff
Merge commit '
c161ee51
'
* commit '
c161ee51
': Squashed 'Modules/Core/' changes from 37d3173..9450e60
parents
5a00f306
c161ee51
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
501 additions
and
17 deletions
+501
-17
ThemeComposer.php
Modules/Core/Composers/ThemeComposer.php
+22
-0
config.php
Modules/Core/Config/config.php
+0
-10
PublishThemeAssetsCommand.php
Modules/Core/Console/PublishThemeAssetsCommand.php
+25
-1
AssetPublisher.php
Modules/Core/Foundation/Theme/AssetPublisher.php
+83
-0
Theme.php
Modules/Core/Foundation/Theme/Theme.php
+46
-0
ThemeManager.php
Modules/Core/Foundation/Theme/ThemeManager.php
+96
-0
CoreServiceProvider.php
Modules/Core/Providers/CoreServiceProvider.php
+12
-2
select-theme.blade.php
Modules/Core/Resources/views/fields/select-theme.blade.php
+3
-3
BaseTestCase.php
Modules/Core/Tests/BaseTestCase.php
+7
-0
PermissionManagerTest.php
Modules/Core/Tests/Permissions/PermissionManagerTest.php
+1
-1
AssetPublisherTest.php
Modules/Core/Tests/Theme/AssetPublisherTest.php
+80
-0
.gitkeep
Modules/Core/Tests/Theme/Fixture/Themes/demo/.gitkeep
+0
-0
.gitkeep
Modules/Core/Tests/Theme/Fixture/Themes/testassets/.gitkeep
+0
-0
main.css
...Tests/Theme/Fixture/Themes/testassets/assets/css/main.css
+3
-0
main.js
...e/Tests/Theme/Fixture/Themes/testassets/assets/js/main.js
+3
-0
ThemeManagerTest.php
Modules/Core/Tests/Theme/ThemeManagerTest.php
+77
-0
ThemeTest.php
Modules/Core/Tests/Theme/ThemeTest.php
+42
-0
composers.php
Modules/Core/composers.php
+1
-0
No files found.
Modules/Core/Composers/ThemeComposer.php
0 → 100644
View file @
8a6af1c6
<?php
namespace
Modules\Core\Composers
;
use
Illuminate\Contracts\View\View
;
use
Modules\Core\Foundation\Theme\ThemeManager
;
class
ThemeComposer
{
/**
* @var ThemeManager
*/
private
$themeManager
;
public
function
__construct
()
{
$this
->
themeManager
=
app
(
'asgard.themes'
);
}
public
function
compose
(
View
$view
)
{
$view
->
with
(
'themes'
,
$this
->
themeManager
->
all
());
}
}
Modules/Core/Config/config.php
View file @
8a6af1c6
...
...
@@ -12,14 +12,4 @@ return [
'User'
,
'Workshop'
],
/*
|--------------------------------------------------------------------------
| Specify all the front-end themes
| These will be available as a core setting
|--------------------------------------------------------------------------
*/
'front-themes'
=>
[
'demo'
,
'default'
]
];
Modules/Core/Console/PublishThemeAssetsCommand.php
View file @
8a6af1c6
<?php
namespace
Modules\Core\Console
;
use
Illuminate\Console\Command
;
use
Modules\Core\Foundation\Theme\AssetPublisher
;
use
Modules\Core\Foundation\Theme\ThemeManager
;
use
Symfony\Component\Console\Input\InputArgument
;
class
PublishThemeAssetsCommand
extends
Command
{
protected
$name
=
'asgard:publish:theme'
;
protected
$description
=
'Publish theme assets'
;
/**
* @var \Modules\Core\Foundation\Theme\ThemeManager
*/
private
$themeManager
;
public
function
__construct
(
ThemeManager
$themeManager
)
{
parent
::
__construct
();
$this
->
themeManager
=
$themeManager
;
}
public
function
fire
()
{
$this
->
info
(
'Publishing assets for '
.
$this
->
argument
(
'theme'
));
$theme
=
$this
->
argument
(
'theme'
)
?:
''
;
if
(
$theme
)
{
$this
->
comment
(
"Publishing assets for [
$theme
] theme"
);
}
else
{
$this
->
comment
(
'Publishing assets for all themes'
);
}
with
(
new
AssetPublisher
(
$this
->
themeManager
->
find
(
$theme
)))
->
setFinder
(
$this
->
laravel
[
'files'
])
->
setRepository
(
$this
->
themeManager
)
->
publish
();
$this
->
info
(
"Assets published for [
$theme
] theme"
);
}
protected
function
getArguments
()
...
...
Modules/Core/Foundation/Theme/AssetPublisher.php
0 → 100644
View file @
8a6af1c6
<?php
namespace
Modules\Core\Foundation\Theme
;
class
AssetPublisher
{
/**
* @var \Illuminate\Filesystem\Filesystem
*/
protected
$finder
;
/**
* @var ThemeManager
*/
protected
$repository
;
/**
* @var Theme
*/
private
$theme
;
/**
* @param Theme $theme
*/
public
function
__construct
(
Theme
$theme
)
{
$this
->
theme
=
$theme
;
}
/**
* @param $finder
* @return $this
*/
public
function
setFinder
(
$finder
)
{
$this
->
finder
=
$finder
;
return
$this
;
}
/**
* @param $repository
* @return $this
*/
public
function
setRepository
(
$repository
)
{
$this
->
repository
=
$repository
;
return
$this
;
}
/**
* Publish the assets
*/
public
function
publish
()
{
if
(
!
$this
->
finder
->
isDirectory
(
$sourcePath
=
$this
->
getSourcePath
()))
{
$message
=
"Source path does not exist :
{
$sourcePath
}
"
;
throw
new
\InvalidArgumentException
(
$message
);
}
if
(
!
$this
->
finder
->
isDirectory
(
$destinationPath
=
$this
->
getDestinationPath
()))
{
$this
->
finder
->
makeDirectory
(
$destinationPath
,
0775
,
true
);
}
if
(
$this
->
finder
->
copyDirectory
(
$sourcePath
,
$destinationPath
))
{
return
true
;
}
}
/**
* Get the original source path
* @return string
*/
public
function
getSourcePath
()
{
return
$this
->
theme
->
getPath
()
.
'/assets'
;
}
/**
* Get the destination path
* @return string
*/
public
function
getDestinationPath
()
{
return
$this
->
repository
->
getAssetPath
(
$this
->
theme
->
getLowerName
());
}
}
Modules/Core/Foundation/Theme/Theme.php
0 → 100644
View file @
8a6af1c6
<?php
namespace
Modules\Core\Foundation\Theme
;
class
Theme
{
/**
* @var string the theme name
*/
private
$name
;
/**
* @var string the theme path
*/
private
$path
;
public
function
__construct
(
$name
,
$path
)
{
$this
->
name
=
$name
;
$this
->
path
=
realpath
(
$path
);
}
/**
* @return string
*/
public
function
getName
()
{
return
ucfirst
(
$this
->
name
);
}
/**
* @return string
*/
public
function
getPath
()
{
return
$this
->
path
;
}
/**
* Get name in lower case.
*
* @return string
*/
public
function
getLowerName
()
{
return
strtolower
(
$this
->
name
);
}
}
Modules/Core/Foundation/Theme/ThemeManager.php
0 → 100644
View file @
8a6af1c6
<?php
namespace
Modules\Core\Foundation\Theme
;
use
Illuminate\Contracts\Foundation\Application
;
use
Illuminate\Support\Str
;
class
ThemeManager
implements
\Countable
{
/**
* @var Application
*/
private
$app
;
/**
* @var string Path to scan for themes
*/
private
$path
;
/**
* @param Application $app
* @param $path
*/
public
function
__construct
(
Application
$app
,
$path
)
{
$this
->
app
=
$app
;
$this
->
path
=
$path
;
}
/**
* @param string $name
* @return Theme|null
*/
public
function
find
(
$name
)
{
foreach
(
$this
->
all
()
as
$theme
)
{
if
(
$theme
->
getLowerName
()
==
strtolower
(
$name
))
{
return
$theme
;
}
}
return
null
;
}
/**
* Return all available themes
* @return array
*/
public
function
all
()
{
$themes
=
[];
if
(
!
$this
->
getFinder
()
->
isDirectory
(
$this
->
path
))
{
return
$themes
;
}
$directories
=
$this
->
getFinder
()
->
directories
(
$this
->
path
);
foreach
(
$directories
as
$theme
)
{
if
(
!
Str
::
startsWith
(
$name
=
basename
(
$theme
),
'.'
))
{
$themes
[
$name
]
=
new
Theme
(
$name
,
$theme
);
}
}
return
$themes
;
}
/**
* Return the theme assets path
* @param string $theme
* @return string
*/
public
function
getAssetPath
(
$theme
)
{
return
public_path
(
$this
->
getConfig
()
->
get
(
'themify::themes_assets_path'
)
.
'/'
.
$theme
);
}
/**
* @return \Illuminate\Filesystem\Filesystem
*/
protected
function
getFinder
()
{
return
$this
->
app
[
'files'
];
}
/**
* @return \Illuminate\Config\Repository
*/
protected
function
getConfig
()
{
return
$this
->
app
[
'config'
];
}
/**
* Counts all themes
*/
public
function
count
()
{
return
count
(
$this
->
all
());
}
}
Modules/Core/Providers/CoreServiceProvider.php
View file @
8a6af1c6
...
...
@@ -5,6 +5,7 @@ use Illuminate\Routing\Router;
use
Illuminate\Support\ServiceProvider
;
use
Modules\Core\Console\InstallCommand
;
use
Modules\Core\Console\PublishThemeAssetsCommand
;
use
Modules\Core\Foundation\Theme\ThemeManager
;
use
Modules\Core\Services\Composer
;
use
Modules\Menu\Entities\Menuitem
;
use
Modules\Menu\Repositories\Eloquent\EloquentMenuItemRepository
;
...
...
@@ -45,6 +46,7 @@ class CoreServiceProvider extends ServiceProvider
$this
->
registerMenuRoutes
();
$this
->
registerFilters
(
$this
->
app
[
'router'
]);
$this
->
registerCommands
();
$this
->
registerServices
();
}
/**
...
...
@@ -104,8 +106,8 @@ class CoreServiceProvider extends ServiceProvider
private
function
registerThemeCommand
()
{
$this
->
app
->
bindShared
(
'command.asgard.publish.theme'
,
function
()
{
return
new
PublishThemeAssetsCommand
;
$this
->
app
->
bindShared
(
'command.asgard.publish.theme'
,
function
(
$app
)
{
return
new
PublishThemeAssetsCommand
(
new
ThemeManager
(
$app
,
$app
[
'config'
]
->
get
(
'themify::themes_path'
)))
;
});
}
...
...
@@ -121,4 +123,12 @@ class CoreServiceProvider extends ServiceProvider
return
$app
->
make
(
'Modules\Menu\Repositories\MenuItemRepository'
)
->
getForRoutes
();
});
}
private
function
registerServices
()
{
$this
->
app
->
bindShared
(
'asgard.themes'
,
function
(
$app
)
{
$path
=
$app
[
'config'
]
->
get
(
'themify::themes_path'
);
return
new
ThemeManager
(
$app
,
$path
);
});
}
}
Modules/Core/Resources/views/fields/select-theme.blade.php
View file @
8a6af1c6
<div
class=
"form-group"
>
<label
for=
"{{ $settingName }}"
>
{{ $moduleInfo['description'] }}
</label>
<select
class=
"form-control"
name=
"{{ $settingName }}"
id=
"{{ $settingName }}"
>
<?php
foreach
(
Config
::
get
(
'core::config.front-themes'
)
as
$theme
)
:
?>
<option
value=
"{{ $
theme }}"
{{
isset
($
dbSettings
[$
settingName
])
&&
$
dbSettings
[$
settingName
]
-
>
plainValue == $the
me ? 'selected' : '' }}>
{{
ucfirst($theme
) }}
<?php
foreach
(
$themes
as
$name
=>
$theme
)
:
?>
<option
value=
"{{ $
name }}"
{{
isset
($
dbSettings
[$
settingName
])
&&
$
dbSettings
[$
settingName
]
-
>
plainValue == $na
me ? 'selected' : '' }}>
{{
$theme->getName(
) }}
</option>
<?php
endforeach
;
?>
</select>
...
...
Modules/Core/Tests/BaseTestCase.php
View file @
8a6af1c6
...
...
@@ -4,6 +4,13 @@ use TestCase;
abstract
class
BaseTestCase
extends
TestCase
{
protected
$app
;
public
function
setUp
()
{
parent
::
setUp
();
}
protected
function
checkResponseIsOkAndContains
(
$request
,
$filter
)
{
$crawler
=
$this
->
client
->
request
(
$request
[
0
],
$request
[
1
]);
...
...
Modules/Core/Tests/PermissionManagerTest.php
→
Modules/Core/Tests/Permission
s/Permission
ManagerTest.php
View file @
8a6af1c6
<?php
namespace
Modules\Core\Tests
;
<?php
namespace
Modules\Core\Tests
\Permissions
;
use
Mockery
;
use
Modules\Core\Permissions\PermissionManager
;
...
...
Modules/Core/Tests/Theme/AssetPublisherTest.php
0 → 100644
View file @
8a6af1c6
<?php
namespace
Modules\Core\Tests\Theme
;
use
Modules\Core\Foundation\Theme\AssetPublisher
;
use
Modules\Core\Foundation\Theme\Theme
;
use
Modules\Core\Foundation\Theme\ThemeManager
;
use
Modules\Core\Tests\BaseTestCase
;
class
AssetPublisherTest
extends
BaseTestCase
{
/**
* @var \Modules\Core\Foundation\Theme\AssetPublisher
*/
protected
$publisher
;
/**
* @var \Modules\Core\Foundation\Theme\Theme
*/
protected
$theme
;
/**
* @var \Illuminate\Filesystem\Filesystem
*/
protected
$finder
;
public
function
setUp
()
{
parent
::
setUp
();
$this
->
finder
=
$this
->
app
[
'files'
];
$this
->
theme
=
new
Theme
(
'testAssets'
,
$this
->
getThemePath
());
$this
->
publisher
=
with
(
new
AssetPublisher
(
$this
->
theme
))
->
setFinder
(
$this
->
finder
)
->
setRepository
(
new
ThemeManager
(
$this
->
app
,
$this
->
getPath
()));
}
/** @test */
public
function
it_gets_the_source_path
()
{
$this
->
assertEquals
(
$this
->
getThemePath
()
.
'/assets'
,
$this
->
publisher
->
getSourcePath
());
}
/** @test */
public
function
it_gets_the_destination_path
()
{
$expectedPath
=
$this
->
getAssetsThemePath
();
$this
->
assertEquals
(
$expectedPath
,
$this
->
publisher
->
getDestinationPath
());
}
/** @test */
public
function
it_publishes_the_assets
()
{
$this
->
publisher
->
publish
();
$this
->
assertTrue
(
$this
->
finder
->
isDirectory
(
$this
->
getAssetsThemePath
()));
$this
->
assertTrue
(
$this
->
finder
->
isDirectory
(
$this
->
getAssetsThemePath
()
.
'/css'
));
$this
->
assertTrue
(
$this
->
finder
->
isDirectory
(
$this
->
getAssetsThemePath
()
.
'/js'
));
$this
->
assertTrue
(
$this
->
finder
->
isFile
(
$this
->
getAssetsThemePath
()
.
'/css/main.css'
));
$this
->
assertTrue
(
$this
->
finder
->
isFile
(
$this
->
getAssetsThemePath
()
.
'/js/main.js'
));
}
private
function
getThemePath
()
{
return
__DIR__
.
'/Fixture/Themes/testAssets'
;
}
private
function
getAssetsThemePath
()
{
return
public_path
(
$this
->
app
[
'config'
]
->
get
(
'themify::themes_assets_path'
)
.
'/'
.
'testassets'
);
}
private
function
getPath
()
{
return
__DIR__
.
'/Fixture/Themes'
;
}
public
function
tearDown
()
{
$this
->
finder
->
deleteDirectory
(
$this
->
getAssetsThemePath
());
}
}
Modules/Core/Tests/Theme/Fixture/Themes/demo/.gitkeep
0 → 100644
View file @
8a6af1c6
Modules/Core/Tests/Theme/Fixture/Themes/testassets/.gitkeep
0 → 100644
View file @
8a6af1c6
Modules/Core/Tests/Theme/Fixture/Themes/testassets/assets/css/main.css
0 → 100644
View file @
8a6af1c6
body
{
background
:
#ff0000
;
}
Modules/Core/Tests/Theme/Fixture/Themes/testassets/assets/js/main.js
0 → 100644
View file @
8a6af1c6
$
(
document
).
ready
(
function
()
{
});
Modules/Core/Tests/Theme/ThemeManagerTest.php
0 → 100644
View file @
8a6af1c6
<?php
namespace
Modules\Core\Tests\Theme
;
use
Modules\Core\Foundation\Theme\ThemeManager
;
use
Modules\Core\Tests\BaseTestCase
;
class
ThemeManagerTest
extends
BaseTestCase
{
/**
* @var \Modules\Core\Foundation\Theme\ThemeManager
*/
protected
$repository
;
/**
*
*/
public
function
setUp
()
{
parent
::
setUp
();
$this
->
repository
=
new
ThemeManager
(
$this
->
app
,
$this
->
getPath
());
}
/** @test */
public
function
it_should_return_all_themes
()
{
$this
->
assertTrue
(
is_array
(
$this
->
repository
->
all
()));
$this
->
assertEquals
(
$this
->
repository
->
count
(),
2
);
}
/** @test */
public
function
it_should_return_a_theme
()
{
$theme
=
$this
->
repository
->
find
(
'demo'
);
$this
->
assertInstanceOf
(
'Modules\Core\Foundation\Theme\Theme'
,
$theme
);
$this
->
assertEquals
(
'demo'
,
$theme
->
getLowerName
());
}
/** @test */
public
function
it_should_return_null_if_not_theme_found
()
{
$theme
=
$this
->
repository
->
find
(
'fakeTheme'
);
$this
->
assertNull
(
$theme
);
}
/** @test */
public
function
it_should_return_empty_array_if_no_themes
()
{
$repository
=
new
ThemeManager
(
$this
->
app
,
$this
->
getEmptyThemesPath
());
$this
->
assertEquals
([],
$repository
->
all
());
}
/** @test */
public
function
it_should_return_empty_array_if_no_folder
()
{
$repository
=
new
ThemeManager
(
$this
->
app
,
$this
->
getFakePath
());
$this
->
assertEquals
([],
$repository
->
all
());
}
private
function
getPath
()
{
return
__DIR__
.
'/Fixture/Themes'
;
}
private
function
getEmptyThemesPath
()
{
return
__DIR__
.
'/Fixture/EmptyThemes'
;
}
private
function
getFakePath
()
{
return
__DIR__
.
'/Fixture/fakeFolder'
;
}
}
Modules/Core/Tests/Theme/ThemeTest.php
0 → 100644
View file @
8a6af1c6
<?php
namespace
Modules\Core\Tests\Theme
;
use
Modules\Core\Foundation\Theme\Theme
;
use
Modules\Core\Tests\BaseTestCase
;
class
ThemeTest
extends
BaseTestCase
{
/**
* @var \Modules\Core\Foundation\Theme\Theme
*/
protected
$theme
;
public
function
setUp
()
{
parent
::
setUp
();
$this
->
theme
=
new
Theme
(
'demo'
,
$this
->
getPath
());
}
/** @test */
public
function
it_should_return_name
()
{
$this
->
assertEquals
(
'Demo'
,
$this
->
theme
->
getName
());
}
/** @test */
public
function
it_should_return_name_in_lowercase
()
{
$this
->
assertEquals
(
'demo'
,
$this
->
theme
->
getLowerName
());
}
/** @test */
public
function
it_should_return_correct_path
()
{
$this
->
assertEquals
(
$this
->
getPath
(),
$this
->
theme
->
getPath
());
}
private
function
getPath
()
{
return
__DIR__
.
'/Fixture/Themes/demo'
;
}
}
Modules/Core/composers.php
View file @
8a6af1c6
...
...
@@ -2,3 +2,4 @@
View
::
creator
(
'core::partials.sidebar-nav'
,
'Modules\Core\Composers\SidebarViewCreator'
);
View
::
composer
(
'core::layouts.master'
,
'Modules\Core\Composers\MasterViewComposer'
);
View
::
composer
(
'core::fields.select-theme'
,
'Modules\Core\Composers\ThemeComposer'
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment