Showing posts with label radiant. Show all posts
Showing posts with label radiant. Show all posts

Saturday, August 7, 2010

Multiple sites hosting using radiant cms

by sandipransing 4 comments
There are almost 4 to 5 simple steps you need to followed before
getting multiple sites working using radiant cms
1. Setup radiant cms
first Install radiant gem
sudo gem install radiant

set 'radiant' under path
export PATH=$PATH:/var/lib/gems/1.8/gems/radiant-0.8.0/bin

Now, we have done with radiant installation.
Let's create new project..
$ radiant multisite -d mysql

$ cd multisite/

Edit database.yml
$ vi config/database.yml
development:
  adapter: mysql
  database: multisite_development
  username: root
  password: abcd
  host: localhost

Migrations
rake db:create

Run the database bootstrap rake task:
rake db:bootstrap
This task will destroy any data in the database. Are you sure you want
to continue? [yn] yes
...
Create the admin user (press enter for defaults).
Name (Administrator): admin
Username (admin): admin
Password (radiant): 
....
Select a database template:
1. Empty
2. Roasters (a coffee-themed blog or brochure)
3. Simple Blog
4. Styled Blog
[1-4]: 2
....

Now we are ready to start
script/server

Open following URL in browser.
http://localhost:3000

You should see site homepage. To manage site goto admin panel.

http://localhost:3000/admin

Now Lets start with multiple sites management
1) Clone multi_site extension into vendor/extensions of your project.
  cd vendor/extensions/
  git clone git://github.com/zapnap/radiant-multi-site-extension.git multi_site

2) Run the extension migrations.
  rake db:migrate:extensions

3) Run the extension update task.
  rake radiant:extensions:multi_site:update

4) Restart your server
And we are done with multisite installation, Open following URL in browser.

http://localhost:3000/admin/sites

Add multiple sites as you wanted
 Name        Domain pattern     Base domain name

================================================

 site 1      sandip             sandip

 site 2      gautam             gautam

 
Don't forget to make dns entries in /etc/hosts.
vi /etc/hosts
 
127.0.0.1 localhost
...
127.0.0.1 sandip
127.0.0.1 gautam
One more, by deault pages created for new sites added are not published.
Please be sure to make them published and modify contents to identify them

Now you can view different sites.
http://sandip:3000
http://gautam:3000


Thats, All
Cheers !
$@ndip
Read More…

Thursday, March 4, 2010

Page Cache control in radiant cms

by sandipransing 0 comments
Radiant Caching

Radiant cms is very powerful and customizable cms as of now which has inbuilt support for page caching.
Radiant caching mechanisam is somehow similar to action caching in rails.

In latest radiant version i.e. > 0.8 Responsecache has been replaced with Radiant::Cache.

By default radiant cache gets automatically invalidated after every 5 
minutes and that is configurable.

The interval is easily configurable by adding following lines inside environment

if defined? ResponseCache == 'constant'    
    ResponseCache.defaults[:expire_time] = 4.hours
else
    SiteController.cache_timeout = 4.hours
end
There are situations where automatic cache inavalidation won't work
and we need to clear radiant cache on the fly.
There are two ways to do that to invalidate radiant cache immediately.

1. Navigate to the root of your Radiant project and delete the cache directory.

cd /home/deploy/radiant_site/tmp
rm -r cache

2. Clearing the page cache from within your code
    
if defined? ResponseCache == 'constant'
    ResponseCache.instance.clear
else
    Radiant::Cache.clear
end

While building website using radiant cms, it happens that there are certain pages they are static and not going to change frequently that time configuring cache expiry time to long interval is going to be always beneficial and for pages which conatins dynamic content (displaying logged in user on homepage), we need to disable radiant cache for such pages. this can be done by using page_options extension.

Installation for radiant version  0.7
From your RADIANT_ROOT:

$ script/extension install page_options

Installation for radiant version  0.8 and higher
git clone git://github.com/sandipransing/radiant-page_options-extension.git vendor/extensions/page_options

Restart server

Usage

1. Goto /admin/pages
2. Edit any page
3. Click on more link and edit cache settings.

For more information visit

Read More…

Tuesday, November 10, 2009

Understanding and creating radinat extensions

by sandipransing 0 comments
Understanding and creating radinat extensions To start with, first of all lets know what is radiant and why to use it ? Radiant is a open source content management system designed that serves cms needs for small organisations Creating new radint application
 radiant -d  mysql cms
    create
    create    CHANGELOG
    create    CONTRIBUTORS
    create    INSTALL
    create    LICENSE
    create    README
    create    config
    create    config/environments
    .....
Radiant supports extensions. It means one can add extra features to radiant based cms to add extra capabilities. Extension directory structure is almost similar to any standard rails application Radiant Extension Directory structure
       |-- app
              |-- controllers
              |-- helpers
              |-- models
              |-- views
       |-- db
              |-- migrate
              |-- seeds.rb
       |-- lib
              |-- spec
                 |-- controllers
                 |-- helpers
                 |-- models
                 |-- spec.opts
                 |-- spec_helper
                 |-- views
Creating radiant extension radiant has generators to create new radint extension script/generate extension ExtensionName Lets create session management extension for radint cms It will create directory structure for extension.
script/generate extension session_management
    create    vendor/extensions/session_management/app/controllers
    create    vendor/extensions/session_management/app/helpers
    create    vendor/extensions/session_management/app/models
    create    vendor/extensions/session_management/app/views
     create vendor/extensions/session_management/db/migrate
     create vendor/extensions/session_management/lib/tasks
     create vendor/extensions/session_management/README
     create vendor/extensions/session_management/session_management_extension.rb
     create
