masterview 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,4 +1,12 @@
1
- 0.2.4
1
+ 0.2.5 - August 19th, 2006
2
+ Added default generate filter which will add in a default generate directive if none is found in template
3
+ Changed default_parser_options to be merged in with original set rather than to be absolute replacement
4
+ Corrected example settings.rb win32 tidy_path to point to tidy.dll not tidy.exe.
5
+ Fix AdminPage compatibility with Rails 1.1.5+ which uses safe_load_paths to find controllers
6
+ Fix rake mv:view_rhtml RHTML=foo/_bar.rhtml was not able to find partials
7
+ Fix rails environment not being passed into configuration
8
+
9
+ 0.2.4 - July 26, 2006
2
10
  Added interactive render to admin pages with example templates
3
11
  Fixed problem where apache2 with scgi was failing to initialize MasterView
4
12
  Updated documentation.
data/RELEASE_NOTES CHANGED
@@ -1,4 +1,19 @@
1
- = MasterView - Rails-optimized (x)html friendly template engine
1
+ = MasterView - Rails-optimized (x)html friendly template engine
2
+
3
+ == Recent changes (Release 0.2.5)
4
+ Fix AdminPage compatibility with Rails 1.1.5+ which uses safe_load_paths to find controllers
5
+ Fix rake mv:view_rhtml RHTML=foo/_bar.rhtml was not able to find partials
6
+ Fix rails environment not being passed into configuration
7
+ Added default generate filter which will add in a default generate directive if none is found in template
8
+ Changed default_parser_options to be merged in with original set rather than to be absolute replacement
9
+ Corrected example settings.rb win32 tidy_path to point to tidy.dll not tidy.exe.
10
+
11
+
12
+ == Recent changes (Release 0.2.4)
13
+ Maintenance release to add scgi support for MasterView.
14
+ Also introduced interactive template page to admin pages allowing
15
+ template html to be tested in MasterView showing the rendered
16
+ rhtml.
2
17
 
3
18
  == Recent changes (Release 0.2.3)
4
19
 
data/TODO CHANGED
@@ -3,6 +3,7 @@
3
3
  - create namespace for mv and publish, update generated files
4
4
  - more videos
5
5
  - allow multiple namespace prefixes for directives (allow custom directives to declare their own namespace)
6
+ - publish .xsd namespace definition for builtin directives to enable xhmtl docs using mv markup to validate
6
7
  - wiki for site
7
8
  - render from db
8
9
  - app for syntax
@@ -33,6 +34,8 @@
33
34
 
34
35
  --####################
35
36
 
37
+ - make tidy installation easier
38
+
36
39
  DSL for creating directives
37
40
  maybe something like
38
41
 
@@ -387,6 +387,13 @@ with the pathname of the source template file.
387
387
  <td class="description">Escape <code>&lt;%&nbsp;%&gt;</code> before parsing</td>
388
388
  </tr>
389
389
  <tr>
390
+ <td>&nbsp;</td>
391
+ <td class="default"><b>:default_generate</b> => true</td>
392
+ <td class="description">Ensure that a mv:generate or mv:gen_partial is present in a template,
393
+ otherwise add a mv:generate="{template_path}" to the body tag if one is present or the root
394
+ element. If a body tag is present and mv:generate is being added then also add mv:omit_tag="".</td>
395
+ </tr>
396
+ <tr>
390
397
  <td class="setting">tidy_path</td>
391
398
  <td class="default">&nbsp;</td>
392
399
  <td class="description">Path on this system to tidy library if <b>:tidy</b> parser option is enabled so that masterview templates will be run through tidy before being parsed.</td>
data/doc/directives.html CHANGED
@@ -86,6 +86,18 @@ it's relative path within the Rails <code>app/views</code> directory in the
86
86
  directive markup in the template.
87
87
  </p>
88
88
 
89
+ <h3>Default generation (output)</h3>
90
+ <p>
91
+ Typically MasterView template files will contain mv:generate or mv:gen_partial directives
92
+ to tell MasterView where to output the rendered rhtml. However if none are found in the template
93
+ file, MasterView will automatically add in a mv:generate="{template_path}" to the body tag
94
+ if found otherwise the root element. Additionally if MasterView was adding this to the body tag,
95
+ it will add in a mv:omit_tag="" which will prevent the body tag from being included in the generated
96
+ output. If you wish to disable this default generate mechanism, set the
97
+ config.default_parser_options[:default_generate] = false in your masterview settings or
98
+ environments files.
99
+ </p>
100
+
89
101
 
90
102
  <h2>Directives Summary</h2>
91
103
  <table class="toc" summary="summary of directives, grouped by functional area">
@@ -44,7 +44,7 @@
44
44
  #config.handle_parse_exceptions = true
45
45
  #config.default_parser_options = { :tidy => false, :escape_erb => true }
46
46
  #config.tidy_path = '/usr/lib/libtidy.so' # *nix
47
- #config.tidy_path = 'tidy.exe' # Win32 (assumes on system PATH)
47
+ #config.tidy_path = 'c:/tidy/lib/tidy.dll' # Win32
48
48
  #config.namespace_prefix = 'mv:'
49
49
  #config.inline_erb_start = '{{{'
50
50
  #config.inline_erb_end = '}}}'
@@ -47,6 +47,7 @@
47
47
  require 'masterview/extras/sample_templates'
48
48
 
49
49
  class MasterviewController < ApplicationController
50
+ include MasterView::DefaultGenerateMIOFilter
50
51
 
51
52
  before_filter :check_authorization, :except => [ :access_not_allowed ]
52
53
 
@@ -148,8 +149,10 @@ class MasterviewController < ApplicationController
148
149
  @results = []
149
150
  @src = params[:src]
150
151
  if @src
