From 4aa4a0e4a44735d22ac7f8fd1b12b19699af087b Mon Sep 17 00:00:00 2001 From: hukl Date: Tue, 1 Sep 2009 11:49:56 +0200 Subject: added expirimental routing for image galeries added plain image gallery template refinements --- app/controllers/content_controller.rb | 15 ++++++++++++--- app/helpers/content_helper.rb | 10 ++++++++++ app/models/page.rb | 2 +- app/models/related_asset.rb | 2 +- app/views/custom/page_templates/public/gallery.html.erb | 5 +++++ .../page_templates/public/standard_template.html.erb | 1 + config/routes.rb | 9 ++++++--- 7 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 app/views/custom/page_templates/public/gallery.html.erb diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb index d548a34..d1bfa6b 100644 --- a/app/controllers/content_controller.rb +++ b/app/controllers/content_controller.rb @@ -1,14 +1,13 @@ class ContentController < ApplicationController + before_filter :find_page + # This is the method that renders most of the the public content. It recieves # a :locale and a :page_path parameter through the params hash. It looks up # the node with the corresponding unique_name attribute. The method doesn't # return a node though, the node is really a proxy object for pages. It # returns the most recent page associated to this node instead. def render_page - path = params[:page_path].join('/') - - @page = Node.find_page(path) if @page and @page.public? template = @page.valid_template @@ -26,4 +25,14 @@ class ContentController < ApplicationController end + def render_gallery + @images = @page.assets.images + render :file => "custom/page_templates/public/gallery"#, :layout => true + end + + private + def find_page + path = params[:page_path].join('/') + @page = Node.find_page(path) + end end diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb index 6309c8b..8b16462 100644 --- a/app/helpers/content_helper.rb +++ b/app/helpers/content_helper.rb @@ -16,6 +16,16 @@ module ContentHelper ) end + def headline_image + image = @page.assets.images.first + if image + link_to_path( + image_tag(image.upload.url(:headline)), + ("galleries/" + @page.node.unique_name) + ) + end + end + # Returns the published_at attribute of a page if it is not nil, otherwise # it returns the auto-filled value of the created_at attribute diff --git a/app/models/page.rb b/app/models/page.rb index d697a96..47ecdfd 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -31,7 +31,7 @@ class Page < ActiveRecord::Base belongs_to :node belongs_to :user has_many :related_assets - has_many :assets, :through => :related_assets, :order => "position DESC" + has_many :assets, :through => :related_assets, :order => "position ASC" # Filter before_create :set_page_title diff --git a/app/models/related_asset.rb b/app/models/related_asset.rb index dc4dc3d..036e79e 100644 --- a/app/models/related_asset.rb +++ b/app/models/related_asset.rb @@ -2,5 +2,5 @@ class RelatedAsset < ActiveRecord::Base belongs_to :page belongs_to :asset - acts_as_list, :scope => :page_id + acts_as_list :scope => :page_id end \ No newline at end of file diff --git a/app/views/custom/page_templates/public/gallery.html.erb b/app/views/custom/page_templates/public/gallery.html.erb new file mode 100644 index 0000000..7511db3 --- /dev/null +++ b/app/views/custom/page_templates/public/gallery.html.erb @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/app/views/custom/page_templates/public/standard_template.html.erb b/app/views/custom/page_templates/public/standard_template.html.erb index 1822491..6fe7176 100644 --- a/app/views/custom/page_templates/public/standard_template.html.erb +++ b/app/views/custom/page_templates/public/standard_template.html.erb @@ -2,6 +2,7 @@

<%= @page.title %>

<%= date_for_page @page %>, <%= @page.user.try(:login) %>


+

<%= headline_image %>

<%= @page.abstract %>

<%= aggregate?(@page.body) %> diff --git a/config/routes.rb b/config/routes.rb index e1da95c..f94b61c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,7 +14,7 @@ ActionController::Routing::Routes.draw do |map| map.resources :events map.resources :revisions, :member => {:diff => :post, :restore => :put} map.resources :pages, :member => {:preview => :get} - map.resources :nodes, :member => {:publish => :put, :unlock => :put} + map.resources :nodes, :member => {:publish => :put, :unlock => :put} map.logout '/logout', :controller => 'sessions', :action => 'destroy' map.login '/login', :controller => 'sessions', :action => 'new' map.admin_search 'admin/search', :controller => 'admin', :action => 'search' @@ -22,8 +22,11 @@ ActionController::Routing::Routes.draw do |map| map.resources :menu_items, :member => {:sort => :post} map.resource :session - map.connect ':controller/:action/:id' - map.connect ':controller/:action/:id.:format' + map.connect ':controller/:action/:id' + map.connect ':controller/:action/:id.:format' + + map.connect 'galleries/*page_path', + :controller => 'content', :action => 'render_gallery' map.connect '/*page_path', :controller => 'content', :action => 'render_page' -- cgit v1.3