Class: MasterView::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/masterview/initializer.rb

Overview

A Configuration holds all the configuration settings used the MasterView::Initializer to configure the template engine.

Configuration provides defaults that suit most Rails applications. You can change the default settings in the configuration to customize MasterView with options suitable for your application.

In the most common usage pattern, a Configuration instance initialized with the standard default settings is created implicitly when the Initializer is run, which happens automatically when Masterview is installed as a plugin in a Rails application. Application-specific settings are then loaded from the application’s config directory and used by the Initializer to configure the MasterView template engine for operation.

When using MasterView in a standalone application (i.e., not within rails), it is also possible to create the Configuration instance in advance and pass it in explicitly to the Initializer. This technique can be useful when it is necessary to establish the application root directory location that MasterView uses during its operation or to specify to location of the application’s configuration files.

require 'masterview/initializer'
config = MasterView::Configuration.new( :app_root_path => '/path/to/my/app' )
config.template_src_dir_path = "masterview/templates"
config.template_dst_dir_path = "masterview/output"
#...set other config options...
MasterView::Initializer.run( :process, config )

Constant Summary collapse

OriginalDefaultParserOptions =

These are the original default parser options, whatever is set in the config will be merged with these to arrive at the result. This allows us to easily add new defaults in and even if users empty this hash, the defaults will get added to disable they specifically set something to false or nil

{ :tidy => false, :escape_erb => true, :default_generate => true }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Configuration

Create a new Configuration instance, initialized with the default values.

Optional arguments to the constructor allow for initializing defaults for a rails app when not actually running rails or for initializing defaults for a standalone app with context anchored at some well-defined point in space (other than where we’re actually running).

:app_root_path => path to the root directory of the application
:rails_app_root_path => path to the root directory of a Rails app
:environment => current environment for loading settings

The app_root_path and rails_app_root_path arguments are mutually exclusive. Use rails_app_root_path when operating on a Rails application which isn’t actually running; use app_root_path for a non-rails application.



557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
# File 'lib/masterview/initializer.rb', line 557

