-
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.
Wiring up a backend that exposes actual content in the frontend.
Content can be fetched for a field and a completely random piece will be returned. The `render_details` method on the Content model can pass additional information to the frontend rendering code specific to the content type being rendered.
- Loading branch information
Showing
12 changed files
with
98 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class Frontend::ContentsController < ApplicationController | ||
layout false | ||
|
||
before_filter :scope_setup | ||
|
||
def scope_setup | ||
@screen = Screen.find(params[:screen_id]) | ||
@field = Field.find(params[:field_id]) | ||
end | ||
|
||
def index | ||
@content = [Content.first(:offset => rand(Content.count))] | ||
@content.each do |c| | ||
c.pre_render(@screen, @field) | ||
end | ||
respond_to do |format| | ||
format.json { | ||
render :json => @content.to_json( | ||
:only => [:name, :id, :duration, :type], | ||
:methods => [:render_details] | ||
) | ||
} | ||
end | ||
end | ||
|
||
# GET /frontend/1/fields/1/contents/1 | ||
# 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 show | ||
@content = Content.find(params[:id]) | ||
@file = @content.render(params) | ||
send_data @file.file_contents, :filename => @file.file_name, :type => @file.file_type, :disposition => 'inline' | ||
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 |
---|---|---|
@@ -1,9 +1,3 @@ | ||
class Frontend::FieldsController < ApplicationController | ||
layout false | ||
|
||
def contents | ||
respond_to do |format| | ||
format.json { render :json => [] } | ||
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::ContentsHelper | ||
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,18 @@ | ||
require 'test_helper' | ||
|
||
class Frontend::ContentsControllerTest < ActionController::TestCase | ||
include Devise::TestHelpers | ||
fixtures :screens | ||
fixtures :fields | ||
fixtures :contents | ||
|
||
test "should get content for field" do | ||
get(:index, {:screen_id => screens(:one).id, :field_id => fields(:one).id, :format => :json}) | ||
assert_response :success | ||
assert_template false | ||
|
||
data = ActiveSupport::JSON.decode(@response.body) | ||
assert data.length > 0 | ||
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
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::ContentsHelperTest < ActionView::TestCase | ||
end |