Artur Baldyga wrote:
I want to create my own extension. I made my extension using this link:

http://dev.radiantcms.org/radiant/wiki/HowToUseMailerExtension

Is there any bigger tutorial with more details what I have to do , step
by step or something else??

I'm working on one, but it is unfinished. (See attached.)

--
John Long
http://wiseheartdesign.com

Getting Started with Radiant Extensions
---------------------------------------

One of the most exciting aspects of Radiant 0.6 is the support that has been 
added for extensions. Since Radiant is a "no-fluff" content management system 
there are a lot of features supported by other systems that will never make it 
into Radiant. I've tried to keep things clean and simple so that Radiant is 
easy to learn and easy to support. The trouble is, my opinion of what features 
constitute "fluff" and what features are absolutely necessary is probably 
different than your own. Extensions give you the opportunity to change this.

Using extensions you can customize nearly every aspect of Radiant. And because 
Radiant is made with Ruby on Rails developing an extension is almost as easy as 
developing a regular Ruby on Rails application.

In this tutorial I want to help you get started with your first extension. We 
will cover:

* Using extension generators
* Creating a custom model and controller
* Running extension migrations
* Creating custom tags

This tutorial assumes that you already have the latest Radiant gem installed on 
your local computer and that you have a basic understanding of Ruby on Rails. 
If you have never used Ruby on Rails before please run through the Rolling with 
Rails tutorials ("Part 
I":http://www.onlamp.com/pub/a/onlamp/2006/12/14/revisiting-ruby-on-rails-revisited.html,
 "Part 
II":http://www.onlamp.com/pub/a/onlamp/2007/01/05/revisiting-ruby-on-rails-revisited-2.html,
 and "Part 
III":http://www.slash7.com/articles/2005/01/24/really-getting-started-in-rails) 
before you begin.


Creating a New Project
----------------------

Let's create a test project. Open up a command prompt and "cd" to the 
appropriate directory, then execute the `radiant` command to create a new 
project:

<pre><code>
% radiant -d sqlite3 path/to/new/project
</code></pre>

As you can see I've chosen to use SQLite 3 as my database engine, but you are 
welcome to choose MySQL or PostgreSQL instead.

The `radiant` command will create a skeleton for our new project and then 
output the following instructions:

<pre>
== Installation and Setup

Once you have extracted the files into the directory where you would like to
install Radiant:

1. Create the MySQL/PostgreSQL/SQLite databases for your Web site. You only
   need to create the "production" database, but you may also want to create
   the "development" and "test" databases if you are developing extensions
   or running tests.

2. Edit config/database.yml to taste.

3. Run the database bootstrap rake task:

     % rake production db:bootstrap

   (If you would like bootstrap your development database run `rake
   development db:bootstrap`.)

4. Start it like a normal Rails application. To test execute:

     % script/server -e production

   And open your Web browser on port 3000 (http://localhost:3000). The
   administrative interface is available at /admin/. By default the bootstrap
   rake task creates a user called "admin" with a password of "radiant".

When using Radiant on a production system you may also need to set permissions
on the public and cache directories so that your Web server can access those
directories with the user that it runs under.

Once you've installed Radiant on your own Web site, be sure to add your name
and Web site to the list of radiant users:

http://dev.radiantcms.org/radiant/wiki/RadiantUsers
</pre>

If you've chosen to use SQLite 3 as your database engine for this tutorial you 
can ignore steps 1 and 2. Otherwise create all three databases for the 
development, production, and test environments and edit "config/database.yml" 
to taste. Then run the bootstrap rake task for the production and development 
environments:

<pre><code>
% rake db:bootstrap
% rake production db:bootstrap
</code></pre>

Once you have bootstrapped both databases, start Radiant up from the command 
line and verify that the site is running correctly before continuing:

<pre><code>
% script/server -e production
</code></pre>

Now go to "http://localhost:3000"; and verify that the site is running 
correctly. You should see a screen that looks like this if Radiant is 
configured correctly:

Once you've verified that Radiant is running correctly go back to the console 
and press Ctrl+C to stop the test server.


Generating an Extension
-----------------------

Let's create our first extension now. The extension we will be creating is one 
that will make it easy for us to manage a list of links on our Web site. To 
create a new extension you should use the extension generator. The format for 
the command is:

<pre><code>
script/generate extension ExtensionName
</code></pre>

In our case we will call our extension LinkRoll. At the command prompt type:

<pre><code>
% script/generate extension LinkRoll
</code></pre>

You should see the following output:

<pre><code>
  create  vendor/extensions/link_roll/app/controllers
  create  vendor/extensions/link_roll/app/helpers
  create  vendor/extensions/link_roll/app/models
  create  vendor/extensions/link_roll/app/views
  create  vendor/extensions/link_roll/db/migrate
  create  vendor/extensions/link_roll/lib/tasks
  create  vendor/extensions/link_roll/test/fixtures
  create  vendor/extensions/link_roll/test/functional
  create  vendor/extensions/link_roll/test/unit
  create  vendor/extensions/link_roll/README
  create  vendor/extensions/link_roll/Rakefile
  create  vendor/extensions/link_roll/link_roll_extension.rb
  create  vendor/extensions/link_roll/lib/tasks/link_roll_extension_tasks.rake
  create  vendor/extensions/link_roll/test/test_helper.rb
  create  
vendor/extensions/link_roll/test/functional/link_roll_extension_test.rb
</code></pre>

As you can see, the extension generator has created a skeleton extension for us 
in the vendor/extensions/link_roll folder. The extension we will create will be 
entirely contained in the link_roll folder. To use it in another project all we 
need to do is copy the link_roll folder into that project's vendor/extensions 
folder.

Open up the "link_roll_extension.rb" file. It should look something like this:

<pre><code>
class LinkRollExtension < Radiant::Extension
  version "1.0"
  description "Describe your extension here"
  url "http://yourwebsite.com/link_roll";

  # define_routes do |map|
  #   map.connect 'admin/link_roll/:action', :controller => 'admin/link_roll'
  # end

  def activate
    # admin.tabs.add "Link Roll", "/admin/link_roll", :after => "Layouts", 
:visibility => [:all]
  end

  def deactivate
    # admin.tabs.remove "Link Roll"
  end

end
</code></pre>

Let's edit the attributes of the LinkRollExtension. First, change the 
description to:

  Allows you to add a link roll to your Web site.
  
Then change the url to: 

  http://dev.radiantcms.org/radiant/browser/trunk/extensions/link_roll/

We will deal with the other two attributes in a moment. For now, let's start 
the server up again:

<pre><code>
% script/server -e production
</code></pre>

And open your web browser up to "http://localhost:3000/admin/";. Click the 
"Extensions" link in the upper right corner. In the list of extensions you 
should now see the "Link Roll" extension:

Note that the description and the website correspond to the attributes that you 
just edited.
_______________________________________________
Radiant mailing list
Post:   Radiant@lists.radiantcms.org
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Reply via email to