def initialize( params={} ) #:nodoc:

  rails_env = (defined?(RAILS_ENV)) ? RAILS_ENV : nil
  # unpack the supported keyword args
  app_root_path = params[:app_root_path]
  rails_app_root_path = params[:rails_app_root_path]
  env = params[:environment] || rails_env
  is_development = env == 'development'

  program_root_path = File.expand_path( '.' )
  #assert program_root_path == Dir.pwd

  debug_TRACE_HACK = false  #temp dev debug tracking for rails vs. non-rails init

  @mv_code_base_dir = File.expand_path( File.dirname(__FILE__) )
  builtin_directives_path = File.join( mv_code_base_dir, 'directives')
  @mv_installation_dir = File.expand_path( "#{File.dirname(__FILE__)}/../.." )
  @auto_copy_file_entries = []

  #ISSUE: should probably also detect std console or breakpointer launch scripts [DJL 10-Jun-2006]
  @rails_runner_scripts_pattern = /server|dispatch|mongrel_rails|cgi|-e/ #cgi picks up scgi and fcgi, -e for RadRails

  @has_rails_context = (defined?(::RAILS_ROOT) != nil)
  decide_if_running_rails

  # only run if auto parsing and when launching server, check if need to update mv files
  # MasterView::ParseMasterViewTemplatesAtStartup
  #ISSUE: what about console and breakpointer scripts?

  if debug_TRACE_HACK
    STDOUT.puts "\n####Initializing MasterView config (default settings)"
    STDOUT.puts "...RAILS_ROOT=#{defined?(::RAILS_ROOT) ? ::RAILS_ROOT : '(undefined)'}"
    STDOUT.puts "...has_rails_context=#{has_rails_context.nil? ? 'nil' : has_rails_context}"
  end

  # establish the fundamental roots for anchoring relative references
  # Scenarios: running a rails app, operating on a rails app but not running it, standalone
  #assert at most one of the two args is supplied, they're mutually exclusive
  if has_rails_context
    @rails_root_path = File.expand_path( ::RAILS_ROOT )
  elsif rails_app_root_path
    @rails_root_path = File.expand_path( rails_app_root_path )
  elsif app_root_path.nil? && looks_like_rails_app?
    # if client hasn't specifically provided an app or rails root anchor parm
    # and we aren't actually launching rails, sniff around and make a good guess
    # at whether this app has the rails structure so we can set proper defaults
    # (e.g., running rake tasks on a rails app)
    # ISSUE: Is this just too clever?  Maybe the rakefile should establish this?
    # [DJL 15-Ajun-2006]
    @rails_root_path = program_root_path
  else
    @rails_root_path = nil
  end
  @rails_views_dir_path = rails_app? ? File.join( rails_root_path, 'app/views' ) : nil
  #if on_rails?
  #  #ISSUE: ActionController::Base.template_root vs. ActionController::Base.view_root???? significant diff??
  #  #assert rails_views_path ==ActionController::Base.template_root
  #end

  if debug_TRACE_HACK
    STDOUT.puts "...rails_app?=#{rails_app? ? 'yes' : 'nope'}"
    STDOUT.puts "...on_rails?=#{on_rails? ? 'yes' : 'nope'}"
  end
  if debug_TRACE_HACK and rails_app?
    STDOUT.puts "...rails_root_path=#{self.rails_root_path}"
    STDOUT.puts "...rails_views_dir_path=#{rails_views_dir_path}"
  end

  # general options - establish the roots to anchor MV in an operating context
  if rails_app?
    self.root_path = self.rails_root_path
  elsif app_root_path
    self.root_path = File.expand_path( app_root_path )
  else
    #ISSUE: add hook here to check for MASTERVIEW_ROOT_PATH or ENV[xxx]???
    self.root_path = program_root_path
  end
  # For a rails app, we have a point of view on where to find config files.
  # A standalone client needs to proactively tell us where to find their settings.
  self.config_dir_path = rails_app? ? "config/masterview" : nil
  self.environment = on_rails? ? ::RAILS_ENV : env
  self.directive_load_path = DirectiveLoadPath::Path.new
  add_directive_path builtin_directives_path, { :use_masterview_namespace => true, }
  discover_standard_directive_path_additions()

  #TODO: if rails_app? && File.exist?( "#{rails_root_path}/app/masterview/directives" ) THEN append it as well
  self.rebuild_backups_tmp_dir_path = rails_app? ? File.join( rails_root_path, 'tmp/masterview/rebuild/backups') : nil
  # use Log4r by default if available, otherwise Logger from standard ruby library
  # find out if Kernel#require will succeed if we try to load Log4R
  log4r_dir = $:.detect { |dir| File.exists?("#{dir}/log4r.rb") }  #? path_contains? predicate somewhere??
  self.logger = log4r_dir ? 'log4r' : 'logger'
  #self.log_level = nil  # use the default level of the logger
  self.log_level = (self.environment == 'development') ? 'INFO' : 'WARN'

  if debug_TRACE_HACK
    STDOUT.puts "...root_path=#{root_path}"
    STDOUT.puts "...config_dir_path=#{config_dir_path || 'nil'}"
    STDOUT.puts "...environment=#{environment || 'nil'}"
    STDOUT.puts "...directive_load_path=[ #{directive_load_path.directory_paths.join(', ')} ]"
  end

  # template source options
  self.template_src_dir_path = rails_app? ? 'app/views' : 'masterview/templates'  # bolts down abs ref
  self.template_filename_pattern = '*.html'
  self.template_asset_base_ref_pattern = {
    :images => /public\/images\/(.*)/,
    :stylesheets => /public\/stylesheets\/(.*)/,
    :javascripts => /public\/javascripts\/(.*)/,
  }

  STDOUT.puts "...template_src_dir_path=#{template_src_dir_path || 'nil'}" if debug_TRACE_HACK

  # template generation options
  self.template_dst_dir_path = rails_app? ? 'app/views' : 'masterview/output'  # bolts down abs ref
  self.output_filename_extension = '.rhtml'
  self.generated_file_default_extension = '.rhtml'
  self.include_generated_file_comment = true
  self.generated_file_comment = <<-END