vendor/extensions/session_management/lib/tasks/session_management_extension_tasks.rake
     create vendor/extensions/session_management/spec/controllers
     create vendor/extensions/session_management/spec/models
     create vendor/extensions/session_management/spec/views
     create vendor/extensions/session_management/spec/helpers
     create vendor/extensions/session_management/features/support
     create vendor/extensions/session_management/features/step_definitions/admin
     create vendor/extensions/session_management/Rakefile
     create vendor/extensions/session_management/spec/spec_helper.rb
     create vendor/extensions/session_management/spec/spec.opts
     create vendor/extensions/session_management/cucumber.yml
     create vendor/extensions/session_management/features/support/env.rb
     create vendor/extensions/session_management/features/support/paths.rb
Edit session_management_extension.rb where extension version, description and website url can be added.
# require_dependency 'application_controller'
class SessionManagementExtension < Radiant::Extension
  version "1.0"
  description "Describe your extension here"
  url "http://yourwebsite.com/session_management"
  # define_routes do |map|
  # map.namespace :admin, :member => { :remove => :get } do |admin|
  #     admin.resources :session_management
  # end
  # end
  def activate
    # admin.tabs.add "Session Management", "/admin/session_management", :after =>
"Layouts", :visibility => [:all]
  end
  def deactivate
    # admin.tabs.remove "Session Management"
  end
In activate block, specify what are the library files , modules that needs to be activated while application starts. In my case, activate method looks like below..
  def activate
    # admin.tabs.add "Session Management", "/admin/session_management", :after =>
"Layouts", :visibility => [:all]
   ApplicationController.send(:include, SessionManagementExt::ApplicationControllerExt)
  end
Generating models and controllers.
 script/generate extension_model session_management session_info
session_id:string url:string ip:string
In above command first attribute is the extension name and next is model name and rest specifies attributes that needs to created. It will create
     exists   app/models/
     exists   spec/models/
     create   app/models/session_info.rb
     create   spec/models/session_info_spec.rb
     exists   db/migrate
     create   db/migrate/20091110075042_create_session_infos.rb
Generating controller
script/generate extension_controller session_management admin/session_managements
It will create an output
create app/controllers/admin
     create app/helpers/admin
     create app/views/admin/session_managements
     create spec/controllers/admin
     create spec/helpers/admin
     create spec/views/admin/session_managements
     create spec/controllers/admin/session_managements_controller_spec.rb
     create spec/helpers/admin/session_managements_helper_spec.rb
     create app/controllers/admin/session_managements_controller.rb
     create app/helpers/admin/session_managements_helper.rb
Modify session managements controller for displaying sesssion infos tracked. We need before filter for every request that will capture session, ip and page url so, we need to override behaviour of application controller to add before_filter We have already added ApplicationControllerExt in activate of extension.
   ApplicationController.send(:include, SessionManagementExt::ApplicationControllerExt)
Lets look into ApplicationControllerExt module.
module SessionManagementExt
  module ApplicationControllerExt
    def self.included(base)
     base.class_eval do
       before_filter :track_session
     end
    end
    def track_session
     #**"Hello from Session tracker !!!"**
     #TODO: location track
     # It can be delayed task
     #sudo gem install geoip_city -- --with-geoip-dir=/opt/GeoIP
     # require 'geoip_city'
     # g = GeoIPCity::Database.new('/opt/GeoIP/share/GeoIP/GeoLiteCity.dat')
     # res = g.look_up('201.231.22.125')
     # {:latitude=>-33.13330078125, :country_code3=>"ARG",
:longitude=>-64.3499984741211, :city=>"Río Cuarto", :country_name=>"Argentina",
:country_code=>"AR", :region=>"05"}
     SessionInfo.create( :ip => request.remote_ip, :page_url =>
"http://#{request.env["HTTP_HOST"]}#{request.request_uri}", :session_id =>
request.session.session_id )
    end
  end
end
That's all Creating rake task for extension module here is default genrated rake task for session management under vendor/extensions/session_management/lib/tasks/session_management_extension_tasks.rake It includes task to migrate database and update extension
namespace :radiant do
  namespace :extensions do
    namespace :session_management do
     desc "Runs the migration of the Session Management extension"
     task :migrate => :environment do
       require 'radiant/extension_migrator'
       if ENV["VERSION"]
         SessionManagementExtension.migrator.migrate(ENV["VERSION"].to_i)
       else
         SessionManagementExtension.migrator.migrate
       end
     end
     desc "Copies public assets of the Session Management to the instance public/ directory."
     task :update => :environment do
       is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
       puts "Copying assets from SessionManagementExtension"
       Dir[SessionManagementExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do
|file|
         path = file.sub(SessionManagementExtension.root, '')
         directory = File.dirname(path)
         mkdir_p RAILS_ROOT + directory, :verbose => false
         cp file, RAILS_ROOT + path, :verbose => false
       end
     end
    end
  end
end
Add as many custom tasks needed inside this file without changing default tasks. Migrate all radiant extensions
rake db:migrate:extensions
Read More…

About The Author

Sandip is a ruby on rails developer based in pune and also a blogger at funonrails. Opensource contributor and working with Josh software Private Limited. for more info read Follow Sandip on Twitter for updates.

Connect With Me...

Github Projects

@sandipransing Twitter