# \[ANN\] SnS Minifier

**URL:** <https://www.ruby-forum.com/t/ann-sns-minifier/142353>\
**Category:** Radiant CMS\
**Created:** [July 7, 2008, 7:31am UTC](https://www.ruby-forum.com/t/ann-sns-minifier/142353 "2008-07-07T07:31:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mahadewa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9e8a1a/32.png) [@mahadewa](https://www.ruby-forum.com/u/mahadewa)\
**Post date:** [July 7, 2008, 7:31am UTC](https://www.ruby-forum.com/t/ann-sns-minifier/142353/1 "2008-07-07T07:31:33Z")

</div>

I did say more coming soon, right… So here’s another.

This time it’s the SnS Minifier Extension found at:  
[https://secure.svnrepository.com/s\_swanki/open/radiant/extensions/sns\_minifier/tags/latest](https://secure.svnrepository.com/s_swanki/open/radiant/extensions/sns_minifier/tags/latest)

Again, early release (v0.1) so please give me feedback.

From the README file:

= Styles 'n Scripts Minifier

Adds the ability to minify CSS and JS files. This way, you can keep your  
code  
the way you like it in the editor but serve up minified files. (And if  
you  
really want to speed things up, add GZip to the mix to have your server  
crunch  
it further).

== Available Minifiers

- JSMin v1.0.0 - This is based on the original C code by Douglas  
Crockford  
([JSMin](http://www.crockford.com/javascript/jsmin.html)) but wonderfully  
repackaged  
into a plugin by Ryan Grove  
([GitHub - rgrove/cssmin: 💀 Ruby library for minifying CSS. Unmaintained.](http://github.com/rgrove/cssmin/tree/master)).

JSMin is often seen as being an older but safer technology. It certainly  
doesn’t pack as well as some others out there but is tried and true.

- CSSMin v1.0.0 - This is Ryan Grove’s port of the YUI Compressor’s  
([http://www.julienlecomte.net/yuicompressor/](http://www.julienlecomte.net/yuicompressor/)) CSS minifier (which was  
itself  
taken from Isaac Schlueter’s regular expression based CSS minifier  
([Isaac Z. Schlueter](http://foohack.com/2007/09/squish-it-good-code-compression-for-the-masses/))

Ryan nicely ported this one to a plugin too. And I added a minor  
addition  
too (which is available via options – see below)

- Packr - James C. was nice enough to port Dean Edward’s famous  
Packer  
([/packer/](http://dean.edwards.name/packer/)). More about the plugin version used  
here  
can be found at: ([http://blog.jcoglan.com/packr/](http://blog.jcoglan.com/packr/))

Packer is a great tool but it is pretty strict about terminating  
javascripts  
with semicolons ([/packer/usage/sample.html](http://dean.edwards.name/packer/usage/sample.html)).

- Rainpress - This is a newer ruby project by Uwe L. Korn to minify CSS  
files  
([Google Code Archive - Long-term storage for Google Code Project Hosting.](http://code.google.com/p/rainpress/)). There isn’t much history but it  
seems solid enough.

I had to repackage this one into a plugin (and strip a lot of the  
command  
line stuff out). Originally I did all this as I didn’t know about  
CSSMin.  
Anyway, I included this too basically because I’d already done  
everything.

== Usage  
It’s pretty simple, really. Once installed, it adds a “Minify?” checkbox  
to the  
bottom of your Stylesheet and Javascript pages. Just check the box and  
save the  
file. Viola, the content is minified.

The configuration can be changed via the @@settings variable inside:  
/lib/text\_asset\_mixins.rb

There, you can choose which minifiers you want to use and set any of  
their  
available options.

== Requirements  
You’ll need:

- Radiant v0.6.7 or higher
- Styles 'n Scripts Extension v0.5 or higher

== Installation  
Install the extension in your Radiant project like:  
[your project]/vendor/extensions/sns\_minifier

You will need the Styles 'n Scripts extension installed for this to work  
and you  
will also probably need to change your project’s environment.rb file to  
twiddle  
the load order (the SnS Extension must be loaded before this one). For  
example,  
you could use something like:  
config.extensions = [:all, :sns\_minifier]

== To Do  
Well first of all this extension needs some specs.

But after that I’d _love_ to find where someone ported the YUI  
Compressor (JS  
version) to ruby. It appears to be much more flexible (read forgiving)  
than  
Packer while still crunching stuff way down. A second option would be to  
let  
admins install the java version and make this plugin interact with that.

---

<div class="post-metadata">

**Author:** ![mahadewa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9e8a1a/32.png) [@mahadewa](https://www.ruby-forum.com/u/mahadewa)\
**Post date:** [July 7, 2008, 2:55pm UTC](https://www.ruby-forum.com/t/ann-sns-minifier/142353/2 "2008-07-07T14:55:42Z")

</div>

On Mon, Jul 7, 2008 at 1:30 AM, Chris P. \<  
removed\_email\_address@domain.invalid\> wrote:

> You will need the Styles 'n Scripts extension installed for this to work  
> and you  
> will also probably need to change your project’s environment.rb file to  
> twiddle  
> the load order (the SnS Extension must be loaded before this one). For  
> example,  
> you could use something like:  
> config.extensions = [:all, :sns\_minifier]

I think extensions are loaded in alphabetical order unless otherwise  
specified by config.extensions. If you rename this extension to  
styles\_n\_scripts\_minifier (or rename styles\_n\_scripts to sns), you won’t  
need the change in environment.rb.

I was poking around in the SVN repo last night and spotted these new  
extensions. They look great!

–  
Tim G.

---

<div class="post-metadata">

**Author:** ![mahadewa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9e8a1a/32.png) [@mahadewa](https://www.ruby-forum.com/u/mahadewa)\
**Post date:** [July 7, 2008, 3:25pm UTC](https://www.ruby-forum.com/t/ann-sns-minifier/142353/3 "2008-07-07T15:25:36Z")

</div>

I got the following error for /admin/css/new:

undefined method `minify’ for #Stylesheet:0x2756ac8

(I’m on OS X 10.5, Rails 2.1, Radiant 0.6.7 using SQLite3)

When I rake db:extensions:sns\_minifier:migrate, the add\_column never  
gets executed. I renamed  
sns\_minifier/lib/tasks/minify\_extension\_tasks.rake to  
sns\_minifier/lib/tasks/sns\_minifier\_extension\_tasks.rake and  
remigrated (migrate VERSION=0 then migrate), and it was fixed.

I am now enjoying SASS-filtered, minified stylesheets. Thanks a bunch,  
Chris!

–  
Tim G.

---

<div class="post-metadata">

**Author:** ![mahadewa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9e8a1a/32.png) [@mahadewa](https://www.ruby-forum.com/u/mahadewa)\
**Post date:** [July 7, 2008, 5:03pm UTC](https://www.ruby-forum.com/t/ann-sns-minifier/142353/4 "2008-07-07T17:03:35Z")

</div>

Tim G. wrote:

> > you could use something like:  
> > extensions. They look great!

Tim, you’re right about the load order thing. I had debated naming the  
new extensions “styles\_n\_scripts\_xxx” but I’ve decided that carpal  
tunnel syndrome just is not for me.

But I hadn’t considered renaming the whole extension to “sns” though. I  
think I like that idea for several reasons.

However, it would require users to physically change something on their  
servers – not just update from svn. You would have to change from:  
/vendor/extensions/styles\_n\_scripts  
to:  
/vendor/extensions/sns

Would anyone be opposed to my renaming the extension like this?

-Chris

P.S. Just to be clear, I’d only be renaming files and their related  
code. Oh, and rake tasks would now be “rake radiant:extensions:sns” But  
otherwise everything would be _identical_ to your users (even the  
extension name in the Admin panel would still show “Styles 'n Scripts”).

---

<div class="post-metadata">

**Author:** ![mahadewa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9e8a1a/32.png) [@mahadewa](https://www.ruby-forum.com/u/mahadewa)\
**Post date:** [July 7, 2008, 6:15pm UTC](https://www.ruby-forum.com/t/ann-sns-minifier/142353/5 "2008-07-07T18:15:46Z")

</div>

On Mon, Jul 7, 2008 at 11:02 AM, Chris P. \<  
removed\_email\_address@domain.invalid\> wrote:

> to:  
> /vendor/extensions/sns
> 
> Would anyone be opposed to my renaming the extension like this?
> 
> -Chris
> 
> P.S. Just to be clear, I’d only be renaming files and their related code.  
> Oh, and rake tasks would now be “rake radiant:extensions:sns” But otherwise  
> everything would be _identical_ to your users (even the extension name in  
> the Admin panel would still show “Styles 'n Scripts”).

I think renaming the whole thing to SnS would be in-line with your  
preference against carpal tunnel syndrome 🙂

None of the models would be renamed (right?), so users should be able to  
swap out the existing extension directory for a renamed one and get off  
without a hitch. If I had a few spare moments, I’d try it for myself  
right  
now… maybe there’d be a clash with the version number in the  
extension\_meta table, and maybe there wouldn’t because it’s listed as  
“Styles 'n Scripts”.

–  
Tim G.

---

<div class="post-metadata">

**Author:** ![mahadewa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9e8a1a/32.png) [@mahadewa](https://www.ruby-forum.com/u/mahadewa)\
**Post date:** [July 7, 2008, 4:44pm UTC](https://www.ruby-forum.com/t/ann-sns-minifier/142353/6 "2008-07-07T16:44:13Z")

</div>

New release! You can find v0.1.1 at:  
[https://secure.svnrepository.com/s\_swanki/open/radiant/extensions/sns\_minifier/tags/latest](https://secure.svnrepository.com/s_swanki/open/radiant/extensions/sns_minifier/tags/latest)

Thanks to Tim who found this naming issue (see below). What can I say -  
it was getting late.

-Chris

---

<div class="post-metadata">

**Author:** ![mahadewa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9e8a1a/32.png) [@mahadewa](https://www.ruby-forum.com/u/mahadewa)\
**Post date:** [July 7, 2008, 6:43pm UTC](https://www.ruby-forum.com/t/ann-sns-minifier/142353/7 "2008-07-07T18:43:54Z")

</div>

Tim G. wrote:

> None of the models would be renamed (right?), so users should be able to  
> swap out the existing extension directory for a renamed one and get off  
> without a hitch. If I had a few spare moments, I’d try it for myself right  
> now… maybe there’d be a clash with the version number in the  
> extension\_meta table, and maybe there wouldn’t because it’s listed as  
> “Styles 'n Scripts”.

No, I can keep the “Styles 'n Scripts” name in the meta table and in the  
Admin-Extensions page. So all that would be needed is for the user to  
update to the latest version of SnS and to change the  
“styles\_n\_scripts” folder name to “sns”. (Or change the  
/vendor/extensions folder’s properties if using svn:externals).

But for me it does require renaming all the rake tasks, the  
xx\_extension.rb file, and probably something else I’m not thinking of.

I’d also probably change StylesNScripts::Config to SnS::Config (and  
there would be a _bunch_ of references to that that would need to change  
accordingly). Not strictly necessary but something I’d want.

-Chris