#    WARNING - This is a generated file created by MasterView.
#    Do not edit - changes will be lost when this file is re-generated.
#
#    To make changes, edit the MasterView source file located at:
  END
  self.generated_file_comment << '#    #{template_path}'  # carefully avoid premature subst eval

  STDOUT.puts "...template_dst_dir_path=#{template_dst_dir_path || 'nil'}" if debug_TRACE_HACK

  # template parsing options
  self.handle_parse_exceptions = true
  self.default_parser_options = OriginalDefaultParserOptions.clone #we'll merge in whatever changes they make over the original set in const above
  # default locations where tidy likely to be found; assume on user's PATH if on Windows
  self.tidy_path = RUBY_PLATFORM =~ /mswin32/ ? 'c:/tidy/lib/tidy.dll' : '/usr/lib/libtidy.so'
  self.namespace_prefix = 'mv:'
  self.namespace_prefix_extensions = 'mvx:'
  self.inline_erb_start = '{{{'
  self.inline_erb_end = '}}}'
  self.inline_erb_substitution_regex = /\{\{\{(([^}]|\}[^}]|\}\}[^}])*)\}\}\}/

  # Rails application options
  self.parse_masterview_templates_at_startup = true
  self.reparse_changed_masterview_templates = (on_rails? && defined?(::ActionController)) ? (not ::ActionController::Base.perform_caching) : false # when in cruise control ActionController was not defined yet
  self.admin_auth_mixin = nil # if defined then this module will be included in MasterView controller
  self.enable_admin_pages = is_development
  self.enable_view_rhtml = is_development
  self.generate_rhtml_files = false

  STDOUT.puts "...mv config initialized with default settings\n" if debug_TRACE_HACK

  self.initialization_messages = []  # for installer validation checking and problem reporting

end

Instance Attribute Details

#admin_auth_mixinObject

Authorization module which will be mixed into MasterView Admin controller to determine whether access should be granted to a user.

The module must implement the method allow_access? which returns a boolean indicating whether access is allowed to the MasterView administration pages. By default, the module name for a custom mixin is MasterViewAdminAuthMixin.

The admin_auth_check mixin is included in an ApplicationController subclass and thus may use any services available to controllers in your application.

Defaults to local machine access only using local_request? check. Automatically installs custom mixin from app/masterview/admin_auth_mixin.rb if available.

To load a different file from app/masterview or use a different module name:

config.admin_auth_mixin =

:file => 'alt_admin_auth_mixin', # module file in #{RAILS_ROOT/app/masterview dir
:module => :AltMasterViewAdminAuthMixin, # default is :MasterViewAdminAuthMixin

}

To load a mixin from the rails app’s lib directory:

config.admin_auth_mixin = {

:file => 'lib/custom/mv_admin_auth_mixin', # module file in rails lib dir
:file_loc => :RAILS_ROOT,  # default location for rel refs is #{RAILS_ROOT}/app/masterview
:module => :CustomMasterViewAdminAuthMixin, # default is :MasterViewAdminAuthMixin

}

see examples/rails_app_admin_auth/admin_auth_mixin.rb for more details



502
503
504
# File 'lib/masterview/initializer.rb', line 502

def admin_auth_mixin
  @admin_auth_mixin
end

#auto_copy_file_entriesObject

Configuration for locations of files that MasterView will autocopy to a runtime location. This autocopy feature makes it easy to have prototypes that display properly for WYSIWYG editing and design, using files (images, stylesheets, and javascript) which are not in the standard Rails locations but are automatically copied to proper place for runtime. This is commonly used in conjunction with template_src_dir_path (which changes the location of the source MasterView templates). Developers can have their templates in a non-standard location along with images, stylesheets, and javascript, and then still have everything copied to the proper runtime locations when Rails is fired up. In debug mode, timestamps are checked on every request, in production mode, copy is done only on startup.

