How to make custom theme in MEAN - angularjs

I am new in MEAN and going to create new website using MEAN.
I have created the package in MEAN using the command mean package <package_name>
I have also override the default templates using the app.set('views', __dirname + '/server/views'); command in the app.js of my custom package, but the MEAN is still rendering my angular views within the MEAN's default layout.
The structure of my MEAN package folder is
packages
--core
----admin
----articles
----circles
----swagger
----system
----users
--custom
----<my_package>
------public
--------assets
--------controllers
--------directives
--------routes
--------services
--------views
------server
--------config
--------controllers
--------models
--------routes
--------views
------.bowerrc
------app.js
------bower.json
------package.json
----i18n
----theme
How can I render my own theme

To change the layout view to a different one than the default view
In the routes folder under server parent folder, look for the file that has the function mapped to the route '/'.
Now look for that function in the controllers folder. Change the name of the view to render like this:
exports.index = function(req, res) {
res.render('differentviewfile', {
user: req.user || null,
request: req
});
};
To change the look and feel of your site
You can take advantage of numerous Bootstrap themes available out there. A lot of them are free. To use them, all you have to do is change the reference to the css file (you will find it in the server side view base layout page).
Change it from the default bootstrap file to a different one, and your whole app changes. For e.g. take a look at the 16 themes available at https://bootswatch.com You can reference the CDN link to any of the themes they have directly, or you can download the css file for it and add it to your own project.
If you want to add your own styles, you can of course create your own css file and add appropriate css styles.

