Skip to content

Commit

Permalink
Added rough pass at content rendering for grid. Expect howto / docume…
Browse files Browse the repository at this point in the history
…ntation in wiki soon. [concerto#121]
  • Loading branch information
bamnet committed Nov 23, 2010
1 parent 1c40ed2 commit 8e75fd3
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 7 deletions.
10 changes: 10 additions & 0 deletions app/controllers/contents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,14 @@ def destroy
format.xml { head :ok }
end
end

# GET /contents/1/display
# Trigger the render function a piece of content and passes all the params
# along for processing. Should send an inline result of the processing.
def display
@content = Content.find(params[:id])
@file = @content.render(params)
send_data @file.file_data, :filename => @file.file_name, :type => @file.file_type, :disposition => 'inline'
end

end
2 changes: 1 addition & 1 deletion app/helpers/contents_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def render_content(content, options={})

options[:type] ||= 'default'

render :partial => "contents/#{content.type.underscore}/render_#{options[:type]}",
render :partial => "contents/#{content.class.to_s.underscore}/render_#{options[:type]}",
:locals => {:content => content, :options => options}
end
end
25 changes: 25 additions & 0 deletions app/models/graphic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,29 @@ def set_kind
self.kind = Kind.where(:name => 'Graphics').first
end

# Responsible for display transformations on an image.
# Resizes the image to fit a width and height specified (both required ATM).
# Returns a new (unsaved) Media instance.
def render(options={})
# In theory, there should be more code in here to look for a cached image and be smarter
# about the resizing, but this is a good first pass.
if options.key?(:width) && options.key?(:height)
require 'RMagick'
@media = self.medias.original.first

image = Magick::ImageList.new
image.from_blob(@media.file_contents)
image.resize!(options[:width].to_i, options[:height].to_i)

file = Media.new(
:attachable => self,
:file_data => image.to_blob,
:file_type => image.mime_type,
:file_name => @media.file_name
)

return file
end
end

end
4 changes: 2 additions & 2 deletions app/views/contents/_grid.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<a href="">
<div class="iconlist_padding">
<div class="ins">
<div class="type-folder"><%= content.data %><%#= image_tag("ph/ph.png", :alt => "") %></div>
<div class="type-folder"><%= render_content(content, :type =>'grid') %></div>
</div>
<h2>
<%= content.name %>
Expand All @@ -16,4 +16,4 @@
</li>
</ul>
<% end %>
<div style="clear:both;"></div>
<div style="clear:both;"></div>
2 changes: 1 addition & 1 deletion app/views/contents/graphic/_render_grid.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= image_tag media_path(content.medias.original.first), :alt => content.name %>
<%= image_tag display_content_path(content, :width => 150, :height => 117), :alt => content.name %>
1 change: 1 addition & 0 deletions app/views/contents/ticker/_render_grid.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= content.data %>
10 changes: 7 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@
# feeds.resources :submissions
#end

resources :contents, :path => "content"
resources :contents, :path => "content" do
get :display, :on => :member
end

resources :graphics, :controller => :contents, :path => "content"
resources :tickers, :controller => :contents, :path => "content"
resources :graphics, :controller => :contents, :path => "content" do
get :display, :on => :member
end

resources :tickers, :controller => :contents, :path => "content"
# The priority is based upon order of creation:
# first created -> highest priority.

Expand Down

0 comments on commit 8e75fd3

Please sign in to comment.