Each entry is a hash that needs to contain :source => ‘path to source folder’ # absolute or relative to RAILS_ROOT :destination => ‘path to place to copy to’ # absolute or relative to RAILS_ROOT

and can optionally have a file extension filter :extensions => [:gif, :GIF, :jpg, :JPG] # limit files copied to this array of extensions, case sensitive

Default: [] (empty array) - nothing is auto copied Example usage showing three paths added to be auto copied: config.auto_copy_file_entries << { :source => ‘path_to_my_images’, :destination => ‘public/images’ } config.auto_copy_file_entries << { :source => ‘path_to_my_scripts’, :destination => ‘public/javascripts’, :extensions => [:js, :JS] } # only copy js files config.auto_copy_file_entries << { :source => ‘path_to_my_css’, :destination => ‘public/stylesheets’ }



315
316
317
# File 'lib/masterview/initializer.rb', line 315

def auto_copy_file_entries
  @auto_copy_file_entries
end

#config_dir_pathObject

Path to the directory containing the application’s MasterView configuration settings files (if any). If no configuration directory or settings files are defined, MasterView runs with the standard default configuration options.

Specified as a relative path from the application’s root_path.

Default: for a Rails application, this is RAILS_ROOT/config/masterview.



139
140
141
# File 'lib/masterview/initializer.rb', line 139

def config_dir_path
  @config_dir_path
end

#default_parser_optionsObject

Default option settings for template parsing (a hash)

:tidy => false - run tidy before parsing (tidy_path must be set if enabled)
:escape_erb => true - escapes <% %> before parsing
:default_generate => true - adds in mv:generate="{template_path}" if none found


394
395
396
# File 'lib/masterview/initializer.rb', line 394

def default_parser_options
  @default_parser_options
end

#directive_load_pathObject

Paths of directories to load directives from.

The directory containing the built-in MasterView directives is installed by default. If the application provides a masterview/directives directory in its root_path, that directory is also automatically added to the directives load path.

A directive load path entry specifiess a directory path from which masterview directives are loaded. Configuration options can optionally be specified to override or extend any .metadata specifications in the directory.

Use add_directive_path to append additional directory path(s) from which to load custom directives.



172
173
174
# File 'lib/masterview/initializer.rb', line 172

def directive_load_path
  @directive_load_path
end

#enable_admin_pagesObject

Enable MasterView admin pages in the rails application.

Enables the masterview admin controller at http://yourappdomain/masterview.

Default: false



509
510
511
# File 'lib/masterview/initializer.rb', line 509

def enable_admin_pages
  @enable_admin_pages
end

#enable_view_rhtmlObject

Enable MasterView admin view rhtml feature

If MasterView admin pages are enabled, then you may set this feature to true and it will allow you to get to the generated rhtml from the MasterView admin page which is especially useful for debugging or understanding how MasterView is interpretting the your templates. When enabled you may click on any of the generated rhtml parts from the list view and it will show you the rhtml that is generated. For security purposes you will probably want this to disable this feature in production (or even better disable admin pages itself). Alternatively there is a rake task called mv:view_rhtml which allows you to see the rhtml from the command line (regardless of this setting).

Default false



523
524
525
# File 'lib/masterview/initializer.rb', line 523

def enable_view_rhtml
  @enable_view_rhtml
end

#environmentObject

The current execution environment, if applicable (e.g., ‘development’, ‘test’, ‘production’).

Used for loading application settings from config directory, if available.

For a Rails application, this is RAILS_ENV.



154
155
156
# File 'lib/masterview/initializer.rb', line 154

def environment
  @environment
end

#generate_rhtml_filesObject

Generate rhtml files if true, rails will load them from there. Otherwise when this setting is false, enable rails app to read rhtml(erb) directly from MasterView cache bypassing the serialization to the file system. Default: false



529
530
531
# File 'lib/masterview/initializer.rb', line 529

def generate_rhtml_files
  @generate_rhtml_files
