Module: MasterView::MIO::DefaultGenerateMIOFilter
- Included in:
- MasterviewController
- Defined in:
- lib/masterview/io.rb
Overview
checks to see that mv:generate or mv:gen_partial has been used somewhere in file and if not then it puts in a default mv:generate directive based on the following logic. If a body tag exists then add the mv:generate directive to the body tag and also add a mv:omit_tag=“” directive. This is based on the assumption that we are body will be defined in a layout somewhere so we are only interested in the internal content of it (excluding the body tag itself). If a body tag does not exist, then simply add the mv:generate tag to the root element.
Examples: <html><body>Hello world</body></html> becomes <html><body mv:generate=“template_path” mv:omit_tag=“”>Hello world</body></html>
<div>Hello</div> becomes <div mv:generate=“template_path”>Hello</div>
Instance Method Summary collapse
-
#add_default_gen_if_needed(content) ⇒ Object
do the actual insertion of generate directive if not found.
- #read(options = {}) ⇒ Object
Instance Method Details
#add_default_gen_if_needed(content) ⇒ Object
do the actual insertion of generate directive if not found
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
# File 'lib/masterview/io.rb', line 379 def add_default_gen_if_needed(content) # building this right before needed in case the Namespace was changed during initialize mv_ns = DirectiveRegistry.current.mv_namespace_prefix @@generate_gen_partial_search_regex ||= Regexp.new( '\s'+mv_ns+'(generate=|gen_partial=)' ) # these are the directives that will be used for body and no body cases @@generate_body_directives ||= mv_ns+'generate="{template_path}" '+mv_ns+'omit_tag=""' @@generate_non_body_directives ||= mv_ns+'generate="{template_path}"' unless content =~ @@generate_gen_partial_search_regex Log.debug { "no generate or gen_partial directives found, DefaultGenerateFilter is adding generate=\"{template_path}\"" } content = content.clone # leave original alone unless content.sub!( /<body/i ){ |x| x+' '+@@generate_body_directives } # unless we found body tag and substituted content.sub!( /<\w+/ ){ |x| x+' '+@@generate_non_body_directives } end end content end |
#read(options = {}) ⇒ Object
373 374 375 376 |
# File 'lib/masterview/io.rb', line 373 def read(={}) content = super add_default_gen_if_needed(content) end |