Did you injected a dependency to system package in your app.js file?
var MyCustomModule = new Module('mycustommodule');
/*
* All MEAN packages require registration
* Dependency injection is used to define required modules
*/
MyCustomModule.register(function(system, app, auth, database) {
You need to do that in order to wait until the system package is loaded. Then the line:
app.set('views', __dirname + '/server/views');
will override the views config set in the system package :D

Related

Changes to transitive dependencies not triggering live reload

I've added Snowpack 3 to my application and it works for JS/TS files as well as directly imported stylus files.
The file structure is similar to the following:
view.js:
import 'view-styles.styl'
export default function view() {
return (
<div className='example-view'>Hello World</div>
);
}
view-styles.styl
#require './colors.styl'
.example-view
background-color: $mainColor
colors.styl
$mainColor = #ff0000
The LiveReload/HMR works as expected when changing the directly imported stylus file. It does not work when changing anything in the colors.styl file. Changes in this file are only picked up once the view-styles.styl file is updated.
Is this a known limitation of Snowpack?
I would also be ok to trigger the update manually, as I have a way to identify these files using their filenames. I haven't found a way yet to trigger live reloads using Snowpack's JavaScript API. I was able to load the file using the SnowpackDevServer.loadUrl function, but that doesn't help either.
I was able to contribute this to the snowpack stylus plugin. The change was already integrated into the plugin: https://github.com/fansenze/snowpack-plugin-stylus

Unload modules/styles dynamically in webpack

I have to import certain list of styles dynamically based on landing page and all the other pages.
but when navigating from landing page to another page, I have to unload bootstrap style, as bootstrap conflict with myStyle:
// if we are in landing page then load bootstrap otherwise load myStyle
if (props.location.pathname === '/') {
import(`./assets/css/bootstrap.css`);
} else {
import(`./assets/css/myStyle.css`);
}
this is what I have tried so far but it doesn't do anything.(my theme collapse because of conflicting styles)
what I want is a way to dynamically unload a style completely in a page.
if (props.location.pathname === '/') {
delete require.cache[require.resolve('./assets/css/myStyle.css')];
import(`./assets/css/bootstrap.css`);
} else {
delete require.cache[require.resolve('./assets/css/bootstrap.css')];
import(`./assets/css/myStyle.css`);
}
does Webpack support such a scenario?
Please let me take you a step back just to clarify what webpack is all about. It creates bundles according to defined entrypoints. Using import/require declarations it collects all the files that are necessary to create such bundles (using appropriate loaders).
Now, let me go back to your question. You are saying that under some conditions depending on URL address you need or need not bootstrap.
Assuming that you are not using SPA, you can load bootstrap in <script> tag independently on the page that you need (landing) and on others - don't. Assuming that you are creating SPA - I don't even know how to accomplish what you are looking for. Please remember that at the end of a day, after all what webpack does, we are given static html + css + js files.
Moreover, I don't quite get how the unloading would even look like, I feel that you may think about webpack-dev-server and HMR stuff which obviously should not be used on production.

CakePHP 2.x How to determine view path in controller in beforeRender() or earlier?

I have the need to determine what app path my controller method will use for serving up the view before it does so. I'm using a theme but I also have many non-themed view files. I'm switching my themes based on domain name (2 domains point to the same Cake install) but need to exclude the non-themed views from rendering inside my theme.
This may sound confusing. Here's what is currently happening if a URL is accessed that does not have a theme view associated with it:
domainA.com/examples/index will render the view app/View/Examples/index.ctp with the layout from app/View/Layouts
domainB.com/examples/index will render the view app/View/Examples/index.ctp BUT with the layout from app/View/Themed/MyTheme/Layouts
This is because the "MyTheme" theme does not contain a view file for this controller-method pair (this is intentional). So I would like to instead have the following established:
domainB.com/examples/index continues to render the view app/View/Examples/index.ctp BUT INSTEAD with the layout from app/View/Layouts
This should only happen, of course, if and only if there is no view file within the "MyTheme" directory structure.
I think this is what you are looking for $this->View->viewPath.
You can use this in any controller call back function or action.

#section syntax instead of requirejs or browserify for angularjs application

I understand that requirejs and browserify can load my files dependent on its current context, and that it is amazing. I would really prefer to use the #section sections syntax that the razor engine uses. Was just wondering if there is a way to implement this into a typescript / angularjs application.
for example
index.html
#renderSection scripts;
// which could turn into something like
<script data-render="scripts"></scripts>
// the app.run() could declare all the scripts that will be needed on every
// page view
view.html
<script ng-section-repeat="injected in injection"></script>
// the ng-section-repeat is basically taking all the items in the
// typescript constructor and then finding out which ones are needed for
// that view.
I like the idea injecting application file dependencies in the view , without a configuration file and all the added extras that comes with the loaders.
I just want to easily define what files are needed in the actual view and get them loaded, with angular's dependency injection handling the dependency itself.
If you are handling all your dependencies with $inject then , as far as i can tell, dependency is technically already setup in the controllers, all one would need, is to load this as it is called. Which could even eliminate the need for the #section scripts completely
Update:
What i have done to sort of replicate the module loaders is to just use gulp-concat and define the file order in my gulp.config.js and then pass it to the gulp-src before running $.concat .this allows me to have the files in the gulp steam , in dependent order . They are however loaded on the first load. With gulp-uglify the files are tiny ( its now at 566Kb with 16 external libraries loading in 69ms . To put that into perspective it takes 209ms to load one google font ).
I dont know maybe i am not understanding browserify correctly but i honestly struggle to see the need for it, its seems extremely convoluted for something so simple
It is possible using external modules and an injector to do what you asked for:
I just want to easily define what files are needed in the actual view
import {UserFactory} from 'models/userFactory';
import {UserValidator} from 'models/userValidator';
import {Inject} from 'angular2/di';
and get them loaded, with angular's dependency injection handling the dependency itself.
Note: My example uses angular 2.x because I less familiar with angular 1.x and I'm sure you can do something really similar...
class SomeComponent {
userName: string;
userRating: number;
rating: number;
constructor(
#Inject(UserFactory) UserFactory
#Inject(UserValidator) UserValidator
)
{
this.UserFactory = UserFactory;
this.UserValidator = UserValidator;
}
}
Then you can use Browserify to create a bundle.js file that can be executed in a web browser.

Linking a CSS or JS to default layout

I'm trying to undestand how to link CSS or JS I'll use it all over my CakePHP 1.3 application. I've read about putting assets in folder /app/webroot/css or /app/layouts/css (for css only in this case).
I've put a file named main.css and default.css but I'm missing something.
How can I do to fix it and which are the default rules for the default layout?
Normal
$this->Html->css('my_file'); corresponds to /app/webroot/css/my_file.css
$this->Html->script('my_file'); corresponds to /app/webroot/js/my_file.js
you add the php part from above to your layout file which is by default in /app/views/layouts/default.ctp (or in cake dir if you have not created one)
you can set the layout in the controller/app_controller setting $this->layout = 'foo'; which points to /app/views/layouts/foo.ctp
Themes
Setting the controller to $this->view = 'Theme'; will make cake use themes then setting $this->theme = 'SomeTheme'; in the controller will make cake use /app/views/themed/some_theme/* files
using $this->Html->script('my_file'); now points to /app/views/themed/some_theme/js/my_file.js and the same goes for the css.
css = http://book.cakephp.org/view/1437/css
js = http://book.cakephp.org/view/1589/script
themes = http://book.cakephp.org/view/1093/Themes
themes have the problem of serving css, js and other assets through php (ob_start(); include etc) and this is obviously slower than normal http serving. you can either copy files across to the webroot folder as explained in the bottom or be lazy and do something like the following https://gist.github.com/712622

Resources