end

#generated_file_commentObject

Text for generated-file comment inserted in rhtml template output files generated by MasterView.

Standard comment includes the name of the master template file which contains the source to edit.

Variable substitution on the comment text will replace a reference to {template_path} with the pathname of the source template file.



370
371
372
# File 'lib/masterview/initializer.rb', line 370

def generated_file_comment
  @generated_file_comment
end

#generated_file_default_extensionObject

Filename extension to use for generated files if not explicitly specified.

Default: '.rhtml'



348
349
350
# File 'lib/masterview/initializer.rb', line 348

def generated_file_default_extension
  @generated_file_default_extension
end

#handle_parse_exceptionsObject

Specify whether MasterView should handle exceptions when parsing template files.

Exceptions that occur during template parsing are always recorded in the debug log. These are generally problems caused by invalid (x)html in the template.

Set to true to have the template parser catch exceptions and continue processing after logging a problem report.

Set to false to have exceptions raised to the application.

Default: true



388
389
390
# File 'lib/masterview/initializer.rb', line 388

def handle_parse_exceptions
  @handle_parse_exceptions
end

#has_rails_contextObject (readonly)

is RAILS_ROOT defined?



106
107
108
# File 'lib/masterview/initializer.rb', line 106

def has_rails_context
  @has_rails_context
end

#include_generated_file_commentObject

Boolean which controls whether to include a comment in template output files indicating that the file was generated by MasterView.

By default, a warning comment is generated in template output files indicating that the file was generated by MasterView from a template and should not be directly edited, as any changes would be lost when the output file is regenerated.

Default: true



359
360
361
# File 'lib/masterview/initializer.rb', line 359

def include_generated_file_comment
  @include_generated_file_comment
end

#initialization_messagesObject

list of [ :log_level, msg ] pairs for config initialization/validation messages used by the initializer to validate load path and report any problems



539
540
541
# File 'lib/masterview/initializer.rb', line 539

def initialization_messages
  @initialization_messages
end

#inline_erb_endObject

Xhtml safe substitution for ‘%>’in a masterview template NOTE: you must also update inline_erb_substitution_regex if this is changed.

Default: '}}}'



423
424
425
# File 'lib/masterview/initializer.rb', line 423

def inline_erb_end
  @inline_erb_end
end

#inline_erb_startObject

Xhtml-safe substitution for ‘<%’ in a masterview template NOTE: you must also update inline_erb_substitution_regex if this is changed.

Default: '{{{'



417
418
419
# File 'lib/masterview/initializer.rb', line 417

def inline_erb_start
  @inline_erb_start
end

#inline_erb_substitution_regexObject

regex used to find escaped inline_erb markup. Needs to match inline_erb_start and inline_erb_end.



427
428
429
# File 'lib/masterview/initializer.rb', line 427

def inline_erb_substitution_regex
  @inline_erb_substitution_regex
end

#log_levelObject

Logging severity threshold for the logger.

Specify the name of the logging level to use with the configured logger. Standard logging levels in both Log4r and ruby Logger are DEBUG, INFO, WARN, ERROR, FATAL. Other level names depend on the configured logger.

Default: INFO for development, WARN otherwise



231
232
233
# File 'lib/masterview/initializer.rb', line 231

def log_level
  @log_level
end

#loggerObject

Logger which will be used to record debug, warning, and error messages.

Supported loggers:

'log4r' - the Log4r logging library
'logger' - Logger in the ruby standard class library

Default: uses Log4r if available, otherwise a standard ruby Logger.



221
222
223
# File 'lib/masterview/initializer.rb', line 221

def logger
  @logger
end

#mv_code_base_dirObject (readonly)

root directory of MasterView itself and the built-in directives This is lib/masterview w/in the plugin or gem installation directory.



94
95
96
# File 'lib/masterview/initializer.rb', line 94

def mv_code_base_dir
  @mv_code_base_dir
end

#mv_installation_dirObject (readonly)

directory in which the MasterView plugin or gem is installed



