Integrated some stuff I've been using

3 views
Skip to first unread message

Alex Chaffee

unread,
Sep 29, 2009, 10:48:19 AM9/29/09
to erector
I pulled in some code I've been using in my apps. All on github now;
go check it out.

* FieldTable -- a simple table where each row has a label and a value,
and an optional note. Good for simple forms.

* externals -- for a widget to declare that it needs some external
resource, like a script or a stylesheet. It gets collected inside a
class var and then emitted in HEAD by...

* Page -- a widget that emits a whole HTML page, complete with doctype
and externals

* jquery -- a method that takes a JS snippet and then executes it
during $(document).ready

I'd like feedback on all this. Especially naming. Is 'externals'
meaningful? etc. etc.

Also, I left Page and FieldTable in the root namespace because it's so
cumbersome to say Erector::Widgets::FieldTable.new... Is there an easy
way to suck in a module namespace in Ruby? Would 'include' do that?

---
Alex Chaffee - al...@cohuman.com - http://alexch.github.com
Stalk me: http://friendfeed.com/alexch | http://twitter.com/alexch |
http://alexch.tumblr.com

John Firebaugh

unread,
Oct 13, 2009, 1:24:19 AM10/13/09
to erector
Hi Alex,

Cool, these are exactly the sorts of things I had started to build in
my haml templates before I started checking out erector. Here are my
thoughts.

> * Page -- a widget that emits a whole HTML page, complete with doctype
> and externals

This would need a few changes before I could use it in my rails
project:

* Remove the default style block. These conflict with my stylesheets,
and I think in such a basic widget, any default styles are in fact
going to be controversial.
* Fix most of the TODOs. Most important for me would be different CSS
media. (Actually, unless externals gains all the features of the Rails
stylesheet_link_tag and javascript_include_tag helpers, I can't really
use it at all.)

It would also be nice to have a way to specify classes for the body
tag without overriding content. (I like to use haml's page_class
helper for the body class.)

> * jquery -- a method that takes a JS snippet and then executes it
> during $(document).ready

This should support pages running with jQuery.noConflict(), i.e. use:

jQuery(document).ready(function($){ ... });

> I'd like feedback on all this. Especially naming. Is 'externals'
> meaningful? etc. etc.

I'd prefer having dedicated class methods like 'css' and 'js' over
passing the type as a symbol. And as I mentioned above, I would need
them to support all the features of stylesheet_link_tag and
javascript_include_tag.

Thanks,
John

Alex Chaffee

unread,
Oct 13, 2009, 12:32:59 PM10/13/09
to john.fi...@gmail.com, erector
Thanks for the feedback! Most of your requests are no-brainers. If you
get to them before I do, just send a patch or pull request.

However, on changing the API --

> I'd prefer having dedicated class methods like 'css' and 'js' over
> passing the type as a symbol

-- I'd like to go into more detail on why I switched from doing it
that way (several class methods, named "css" etc.) to the current way
(a single class method that takes params, e.g. "external :css, 'body
{display:none;}'"(heh)).

* "external" is now defined in a module, which leads to arguably
better code reuse and clarity

* there was confusion seeing the same method names to refer to
in-method styles and page styles, especially since style and JS can
easily span multiple pages so it's not clear what the context is

* the word "external" makes code more self-documenting; someone coming
in fresh to the code will instantly know (or at least have a clue)
that this snippet is external to the component in question

* anyone can extend the externals mechanism without changing Erector
library code or monkey-patching; e.g. to make a new "sass" external
type and then have their own Page subclass emit it in their own
head_content method

Not that I'm not open to revisiting the decision, just wanted to give
more context for it.

Alex Chaffee

unread,
Oct 26, 2009, 9:37:05 AM10/26/09
to john.fi...@gmail.com, erector
> This would need a few changes before I could use it in my rails
> project:
>
> * Remove the default style block. These conflict with my stylesheets,
> and I think in such a basic widget, any default styles are in fact
> going to be controversial.

Done, sort of: I extracted a basic_styles method which you can override.

> * Fix most of the TODOs. Most important for me would be different CSS
> media.

Done.

> (Actually, unless externals gains all the features of the Rails
> stylesheet_link_tag and javascript_include_tag helpers, I can't really
> use it at all.)

You mean timestamps and asset hosts?

> It would also be nice to have a way to specify classes for the body
> tag without overriding content. (I like to use haml's page_class
> helper for the body class.)

Done. Override the body_attributes method.

>> * jquery -- a method that takes a JS snippet and then executes it
>> during $(document).ready
>
> This should support pages running with jQuery.noConflict(), i.e. use:
>
> jQuery(document).ready(function($){ ... });

Done.

Reply all
Reply to author
Forward
0 new messages