151
- sh_mio = MasterView::StringHashMIOTree.new({}, '.rhtml')
152
- MasterView::Parser.parse( @src, { :output_mio_tree => sh_mio, :omit_comment => true } )
152
+ sh_mio = MasterView::StringHashMIOTree.new({}, MasterView::LoadedConfiguration.generated_file_default_extension )
153
+
154
+ src_with_default_gen = add_default_gen_if_needed(@src) # apply a default generate
155
+ MasterView::Parser.parse( src_with_default_gen, { :output_mio_tree => sh_mio, :omit_comment => true, :template_pathname => 'YOUR_TEMPLATE_PATH_HERE' } )
153
156
  @results = sh_mio.string_hash.sort.collect do |file,rhtml|
154
157
  os = OpenStruct.new
155
158
  os.file = file
@@ -0,0 +1,55 @@
1
+
2
+ # verify that stylesheets we use are available and if not copy them to public/stylesheets
3
+ mv_generator_templates_dir = "#{MasterView::LoadedConfiguration.mv_installation_dir}/generators/masterview/templates"
4
+ unless File.exist?(mv_generator_templates_dir)
5
+ # we are in a gem so things are in different directories
6
+ MasterView::Log.debug{ 'MasterView appears to be installed as a gem...' }
7
+ mv_generator_dir = MasterView::LoadedConfiguration.mv_installation_dir.gsub('\\','/').gsub( %r{/masterview-([^/]+)$}, '/masterview_generator-\1' )
8
+ mv_generator_templates_dir = "#{mv_generator_dir}/templates"
9
+ end
10
+ MasterView::Log.debug{ 'MasterView gem admin stylesheet src dir='+mv_generator_templates_dir }
11
+
12
+ if File.directory?(mv_generator_templates_dir)
13
+ rails_app_stylesheets_dir = Pathname.for_path(RAILS_ROOT) + 'public/stylesheets/masterview'
14
+ stylesheet_specs = [
15
+ # from/to spec: [ <src filename in templates dir>, <target filename in app stylesheets dir> ]
16
+ [ 'style.css', 'style.css' ],
17
+ [ 'sidebox.css', 'sidebox.css' ],
18
+ [ 'color-scheme.css', 'color-scheme.css' ]
19
+ ]
20
+ src_dir_accessor = MasterView::FileMIOTree.new( mv_generator_templates_dir )
21
+ dst_dir_accessor = MasterView::FileMIOTree.new( rails_app_stylesheets_dir, '.css', :logging => true)
22
+ stylesheet_specs.each { | from, to |
23
+ src_file = src_dir_accessor.path(from)
24
+ dst_file = dst_dir_accessor.path(to)
25
+ dst_file.write( src_file.read ) unless dst_file.exist?
26
+ }
27
+ end
28
+
29
+ # add our app directories with the masterview_controller to the load path
30
+ mv_controller_code_dirs = Dir[File.join(MasterView::LoadedConfiguration.mv_code_base_dir, '/extras/app/controllers')].select { |dir| File.directory?(dir) }
31
+ mv_controller_code_dirs.each { |dir| $LOAD_PATH.push dir }
32
+ MasterView::Log.debug{ 'MasterView AdminPages controller directories = '+mv_controller_code_dirs.inspect }
33
+
34
+ # rails 1.1.5+ added additional safe_load_path which we need to add our directories so that controller will be found
35
+ if (not mv_controller_code_dirs.empty? and #we have dirs to add
36
+ ActionController::Routing::ControllerComponent.respond_to?(:safe_load_paths) and #we are in rails 1.1.5+
37
+ not ActionController::Routing::ControllerComponent.respond_to?(:safe_load_paths_pre_mv)) # we have not already been added
38
+
39
+ MasterView::Log.info{ 'Adding MasterView AdminPages controller directory to safe_load_path' }
40
+ ActionController::Routing::ControllerComponent.class_eval <<-END
41
+ class << self
42
+ alias_method :safe_load_paths_pre_mv, :safe_load_paths
43
+
44
+ protected
45
+
46
+ def safe_load_paths #:nodoc:
47
+ # concatenate our controller dirs to original safe_load_path
48
+ safe_load_paths_pre_mv.concat #{mv_controller_code_dirs.inspect}
49
+ end
50
+ end
51
+ END
52
+
53
+ end
54
+
55
+ MasterView::Log.info{ 'MasterView Admin pages enabled' }
@@ -44,6 +44,9 @@
44
44
  # [JJB 13-Jun-2006]
45
45
  #++
46
46
  #
47
+
48
+ require 'date'
49
+
47
50
  module MasterView
48
51
 
49
52
  # A Configuration holds all the configuration settings used the
@@ -76,7 +79,6 @@ module MasterView
76
79
  # MasterView::Initializer.run( :process, config )
77
80
  #
78
81
  class Configuration
79
-
80
82
  # directory in which the MasterView plugin or gem is installed
81
83
  attr_reader :mv_installation_dir #:nodoc:
82
84
 
@@ -323,6 +325,7 @@ module MasterView
323
325
  # Default option settings for template parsing (a hash)
324
326
  # :tidy => false - run tidy before parsing (tidy_path must be set if enabled)
325
327
  # :escape_erb => true - escapes <% %> before parsing
328
+ # :default_generate => true - adds in mv:generate="{template_path}" if none found
326
329
  attr_accessor :default_parser_options
327
330
 
328
331
  # Path on this system to tidy library if <tt>:tidy</tt> parser option is enabled
@@ -413,6 +416,12 @@ module MasterView
413
416
  # Default: +false+
414
417
  attr_accessor :generate_rhtml_files
415
418
 
419
+ # These are the original default parser options, whatever is set in the config
420
+ # will be merged with these to arrive at the result. This allows us to easily
421
+ # add new defaults in and even if users empty this hash, the defaults will get added
422
+ # to disable they specifically set something to false or nil
423
+ OriginalDefaultParserOptions = { :tidy => false, :escape_erb => true, :default_generate => true } # :nodoc: save the originals
424
+
416
425
  # Create a new Configuration instance, initialized with the default
