I spent quite a lot of time thinking about how should I organize a good modular structure for my Qt C++ project. Unfortunately, I did not find a complete example on how to do it right (am I missing something?), so I am looking for an advice. So far, I came with the following assumptions:
I would like to have separate directory for modules, because each of them may be used in sevaral apps.
I would like to have unit tests for each module.
I also thought that keepng tests right inside module's folder is a good decision, because if I want to move or rename a module, nothing will be broken, because I can use relative paths to the module's sources in my tests.
So my desired project structure looks like this:
|project_root
|src
src.pro (TEMPLATE = subdirs)
|apps
apps.pro (TEMPLATE = subdirs)
|my_app
my_app.pro (TEMPLATE = app)
main.cpp
...
|modules
modules.pro (TEMPLATE = subdirs)
|my_module
my_module.pro (TEMPLATE = ???)
|tests
tests.pro (TEMPLATE = subdirs)
|MyClass1Test
MyClass1Test.pro (TEMPLATE = app)
tst_myclass1test.cpp
|MyClass2Test
MyClass2Test.pro (TEMPLATE = app)
tst_myclass2test.cpp
MyClass1.h
MyClass1.cpp
MyClass2.h
MyClass2.cpp
My first question is - is this structure good in context of Qt Creator's logic? Am I doing something completely wrong?
My second question is about implementation of my_module.pro. Which template should I use here? I was playing around four types of project templates: subdirs, lib, aux, and I could not manage to organize my module structure as above (that's why I am looking for a logical error). There are some reasons for that:
If I use TEMPLATE = subdirs for my_module.pro, Qt Creator does not recognize any files inside it (MyClass1.h, MyClass1.cpp, ... disapper from project structure) and I can't build a library any more
If I use a TEMPLATE = lib or TEMPLATE = aux, then I'm unable to create tests subproject in this folder
So my third question is: How should I organize my project in a good way to overcome these issues?
Related
I just want to ask what is the best approach to integrate sass/scss on ember project?
Currently my project is in pod structure and I just import style.scss on main app.scss under styles folder.
Is it fine or there is a better approach?
--- app
---- pods
------- home
---------- template.hbs
---------- controller.js
---------- style.scss
---- styles
------- app.scss
Then in app.scss styles imported look like this
#import "./app/pods/home/style.scss";
I haven't used pods in years - because (like expecting controllers to be removed) - I was told that there was going to be a new file layout system. Since hearing that / I've heard bits and pieces of conversation that lead me to believe that pods aren't really a go-to for new projects.
That being said, I share your desire to have a nice file structure. I'd love to 'drag' a folder from one project to another / and just have all the parts of the component copy over.
Since we have the app.scss - (you said you're using sass) - / that kinda acts as the index.
I include resets and mixins and a bunch of stuff for setup. - so, that's not really podish... and maybe there are 'page' level kinda layout... which doesn't really fit either... - so, what it comes down to is really 'components', right?
ember-component-css is pretty cool - but it also has some opinions that could clash.
There's this - https://github.com/justtal/ember-cli-sass-pods - but it's 4 years old / (but so are pods) - so, it might still work great.
Because there isn't a really clear path here... I just create a component folder in styles/components/component-name.styl - and then in my styles/components.styl I #import 'component-name.styl - and then in my app.styl I import the components...
In my case / I actually like to use the cascade - and I need the files to all to be combined - in order. I can't have some of it in the vendor file.
It's not ideal (just because I have to create each file explicitly and register it) - but I can't afford to just keep wishing there was a better file layout.
Instead of fuzzy searching component-name > template
I just search template > component-name
¯\_(ツ)_/¯
I wonder which style will cause me less pain in future transitions. They'll offer codemods to help / but they can't account for unique configurations.
I'd suggest asking this in the official discuss forum. You'll get the real answers there. : )
https://discuss.emberjs.com/
app/styles directory, is the home for stylesheets like CSS, SASS, or LESS.
Folders like vendor and public that can also hold many other files of the developer's choice.
So in your case if you wish to have separate scss file for each pod,
you can put it in the place as you mentioned. (else)
have it under app/styles/pod1.scss and import it under .ember-cli-build.js -> app.import('app/styles/pod1.scss')
[References]
You can get the detailed view of Project layouts, Stylesheet compilation, Assets and dependencies below
Project layouts
Stylesheet compilation
Assets and dependencies
Besides ember-component-css there is ember-css-modules.
Both addons try to achieve about the same goal, however I really prefer ember-css-modules.
That addon has an addon called ember-css-modules-sass. Both together will easily allow you to write one sass file per component.
You just place a styles.scss file in your component pod (app/components/my-component/styles.scss and then use local-class="my-class" instead of class="my-class" in your template.
Your classes in your scss will be automatically namespaces.
I am trying to create a custom gitbook theme and in that I also want to change the layout so that the book I create using the theme have the layout that I want. I copied the default templates dir in my assests dir of the custom theme and then modified the layout.html and header.html files as I wanted. Then to include the modified template files, I added the following attribute to the index.js file
module.exports = {
book: {
assets: "./assests",
templates: {
"layout":"templates/layout.html",
"header":"templates/includes/book/header.html",
},
......
......
However with this configuration, the generated book is not picking the template file changes. However I do see the css/js changes that I had done.
For the record, layout and header template files do exist if you're going the "unadvised" (emphasizing the unadvised nature of this) route of:
Add "theme": "./customtheme" to your book.json file.
Create your customtheme folder in the root with the files from the Gitbook repo
Edit from there
This is so far the only way I've found edit your favicon, sidebar, header, and layout files. It's not recommended because you're no longer using the files in the repo, so updates could break it, but some things either aren't easy or possible to make changes without doing something messy and hacky like this. Hopefully simple things like updating a favicon, header, or sidebar could be made to be easier in the future. I've only found this solution after many, many google searches and plugin comparisons, so maybe some one has a better solution that I haven't found yet.
Templates "layout" and "header" don't exist. You can only change:
site: template for the website
glossary: template for the glossary
langs: template for the choice of languages
page: template for the ebook
Changing templates is really not advised, you should use plugins to only extend html,css,js using: https://github.com/GitbookIO/plugin/blob/master/index.js#L2
I am not quite sure if my directory structure has the correct hierarchy and I decided to stop the development unless I will have it good.
I have order, customers, users .
So what I have is:
myproj
|-myproj
|-web_app
|---orders (with views.py, ajax.py)
|----templatetags
|---users
|---customers
|---search
|---static
|-----app
|-------_base
|---------css
|---------images
|---------js
|-------orders
|---------css
|---------images
|---------js
|-------customers
|---------css
|---------images
|---------js
|-------users
|---------css
|---------images
|---------js
|-----bootbox
|-----bootstrap
|-------css
|-------fonts
|-------js
|-----dajax
|---templates
models.py is in web_app directory, there are models common for all modules. My questions are:
1) What changes would you do in this structure? (static files for every module should be where?)
2) I have problem of inserting custom template tag defined in orders/templatetags/orders_extras.py from users template. How can I make some common templatetags for every "module" ?
Thank you.
This is explained in Django documentation very well. The good approach is:
Project
- App1
(Put app specfic templates to the app templates/App1/templates/App1/template files
- App2
- App3
- template for project (templates/ files)
Now, if you want template tags only for specific app create /templatetag directory under that app and do that.
For universal template tag do this:
Project
- templatetags
- __init__.py (Make sure it contains __init__.py)
- polltag.py
Explained here: https://docs.djangoproject.com/en/dev/howto/custom-template-tags/
How can I make some common templatetags for every "module" ?
You should place it near the templates directory
myproj
|-myproj
|-web_app
|---templates
|---templatetags
|---orders (with views.py, ajax.py)
|----static
|-----static_files_here
dajax
Is this about dajax? If you are new to django, I recommend to get away from this stuff. You can just watch the issues list of this project to decide whether you should use it or not. The problem not only about that dajax is bad or good, but that these issues are being made by newbies that don't understand how ajax works, what are csrf tokens and so on.
When I started to learn django, I tried dajax too, but finally I have realized that you should understand how ajax and django works by their own and then try to combine them.
I am working with Joomla 1.5 and using two different templates. To customise the frontend, I am overriding components and modules in /template/myTemplate/html/componentOrModule/. In a few cases I need the same overide in both templates.
Until now, I am using include to reuse the code. But it is still annoying, that I have to create the folders and files twice.
I reckon, that there is a better/easier way of doing it. But I do not have clue.
Did someone have the same problem and has already solved it? Any ideas appreciated.
There is no Joomla solution to this issue. My proposal would be to have a stub file in your template html folder and then include that file from a third folder. Something like the following:
/templates//html/com_content/article/default.php
You can copy that file into all the relevant override folders and then have one folder in the templates folder named "common" where you have the actual files with the output.
Don't get me wrong, I'm not talking about putting my HTML next to the settings.py file but rather add the project directory (which does contains the settings.py file) in the TEMPLATE_DIR list so I can call any template by naming it 'app/template/file.html'.
I was just wondering why Django didn't come with template name space. It forces you either to:
create a template dir separate from all apps, then create a dir for each app and put your HTML in it.
create a template dir in each app dir and create another dir in it with the application name, then put the HTML in it.
This is less than ideal, since:
forces you to have your HTML outside your app. So much for being pluggable.
violates DRY by forcing you to create a redundant dir tree project_dir/app_name/template/appname otherwise if you have several templates named 'index.html', you are screwed big time.
So is it a bad idea to just define the project dir as a template dir to call all template files 'app_name/template/file.html'? If yes, why? How would you do it cleanly?
I personally use app_name/templates for app related templates and projects/templates for global templates. Personally I find this useful as i really like loose coupling between my apps and my projects, so I tend to keep them detached.
However django gives you freedom of choice. If you feel fine with you're choice I don't see any problem at all.
You make an interesting argument against the way app_directories template loader works. Other than polluting the app's root directory with templates, I cannot think of something going wrong because of this.
Perhaps it'd be worth investigating in making your own template loader instead?