lib/masterview/extras/app/controllers/masterview_controller.rb in masterview-0.2.2 vs lib/masterview/extras/app/controllers/masterview_controller.rb in masterview-0.2.3
- old
+ new
@@ -42,17 +42,28 @@
# We'll have to leave this as an exercise for the user and give
# them tips on how to make it happen.
# [DJL 17-Jun-2006]
#++
#
+
+
class MasterviewController < ApplicationController
before_filter :check_authorization, :except => [ :access_not_allowed ]
+ ENABLE_ADMIN_LAYOUT = false #:nodoc: #UNDER CONSTRUCTION - fine idea, but doesn't work yet [DJL 03-Jun-2006]
+
# Describe the MasterView configuration option settings
def configuration
- render :text => configuration_html, :layout => true
+ if ENABLE_ADMIN_LAYOUT
+ smart_render_with_layout('masterview/admin/configuration', 'masterview_admin')
+ else
+ #ugly, but keep this version
+ aint_got_no_layout_backstop = '<div style="padding-top: 6px;">(back to <a href=".">Admin home</a>)</div>'
+ config_html = MasterView::Info.to_html( :postscript => aint_got_no_layout_backstop )
+ render :text => config_html
+ end
end
def index
redirect_to :action => :list
end
@@ -153,65 +164,10 @@
if ! allow_access?
redirect_to :action => :access_not_allowed
end
end
- # Answer an HTML rendering of the current MasterView configuration
- def configuration_html
- # This is a quick-and-dirty impl until a more elegant solution is provided
- #e.g. do something more like Rails::Info
-
- config = MasterView::ConfigSettings
-
- section_general_options = 'General Options'
- section_specs = [
- # [ <section-name>, [prop-name [, prop-name]... ] ]
- [ 'MasterView Roots',
- [ :mv_installation_dir, :rails_app?, :on_rails? ] ],
- [ section_general_options,
- [ :root_path, :config_dir_path, :environment ] ], #:directive_paths
- [ 'Template Source Options',
- [ :template_src_dir_path, :template_filename_pattern ] ],
- [ 'Template Generation Options',
- [ :template_dst_dir_path, :output_filename_extension, :generated_file_default_extension, :include_generated_file_comment ] ],
- [ 'Template Parsing Options',
- [ :default_parser_options, :namespace_prefix ] ],
- [ 'Rails Application Options',
- [ :parse_masterview_templates_at_startup, :reparse_changed_masterview_templates, :generate_rhtml_files ] ]
- ]
-
- #"<h1>MasterView Configuration</h1>\n<table>\n<tbody>\n#{html}</tbody>\n</table>\n<div style=\"padding-top: 6px;\">(back to <a href=\".\">Admin home</a>)</div>"
- html_config_settings = "<h1>MasterView Configuration</h1>\n<table>\n<tbody>\n%s</tbody>\n</table>\n<div style=\"padding-top: 6px;\">(back to <a href=\".\">Admin home</a>)</div>" % '%s'
-
- #"<tr style=\"background-color: #dcdcdc; font-weight: bold; margin-top: 6px;\"><td colspan=\"2\">#{section_name}</td></tr>"
- html_subsection_entry = '<tr style="background-color: #dcdcdc; font-weight: bold; margin-top: 6px;"><td colspan="2">%s</td></tr>' #parm: section_name
-
- # "<tr><td><b>#{option_name}</b></td><td>#{option_value}</td></tr>"
- html_option_entry = '<tr><td style="padding-left: 6px; padding-right: 6px; font-weight: bold;">%s</td><td>%s</td></tr>' #parms: option_name, option_value
-
- html = []
- section_specs.each { | section_name, options |
- html << html_subsection_entry % section_name
- options.each { | option |
- option_name = CGI.escapeHTML(option.to_s)
- option_value = config.send(option)
- #tbd: option_value.kind_of?(Hash) then make it pretty?
- option_value = option_value.nil? ? '(nil)' : CGI.escapeHTML(option_value.inspect)
- html << html_option_entry % [ option_name, option_value ]
- }
- if section_name == section_general_options
- option_name = 'logger'
- option_value = MasterView::Log.class.name
- html << html_option_entry % [ option_name, option_value ]
- option_name = 'log_level'
- option_value = MasterView.log_level
- html << html_option_entry % [ option_name, option_value ]
- end
- }
- html_config_settings % html.join("\n")
- end
-
private
# checks app path first for views and files, then falls back to files in MV
def find_path(path)
local_path = File.join(RAILS_ROOT, path)
@@ -223,12 +179,43 @@
def smart_render(short_path)
local_path = File.join(RAILS_ROOT, 'app/views', short_path)+'.rhtml'
if File.exist?(local_path)
render :template => short_path
else
- mv_path = File.join(File.dirname(__FILE__), '../../app/views', short_path)+'.rhtml'
- MasterView::Log.debug { 'mv_path='+mv_path }
- render :file => mv_path
+ mv_path = File.join(File.dirname(__FILE__), '../../app/views', short_path)+'.rhtml'
+ MasterView::Log.debug { 'mv_path='+mv_path }
+ render :file => mv_path
+ end
+ end
+
+ # render local template file if exists otherwise render file from mv
+ def smart_render_with_layout(short_path, layout) #:nodoc: #UNDER CONSTRUCTION
+ #DOESN'T WORK YET - we get the right path, but need a way into template rendering
+ # (usual path through rails bolts in assumption of app/views rel path)
+ # [DJL 03-Jul-2006]
+ local_path = File.join(RAILS_ROOT, 'app/views', short_path)+'.rhtml'
+ if File.exist?(local_path)
+ render :template => short_path, :layout => smart_layout_path(layout)
+ else
+ mv_path = File.join(File.dirname(__FILE__), '../../app/views', short_path)+'.rhtml'
+ MasterView::Log.debug { 'mv_path='+mv_path }
+ render :file => mv_path, :layout => smart_layout_path(layout)
+ end
+ end
+
+ def smart_layout_path(short_path) #:nodoc: #UNDER CONSTRUCTION
+ local_path = File.join(RAILS_ROOT, 'app/views/layouts', short_path)+'.rhtml'
+ if File.exist?(local_path)
+ short_path
+ else
+ mv_layouts_dir_path = File.expand_path( File.join(File.dirname(__FILE__), '../../app/views/layouts') )
+ mv_path = File.join(mv_layouts_dir_path, short_path)+'.rhtml'
+ if File.exist?(mv_path)
+ MasterView::Log.debug { 'admin layout mv_path='+mv_path }
+ else
+ MasterView::Log.error { '***BAD ADMIN PAGE LAYOUT REF: mv_path='+mv_path }
+ end
+ mv_path
end
end
end