# \[ANN\] Styles 'n Scripts Extension

**URL:** <https://www.ruby-forum.com/t/ann-styles-n-scripts-extension/137762>\
**Category:** Radiant CMS\
**Created:** [May 16, 2008, 1:56am UTC](https://www.ruby-forum.com/t/ann-styles-n-scripts-extension/137762 "2008-05-16T01:56:11Z")\
**Posts on this page:** 20\
**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:** [May 16, 2008, 1:56am UTC](https://www.ruby-forum.com/t/ann-styles-n-scripts-extension/137762/1 "2008-05-16T01:56:11Z")

</div>

Hello all. John had asked me to create this some time ago as a  
proof-of-concept for an enhancement to the core of Radiant. Well, it’s  
finally here and I would appreciate any and all feedback (directly or on  
the mailing list) to improve this.

Note: this is a Rails 2.x/Radiant 0.6.6 extension and it won’t work with  
previous versions.

# What it Does

Adds Stylesheet and Javascript objects to Radiant. It should be very  
self explanatory to use but it has some real benefits (like its own  
caching mechanism to speed up server responses). Check out the README  
file for a list of features/benefits and usage.

# Where to Get It

I’m not running on git so you get to use good 'ol svn:  
[https://secure.svnrepository.com/s\_swanki/open/radiant/extensions/styles\_n\_scripts/tags/v0.2](https://secure.svnrepository.com/s_swanki/open/radiant/extensions/styles_n_scripts/tags/v0.2)

Thanks and enjoy!

Chris P.  
Swank Innovations, LLC

---

<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:** [May 17, 2008, 2:57am UTC](https://www.ruby-forum.com/t/ann-styles-n-scripts-extension/137762/2 "2008-05-17T02:57:57Z")

</div>

This looks very nice Chris.

Instead of calling the tabs “CSS” and “JS” why not “Styles” and  
“Scripts”? (Seems appropriate considering the name of the plugin.)

I’m getting an ActionController::InvalidAuthenticityToken exception on  
the O.6.7 when I try and submit a form.

I’m also getting a undefined method `updated\_by’ for #\<Javascript:  
0x236d6c8\> on 0.6.6 when I try to edit a javascript that I just created.

Have you taken a look at the prototype directory in trunk? We have a  
working HAMl prototype there that you can play around with using serve.

–  
John L.  
[http://wiseheartdesign.com](http://wiseheartdesign.com)

---

<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:** [May 17, 2008, 7:21am UTC](https://www.ruby-forum.com/t/ann-styles-n-scripts-extension/137762/3 "2008-05-17T07:21:35Z")

</div>

John W. Long wrote:

> This looks very nice Chris.
> 
> Instead of calling the tabs “CSS” and “JS” why not “Styles” and  
> “Scripts”? (Seems appropriate considering the name of the plugin.)

Thought about that. Just trying to be considerate of other extension  
developers by conserving tab space

Also we had entertained the idea of putting the two items inside one tab  
at one time (and even putting them all together with images onto an  
“assets” tab). Anyway, I wasn’t too focused on any one name for now.

> I’m getting an ActionController::InvalidAuthenticityToken exception on  
> the O.6.7 when I try and submit a form.

Dude, I released this _before_ 0.6.7. Man, tough crowd 😉

I haven’t loaded 0.6.7 yet – I’ll look into it.

> I’m also getting a undefined method `updated\_by’ for  
> #\<Javascript:0x236d6c8\> on 0.6.6 when I try to edit a javascript that  
> I just created.

Thanks. Looks like a last minute change + no spec coverage on view  
(yet) = sloppy programmer.

I’ll look into that too.

> Have you taken a look at the prototype directory in trunk? We have a  
> working HAMl prototype there that you can play around with using serve.

Not yet. I remember you mentioning something about that idea several  
months back – glad to see it launched. Sounds slick.

-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:** [May 17, 2008, 4:43pm UTC](https://www.ruby-forum.com/t/ann-styles-n-scripts-extension/137762/4 "2008-05-17T16:43:45Z")

</div>

On 5/17/08, Chris P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> it seems to wipe out the existing observation of Page, Snippet, etc.

I had this same issue some time ago and you can take a look at how I  
fixed it here:

[http://mgr.devjavu.com/browser/audioguide/vendor/extensions/forum/forum\_extension.rb#L34](http://mgr.devjavu.com/browser/audioguide/vendor/extensions/forum/forum_extension.rb#L34)

---

<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:** [May 17, 2008, 4:45pm UTC](https://www.ruby-forum.com/t/ann-styles-n-scripts-extension/137762/5 "2008-05-17T16:45:32Z")

</div>

> Does anyone know how to append classes to UserActionObserver? I’d  
> like to fix this issue but if I have my extension’s activate method call:  
> UserActionObserver.observe Stylesheet, Javascript

Yes, for some unknown reason, observe redefines the “observed\_classes”  
method instead of changing a class variable. Go figure.

I would do something like this:

new\_classes = UserActionObserver.instance.send(:observed\_classes) +  
[Stylesheet, Javascript]  
class \<\< UserActionObserver.instance  
define\_method :observed\_classes { new\_classes }  
end

Not sure about the scoping on that, etc, but that’s the general outline.

Sean

---

<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:** [May 17, 2008, 4:46pm UTC](https://www.ruby-forum.com/t/ann-styles-n-scripts-extension/137762/6 "2008-05-17T16:46:08Z")

</div>

I like your solution better, Martins.

Sean

---

<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:** [May 17, 2008, 4:37pm UTC](https://www.ruby-forum.com/t/ann-styles-n-scripts-extension/137762/7 "2008-05-17T16:37:17Z")

</div>

I fixed the issue mentioned below. The updated version can be found at:  
[https://secure.svnrepository.com/s\_swanki/open/radiant/extensions/styles\_n\_scripts/tags/v0.2.1](https://secure.svnrepository.com/s_swanki/open/radiant/extensions/styles_n_scripts/tags/v0.2.1)

This fix solves the error but still does not properly register the  
created\_by\_id and updated\_by\_id fields in Stylesheets and Javascripts  
(which was tied to the source of the original error).

Does anyone know how to append classes to UserActionObserver? I’d like  
to fix this issue but if I have my extension’s activate method call:  
UserActionObserver.observe Stylesheet, Javascript

it seems to wipe out the existing observation of Page, Snippet, etc.

The 0.6.7 issue will have to wait another day…

-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:** [May 17, 2008, 5:56pm UTC](https://www.ruby-forum.com/t/ann-styles-n-scripts-extension/137762/8 "2008-05-17T17:56:04Z")

</div>

Could someone work up a patch for this issue.

–  
John L.  
[http://wiseheartdesign.com](http://wiseheartdesign.com)

---

<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:** [May 17, 2008, 4:52pm UTC](https://www.ruby-forum.com/t/ann-styles-n-scripts-extension/137762/9 "2008-05-17T16:52:04Z")

</div>

Thanks for the quick responses you two. I’ll be able to look at things  
this evening and hopefully be able to add a few new specs and the code  
you so wonderfully provided.

I’ll also take a look at the 0.6.7 error that John mentioned.

BTW, if any of you know (or think you know) what’s up with that one,  
feel free to send some guidance. (I haven’t even downloaded 0.6.7 yet  
so I haven’t seen the issue myself).

-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:** [May 17, 2008, 9:25pm UTC](https://www.ruby-forum.com/t/ann-styles-n-scripts-extension/137762/10 "2008-05-17T21:25:46Z")

</div>

Sean, I got an attachment but it looks to only contain the mailing list  
email footer. Is the mailing list server whacking attachments possibly?

Could you send it to me directly or perhaps paste it into the body if  
you want to share it with all…

Thanks,  
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:** [May 17, 2008, 6:40pm UTC](https://www.ruby-forum.com/t/ann-styles-n-scripts-extension/137762/11 "2008-05-17T18:40:45Z")

</div>

Chris,

See attached patch. Extension developers – if you aren’t using the  
built-in form helpers in your views, please switch to them. They will  
automatically add the proper authenticity token to the form for you.

Sean

---

<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:** [May 18, 2008, 12:12pm UTC](https://www.ruby-forum.com/t/ann-styles-n-scripts-extension/137762/12 "2008-05-18T12:12:47Z")

</div>

I could get it run on a clean install (0.6.7) tho, with sqlite3 and no  
other extension installed

it gives Could not find table ‘config’ error

On 5/18/08, Chris P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<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:** [May 18, 2008, 7:08am UTC](https://www.ruby-forum.com/t/ann-styles-n-scripts-extension/137762/13 "2008-05-18T07:08:01Z")

</div>

All of the aformentioned bugs have been squished (with thanks going out  
to MÄrtiÅ†Å¡ and Sean for the exceptional help). The latest tag of the  
Styles 'n Scripts extension can now be found at:  
[https://secure.svnrepository.com/s\_swanki/open/radiant/extensions/styles\_n\_scripts/tags/v0.2.2](https://secure.svnrepository.com/s_swanki/open/radiant/extensions/styles_n_scripts/tags/v0.2.2)

It runs on Radiant 0.6.6 and 0.6.7 so far.

-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:** [May 18, 2008, 6:42pm UTC](https://www.ruby-forum.com/t/ann-styles-n-scripts-extension/137762/14 "2008-05-18T18:42:52Z")

</div>

I think this is a fault of Radiant. Could be wrong.

nurullah wrote:

> I could get it run on a clean install (0.6.7) tho, with sqlite3 and no  
> other extension installed
> 
> it gives Could not find table ‘config’ error
> 
> On 5/18/08, Chris P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<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:** [May 19, 2008, 9:53am UTC](https://www.ruby-forum.com/t/ann-styles-n-scripts-extension/137762/15 "2008-05-19T09:53:34Z")

</div>

although all installation steps fail it adds tabs on panels and some  
columns  
on config table

5|stylesheet\_mime\_type|text/css  
6|response\_cache\_directory|text\_asset\_cache  
7|javascript\_mime\_type|text/javascript  
8|javascript\_directory|js  
9|stylesheet\_directory|css

but you are right production.log says it cannot find text\_assets table  
and  
right there is no such table on db file

On 5/19/08, Chris P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<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:** [May 19, 2008, 5:27pm UTC](https://www.ruby-forum.com/t/ann-styles-n-scripts-extension/137762/16 "2008-05-19T17:27:06Z")

</div>

Ok, so now that you have a running Radiant app, you now should do the  
following to install the extension:

1. Copy the Styles 'n Scripts Extension to the following path:  
radiant\_app/vendor/extensions/styles\_n\_scripts

2. From your radiant\_app directory, migrate the extension’s db  
changes (adding the text\_assets table). Run:  
rake radiant:extensions:styles\_n\_scripts:migrate

```
  If you have any problems, run the rake task with the '--trace'
  option to show the details (and post them here).

```

1. Finally, copy the images used by the extension. Again, from your  
radiant\_app directory, run:  
rake radiant:extensions:styles\_n\_scripts:update

Good luck and let us know how it goes and post any specific error  
messages here.

-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:** [May 21, 2008, 3:57am UTC](https://www.ruby-forum.com/t/ann-styles-n-scripts-extension/137762/17 "2008-05-21T03:57:16Z")

</div>

1. 

nope that gave the same config error…

but this way it worked charmly… thank you  
rake RAILS\_ENV=“production” radiant:extensions:styles\_n\_scripts:migrate  
rake RAILS\_ENV=“production” radiant:extensions:styles\_n\_scripts:update

p.s.: uncommenting ENV[‘RAILS\_ENV’] ||= ‘production’ on  
config/enviroment.rb  
dont help

1. 

is there any way to call js/css files from anywhere of the page/layout?  
suppose, i use one template and many subpages?  
but i use different/extra css/js files on subpages (and also common),  
for  
example i will use accordion script on a subpage and putting this on  
template or on header snippet is nonsense  
so i am looking for a way to call these files from inside page/layout

---

<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:** [May 19, 2008, 12:18am UTC](https://www.ruby-forum.com/t/ann-styles-n-scripts-extension/137762/18 "2008-05-19T00:18:15Z")

</div>

The Styles 'n Scripts extension makes use of Radiant’s built-in  
Radiant::Config settings (which get stored in the config table). So  
this sound like a Radiant setup issue. (The only table my extension adds  
is text\_assets).

Remove my extension (all extensions, really) and make sure that your  
plain-vanilla Radiant extension has this table created (should have been  
created when you ran:  
rake db:bootstrap (or rake production db:bootstrap if running in  
production mode).

-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:** [May 21, 2008, 6:31am UTC](https://www.ruby-forum.com/t/ann-styles-n-scripts-extension/137762/19 "2008-05-21T06:31:12Z")

</div>

> is there any way to call js/css files from anywhere of the page/layout?  
> suppose, i use one template and many subpages?  
> but i use different/extra css/js files on subpages (and also common), for  
> example i will use accordion script on a subpage and putting this on  
> template or on header snippet is nonsense  
> so i am looking for a way to call these files from inside page/layout

The way I usually do this is to put a content part in my layout’s  
header called “head-meta” that appears in the header, e.g.

...other header stuff ...

Then you can just add a part to the page called (what else) head-meta  
and add whatever page-specific Javascript, CSS, meta tags, etc. you  
might want.

Hope this helps!

Rufo

---

<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:** [May 21, 2008, 12:10pm UTC](https://www.ruby-forum.com/t/ann-styles-n-scripts-extension/137762/20 "2008-05-21T12:10:12Z")

</div>

I played around with the idea of creating an \<r:stylesheet\> and  
\<r:javascript\> tag or even enhancing the \<r:content\> tag to let you add  
stylesheet/javascript content in addition to page part content.

The problem is that in either case you have to specify which file you  
want (either explicitly or by first setting up a context to that item)  
so why not just manually type it and save the noise of yet another  
radius tag.

This case, however, has me thinking the other way. (Plus the other  
benefit that your users only need to know the name of the script or  
stylesheet and not their full path – my tag would build that).

I’m going to be putting out a new rev shortly – it would be simple to  
add a \<r:stylesheet\> and \<r:javascript\> tag.

I’d certainly welcome other ideas as well.

-Chris

[Next page](https://www.ruby-forum.com/t/ann-styles-n-scripts-extension/137762.md?page=2)
