How can you pack/minify css and js files in mod_perl? - perl

Is there a utility/module similar to pack in Java where you can compile all the css files into one css file and all the js files into a one js file?

Would this work for you:
https://metacpan.org/module/Apache2::Response::FileMerge

Two modules that look like they ought to do what you want (sorry I haven't personally used either):
JavaScript::Minifier
CSS::Minifier

Related

Using Harp with p5.js and coffeescript

I am using harp (harpjs.com) and p5.js (p5js.org) and I would like to write everything in coffeescript.
Harp understands .coffee files, so I simply wrote a sketch.coffee but it didnt work. Renaming it to sketch.js worked, but I prefer .coffee. Do i need any special libraries to hook this up?
Via http://harpjs.com/docs/development/coffeescript - if you include <script src="sketch.js"></script> in your html, and have a sketch.coffee file in the same directory, it should just work...

Grunt Inline CSS and Javascript

Short Version:
Is there a way, using Grunt, to include minified CSS and JavaScript inline?
To use usemin's formatting as an example, I would like to see something like this:
<!-- build:css inline -->
<link rel="stylesheet" href="styles/foo.css">
<link rel="stylesheet" href="styles/bar.css">
...
<!-- endbuild -->
<!-- build:js inline -->
<script src="js/foo.js"></script>
<script src="js/bar.js"></script>
...
<!-- endbuild -->
Turned into this something like this:
<style>body { color: red; } /*css is here*/</style>
<script>var foo = 1; bar = 'some javascript code is here'; ...</script>
Long Version:
So, I'm working on a Tumblr theme. In order to use CSS or JS files in a theme, they have to be uploaded to Tumblr. The only way to upload is a crappy little web form that often crashes. I'm trying to avoid this interface until I'm ready to upload the final code because
there's no way to delete uploaded files, and
while I'm in the middle of development, these extra steps take too much time
To get this, I've been copying my CSS and JS into <style> and <script> tags in my file, then copying the whole thing into the Tumblr theme editor. It's faster, so I'm happy with that, but manually copying and pasting CSS and JS into a file seems to go against the spirit of Grunt and the automation it provides.
Ideally, I would be able to run grunt build and have it spit out an html file with the CSS and JS inline, then I can just copy that into the Tumblr interface (well, ideally, I would be able to copy that HTML file to Tumblr, but Tumblr doesn't provide FTP or SSH or any useful interface, so I'll settle for this).
It seemed like grunt-usemin could provide the functionality I'm looking for, but I haven't been able to get it working as I described. Maybe it's only made to put everything into a separate file.
I'm open to using any Grunt tool if anyone knows of one that could accomplish this.
I've used this one before: https://github.com/motherjones/grunt-html-smoosher. It's very straightforward, just provide an input file and output file; no extra configuration, it just finds the files automatically and inlines them.
grunt.initConfig({
smoosher: {
dist: {
files: {
'dest-index.html': 'source-index.html',
},
},
},
});
Hope this helps.
Just providing other references that might be useful:
This grant-inline task do inline css and javascripts but you can do it selective using the _inline parameter. There is also a similar task grunt-inline-assests that do same thing. Both are good to generate HTML e-mails.
Finally, the purpose of this one is a bit different; it inserts all your css and js as externals based on a tag in your HTML. This can be very useful when developing themes and front-ends where you want to have you js or css contained in many small files to easy maintenance. Sails-linker task can be used to inject all css and js while in development and one of the inliners above can be used to generate the final production HTML file with CSS and JS minified and inlined.

Adding custom file extension to netbeans ide

I'm using NetBeans 7.2.1 for my developments with CodeIgniter/Bonfire.
In my controllers i'm loading my for the view needed JavaScripts via
Assets::add_js($this->load->view('admin/index_js', $data, true), 'inline');
to preparse some php variables in the JavaScript (like dynamic url's).
This forces me to save these JavaScript files witht he extension ".php" so that i can load it via
$this->load->view
All these JavaScript files are using the filename syntac
*_js.php
Since i load it via view and Assets with "inline" parameter i can't put the
<script>
</script>
tags in the script so NetBeans is not recognizing it as JavaScript and i have no syntax highlightning and no formatting options.
Any idea how i can get it that NetBeans can recognize it as JavaScript?
Thanks a lot.
Okay... got it...
One of my collegues made a change to the assets library to "erase" the script tags from assets::js inline included files:
http://forums.cibonfire.com/discussion/1134/assetsjs-inline_js-change-to-load-js-via-view#Item_1

Excluding code sections from EPIC/tidyperl source formatting

I in a large codebase of an application written in perl there is a lot of HTML and JS written inline in the perl file.
$html_str = qq^ <A LOT OF HTML> ^;
All the code development in done using Eclipse IDE and EPIC plugin. For ease of merging/diffs et al, I am looking for a way to tell the EPIC source formatter not to apply formatting rules to the HTML and JS that is written inline. Is there a way to do this?
HTML embedded in the code is a red flag. That's stuff a designer is going to want to tweak, and so should be able to get at easily. The HTML should be split out into template files. I realize this doesn't answer your question, but it does solve your problem.
Otherwise, use perltidy to handle Perl code formatting. It won't mess with content inside strings and certainly isn't going to try and format HTML.

What's a good way to view dojo's javascript source files in Eclipse with Aptana?

I have Aptana installed within Eclipse. I'm working on a project with the dojo 1.2 JavaScript library installed.
When I open one of dojo's dijit .js files, the code is formatted in a rather difficult to read way. The Eclipse "Outline" view shows a list of functions with names like "_2" and "ew". Not very human friendly.
I'm talking about source code that looks like this:
dojo.declare("dijit.InlineEditBox",dijit._Widget,{editing:false,autoSave:true,buttonSave:"",buttonCancel:"",renderAsHtml:false,editor:"dijit.form.TextBox",editorParams:{},onChange:function(_1){
},onCancel:function(){
},width:"100%",value:"",noValueIndicator:" ✍ ",constructor:function(){
this.editorParams={};
},postMixInProperties:function(){
this.inherited(arguments);
this.displayNode=this.srcNodeRef;
var _2={ondijitclick:"_onClick",onmouseover:"_onMouseOver",onmouseout:"_onMouseOut",onfocus:"_onMouseOver",onblur:"_onMouseOut"};
for(var _3 in _2){
this.connect(this.displayNode,_3,_2[_3]);
}
dijit.setWaiRole(this.displayNode,"button");
if(!this.displayNode.getAttribute("tabIndex")){
this.displayNode.setAttribute("tabIndex",0);
}
this.attr("value",this.value||this.displayNode.innerHTML);
},setDisabled:function(_4){
dojo.deprecated("dijit.InlineEditBox.setDisabled() is deprecated. Use attr('disabled', bool) instead.","","2.0");
this.attr("disabled",_4);
How do I get a clearer, "friendlier" view of such a .js file?
You should be able to download uncompressed versions of the library at dojotoolkit.org.
Here is the source tree for 1.2.2.
You should download the dojo source distribution because the "standard" release is compressed with dojo ShrinkSafe tool (something similar to yui compress method based on Rhino) that is 100% safe and saves about 20% space usage. Within the source archive you will find an Util folder full with utils tools for unit testing, compressing, building and documenting :)
http://download.dojotoolkit.org/ - here you will find a list of all downloadable distributions