90
91
92
# File 'lib/masterview/initializer.rb', line 90

def mv_installation_dir
  @mv_installation_dir
end

#namespace_prefixObject

XML name space prefix for builtin MasterView directive attributes in template html. e.g. mv:generate=“target.rhtml”.

Default: 'mv:'



405
406
407
# File 'lib/masterview/initializer.rb', line 405

def namespace_prefix
  @namespace_prefix
end

#namespace_prefix_extensionsObject

XML name space prefix for MasterView extension directive attributes in template html. e.g. mvx:custom_directive=“foo”.

Default: 'mvx:'



411
412
413
# File 'lib/masterview/initializer.rb', line 411

def namespace_prefix_extensions
  @namespace_prefix_extensions
end

#output_filename_extensionObject

Filename extension to use for generated output files if not explicitly specified in the mv:generate attribute value.

Default: '.rhtml'



343
344
345
# File 'lib/masterview/initializer.rb', line 343

def output_filename_extension
  @output_filename_extension
end

#parse_masterview_templates_at_startupObject

Boolean which specifies whether masterview templates are parsed during initial application startup loading.

Set to false to disable all load-time parsing. Template parsing must be manually triggered when the auto-parse option is disabled.

Default: true



447
448
449
# File 'lib/masterview/initializer.rb', line 447

def parse_masterview_templates_at_startup
  @parse_masterview_templates_at_startup
end

#rails_root_pathObject (readonly)

root directory when operating context is a rails app



97
98
99
# File 'lib/masterview/initializer.rb', line 97

def rails_root_path
  @rails_root_path
end

#rails_runner_scripts_patternObject

RE spec for scripts which are used to launch rails



103
104
105
# File 'lib/masterview/initializer.rb', line 103

def rails_runner_scripts_pattern
  @rails_runner_scripts_pattern
end

#rails_views_dir_pathObject (readonly)

directory in a rails app for views (RAILS_ROOT/app/views)



100
101
102
# File 'lib/masterview/initializer.rb', line 100

def rails_views_dir_path
  @rails_views_dir_path
end

#rebuild_backups_tmp_dir_pathObject

Relative path from root_path of the temp directory used for creating backup files before rebuilding/updating a template file.

Set to nil to suppress backups.

Default: RAILS_ROOT/tmp/masterview/rebuild/backups – ISSUE: change this to use IOMgr mapping, how best to do this config?? Leave existing mechanism here, but drop out of documentation and examples until resolved ++



212
213
214
# File 'lib/masterview/initializer.rb', line 212

def rebuild_backups_tmp_dir_path
  @rebuild_backups_tmp_dir_path
end

#reparse_changed_masterview_templatesObject

Boolean which determines whether masterview templates are automatically reparsed if the template changes after initial application loading.

Set to true to monitor masterview templates for file system changes during Rails request dispatching.

Set to false to disable changed-template monitoring. Template parsing must be manually triggered when the auto-parse option is disabled.

This option is only supported when running as part of a Rails application. It is enabled by default in the standard Rails development configuration (parse_masterview_templates_at_startup is enabled and ActionController::Base.perform_caching is false so that changed classes are dynamically reloaded during request dispatching).

Automatic change-detection and reparsing of masterview templates is disabled by default in the usual Rails configuration for production mode (ActionController::Base.perform_caching is on to enable loaded class caching).

Default: true if parse_masterview_templates_at_startup is enabled and ActionController is reloading changed classes (no caching)



470
471
472
# File 'lib/masterview/initializer.rb', line 470

def reparse_changed_masterview_templates
  @reparse_changed_masterview_templates
end

#root_pathObject

Path to the root location for the application. Used for resolving relative references.

For a rails application, this is RAILS_ROOT.



128
129
130
# File 'lib/masterview/initializer.rb', line 128

def root_path
  @root_path
end

#running_railsObject

Set to indicate that we’re actually running the rails app (server or console…)



114
115
116
# File 'lib/masterview/initializer.rb', line 114

def running_rails
  @running_rails
end

