[Module dev] Access to Library (and other) Api

41 views
Skip to first unread message

Marc

unread,
Oct 29, 2011, 11:12:04 AM10/29/11
to Alchemy CMS
Hi there,

the first steps towards my own module are done. Now I'm wondering if
there's a nice and convenient way to access the library?
Is there any documentation for these api-accesses around?

Regards
Marc

Thomas von Deyen

unread,
Oct 29, 2011, 12:00:55 PM10/29/11
to alche...@googlegroups.com
What do you mean with Library?
Could you give an example of what you are want to do?

Regards

Thomas

Marc

unread,
Oct 29, 2011, 12:29:17 PM10/29/11
to Alchemy CMS
With Library I mean the Picture/File-Library.

Actually my Module requires to use Pictures in a certain context.
Would be cool if there are some methods I can use to list all Pictures
and easily "insert" them in my model.
This would require the path for the view, properties and so on.

Meanwhile I browsed through the source-code a bit. An image can be
retrieved by pictures/{id}/show/{size}/{filename}, right? So if there
are some Classes/Helpers to easily get that information that would be
great!

Regards
Marc

Robin Böning

unread,
Oct 30, 2011, 2:32:01 PM10/30/11
to alche...@googlegroups.com
I dont understand what you really want to do.

I am wondering what you mean with "insert them in my model"?
In wich model? Picture model? Or another model (I dont think you want to store a picture twice.)?

Do you rather mean rendering the images in a view?
Normally you want to render a page with its nested elements.
These elements might contain images as contents.

For this, you firstly have to prepare the elements.yml for your picture element.
Then you should generate your element via the rails generator: "rails g alchemy:elements --skip".
You'll get two partials for this element, with some code for rendering the images.

If I didnt understand correctly, please try to describe your situation a bit more.

bye
Robin

Marc

unread,
Oct 31, 2011, 4:27:27 AM10/31/11
to Alchemy CMS
Ok. First example:

Batch creation/upload/parsing:
In a module you can upload some data and it parses and saves it as new
pages/elements/images... automatically.
The pictures needed are uploaded or choosen from the library. So I'm
looking for functions like:

bring_into_library(file, metadata)
get_image_by_name(filename)
get_image_by_metadata(metadata)

Second Example:
Assuming your guestlist-module has a custom Model "guest". I want to
assign a picture to a guest manually, the picture has been uploaded
before.
To fill a sidebar-like container with all pictures I'd like to have
something like
images = get_all_images_from_library

<img src="<%= images.first.src %>

I hope it's become clear now.

It's of course no problem if no such methods exist. I will dig into
the code and write my own ones. But why do redundant work if it has
already been done!

Greetings
Marc

On 31 Okt., 02:32, Robin Böning <robin.boen...@nethosting4you.de>
wrote:

Thomas von Deyen

unread,
Oct 31, 2011, 6:49:26 AM10/31/11
to alche...@googlegroups.com
Ok.

This is more Rails specific then alchemy specific, but I'll explain:

Getting all Pictures from Library:

Picture.all

Assigning a picture to one of your models you should have something like a picture_id column.

Then you just assign a Pictures#id to your model. Or, if you want to have more then one picture make a habtm table to have a m to n connection.

You see, their is not much magic in there. Just basic Rails stuff.

I hope I could help.

Don't hesitate to ask more questions.

Thomas von Deyen

unread,
Oct 31, 2011, 7:16:21 AM10/31/11
to alche...@googlegroups.com
I will write a Guide for this.

Marc

unread,
Nov 1, 2011, 9:57:00 AM11/1/11
to Alchemy CMS
A guide would be nice!!

Don't need to be a full blown thing at the beginning, some hints in
the right direction would do.

I figured out, that alchemy uses fleximage, hence their methods are
available.
Moreover rdoc reveals a good overview for the methods (a bit clearer
than directly in the code).
You should consider to host the generated docs anywhere.

Regards

On 31 Okt., 19:16, Thomas von Deyen <tvde...@googlemail.com> wrote:
> I will write a Guide for this.
>

Thomas von Deyen

unread,
Nov 1, 2011, 1:09:25 PM11/1/11
to alche...@googlegroups.com
As stated in the README under Resources:


RTFM ;)

best regards from the other side of the globe
Reply all
Reply to author
Forward
0 new messages