Class: MasterviewController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- MasterviewController
- Includes:
- MasterView::MIO::DefaultGenerateMIOFilter, MasterView::MasterViewAdminAuthMixin
- Defined in:
- lib/masterview/extras/app/controllers/masterview_controller.rb
Constant Summary collapse
- MV_ADMIN_INSTALL_DIR =
layout ‘masterview_admin’
File.( File.join(File.dirname(__FILE__), '../..') )
- FILE_LOC_APP =
CONTEXT_REF_VIEW = ‘app/views’ CONTEXT_REF_LAYOUT = ‘app/views/layout’
'app'
- FILE_LOC_MV =
:nodoc:
'mv'
Instance Method Summary collapse
-
#configuration ⇒ Object
Describe the MasterView configuration option settings.
-
#create ⇒ Object
Create a new, empty template.
-
#directives ⇒ Object
Describe the installed set of MasterView directives (builtin and addons).
-
#features ⇒ Object
Describe the installed set of MasterView features.
-
#index ⇒ Object
:nodoc:.
-
#interact ⇒ Object
interactive template editor - parse template source and show generated output.
-
#list ⇒ Object
List the templates in the application and their status.
-
#rebuild ⇒ Object
Rebuild a specific template.
-
#rebuild_all ⇒ Object
Rebuild all templates in the application.
-
#view_rhtml ⇒ Object
View the generated rhtml.
Methods included from MasterView::MIO::DefaultGenerateMIOFilter
#add_default_gen_if_needed, #read
Instance Method Details
#configuration ⇒ Object
Describe the MasterView configuration option settings
78 79 80 |
# File 'lib/masterview/extras/app/controllers/masterview_controller.rb', line 78 def configuration masterview_render_with_layout( 'masterview/admin/configuration', 'masterview_admin_config' ) end |
#create ⇒ Object
Create a new, empty template. Invoked from the main masterview admin page.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/masterview/extras/app/controllers/masterview_controller.rb', line 126 def create if request.post? action_to_create = params[:action_name] src_file = params[:file] empty_file_path = find_path('app/views/masterview/admin/empty.rhtml') empty_insert_erb = File.readlines(empty_file_path).join dst_file = MasterView::TemplateSpec.create_empty_shell_for_action(src_file, action_to_create, empty_insert_erb, :write_to_file => true) flash[:notice] = dst_file+' was created' redirect_to :action => :list else smart_render 'masterview/admin/create' end end |
#directives ⇒ Object
Describe the installed set of MasterView directives (builtin and addons)
83 84 85 |
# File 'lib/masterview/extras/app/controllers/masterview_controller.rb', line 83 def directives masterview_render_with_layout( 'masterview/admin/directives', 'masterview_admin_config' ) end |
#features ⇒ Object
Describe the installed set of MasterView features
88 89 90 |
# File 'lib/masterview/extras/app/controllers/masterview_controller.rb', line 88 def features masterview_render_with_layout( 'masterview/admin/features', 'masterview_admin_config' ) end |
#index ⇒ Object
:nodoc:
62 63 64 |
# File 'lib/masterview/extras/app/controllers/masterview_controller.rb', line 62 def index redirect_to :action => :list end |
#interact ⇒ Object
interactive template editor - parse template source and show generated output
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/masterview/extras/app/controllers/masterview_controller.rb', line 154 def interact @results = [] @src = params[:src] if @src begin sh_mio = MasterView::MIO::StringHashMIOTree.new({}, MasterView::ConfigSettings.generated_file_default_extension ) src_with_default_gen = add_default_gen_if_needed(@src) # apply a default generate MasterView::Parser.parse( src_with_default_gen, { :output_mio_tree => sh_mio, :omit_comment => true, :template_pathname => 'YOUR_TEMPLATE_PATH_HERE', :rescue_exceptions => false } ) @results = sh_mio.string_hash.sort.collect do |file,rhtml| os = OpenStruct.new os.file = file os.rhtml = rhtml os end rescue REXML::ParseException => e @error_message = e.to_s end end smart_render 'masterview/admin/interact' end |
#list ⇒ Object
List the templates in the application and their status. Provide operations to force rebuild (reparse and regenerate) of specific templates or all templates and create utility to …mumble…
71 72 73 74 75 |
# File 'lib/masterview/extras/app/controllers/masterview_controller.rb', line 71 def list template_specs, content_hash = MasterView::TemplateSpec.scan @template_specs_sorted = template_specs.sort masterview_render_with_layout( 'masterview/admin/list', 'masterview_admin' ) end |
#rebuild ⇒ Object
Rebuild a specific template. Invoked from the main masterview admin page.
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/masterview/extras/app/controllers/masterview_controller.rb', line 111 def rebuild path = params[:file] template_specs, content_hash = MasterView::TemplateSpec.scan template_spec = template_specs[path] raise 'Template '+path+' not found' unless template_spec if template_spec.rebuild_template(content_hash, :write_to_file => true) flash[:notice] = 'File '+path+' updated' else flash[:notice] = 'Identical content - no update needed for '+path end redirect_to :action => :list end |
#rebuild_all ⇒ Object
Rebuild all templates in the application. Invoked from the main masterview admin page.
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/masterview/extras/app/controllers/masterview_controller.rb', line 95 def rebuild_all files_rebuilt = [] MasterView::TemplateSpec.scan do |template_spec, content_hash| if template_spec.status == MasterView::TemplateSpec::Status::ImportsOutdated && template_spec.rebuild_template(content_hash, :write_to_file => true) files_rebuilt << template_spec.path end end unless files_rebuilt.empty? flash[:notice] = files_rebuilt.join(', ')+' were updated' end redirect_to :action => :list end |
#view_rhtml ⇒ Object
View the generated rhtml
143 144 145 146 147 148 149 150 151 |
# File 'lib/masterview/extras/app/controllers/masterview_controller.rb', line 143 def view_rhtml raise "View RHTML is disabled. Edit your config/masterview/settings.rb (or config/masterview/environments/xxxx.rb) file and set config.enable_view_rhtml = true. Restart application for change to take effect." unless MasterView::EnableMasterViewAdminViewRHTML @rhtml_file = params[:file] raise "RHTML file not specified" unless @rhtml_file f = MasterView::IOMgr.erb.path(@rhtml_file) raise "RHTML file ("+@rhtml_file+") not found. Maybe automatic parsing is disabled. You may invoke parsing manually by using rake mv:parse" unless f.exist? @rhtml_content = f.read smart_render 'masterview/admin/view_rhtml' end |