Added CmsAdmin:Snippets controller functions.
Hesham E
committed Aug 18, 2010
commit f3c0643a19b03776a404fda29860994f08d7753a
Showing 18
changed files with
166 additions
and 16 deletions
Gemfile
+1
-0
| @@ | @@ -6,6 +6,7 @@ gem 'rails', '3.0.0.rc' |
| # gem 'rails', :git => 'git://github.com/rails/rails.git' | |
| gem 'sqlite3-ruby', :require => 'sqlite3' | |
| + | gem 'haml' |
| # Use unicorn as the web server | |
| # gem 'unicorn' | |
app/controllers/cms_admin/base_controller.rb
+4
-0
| @@ | @@ -0,0 +1,4 @@ |
| + | class CmsAdmin::BaseController < ApplicationController |
| + | layout 'cms_admin' |
| + | |
| + | end |
app/controllers/cms_admin/layouts_controller.rb
+2
-0
| @@ | @@ -0,0 +1,2 @@ |
| + | class CmsAdmin::LayoutsController < CmsAdmin::BaseController |
| + | end |
app/controllers/cms_admin/pages_controller.rb
+2
-0
| @@ | @@ -0,0 +1,2 @@ |
| + | class CmsAdmin::PagesController < CmsAdmin::BaseController |
| + | end |
app/controllers/cms_admin/snippets_controller.rb
+49
-0
| @@ | @@ -0,0 +1,49 @@ |
| + | class CmsAdmin::SnippetsController < CmsAdmin::BaseController |
| + | before_filter :load_cms_snippet, |
| + | :only => [:edit, :update, :destroy] |
| + | before_filter :build_cms_snippet, |
| + | :only => [:new, :create] |
| + | |
| + | def index |
| + | @cms_snippets = CmsSnippet.all |
| + | end |
| + | |
| + | def new |
| + | # ... |
| + | end |
| + | |
| + | def edit |
| + | # ... |
| + | end |
| + | |
| + | def create |
| + | @cms_snippet.save! |
| + | redirect_to [:cms_admin, :snippets], :notice => 'Snippet created' |
| + | rescue ActiveRecord::RecordInvalid |
| + | render :action => :new |
| + | end |
| + | |
| + | def update |
| + | @cms_snippet.update_attributes!(params[:cms_snippet]) |
| + | redirect_to [:cms_admin, :snippets], :notice => 'Snippet updated' |
| + | rescue ActiveRecord::RecordInvalid |
| + | render :action => :edit |
| + | end |
| + | |
| + | def destroy |
| + | @cms_snippet.destroy |
| + | redirect_to [:cms_admin, :snippets], :notice => 'Snippet removed' |
| + | end |
| + | |
| + | protected |
| + | def load_cms_snippet |
| + | @cms_snippet = CmsSnippet.find(params[:id]) |
| + | rescue ActiveRecord::RecordNotFound |
| + | render_not_found |
| + | end |
| + | |
| + | def build_cms_snippet |
| + | params[:cms_snippet] ||= { } |
| + | @cms_snippet = CmsSnippet.new(params[:cms_snippet]) |
| + | end |
| + | end |
app/controllers/cms_content_controller.rb
+1
-1
| @@ | @@ -1,7 +1,7 @@ |
| class CmsContentController < ApplicationController | |
| def show | |
| - | render :text => 'Hello World!' |
| + | render :inline => '<h1>Hello World!</h1>' |
| end | |
| end | |
app/models/cms_snippet.rb
+4
-0
| @@ | @@ -12,5 +12,9 @@ class CmsSnippet < ActiveRecord::Base |
| def self.content_for(label) | |
| (s = find_by_label(label)) ? s.content : '' | |
| end | |
| + | |
| + | # -- Scopes --------------------------------------------------------------- |
| + | |
| + | default_scope :order => 'label' |
| end | |
app/views/cms_admin/snippets/_form.html.haml
+0
-0
app/views/cms_admin/snippets/edit.html.haml
+0
-0
app/views/cms_admin/snippets/index.html.haml
+0
-0
app/views/cms_admin/snippets/new.html.haml
+0
-0
app/views/layouts/cms_admin.html.haml
+9
-13
| @@ | @@ -1,14 +1,10 @@ |
| - | <!DOCTYPE html> |
| - | <html> |
| - | <head> |
| - | <title>ComfortableMexicanSofa</title> |
| - | <%= stylesheet_link_tag :all %> |
| - | <%= javascript_include_tag :defaults %> |
| - | <%= csrf_meta_tag %> |
| - | </head> |
| - | <body> |
| + | !!! 5 |
| + | %head |
| + | %title ComfortableMexicanSofa |
| + | %meta{ 'http-equiv'=>"Content-Type", :content=>"text/html;charset=utf-8"} |
| + | = stylesheet_link_tag :all |
| + | = javascript_include_tag :defaults |
| + | = csrf_meta_tag |
| - | <%= yield %> |
| - | |
| - | </body> |
| - | </html> |
| + | %body |
| + | = yield |
| \ No newline at end of file | |
config/application.rb
+1
-1
| @@ | @@ -31,7 +31,7 @@ module ComfortableMexicanSofa |
| # config.i18n.default_locale = :de | |
| # JavaScript files you want as :defaults (application.js is always included). | |
| - | # config.action_view.javascript_expansions[:defaults] = %w(jquery rails) |
| + | config.action_view.javascript_expansions[:defaults] = %w(jquery rails) |
| # Configure the default encoding used in templates for Ruby 1.9. | |
| config.encoding = "utf-8" | |
config/routes.rb
+5
-1
| @@ | @@ -1,5 +1,9 @@ |
| ComfortableMexicanSofa::Application.routes.draw do | |
| + | namespace :cms_admin, :path => 'cms-admin' do |
| + | resources :layouts, :pages, :snippets, :assets |
| + | end |
| + | |
| # Catch-all route | |
| - | match '*path' => 'cms_content#show' |
| + | match '*path' => 'cms_content#show', :via => :get |
| end | |
test/functional/cms_admin/base_controller_test.rb
+8
-0
| @@ | @@ -0,0 +1,8 @@ |
| + | require 'test_helper' |
| + | |
| + | class CmsAdmin::BaseControllerTest < ActionController::TestCase |
| + | # Replace this with your real tests. |
| + | test "the truth" do |
| + | assert true |
| + | end |
| + | end |
test/functional/cms_admin/layouts_controller_test.rb
+8
-0
| @@ | @@ -0,0 +1,8 @@ |
| + | require 'test_helper' |
| + | |
| + | class CmsAdmin::LayoutsControllerTest < ActionController::TestCase |
| + | # Replace this with your real tests. |
| + | test "the truth" do |
| + | assert true |
| + | end |
| + | end |
test/functional/cms_admin/pages_controller_test.rb
+8
-0
| @@ | @@ -0,0 +1,8 @@ |
| + | require 'test_helper' |
| + | |
| + | class CmsAdmin::PagesControllerTest < ActionController::TestCase |
| + | # Replace this with your real tests. |
| + | test "the truth" do |
| + | assert true |
| + | end |
| + | end |
test/functional/cms_admin/snippets_controller_test.rb
+64
-0
| @@ | @@ -0,0 +1,64 @@ |
| + | require 'test_helper' |
| + | |
| + | class CmsAdmin::SnippetsControllerTest < ActionController::TestCase |
| + | |
| + | def setup |
| + | #http_auth |
| + | end |
| + | |
| + | def test_get_index |
| + | get :index |
| + | assert_response :success |
| + | assert assigns(:cms_snippets) |
| + | end |
| + | |
| + | def test_get_new |
| + | get :new |
| + | assert_response :success |
| + | end |
| + | |
| + | def test_create |
| + | assert_difference 'CmsSnippet.count' do |
| + | post :create, :cms_snippet => cms_snippet_params |
| + | assert_redirected_to [:cms_admin, :snippets] |
| + | assert_equal 'Snippet created', flash[:notice] |
| + | end |
| + | end |
| + | |
| + | def test_get_edit |
| + | get :edit, :id => cms_snippets(:default) |
| + | assert_response :success |
| + | assert assigns(:cms_snippet) |
| + | end |
| + | |
| + | def test_update |
| + | snippet = cms_snippets(:default) |
| + | |
| + | put :update, :id => snippet, :cms_snippet => { |
| + | :label => 'new_test_label', |
| + | :content => 'new test content' |
| + | } |
| + | assert_redirected_to [:cms_admin, :snippets] |
| + | assert_equal 'Snippet updated', flash[:notice] |
| + | |
| + | snippet.reload |
| + | assert_equal 'new_test_label', snippet.label |
| + | assert_equal 'new test content', snippet.content |
| + | end |
| + | |
| + | def test_destroy |
| + | assert_difference 'CmsSnippet.count', -1 do |
| + | delete :destroy, :id => cms_snippets(:default) |
| + | assert_redirected_to [:cms_admin, :snippets] |
| + | assert_equal 'Snippet removed', flash[:notice] |
| + | end |
| + | end |
| + | |
| + | private |
| + | def cms_snippet_params(options = {}) |
| + | { |
| + | :label => 'test_snippet', |
| + | :content => 'test content' |
| + | }.merge(options) |
| + | end |
| + | end |