Permalink
Browse files

add model and controller for saving the used-editable layout to a file

  • Loading branch information...
1 parent 3024603 commit 8c5db1e68511ae49069c35193375566d6b966f1d @timriley committed Aug 11, 2008
@@ -0,0 +1,19 @@
+class Admin::ThemesController < Admin::AdminController
+ def show
+ @theme = Theme.instance
+ end
+
+ def update
+ @theme = Theme.instance
+ @theme.template = params[:theme][:template]
+
+ respond_to do |format|
+ if @theme.save
+ flash[:notice] = 'Theme saved'
+ format.html { redirect_to admin_theme_path }
+ else
+ format.html { render :action => 'show'}
+ end
+ end
+ end
+end
@@ -0,0 +1,2 @@
+module Admin::ThemesHelper
+end
View
@@ -0,0 +1,28 @@
+class Theme
+ include Singleton
+ include Validatable
+
+ THEME_FILE = "#{Rails.root}/config/template.txt"
+
+ attr_accessor :template
+
+ validates_presence_of :template
+
+ def initialize
+ @template = File.read(THEME_FILE) rescue ''
+ end
+
+ def save
+ backup_file
+ File.open(THEME_FILE) do |file|
+ file.write(@template)
+ file.flush
+ end
+ end
+
+ protected
+
+ def backup_file
+ FileUtils.cp_r THEME_FILE, "#{THEME_FILE}~"
+ end
+end
@@ -0,0 +1,13 @@
+- if flash[:notice]
+ %p= flash[:notice]
+
+- form_for :theme, @theme, :url => admin_theme_path, :html => {:method => :put} do |f|
+ %p
+ = f.label :template, 'Template'
+ %br
+ = f.text_area :template
+
+ %p
+ = f.submit 'Save'
+ or
+ = link_to 'Cancel', admin_theme_path
@@ -5,8 +5,7 @@
%ul#navigation
/ need a different call for a route that is the root for the namespace
%li= link_to_unless(current_page?(:controller => 'admin/updates') || controller.request.request_uri =~ /\/admin$/, 'photo updates', admin_updates_path)
- %li
- %a{:href => '#'} theme
+ %li= link_to_unless_current 'theme', admin_theme_path
%li= link_to_unless_current 'settings', admin_settings_path
%li= link_to 'logout', admin_logout_path
View
@@ -5,6 +5,7 @@
map.namespace :admin do |admin|
admin.resources :updates
admin.resource :settings
+ admin.resource :theme
admin.resource :login
admin.logout '/logout', :controller => 'logins', :action => 'destroy'
admin.root :controller => 'updates', :action => 'index'
@@ -0,0 +1,10 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe Admin::ThemesController do
+
+ #Delete this example and add some real ones
+ it "should use Admin::ThemesController" do
+ controller.should be_an_instance_of(Admin::ThemesController)
+ end
+
+end
@@ -0,0 +1,11 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe Admin::ThemeHelper do
+
+ #Delete this example and add some real ones or delete this file
+ it "should include the Admin::ThemeHelper" do
+ included_modules = self.metaclass.send :included_modules
+ included_modules.should include(Admin::ThemeHelper)
+ end
+
+end

0 comments on commit 8c5db1e

Please sign in to comment.