417
426
  # values.
418
427
  #
@@ -429,13 +438,19 @@ module MasterView
429
438
  # Use +rails_app_root_path+ when operating on a Rails application which
430
439
  # isn't actually running; use +app_root_path+ for a non-rails application.
431
440
  #
441
+
442
+ # list of [ :log_level, msg ] pairs for config initialization/validation messages
443
+ # used by the initializer to validate load path and report any problems
444
+ attr_accessor :initialization_messages #:nodoc:
445
+ ####:invalid_directive_paths
446
+
432
447
  def initialize( params={} )
433
448
 
449
+ rails_env = (defined?(RAILS_ENV)) ? RAILS_ENV : nil
434
450
  # unpack the supported keyword args
435
451
  app_root_path = params[:app_root_path]
436
452
  rails_app_root_path = params[:rails_app_root_path]
437
- env = params[:environment]
438
-
453
+ env = params[:environment] || rails_env
439
454
  is_development = env == 'development'
440
455
 
441
456
  program_root_path = File.expand_path( '.' )
@@ -556,9 +571,9 @@ module MasterView
556
571
 
557
572
  # template parsing options
558
573
  self.handle_parse_exceptions = true
559
- self.default_parser_options = { :tidy => false, :escape_erb => true }
574
+ self.default_parser_options = OriginalDefaultParserOptions.clone #we'll merge in whatever changes they make over the original set in const above
560
575
  # default locations where tidy likely to be found; assume on user's PATH if on Windows
561
- self.tidy_path = RUBY_PLATFORM =~ /mswin32/ ? 'tidy.exe' : '/usr/lib/libtidy.so'
576
+ self.tidy_path = RUBY_PLATFORM =~ /mswin32/ ? 'c:/tidy/lib/tidy.dll' : '/usr/lib/libtidy.so'
562
577
  self.namespace_prefix = 'mv:'
563
578
  self.inline_erb_start = '{{{'
564
579
  self.inline_erb_end = '}}}'
@@ -573,6 +588,8 @@ module MasterView
573
588
 
574
589
  STDOUT.puts "...mv config initialized with default settings\n" if debug_TRACE_HACK
575
590
 
591
+ self.initialization_messages = [] # for installer validation checking and problem reporting
592
+
576
593
  end
577
594
 
578
595
  def decide_if_running_rails #:nodoc:
@@ -682,9 +699,8 @@ module MasterView
682
699
 
683
700
  # Create a new Initializer instance that references the given Configuration
684
701
  # instance.
685
- def initialize(configuration) #:nodoc:
686
- @configuration = configuration
687
- @log_msg_q = [] # collect log messages that arrive prior to the logger
702
+ def initialize(config) #:nodoc:
703
+ @configuration = config
688
704
  end
689
705
 
690
706
  # Load the MasterView configuration settings
@@ -701,12 +717,15 @@ module MasterView
701
717
  # Intended for use in testing.
702
718
  def initialize_configuration
703
719
  #?? return if MasterView.const_defined?(:ConfigSettings) ??
720
+ #ISSUE: support format_datetime option on the logger settings?? [DJL 30-Jul-2006]
721
+ configuration.initialization_messages << [ :info,
722
+ "Initializing MasterView configuration (#{DateTime.now.strftime('%Y-%m-%d %H:%M')})" ]
723
+ configuration.initialization_messages << [ :info,
724
+ "Program name = #{$PROGRAM_NAME}" ] # log the program that is starting the session
704
725
  load_config_settings
705
726
  ensure_valid_settings
706
727
  install_config_settings
707
728
  # make a final check for running_rails? (in case config settings changed scripts spec)
708
- # this logging didn't seem to work??
709
- # @log_msg_q << [ :info, 'Program name = '+$PROGRAM_NAME ] # log the program that is starting
710
729
  configuration.decide_if_running_rails
711
730
  # keep a permananent record of how we got started
712
731
  configuration.freeze
@@ -752,11 +771,12 @@ module MasterView
752
771
  if not config.directive_paths.empty?
753
772
  clean_paths = []
