-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor screen template rendering to the frontend namespace.
* Move the template rendering code for the frontend, update the caching slightly. * Pass the template path as part of the screen setup information instead of constructing it on the fly.
- Loading branch information
Showing
10 changed files
with
64 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class Frontend::TemplatesController < ApplicationController | ||
|
||
# GET /frontend/1/template/1 | ||
# Render the template for display on a screen. | ||
def show | ||
template = Template.find(params[:id]) | ||
if stale?(:last_modified => template.last_modified.utc, :etag => template, :public => true) | ||
require'image_utility' | ||
media = template.media.original.first | ||
image = Magick::Image.from_blob(media.file_contents).first | ||
|
||
# Resize the image to a height and width if they are both being set. | ||
# Round these numbers up to ensure the image will at least fill | ||
# the requested space. | ||
height = params[:height].nil? ? nil : params[:height].to_f.ceil | ||
width = params[:width].nil? ? nil : params[:width].to_f.ceil | ||
|
||
image = ImageUtility.resize(image, width, height, false) | ||
case request.format | ||
when Mime::Type.lookup_by_extension(:jpg) | ||
image.format = "JPG" | ||
when Mime::PNG | ||
image.format = "PNG" | ||
else | ||
render :status => 406, :text => "Unacceptable image type." and return | ||
end | ||
|
||
send_data image.to_blob, | ||
:filename => "#{template.name.underscore}.#{image.format.downcase}", | ||
:type => image.mime_type, :disposition => 'inline' | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module Frontend::TemplatesHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'test_helper' | ||
|
||
class Frontend::TemplatesControllerTest < ActionController::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require 'test_helper' | ||
|
||
class Frontend::TemplatesHelperTest < ActionView::TestCase | ||
end |