public
Description: Photo Gallery Management System based on Radiant CMS (Ruby on Rails).
Homepage: http://gravityblast.com/projects/radiant-gallery/
Clone URL: git://github.com/pilu/radiant-gallery.git
Click here to lend your support to: radiant-gallery and make a donation at www.pledgie.com !
Thomas Cowell (author)
Fri Oct 16 01:52:18 -0700 2009
hairballopolis (committer)
Fri Oct 16 11:20:53 -0700 2009
radiant-gallery / gallery_extension.rb
100644 104 lines (93 sloc) 3.391 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
require 'tempfile'
require_dependency 'application_controller'
require_dependency 'open-uri'
require_dependency 'exifr/jpeg'
require_dependency 'exifr/tiff'
 
class GalleryExtensionError < StandardError; end
 
class GalleryExtension < Radiant::Extension
  version RadiantGallery::Version.to_s
  description "Allows to manage list of files/images grouped into galleries"
  url "http://gravityblast.com/projects/radiant-gallery/"
  
  define_routes do |map|
    # FIME: it doesn't work with namespace admin and without :name_prefix and path_prefix (only on production). :(
    #map.namespace(:admin) do |admin|
      map.resources :galleries,
        :name_prefix =>'admin_',
        :path_prefix => 'admin',
        :member => {
          :clear_thumbs => :get,
          :reorder => :get,
          :update_order => :post
        },
        :collection => {
          :children => :get,
          :reorder => :get,
          :update_order => :post
        } do |galleries|
          galleries.resources :children, :controller => 'galleries', :path_prefix => '/admin/galleries/:parent_id'
          galleries.resources :items, :controller => 'gallery_items', :member => { :move => :put }
          galleries.resources :importings, :controller => 'gallery_importings', :member => { :import => :put }
      end
    #end
  end
  
  def activate
    init
    tab_options = {:visibility => [:all]}
    if Radiant::Config.table_exists?
      Radiant::Config["gallery.gallery_based"] == 'true' ? tab_options[:before] = "Pages" : tab_options[:after] = "Layouts"
    end
    admin.tabs.add("Galleries", "/admin/galleries", tab_options)
    admin.page.edit.add :layout_row, 'base_gallery' if admin.respond_to?(:page)
  end
  
  def deactivate
    admin.tabs.remove "Galleries"
  end
  
  def init
    Page.send(:include, PageExtensionsForGallery, GalleryTags, GalleryItemTags, GalleryItemInfoTags, GalleryLightboxTags)
    UserActionObserver.instance
    UserActionObserver.class_eval do
      observe Gallery, GalleryItem
    end
    GalleryPage
    GalleryCachedPage
    load_configuration
    load_content_types
    if Radiant::Config["gallery.gallery_based"] == 'true'
      Admin::WelcomeController.class_eval do
        def index
          redirect_to admin_galleries_path
        end
      end
    end
  end
  
  def load_configuration
    load_yaml('gallery') do |configurations|
      configurations.each do |key, value|
        if value.is_a?(Hash)
          value = value.collect{|k, v| "#{k}=#{v}"}.join(',')
        end
        Radiant::Config["gallery.#{key}"] = value
      end
    end
  end
  
  def load_content_types
   load_yaml('content_types') do |content_types|
     content_types.each do |name, attributes|
       attributes["extensions"].each do |extension|
         GalleryItem::KnownExtensions[extension] = {
           :content_type => name,
           :icon => attributes["icon"]
         }
       end
     end
   end
  end
   
private
  
  def load_yaml(filename)
    config_path = File.join(RAILS_ROOT, 'config', 'extensions', 'gallery')
    filename = File.join(config_path, "#{filename}.yml")
    raise GalleryExtensionError.new("GalleryExtension error: #{filename} doesn't exist. Run the install task and try again.") unless File.exists?(filename)
    data = YAML::load_file(filename)
    yield(data)
  end
    
end