diff --git a/README.md b/README.md index 1f1f2070b77fa23ca1e4277346b8eb24bbb6124a..de382164851f9f5ee1420128f3e77713d579cb26 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,10 @@ # hshassets []() -This is an django-app which provides styles, fonts, javascript and templates. +This django-app provides everything you ever wanted! (probably not, but i hope you feel happy anyways). It brings fonts, +styles, javascript and layouts as templates. -Please read the [wiki](https://lab.it.hs-hannover.de/django/hshassets/wikis/home) for further information and documentation. +Please read the [wiki](https://lab.it.hs-hannover.de/django/hshassets/wikis/home) for further information about the +provided templates. ## Shipped awesome stuff @@ -23,3 +25,94 @@ The current version of this package ships the following own stuff and awesome th #### JavaScript - [jquery](https://github.com/jquery/jquery) (3.1.1) - New Wave JavaScript + + +## Installation + +Simply put this app into your projects `requirements.txt` file and run `pip install -r requirements.txt`. Once you +installed it, you should put the name `hshcdn` into your projects `INSTALLED_APPS` setting. Tadaa! + +## Usage + +Simply create an `assets` folder in your app(s) directory. It can contain the folders `fonts` for custom fonts, `img` +for own images, `js` for custom javascript and `sass` for custom (s)css. + +- *Everything* that exists in the folders `appname/assets/fonts` and `img` will be *copied* to +`appname/static/appname/<folder_name>`. +- Files that exist at `appname/assets/js` and ends with `.js` will be merged and minified to +`appname/static/appname/script(.min).css` +- For (s)css, hshassets will search for the file `appname/assets/sass/_init.scss` and tries to compile it. So you have +to import additional (s)css files there. The compiled and minified result will be copied to +`appname/static/appname/styles(.min).css` + +This example structure ... + +``` +[project name] +│ +├── [app name] +│ │ ┐ +│ ├── assets │ +│ │ ├── fonts ├─ This is new +│ │ │ └── funny_font.woff │ +│ │ ├── img │ +│ │ │ ├── dog.png │ +│ │ │ ├── cat.png │ +│ │ │ └── mouse.png │ +│ │ ├── js │ +│ │ │ └── somescript.js │ +│ │ └── sass │ +│ │ ├── _init.scss │ +│ │ └── stuff.scss │ +│ │ ┘ +│ ├── urls.py +│ ├── wsgi.py +│ └── ... +│ +├── manage.py +├── README.md +└── ... +``` + +... will produce the following result tree: + +``` +[project name] +│ +├── [app name] +│ │ +│ ├── assets - this will still exist +│ │ └── ... +│ │ ┐ +│ ├── static │ +│ │ └── [appname] ├─ The produced result +│ │ ├── fonts │ +│ │ │ └── funny_font.woff │ But be careful, never edit files here directly! +│ │ ├── img │ `hshassets` manages this directory entirely. This +│ │ │ ├── dog.png │ means that everything here will be overwritten or +│ │ │ ├── cat.png │ deleted if it shouldn't be here. Use the `assets` +│ │ │ └── mouse.png │ folder for your custom stuff. +│ │ │ │ +│ │ ├── script.js │ +│ │ ├── script.min.js │ +│ │ ├── styles.css │ +│ │ └── styles.min.css │ +│ │ ┘ +│ ├── urls.py +│ ├── wsgi.py +│ └── ... +│ +├── manage.py +├── README.md +└── ... +``` + +To help you with the development, there are two command available: + +- `python manage.py buildassets` + Will gather, copy, compile and minify everything **once**. After it finished, you can execute other commands. + +- `python manage.py watchassets` + does the exact same as the command before, but doesn't stop at the end. It will continuously watch for changes on + `*.js`, `*.sass`, `*.scss`, `*.css` files and everything at `img/` and `fonts/` to re-compile -minify and -copy + the changed files diff --git a/hshassets/assets/js/foo.js b/hshassets/assets/js/foo.js deleted file mode 100644 index 2f593d2b9962eec847bf46afbbb615fe7ad095c0..0000000000000000000000000000000000000000 --- a/hshassets/assets/js/foo.js +++ /dev/null @@ -1,3 +0,0 @@ -function() { - console.log('changes'); -} diff --git a/hshassets/management/commands/watchassets.py b/hshassets/management/commands/watchassets.py index 0599262779f6f4ca5b06a91cc790d64082ff7a76..8ab82aa1d41c024e91e43b3e34981bc1c5936cc7 100644 --- a/hshassets/management/commands/watchassets.py +++ b/hshassets/management/commands/watchassets.py @@ -48,7 +48,7 @@ class Command(BaseCommand): observer = Observer() build_handler = AssetBuildHandler(patterns=['*.js', '*.sass', '*.scss', '*.css']) - image_handler = ImageHandler(patterns=['*.heavy']) + image_handler = ImageHandler(patterns=['*']) for app_name, app_directories in utils.get_asset_directories().items(): diff --git a/hshassets/static/hshassets/script.js b/hshassets/static/hshassets/script.js index 5b7b30ad63e6b8d688024934e8bc32beff3da5ba..c98b21b86e2f26bd6c2a3ed2c8ce6dbd6919abaf 100644 --- a/hshassets/static/hshassets/script.js +++ b/hshassets/static/hshassets/script.js @@ -1,7 +1,3 @@ -function() { - console.log('changes'); -} - /*! * jQuery JavaScript Library v3.1.1 * https://jquery.com/ diff --git a/hshassets/static/hshassets/script.min.js b/hshassets/static/hshassets/script.min.js index 7c3ae58f956559f28e33f3ee0f8f08ee354ad7a0..3285f1b22a9702f53e404f44280229a88b07c7b7 100644 --- a/hshassets/static/hshassets/script.min.js +++ b/hshassets/static/hshassets/script.min.js @@ -1,4 +1,4 @@ -function(){console.log('changes');}/*! +/*! * jQuery JavaScript Library v3.1.1 * https://jquery.com/ * @@ -11,7 +11,6 @@ function(){console.log('changes');}/*! * * Date: 2016-09-22T22:30Z */ - (function(global,factory){"use strict";if(typeof module==="object"&&typeof module.exports==="object"){module.exports=global.document?factory(global,true):function(w){if(!w.document){throw new Error("jQuery requires a window with a document");} return factory(w);};}else{factory(global);} })(typeof window!=="undefined"?window:this,function(window,noGlobal){"use strict";var arr=[];var document=window.document;var getProto=Object.getPrototypeOf;var slice=arr.slice;var concat=arr.concat;var push=arr.push;var indexOf=arr.indexOf;var class2type={};var toString=class2type.toString;var hasOwn=class2type.hasOwnProperty;var fnToString=hasOwn.toString;var ObjectFunctionString=fnToString.call(Object);var support={};function DOMEval(code,doc){doc=doc||document;var script=doc.createElement("script");script.text=code;doc.head.appendChild(script).parentNode.removeChild(script);}