#template_asset_base_ref_patternObject

Regex pattern specifications for identifying the base directory on asset references in a template document to convert design-time assert references for images, stylesheets, and javascript files into relative references for use with the standard Rails asset helper functions.

The patterns are a hash indexed by asset type. Asset types are :images, :stylesheets, :javascripts

The standard patterns match path prefixes up through public/asset-type. For example, an mv:stylesheet_link directive of the form:

<link rel="stylesheet" type="text/css" href="../../../public/stylesheets/mystyles.css" mv:stylesheet_link="" />

would match the standard base-dir prefix and result in:

<%= stylesheet_link_tag "mystyles" %>


291
292
293
# File 'lib/masterview/initializer.rb', line 291

def template_asset_base_ref_pattern
  @template_asset_base_ref_pattern
end

#template_dst_dir_pathObject

Path to the directory where Masterview template output (rhtml) will be generated.

Assign the value as a relative path from the application’s root_path or use the template_dst_dir_abs_path method to specify an absolute path.

Default: RAILS_ROOT/app/views



327
328
329
# File 'lib/masterview/initializer.rb', line 327

def template_dst_dir_path
  @template_dst_dir_path
end

#template_filename_patternObject

Filename pattern for masterview template files within the template source directory.

Default: '*.html'



270
271
272
# File 'lib/masterview/initializer.rb', line 270

def template_filename_pattern
  @template_filename_pattern
end

#template_src_dir_pathObject

Path to the directory where masterview templates are located.

Assign the value as a relative path from the application’s root_path or use the template_src_dir_abs_path method to specify an absolute path.

Default: RAILS_ROOT/app/views for a rails application or {root_path}/masterview/templates for a non-rails application.



254
255
256
# File 'lib/masterview/initializer.rb', line 254

def template_src_dir_path
  @template_src_dir_path
end

#tidy_pathObject

Path on this system to tidy library if :tidy parser option is enabled so that masterview templates will be run through tidy before being parsed. Allows invalid xhmtl to be corrected before masterview template parsing is performed.



399
400
401
# File 'lib/masterview/initializer.rb', line 399

def tidy_path
  @tidy_path
end

#use_original_rexml_sax2parserObject

boolean to specify whether to use the original (unpatched) rexml sax2parser. If this is not true and the REXML version is 3.1.4 -3.1.6 MasterView will use a patched version of rexml sax2parser which properly handles doctypes. If this is true or the REXML version is outside this range the original sax2 parser will be used

Default: false



436
437
438
# File 'lib/masterview/initializer.rb', line 436

def use_original_rexml_sax2parser
  @use_original_rexml_sax2parser
end

Instance Method Details

#add_directive_path(dir_path, options = nil) ⇒ Object

Add an entry to the directive_load_path list for a directory containing directive implementation classes to be loaded into the MasterView processing configuration.

Optionally specify options for the directives loaded from this directory:

:default - metadata defaults

Metadata defaults extend or override any defaults specified in the dir_path/.metadata file, if defined, allowing application customization of the default defaults.



197
198
199
# File 'lib/masterview/initializer.rb', line 197

def add_directive_path(dir_path, options=nil)
  directive_load_path << DirectiveLoadPath::PathEntry.new( dir_path, options )
end

#add_plugin_directives(*base_paths) ⇒ Object

Add masterview directive implementations from plugins to the masterview directive load path

EXPERIMENTAL PROTOTYPE - NOT YET PUBLICIZED [DJL 13-Feb-2007]



754
755
756
757
758
759
760
761
# File 'lib/masterview/initializer.rb', line 754

def add_plugin_directives(*base_paths) #:nodo:
  # append plugin directives in alphabetical order, per Rails plugin loading
  plugin_directives = find_plugin_directives(base_paths)
  plugin_directives.each { | plugin_dir_path |
    add_directive_path plugin_dir_path
  }
  plugin_directives
end

#after_initialize(&after_initialize_block) ⇒ Object

Sets a block which will be executed after MasterView has been fully initialized. Useful for per-environment configuration which depends on the plugin being fully initialized.



