Added actions that handle css/js overrides
Hesham E
committed Sep 29, 2010
commit 5dbc8d24676e7543a7989ca209a8ad66fd22fc81
Showing 6
changed files with
54 additions
and 6 deletions
app/controllers/cms_content_controller.rb
+15
-3
| @@ | @@ -1,13 +1,25 @@ |
| class CmsContentController < ApplicationController | |
| - | |
| + | before_filter :load_cms_layout, |
| + | :only => [:render_css, :render_js] |
| + | |
| def render_page | |
| # TODO | |
| end | |
| - | def styles |
| + | def render_css |
| + | send_data @cms_layout.css, :filename => 'styles.css', :type => 'text/css' |
| end | |
| - | def javascripts |
| + | def render_js |
| + | send_data @cms_layout.js, :filename => 'jscript.js', :type => 'text/javascript' |
| end | |
| + | protected |
| + | |
| + | def load_cms_layout |
| + | @cms_layout = CmsLayout.find(params[:id]) |
| + | rescue ActiveRecord::RecordNotFound |
| + | render :nothing => true |
| + | end |
| + | |
| end | |
app/views/cms_admin/layouts/_form.html.erb
+3
-1
| @@ | @@ -1,3 +1,5 @@ |
| <%= form.text_field :label, :label => 'Layout Name' %> | |
| <%= form.select :parent_id, CmsLayout.options_for_select(@cms_layout), :include_blank => true, :label => 'Parent Layout' %> | |
| - | <%= form.text_area :content %> |
| \ No newline at end of file | |
| + | <%= form.text_area :content %> |
| + | <%= form.text_area :css %> |
| + | <%= form.text_area :js %> |
config/routes.rb
+6
-1
| @@ | @@ -11,6 +11,11 @@ Rails.application.routes.draw do |
| resources :uploads | |
| end | |
| - | match '*cms_path', :to => 'cms_content#render_page', :via => :get |
| + | scope :path => '/layouts/:id', :controller => :cms_content do |
| + | get 'styles.css' => :render_css |
| + | get 'jscript.js' => :render_js |
| + | end |
| + | get '*cms_path' => 'cms_content#render_page' |
| + | |
| end | |
migrate/01_create_cms.rb b/db/migrate/01_create_cms.rb
+2
-0
| @@ | @@ -7,6 +7,8 @@ class CreateCms < ActiveRecord::Migration |
| t.integer :parent_id | |
| t.string :label | |
| t.text :content | |
| + | t.text :css |
| + | t.text :js |
| t.integer :position, :null => false, :default => 0 | |
| t.timestamps | |
| end | |
test/fixtures/cms_layouts.yml
+7
-1
| @@ | @@ -1,5 +1,4 @@ |
| default: | |
| - | id: 1 |
| label: Default Layout | |
| parent: | |
| content: |- | |
| @@ | @@ -9,6 +8,13 @@ default: |
| layout_content_b | |
| <cms:snippet:default> | |
| layout_content_c | |
| + | css: |- |
| + | body { background-color: red } |
| + | p { color: #fff } |
| + | js: |- |
| + | $(document).ready(function() { |
| + | alert('O HAI THAR'); |
| + | }) |
| nested: | |
| label: Nested Layout | |
test/functional/cms_content_controller_test.rb
+21
-0
| @@ | @@ -6,4 +6,25 @@ class CmsContentControllerTest < ActionController::TestCase |
| flunk | |
| end | |
| + | def test_render_css |
| + | get :render_css, :id => cms_layouts(:default) |
| + | assert_response :success |
| + | assert_match %r{text\/css}, @response.headers["Content-Type"] |
| + | assert_equal cms_layouts(:default).css, @response.body |
| + | end |
| + | |
| + | def test_render_js |
| + | get :render_js, :id => cms_layouts(:default) |
| + | assert_response :success |
| + | assert_match %r{text\/javascript}, @response.headers["Content-Type"] |
| + | assert_equal cms_layouts(:default).js, @response.body |
| + | end |
| + | |
| + | def test_render_css_and_js_for_nonexistent_layout |
| + | get :render_css, :id => 'bogus' |
| + | assert_response :success |
| + | get :render_js, :id => 'bogus' |
| + | assert_response :success |
| + | end |
| + | |
| end | |