Skip to content

Commit

Permalink
Moved CSS location to media folder
Browse files Browse the repository at this point in the history
Fixes meanbee#5
  • Loading branch information
Ash Smith committed Jun 13, 2016
1 parent a396563 commit a095896
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The user stories that this extension should achieve and maintain are as follows.
- The CSS file should be generated on clicking of "Publish" button in cache management.
- Generates CSS File
- CSS file should be in a directory which can be written to be the web.
- While there was a preference for media, we have chosen skin to maintain compatibility with CSS merging.
- The file is generated into the media folder, the drawback of this that the file cannot be merged when css merging is enabled. [More info](https://github.com/meanbee/magento-configuration-powered-css/issues/5)
- CSS file will be plain CSS and will have no interaction with frontend build tools.
- CSS file will be generated with a custom block and template.
- Each theme can then have it’s own template file if required.
Expand Down
65 changes: 63 additions & 2 deletions src/app/code/community/Meanbee/ConfigPoweredCss/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class Meanbee_ConfigPoweredCss_Model_Config
const XML_PATH_HEAD_BLOCK = 'dev/meanbee_configpoweredcss/head_block';
const XML_PATH_LOGGING = 'dev/meanbee_configpoweredcss/logging';
const LOG_FILENAME = 'meanbee_configpoweredcss.log';
const CSS_FILENAME = 'css/meanbee_configpoweredcss_%d.css';
const CSS_FILENAME = 'meanbee_configpoweredcss_%d.css';
const CSS_PATH = 'css/config/%s/%s/';

/**
* Is the extension enabled?
Expand Down Expand Up @@ -77,6 +78,66 @@ public function getCssFilename($store = null)
*/
public function getFullCssFilePath($store = null)
{
return Mage::getBaseDir('skin') . '/frontend/base/default/' . $this->getCssFilename($store);
return $this->getCssDirectoryPath() . $this->getCssFilename($store);
}

/**
* Get directory for CSS files
*
* @param $store
* @return string
*/
public function getCssDirectoryPath($store = null)
{

return Mage::getBaseDir('media') . $this->getCssPath($store);
}

/**
* Retrieve the CSS path relative to the media directory
* @param null $store
* @return string
*/
public function getCssPath($store = null)
{
return sprintf(self::CSS_PATH, $this->_getDesignPackage($store), $this->_getDesignTheme($store));
}

/**
* Get full URL for CSS file
* @param null $store
* @return string
*/
public function getCssFileUrl($store = null)
{
return Mage::getUrl(sprintf('media/%s', $this->getCssPath($store))) . $this->getCssFilename($store);
}

/**
* Get the current package for store
* @param int|null $store
* @return mixed
*/
protected function _getDesignPackage($store = null)
{
return Mage::getStoreConfig('design/package/name', $store);
}

/**
* Get the current theme for the store
* @param int|null $store
* @return string
*/
protected function _getDesignTheme($store = null)
{
$theme = Mage::getStoreConfig('design/theme/template', $store);
if (!$theme) {
$theme = Mage::getStoreConfig('design/theme/default', $store);
}
if (!$theme) {
$theme = 'default';
}

return $theme;
}
}
4 changes: 4 additions & 0 deletions src/app/code/community/Meanbee/ConfigPoweredCss/Model/Css.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ protected function _writeToFile($string, $storeId)
return false;
}

if (!is_dir($this->config->getCssDirectoryPath($storeId))) {
mkdir($this->config->getCssDirectoryPath($storeId), 0755, true);
}

$file = $this->config->getFullCssFilePath($storeId);
$result = file_put_contents($file, $string, LOCK_EX);

Expand Down

0 comments on commit a095896

Please sign in to comment.