236
237
238
# File 'lib/masterview/initializer.rb', line 236

def after_initialize(&after_initialize_block)
  @after_initialize_block = after_initialize_block
end

#after_initialize_blockObject

Returns the block set in Configuration#after_initialize



241
242
243
# File 'lib/masterview/initializer.rb', line 241

def after_initialize_block
  @after_initialize_block
end

#app_settings_pathObject

The path to the application’s config settings file. By default the file is at config/masterview/settings.rb.



740
741
742
# File 'lib/masterview/initializer.rb', line 740

def app_settings_path
  config_dir_path ? "#{config_dir_path}/settings.rb" : nil
end

#decide_if_running_railsObject

:nodoc:



709
710
711
712
713
714
715
716
# File 'lib/masterview/initializer.rb', line 709

def decide_if_running_rails #:nodoc:
  #old way using program name except that this needs to be maintained
  @running_rails = has_rails_context && ($PROGRAM_NAME =~ rails_runner_scripts_pattern) != nil

  # TODO could try checking if things are defined instead but what would we check for?? Something related to Dispatcher?
  # Dispatcher doesn't seemed to be defined when we come through here
  # @running_rails = has_rails_context && (defined?(::Dispatcher.dispatch)) != nil
end

#directive_pathsObject

Deprecated - use directive_load_path



175
176
177
# File 'lib/masterview/initializer.rb', line 175

def directive_paths
  @directive_load_path
end

#discover_standard_directive_path_additionsObject

automatically append directives in std app dir to mv builtins, if available



728
729
730
731
732
733
734
735
736
# File 'lib/masterview/initializer.rb', line 728

def discover_standard_directive_path_additions() #:nodoc:
  return if ! rails_app?  #?or can we take a point of view of std loc? e.g., 'masterview/directives'
  app_directives_path = rails_app? ? "app/masterview/directives" : nil #??"masterview/directives"?
  app_directives_path = File.join( root_path, app_directives_path )
  if File.directory?(app_directives_path)  #?and not empty?
    #{ :use_masterview_namespace => false, }
    add_directive_path app_directives_path  #root_path already expanded
  end
end

#environment_settings_pathObject

The path to the current environment’s settings file (development.rb, etc.). By default the file is at config/masterview/environments/{environment}.rb.



746
747
748
# File 'lib/masterview/initializer.rb', line 746

def environment_settings_path
  (config_dir_path && environment) ? "#{config_dir_path}/environments/#{environment}.rb" : nil
end

#looks_like_rails_app?Boolean

see if this app has the std file structure that indicates a rails application

Returns:

  • (Boolean)


719
720
721
722
723
724
725
# File 'lib/masterview/initializer.rb', line 719

def looks_like_rails_app? #:nodoc:
  std_rails_directories = [ 'app', 'config', 'public' ]
  std_rails_directories.each { | dir_path |
    return if ! File.directory?(dir_path)
  }
  true
end

#on_rails?Boolean

are we actually running rails when our root is a rails app?

Returns:

  • (Boolean)


117
118
119
# File 'lib/masterview/initializer.rb', line 117

def on_rails? #:nodoc:
  @running_rails
end

#rails_app?Boolean

is the root a rails app?

Returns:

  • (Boolean)


109
110
111
# File 'lib/masterview/initializer.rb', line 109

def rails_app? #:nodoc:
  @rails_root_path != nil
end

#template_dst_dir_abs_path(abs_path) ⇒ Object

Specify the absolute path to the directory where masterview template output is generated.



335
336
337
# File 'lib/masterview/initializer.rb', line 335

def template_dst_dir_abs_path(abs_path)
  @template_dst_dir_path = abs_path
end

#template_src_dir_abs_path(abs_path) ⇒ Object

Specify the absolute path to the directory where masterview templates are located.



262
263
264
# File 'lib/masterview/initializer.rb', line 262

def template_src_dir_abs_path(abs_path)
  @template_src_dir_path = abs_path
end