754
773
  config.directive_paths.each { | dir |
755
- if dir.nil? || ! File.directory?(dir)
774
+ if dir.nil?: continue; end
775
+ if ! File.directory?(dir)
756
776
  err_msg = "Invalid directive load path directory: '#{dir}'"
757
- #overzealous: raise InvalidPathError.new()
758
- #but doesn't exist yet: Log.error err_mage
759
- @log_msg_q << [ :error, err_msg ]
777
+ #overzealous: raise InvalidPathError.new(err_msg)
778
+ # just note the problem and let initializer report it later
779
+ config.initialization_messages << [ :error, err_msg ]
760
780
  else
761
781
  dir_path = File.expand_path( dir )
762
782
  clean_paths << dir_path if ! clean_paths.include?(dir_path) # no dups
@@ -794,6 +814,9 @@ module MasterView
794
814
  def set_module_constants #:nodoc:
795
815
 
796
816
  config = configuration
817
+
818
+ # save configuration so we can get to it later
819
+ MasterView.const_set('LoadedConfiguration', config)
797
820
 
798
821
  # create loaded feature map - this map will track exactly what was loaded taking into account failures, so it can differ
799
822
  # from what is configured. key = feature symbol, value = true if enabled and loaded
@@ -814,7 +837,7 @@ module MasterView
814
837
 
815
838
  # template parsing options
816
839
  MasterView.const_set('RescueExceptions', config.handle_parse_exceptions)
817
- MasterView.const_set('DefaultParserOptions', config.default_parser_options)
840
+ MasterView.const_set('DefaultParserOptions', Configuration::OriginalDefaultParserOptions.merge(config.default_parser_options)) # merge in changes with original, so we can add more defaults later, users have to explicitly set an option to false to cancel them
818
841
  MasterView.const_set('TidyPath', config.tidy_path)
819
842
  MasterView.const_set('NamespacePrefix', config.namespace_prefix)
820
843
  MasterView.const_set('InlineErbStart', config.inline_erb_start)
@@ -840,11 +863,11 @@ module MasterView
840
863
  require 'masterview' #:nodoc:
841
864
  end
842
865
 
843
- # Complete installation of masterview after its code has been loaded
866
+ # Complete installation of masterview after its own code has been loaded
844
867
  def complete_plugin_installation #:nodoc:
845
868
  #?? return if MasterView.const_defined?(:Initialized) ??
846
- initialize_mio
847
869
  initialize_logger
870
+ initialize_mio
848
871
  #Back out experiment: causes load order problems
849
872
  ##load_directives # held off on this until logger is installed
850
873
  install_in_rails
@@ -853,6 +876,16 @@ module MasterView
853
876
  after_initialize # callback to client's afer_initialize block
854
877
  end
855
878
 
879
+ # Initialize MasterView::Log with a logger which emits to std output, default DEBUG level
880
+ def initialize_logger #:nodoc:
881
+ #?return if defined?(Log)
882
+ require 'masterview/extras/init_logger'
883
+ # release any queued-up initialization messages yearning to be free
884
+ configuration.initialization_messages.each { | msg_level, msg |
885
+ Log.send msg_level, msg
886
+ }
887
+ end
888
+
856
889
  # Initialize the MasterView I/O subsystem
857
890
  def initialize_mio
858
891
  config = configuration
@@ -861,11 +894,13 @@ module MasterView
861
894
  io_mgr = MIOTrees.new
862
895
  template_extension = File.extname( config.template_filename_pattern )
863
896
  io_mgr.template = FileMIOTree.new( config.template_src_dir_path, template_extension,
864
- :escape_erb => config.default_parser_options[:escape_erb],
865
- :tidy => config.default_parser_options[:tidy],
897
+ :escape_erb => DefaultParserOptions[:escape_erb], # use DefaultParserOptions since already has config merged
898
+ :tidy => DefaultParserOptions[:tidy],
899
+ :default_generate => DefaultParserOptions[:default_generate],
866
900
  #TODO: expose the following in Configuration.default_parser_options and document
867
901
  :caching => false,
868
902
  :logging => true )
903
+
869
904
  if config.generate_rhtml_files
870
905
  io_mgr.erb = FileMIOTree.new( config.template_dst_dir_path, config.generated_file_default_extension, :logging => true)
871
906
  else
@@ -876,17 +911,6 @@ module MasterView
876
911
  MasterView::LoadedFeatures[:tidy_template_read] = config.default_parser_options[:tidy]
877
912
  end
878
913
 
879
- # Initialize MasterView::Log with a logger which emits to std output, default DEBUG level
880
- def initialize_logger #:nodoc:
881
- #?return if defined?(Log)
882
- require 'masterview/extras/init_logger'
883
- # Kick out any queued-up log messages yearning to be free
884
- @log_msg_q.each { | msg_level, msg |
885
- Log.send err_level, msg
886
- }
887
- @log_msg_q.clear
888
- end
889
-
890
914
  def load_directives #:nodoc:
891
915
  # get the directives loaded prior to firing up any template parsing
892
916
  return if ! configuration.on_rails? #ISSUE: causes problem for test cases; is this ever a good idea??
@@ -907,38 +931,7 @@ module MasterView
907
931
  # install the MasterviewController to support masterview admin pages in the site
908
932
  def enable_mv_admin_pages #:nodoc:
909
933
  return if ! configuration.enable_admin_pages #MasterView::EnableMasterViewAdminPages
910
- MasterView::Log.info{ 'MasterView Admin pages enabled' }
911
-
912
- # verify that stylesheets we use are available and if not copy them to public/stylesheets
913
- mv_generator_templates_dir = "#{configuration.mv_installation_dir}/generators/masterview/templates"
914
- unless File.exist?(mv_generator_templates_dir)
915
- # we are in a gem so things are in different directories
916
- MasterView::Log.debug{ 'MasterView appears to be installed as a gem...' }
917
- mv_generator_dir = configuration.mv_installation_dir.gsub('\\','/').gsub( %r{/masterview-([^/]+)$}, '/masterview_generator-\1' )
918
- mv_generator_templates_dir = "#{mv_generator_dir}/templates"
919
- end
920
- MasterView::Log.debug{ 'MasterView gem admin stylesheet src dir='+mv_generator_templates_dir }
921
-
922
- if File.directory?(mv_generator_templates_dir)
923
- rails_app_stylesheets_dir = Pathname.for_path(RAILS_ROOT) + 'public/stylesheets/masterview'
924
- stylesheet_specs = [
925
- # from/to spec: [ <src filename in templates dir>, <target filename in app stylesheets dir> ]
926
- [ 'style.css', 'style.css' ],
927
- [ 'sidebox.css', 'sidebox.css' ],
928
- [ 'color-scheme.css', 'color-scheme.css' ]
929
- ]
930
- src_dir_accessor = MasterView::FileMIOTree.new( mv_generator_templates_dir )
931
- dst_dir_accessor = MasterView::FileMIOTree.new( rails_app_stylesheets_dir, '.css', :logging => true)
932
- stylesheet_specs.each { | from, to |
933
- src_file = src_dir_accessor.path(from)
934
- dst_file = dst_dir_accessor.path(to)
935
- dst_file.write( src_file.read ) unless dst_file.exist?
936
- }
937
- end
938
- # add our app directories with the masterview_controller to the load path
939
- mv_controller_code_dirs = Dir[File.join(configuration.mv_code_base_dir, '/extras/app/**/*')].select { |dir|
940
- File.directory?(dir) }
941
- mv_controller_code_dirs.each { |dir| $LOAD_PATH.push dir }
934
+ require 'masterview/extras/init_mv_admin_pages'
942
935
  end
943
936
 
944
937
  def parse_templates_at_startup #:nodoc:
data/lib/masterview/io.rb CHANGED
@@ -43,6 +43,7 @@ module MasterView
43
43
  # options[:tidy] = true enables tidy processing to cleanup bad xhtml
44
44
  # options[:caching] = true enables caching so that reads are cached
45
45
  # options[:logging] = true enables logging of reads and writes
46
+ # options[:default_generate] = true enables creation of default generate directive if none found
46
47
  def apply_filters(mio, options, block)
47
48
  if block
48
49
  block.call(mio)
@@ -56,6 +57,7 @@ module MasterView
56
57
  lambda do |mio|
57
58
  mio.extend EscapeErbMIOFilter if options[:escape_erb]
58
59
  mio.extend TidyMIOFilter if options[:tidy]
60
+ mio.extend DefaultGenerateMIOFilter if options[:default_generate]
59
61
  mio.extend CachingMIOFilter if options[:caching]
60
62
  mio.extend ReadWriteLoggingMIOFilter if options[:logging]
61
63
  end
@@ -328,6 +330,48 @@ module MasterView
328
330
  end
329
331
  end
330
332
 
333
+ # checks to see that mv:generate or mv:gen_partial has been used somewhere in file
334
+ # and if not then it puts in a default mv:generate directive based on the following
335
+ # logic. If a body tag exists then add the mv:generate directive to the body tag
336
+ # and also add a mv:omit_tag="" directive. This is based on the assumption that we are
337
+ # body will be defined in a layout somewhere so we are only interested in the
338
+ # internal content of it (excluding the body tag itself).
339
+ # If a body tag does not exist, then simply add the mv:generate tag to the root element.
340
+ #
341
+ # Examples:
342
+ # <html><body>Hello world</body></html>
343
+ # becomes
344
+ # <html><body mv:generate="{template_path}" mv:omit_tag="">Hello world</body></html>
345
+ #
346
+ # <div>Hello</div>
347
+ # becomes
348
+ # <div mv:generate="{template_path}">Hello</div>
349
+ module DefaultGenerateMIOFilter
350
+ def read(options={})
351
+ content = super
352
+ add_default_gen_if_needed(content)
353
+ end
354
+
355
+ # do the actual insertion of generate directive if not found
356
+ def add_default_gen_if_needed(content)
357
+ # building this right before needed in case the Namespace was changed during initialize
358
+ @@generate_gen_partial_search_regex ||= Regexp.new( '\s'+::MasterView::NamespacePrefix+'(generate=|gen_partial=)' )
359
+
360
+ # these are the directives that will be used for body and no body cases
361
+ @@generate_body_directives ||= ::MasterView::NamespacePrefix+'generate="{template_path}" '+::MasterView::NamespacePrefix+'omit_tag=""'
362
+ @@generate_non_body_directives ||= ::MasterView::NamespacePrefix+'generate="{template_path}"'
363
+
364
+ unless content =~ @@generate_gen_partial_search_regex
365
+ Log.debug { "no generate or gen_partial directives found, DefaultGenerateFilter is adding generate=\"{template_path}\"" }
366
+ content = content.clone # leave original alone
367
+ unless content.sub!( /<body/i ){ |x| x+' '+@@generate_body_directives } # unless we found body tag and substituted
368
+ content.sub!( /<\w+/ ){ |x| x+' '+@@generate_non_body_directives }
369
+ end
370
+ end
371
+ content
372
+ end
373
+ end
374
+
331
375
  module ReadWriteLoggingMIOFilter #todo
332
376
  def read(options={})
333
377
  Log.debug { "reading file="+self.full_pathname } unless options[:disable_logging]
@@ -2,7 +2,7 @@ module MasterView
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 4
5
+ TINY = 5
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -122,9 +122,10 @@ module MasterView
122
122
  def stag(dcs)
123
123
  context = dcs.context
124
124
  ret = []
125
- ret << "<#{context[:tag].tag_name}"
126
- context[:tag].attributes.sort.each do |name, value|
127
- ret << " #{name}=\"#{value}\""
125
+ ret << "<#{context[:tag].tag_name.to_s}" # allow for symbol tag_name
126
+ sorted_attributes = context[:tag].attributes.sort { |a,b| a[0].to_s <=> b[0].to_s } #allow for symbols using to_s
127
+ sorted_attributes.each do |name, value|
128
+ ret << " #{name.to_s}=\"#{value}\"" # allow for key to by symbol
128
129
  end
129
130
  ret << '>' #must output as separate string so simplify_empty_elements can find it
130
131
  end
@@ -146,7 +147,7 @@ module MasterView
146
147
 
147
148
  def etag(dcs)
148
149
  context = dcs.context
149
- [] << '</' << "#{context[:tag].tag_name}>" #must output </ as separate string so simplify_empty_elements can find it
150
+ [] << '</' << "#{context[:tag].tag_name.to_s}>" #must output </ as separate string so simplify_empty_elements can find it
150
151
  end
151
152
 
152
153
  end
@@ -0,0 +1,183 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ currentPath = File.dirname(__FILE__)
5
+ require File.join( currentPath, '../../lib/masterview' )
6
+ require File.join( currentPath, '../test_helper' )
7
+
8
+ class TestDefaultGenerateMIOFilter < Test::Unit::TestCase
9
+ include MasterView::DefaultGenerateMIOFilter
10
+
11
+ def setup
12
+ MasterView::IOMgr.template = MasterView::StringHashMIOTree.new({}, '.rhtml', :logging => true, :default_generate => true )
13
+ MasterView::IOMgr.erb = MasterView::StringHashMIOTree.new({}, '.rhtml', :logging => true)
14
+ end
15
+
16
+
17
+
18
+ def test_no_gen_no_body_str
19
+ template = <<-END
20
+ <div>
21
+ <span class="red" mv:attr=":class => 'blue', :id => 'testid'">foo bar</span>
22
+ </div>
23
+ END
24
+ expected = <<-END
25
+ <div mv:generate="{template_path}">
26
+ <span class="red" mv:attr=":class => 'blue', :id => 'testid'">foo bar</span>
27
+ </div>
28
+ END
29
+ assert_equal expected, add_default_gen_if_needed(template)
30
+ end
31
+
32
+ def test_no_gen_extract_body_str
33
+ template = <<-END
34
+ <html>
35
+ <body>
36
+ <div>
37
+ <span class="red" mv:attr=":class => 'blue', :id => 'testid'">foo bar</span>
38
+ </div>
39
+ </body>
40
+ </html>
41
+ END
42
+ expected = <<-END
43
+ <html>
44
+ <body mv:generate="{template_path}" mv:omit_tag="">
45
+ <div>
46
+ <span class="red" mv:attr=":class => 'blue', :id => 'testid'">foo bar</span>
47
+ </div>
48
+ </body>
49
+ </html>
50
+ END
51
+ assert_equal expected, add_default_gen_if_needed(template)
52
+ end
53
+
54
+ def test_no_gen_extract_capital_body_str
55
+ template = <<-END
56
+ <html>
57
+ <BODY>
58
+ <div>
59
+ <span class="red" mv:attr=":class => 'blue', :id => 'testid'">foo bar</span>
60
+ </div>
61
+ </BODY>
62
+ </html>
63
+ END
64
+ expected = <<-END
65
+ <html>
66
+ <BODY mv:generate="{template_path}" mv:omit_tag="">
67
+ <div>
68
+ <span class="red" mv:attr=":class => 'blue', :id => 'testid'">foo bar</span>
69
+ </div>
70
+ </BODY>
71
+ </html>
72
+ END
73
+ assert_equal expected, add_default_gen_if_needed(template)
74
+ end
75
+
76
+ def test_has_gen_no_body
77
+ template = <<-END
78
+ <div>
79
+ <div mv:generate="one/two">
80
+ <span class="red" mv:attr=":class => 'blue', :id => 'testid'">foo bar</span>
81
+ </div>
82
+ </div>
83
+ END
84
+ expected = <<-END
85
+ <div>
86
+ <div mv:generate="one/two">
87
+ <span class="red" mv:attr=":class => 'blue', :id => 'testid'">foo bar</span>
88
+ </div>
89
+ </div>
90
+ END
91
+ assert_equal expected, add_default_gen_if_needed(template)
92
+ end
93
+
94
+ def test_has_gen_with_body
95
+ template = <<-END
96
+ <html>
97
+ <body>
98
+ <div>
99
+ <div mv:generate="one/two">
100
+ <span class="red" mv:attr=":class => 'blue', :id => 'testid'">foo bar</span>
101
+ </div>
102
+ </div>
103
+ </body>
104
+ </html>
105
+ END
106
+ expected = <<-END
107
+ <html>
108
+ <body>
109
+ <div>
110
+ <div mv:generate="one/two">
111
+ <span class="red" mv:attr=":class => 'blue', :id => 'testid'">foo bar</span>
112
+ </div>
113
+ </div>
114
+ </body>
115
+ </html>
116
+ END
117
+ assert_equal expected, add_default_gen_if_needed(template)
118
+ end
119
+
120
+ def test_has_gen_partial_no_body
121
+ template = <<-END
122
+ <div>
123
+ <div mv:gen_partial=":partial => 'one/two'">
124
+ <span class="red" mv:attr=":class => 'blue', :id => 'testid'">foo bar</span>
125
+ </div>
126
+ </div>
127
+ END
128
+ expected = <<-END
129
+ <div>
130
+ <div mv:gen_partial=":partial => 'one/two'">
131
+ <span class="red" mv:attr=":class => 'blue', :id => 'testid'">foo bar</span>
132
+ </div>
133
+ </div>
134
+ END
135
+ assert_equal expected, add_default_gen_if_needed(template)
136
+ end
137
+
138
+ def test_has_gen_partial_with_body
139
+ template = <<-END
140
+ <html>
141
+ <body>
142
+ <div>
143
+ <div mv:gen_partial=":partial => 'one/two'">
144
+ <span class="red" mv:attr=":class => 'blue', :id => 'testid'">foo bar</span>
145
+ </div>
146
+ </div>
147
+ </body>
148
+ </html>
149
+ END
150
+ expected = <<-END
151
+ <html>
152
+ <body>
153
+ <div>
154
+ <div mv:gen_partial=":partial => 'one/two'">
155
+ <span class="red" mv:attr=":class => 'blue', :id => 'testid'">foo bar</span>
156
+ </div>
157
+ </div>
158
+ </body>
159
+ </html>
160
+ END
161
+ assert_equal expected, add_default_gen_if_needed(template)
162
+ end
163
+
164
+ def test_no_gen_no_body_using_filter
165
+ template = <<-END
166
+ <div>
167
+ <span class="red" mv:attr=":class => 'blue', :id => 'testid'">foo bar</span>
168
+ </div>
169
+ END
170
+ expected = {
171
+ 'foo/bar.rhtml' => "<div><span class=\"blue\" id=\"testid\">foo bar</span></div>"
172
+ }
173
+
174
+ # write template to mio, then read it through filter
175
+ MasterView::IOMgr.template.path('foo/bar.html').write(template)
176
+ template_read = MasterView::IOMgr.template.path('foo/bar.html').read
177
+
178
+ assert_template_result expected, template_read, :template_pathname => 'foo/bar.html'
179
+ end
180
+
181
+
182
+
183
+ end
@@ -108,18 +108,25 @@ class TestParser < Test::Unit::TestCase
108
108
  dcs.context = { :tag => t2 }
109
109
  ret = s.stag(dcs)
110
110
  assert_equal "<foo", ret[0]
111
+ assert_equal " bar=\"baz\"", ret[1]
112
+ assert_equal " can=\"dog\"", ret[2]
111
113
  assert_equal '>', ret[3]
112
- assert ret.include?(" bar=\"baz\"" )
113
- assert ret.include?(" can=\"dog\"" )
114
114
 
115
115
  dcs.context[:content_part] = 'hello'
116
116
  assert_equal ['hello'], s.characters(dcs)
117
-
118
117
  assert_equal ['<!-- ', 'hello', ' -->'], s.comment(dcs)
119
-
120
118
  assert_equal ['<![CDATA[', 'hello', ']]>'], s.cdata(dcs)
121
-
122
119
  assert_equal ['</', 'foo>'], s.etag(dcs)
120
+
121
+ attributes = { :can => 'dog', :bar => 'baz' } # test that we can use symbols for keys
122
+ tag_name = :foo
123
+ t3 = MasterView::Tag.new(directives, tag_name, attributes, mode_type, parent)
124
+ dcs.context = { :tag => t3 }
125
+ ret = s.stag(dcs)
126
+ assert_equal "<foo", ret[0]
127
+ assert_equal " bar=\"baz\"", ret[1]
128
+ assert_equal " can=\"dog\"", ret[2]
129
+ assert_equal '>', ret[3]
123
130
  end
124
131
 
125
132
  def test_tag
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: masterview
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.4
7
- date: 2006-07-26 00:00:00 -05:00
6
+ version: 0.2.5
7
+ date: 2006-08-19 00:00:00 -05:00
8
8
  summary: A (x)html friendly template engine for rails with the power of layouts, and partials.
9
9
  require_paths:
10
10
  - lib
@@ -45,28 +45,33 @@ files:
45
45
  - lib/masterview/io.rb
46
46
  - lib/masterview/plugin_load_tracking.rb
47
47
  - lib/masterview/initializer.rb
48
- - lib/masterview/string_extensions.rb
49
48
  - lib/masterview/analyzer.rb
49
+ - lib/masterview/string_extensions.rb
50
50
  - lib/masterview/template_spec.rb
51
51
  - lib/masterview/masterview_version.rb
52
52
  - lib/masterview/parser.rb
53
53
  - lib/masterview/mtime_tracking_hash.rb
54
54
  - lib/masterview/directive_helpers.rb
55
+ - lib/masterview/masterview_info.rb
55
56
  - lib/masterview/runtime_helpers.rb
57
+ - lib/masterview/directive_registry.rb
56
58
  - lib/masterview/pathname_extensions.rb
57
59
  - lib/masterview/filter_helpers.rb
58
60
  - lib/masterview/directive_base.rb
59
61
  - lib/masterview/keyword_expander.rb
60
62
  - lib/masterview/attr_string_parser.rb
61
- - lib/masterview/directive_registry.rb
62
- - lib/masterview/masterview_info.rb
63
- - lib/masterview/directives/global_inline_erb.rb
64
63
  - lib/masterview/directives/link_to_if.rb
65
- - lib/masterview/directives/preview.rb
64
+ - lib/masterview/directives/image_tag.rb
66
65
  - lib/masterview/directives/testfilter.rb
67
- - lib/masterview/directives/password_field.rb
66
+ - lib/masterview/directives/select.rb
67
+ - lib/masterview/directives/preview.rb
68
+ - lib/masterview/directives/check_box.rb
69
+ - lib/masterview/directives/javascript_include.rb
70
+ - lib/masterview/directives/global_inline_erb.rb
68
71
  - lib/masterview/directives/text_field.rb
69
72
  - lib/masterview/directives/else.rb
73
+ - lib/masterview/directives/radio_button.rb
74
+ - lib/masterview/directives/collection_select.rb
70
75
  - lib/masterview/directives/block.rb
71
76
  - lib/masterview/directives/if.rb
72
77
  - lib/masterview/directives/hidden_field.rb
@@ -75,67 +80,63 @@ files:
75
80
  - lib/masterview/directives/form.rb
76
81
  - lib/masterview/directives/omit_tag.rb
77
82
  - lib/masterview/directives/submit.rb
78
- - lib/masterview/directives/replace.rb
79
- - lib/masterview/directives/attr.rb
83
+ - lib/masterview/directives/password_field.rb
80
84
  - lib/masterview/directives/insert_generated_comment.rb
81
85
  - lib/masterview/directives/stylesheet_link.rb
82
- - lib/masterview/directives/javascript_include.rb
83
- - lib/masterview/directives/import_render.rb
84
86
  - lib/masterview/directives/link_to_remote.rb
87
+ - lib/masterview/directives/import_render.rb
85
88
  - lib/masterview/directives/import.rb
86
89
  - lib/masterview/directives/content.rb
87
- - lib/masterview/directives/radio_button.rb
90
+ - lib/masterview/directives/attr.rb
91
+ - lib/masterview/directives/replace.rb
88
92
  - lib/masterview/directives/text_area.rb
89
- - lib/masterview/directives/image_tag.rb
90
- - lib/masterview/directives/check_box.rb
91
- - lib/masterview/directives/select.rb
92
- - lib/masterview/directives/collection_select.rb
93
93
  - lib/masterview/extras/app
94
94
  - lib/masterview/extras/init_logger.rb
95
95
  - lib/masterview/extras/watcher.rb
96
+ - lib/masterview/extras/sample_templates.rb
96
97
  - lib/masterview/extras/init_rails_reparse_checking.rb
97
98
  - lib/masterview/extras/init_rails_erb_mv_direct.rb
98
- - lib/masterview/extras/sample_templates.rb
99
+ - lib/masterview/extras/init_mv_admin_pages.rb
99
100
  - lib/masterview/extras/app/controllers
100
101
  - lib/masterview/extras/app/views
101
102
  - lib/masterview/extras/app/controllers/masterview_controller.rb
102
- - lib/masterview/extras/app/views/masterview
103
103
  - lib/masterview/extras/app/views/layouts
104
+ - lib/masterview/extras/app/views/masterview
105
+ - lib/masterview/extras/app/views/layouts/masterview_admin.rhtml
104
106
  - lib/masterview/extras/app/views/masterview/admin
105
- - lib/masterview/extras/app/views/masterview/admin/view_rhtml.rhtml
107
+ - lib/masterview/extras/app/views/masterview/admin/features.rhtml
106
108
  - lib/masterview/extras/app/views/masterview/admin/list.rhtml
107
109
  - lib/masterview/extras/app/views/masterview/admin/empty.rhtml
108
- - lib/masterview/extras/app/views/masterview/admin/interact.rhtml
109
- - lib/masterview/extras/app/views/masterview/admin/create.rhtml
110
- - lib/masterview/extras/app/views/masterview/admin/features.rhtml
111
110
  - lib/masterview/extras/app/views/masterview/admin/configuration.rhtml
112
- - lib/masterview/extras/app/views/layouts/masterview_admin.rhtml
111
+ - lib/masterview/extras/app/views/masterview/admin/view_rhtml.rhtml
112
+ - lib/masterview/extras/app/views/masterview/admin/create.rhtml
113
+ - lib/masterview/extras/app/views/masterview/admin/interact.rhtml
113
114
  - Rakefile
114
115
  - init.rb
116
+ - doc/screenshots
117
+ - doc/images
115
118
  - doc/stylesheets
116
119
  - doc/directives.html
117
120
  - doc/guide.html
118
- - doc/screenshots
121
+ - doc/simple_diagram.html
119
122
  - doc/installation.html
123
+ - doc/developer.html
120
124
  - doc/configuration.html
121
125
  - doc/index.html
122
126
  - doc/troubleshooting.html
123
127
  - doc/media_list.html
124
- - doc/images
125
- - doc/simple_diagram.html
126
- - doc/developer.html
127
- - doc/images/masterview_rhtml_rendering_thumbnail_smaller.png
128
128
  - doc/images/masterview_rhtml_rendering_thumbnail.png
129
- - doc/images/masterview_logo.png
130
129
  - doc/images/masterview_logo_gradient.png
131
- - doc/screenshots/generated_list.png
132
- - doc/screenshots/generated_new.png
130
+ - doc/images/masterview_logo.png
131
+ - doc/images/masterview_rhtml_rendering_thumbnail_smaller.png
132
+ - doc/screenshots/masterview_admin_thumbnail.png
133
+ - doc/screenshots/generated_list_thumbnail.png
133
134
  - doc/screenshots/masterview_admin.png
134
- - doc/screenshots/generated_new_medium.png
135
135
  - doc/screenshots/masterview_admin_medium.png
136
+ - doc/screenshots/generated_new_medium.png
137
+ - doc/screenshots/generated_new.png
138
+ - doc/screenshots/generated_list.png
136
139
  - doc/screenshots/generated_list_medium.png
137
- - doc/screenshots/generated_list_thumbnail.png
138
- - doc/screenshots/masterview_admin_thumbnail.png
139
140
  - doc/screenshots/generated_new_thumbnail.png
140
141
  - doc/stylesheets/mv-directives.css
141
142
  - doc/stylesheets/mv-installation.css
@@ -158,20 +159,21 @@ files:
158
159
  - test/unit/config_settings_test.rb
159
160
  - test/unit/run_parser_test.rb
160
161
  - test/unit/mio_test.rb
161
- - test/unit/directive_helpers_parse_test.rb
162
162
  - test/unit/directive_global_inline_erb_test.rb
163
163
  - test/unit/directive_text_field_test.rb
164
164
  - test/unit/directive_else_test.rb
165
165
  - test/unit/mtime_string_hash_mio_tree_test.rb
166
166
  - test/unit/directive_block_test.rb
167
- - test/unit/parser_test.rb
167
+ - test/unit/directive_helpers_parse_test.rb
168
168
  - test/unit/directive_hidden_field_test.rb
169
169
  - test/unit/directive_if_test.rb
170
+ - test/unit/parser_test.rb
170
171
  - test/unit/directive_link_to_test.rb
171
172
  - test/unit/directive_elsif_test.rb
172
173
  - test/unit/directive_form_test.rb
173
174
  - test/unit/filter_helpers_test.rb
174
175
  - test/unit/directive_javascript_include_test.rb
176
+ - test/unit/directive_base_test.rb
175
177
  - test/unit/directive_import_test.rb
176
178
  - test/unit/directive_link_to_if_test.rb
177
179
  - test/unit/template_test.rb
@@ -184,16 +186,16 @@ files:
184
186
  - test/unit/directive_omit_tag_test.rb
185
187
  - test/unit/directive_password_field_test.rb
186
188
  - test/unit/directive_stylesheet_link_test.rb
189
+ - test/unit/default_generate_mio_filter_test.rb
187
190
  - test/unit/directive_import_render_test.rb
188
191
  - test/unit/directive_attr_test.rb
189
192
  - test/unit/directive_content_test.rb
190
193
  - test/unit/directive_replace_test.rb
191
194
  - test/unit/keyword_expander_test.rb
192
195
  - test/unit/directive_text_area_test.rb
196
+ - test/unit/directive_image_tag_test.rb
193
197
  - test/unit/pathname_extensions_test.rb
194
198
  - test/unit/string_hash_mio_test.rb
195
- - test/unit/directive_image_tag_test.rb
196
- - test/unit/directive_base_test.rb
197
199
  - test/xtras/config_initialize_standalone.rb
198
200
  - test/xtras/config-mv-logger_config.rb
199
201
  - test/fixtures/configs
@@ -228,8 +230,8 @@ files:
228
230
  - CHANGELOG
229
231
  - TODO
230
232
  - RELEASE_NOTES
231
- - README
232
233
  - MIT-LICENSE
234
+ - README
233
235
  test_files: []
234
236
 
235
237
  rdoc_options: []