I am wanting to build a basic theme with a default config file and then I want to build sub themes with config files that are merged with the master theme. Should I use the Kohana::config class to manage this or would it be best to handle this manually by including the config array and merging it with the master config? So far I haven't been able to get the config files to load at all because I've got them located within their own directory.
Basically What I'm trying to do is setup a structure like:
application
|--> classes
|--> myclass
|--> myclass.php // default parent class. Loads the config
|--> config.php // array of default config settings
|--> theme
|--> blue
| |--> blue.php // extends myclass.php
| |--> config.php // merges over the default config settings
|--> red
| |--> red.php // extends myclass.php
| |--> config.php // merges over the default config settings
|--> green
|--> green.php // extends myclass.php
|--> config.php // merges over the default config settings
So I can then call something like:
$theme = new Myclass_Theme_Red_Red();
and have the theme loaded with the default configs from Myclass_Myclass and then have the red theme merged over the defaults. I hope this make sense.
So what is the best way of handling config settings within this sort of structure - or is there a better approach entirely? I don't want to move all the config files into application/config as I would prefer them to be kept with the individual themes.
I'd put the config files into a config directory which is a sibling of the classes directory.
So your new directory structure would be:
application
|- classes
|- config (your files go in here)
|-- theme (and can be in their own namespaced directory)
|--- green
|--- red
|--- blue
This is where your configuration files should always go. If you need to do something which Kohana doesn't support then you can add a custom config reader in your (modules) bootstrap [1].
Kohana::$config->attach(new Kohana_Config_File);
[1] Attaching a new config reader in Kohana
A common example would be to load config files from a sub-directory which can be achieved with:
Kohana::$config->attach(new Kohana_Config_File);
Kohana::$config->attach(new Kohana_Config_File('config'.DIRECTORY_SEPARATOR.Kohana::$environment));
This allows me to use different config settings per environment with Kohana.
If you desperately want to keep your config files with the classes you might want to make each theme a separate module.
If you desperately want to keep your config files with the classes you
might want to make each theme a separate module.
There is no need to make each theme a separate module. Actually, it makes more sense to have one folder per module with your themes.
Say you have a module, and inside that module you have a themes directory.
my-module
|- classes
|- config (your module's config files go in here)
|-- my-module.php
|- themes (in own directory)
|-- green
|--- config
|---- green-config.php
|-- red
|-- blue
Then you could load the config file like this:
Kohana::$config->attach(new Kohana_Config_File('themes/green/config'));
$config = Kohana::$config->load('green-config');
echo $config->test; //Hello World!
The contents of your green-config.php
<?php defined('SYSPATH') or die('No direct access allowed.');
return array('test'=>'Hello World!');
Also, to quickly test if a file is accessible to Kohana:
Kohana::find_file('themes', 'green/config/green-config');
Related
I faced a problem with adjusting paths for my project. The project has following structure:
prj
|-common
| |-types
| |-somefile.ts ...
|
|-server
| |-node_modules
| |-package.json ...
|
|-client
| |-node_modules
| |-package.json
| |-angular.json ...
somefile.ts
import { Observable, Subject } from 'rxjs'; !!!Cannot find module 'rxjs' or its corresponding type declarations
export class Someclass {}
As you may see i want to reuse common types between server and client side. somefile.ts is easily imported in project via relative path. But when the somefile.ts is used in some of the project, popups error for "rxjs" module.
How to properly configure package.json for projects?
If it’s not a core module (you installed it), you need to give a path to node_modules folder. Which I can see there’s two.
You need to make sure which one of them contains rxjs.
Then give the path like this:
const rxjs = require("../../server/node_modules/rxjs");
I created a global scss variable file in my root folder
and for import variables I wrtie
#import '../../../style_config/style_config' (global variable file)
to every scss file
More i work in a deep folder hard to find Relative path
Is there any way to use absolute path ? or better way import scss file?
Env
Create React App on node.js
Tried
1.Import scss variable file at index.js but scss file give me error.
there is no variables
My code structure is:
app
|_ config/webpack.config.js
|_ src/assets/styles/_common.scss
In my _common.scss I have all my variables and mixins.
You need to set alias for your scss files in webpack.config.js
module.exports = {
resolve: {
alias: {
styles: path.join(__dirname, "../src/assets/styles")
}
}
}
and while importing the styles use ~
#import "~styles/common";
P.S: I've been doing the exact same what you are doing now since a long time and have never thought it could be optimised. Thanks for putting this up.
Using app.use(express.static('public')) serves the files located under public folder
But if my files are outside the public folder in my application root directly how to serve them.
If you want to serve files in a folder outside of the current working directory, './../<dir_name>' is the way to go.
If you want to serve individual files instead of a directory, then you can use either,
app.use("/<some_url>", express.static(__dirname + '<path_to_file>'));
or
res.sendFile('<path_to_file>');
or use a simple library like, https://www.npmjs.com/package/connect-static-file.
I recommend the first approach though.
Note: replace the <text> with your file names and path names as required.
You can use ./../ to go the parent of the current folder. If you have the following structure:
project
- public
- app_folder
-- app.js
You can use './../public' as the static folder.
I'm creating a React + Flux web app with a file structure that looks like this:
MyApp
|---
|---scripts
|---app.jsx
|---actions
|---components
|---HomePage.react.jsx
|---NotFoundPage.react.jsx
|--- ...etc
|---dispatcher
|---stores
1) Where do I place public assets like pictures, videos, text files or whatever..
2) Is there a standard/neat way to load them? All I've found is this library but there must be something more people use.
I usually use a dist or public folder where all asset are kept. When I release the app, the bundles are saved in the dist folder.
For example:
MyApp
|-- app
| |---app.jsx
| |---actions
| |---components
| |---HomePage.react.jsx
| |---NotFoundPage.react.jsx
| |--- ...etc
| |---dispatcher
| |---stores
|-- public
| -- js -- bunlde.js
| -- img -- images
| -- css -- app.css
Is there a standard/neat way to load them? All I've found is this library but there must be something more people use.
You can just include them in the index.html. However, recently I've been bundling the css into the javascript file so that I have one single file.
You can do that with:
webpack: https://github.com/webpack/css-loader
browserify: https://github.com/cheton/browserify-css
Let's pretend I have a project structure like so:
root/
|
-- app.js
-- config.json
-- package.json
-- lib/
|
-- config/
|
-- config.js
Further, let's pretend I want to read the root config.json from within the config.js (to override default configuration). I can do the following:
const path = require('path');
let jsonConfig = {};
try {
let moduleDir = path.dirname(process.mainModule.filename);
jsonConfig = require(`${moduleDir}/config.json`);
} catch (e) {}
My question is, should I? The documentation states:
Alternate way to retrieve require.main. The difference is that if the main module changes at runtime, require.main might still refer to the original main module in modules that were required before the change occurred. Generally it's safe to assume that the two refer to the same module.
I don't know what conditions would cause my main module to change at runtime. I assume it would be something that I would explicitly do myself, but I'm not familiar enough with the internals of the runtime to know for sure.
Edit for clarification:
I know that I could use a relative path, e.g. require('../../config.json'). But that makes it more difficult to refactor/move lib/config/config.js at a later date if that's something I end up doing. Thus my desire to require relative to the base project directory.
This config is also specific to the application. Putting it in a module under node_modules is not something I want to do. I only put npm managed dependencies within node_modules.
My question is more about potential unexpected issues that could arise from relying on process.mainModule than it is about the require function.
You could hard-code it like so
require('../../config')
Or, you could take advantage of the node_modules findup functionality in Node, and move config.json to node_modules/config/index.json
root/
|
-- app.js
-- node_modules
|
-- config
|
-- package.json
-- index.json
-- package.json
-- lib/
|
-- config/
|
-- config.js
Then just use
require('config')