masterview 0.2.5 → 0.3.0

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.
Files changed (155) hide show
  1. data/CHANGELOG +31 -1
  2. data/README +70 -69
  3. data/RELEASE_NOTES +70 -64
  4. data/Rakefile +26 -27
  5. data/TODO +13 -29
  6. data/doc/about.html +246 -0
  7. data/doc/configuration.html +49 -36
  8. data/doc/developer.html +423 -41
  9. data/doc/directives.html +139 -51
  10. data/doc/guide.html +19 -9
  11. data/doc/index.html +90 -224
  12. data/doc/installation.html +36 -28
  13. data/doc/media_list.html +30 -20
  14. data/doc/simple_diagram.html +3 -5
  15. data/doc/stylesheets/masterview.css +16 -1
  16. data/examples/rails_app_config/masterview/settings.rb +2 -1
  17. data/init.rb +1 -1
  18. data/lib/#ChangeLog# +6 -0
  19. data/lib/masterview/analyzer.rb +48 -34
  20. data/lib/masterview/attr_string_parser.rb +5 -1
  21. data/lib/masterview/case_insensitive_hash.rb +69 -0
  22. data/lib/masterview/{pathname_extensions.rb → core_ext/pathname.rb} +0 -0
  23. data/lib/masterview/{string_extensions.rb → core_ext/string.rb} +0 -0
  24. data/lib/masterview/deprecated/directive_base.rb +362 -0
  25. data/lib/masterview/directive_base.rb +201 -179
  26. data/lib/masterview/directive_dsl.rb +457 -0
  27. data/lib/masterview/directive_helpers.rb +28 -141
  28. data/lib/masterview/directive_load_path.rb +388 -0
  29. data/lib/masterview/directive_metadata.rb +377 -0
  30. data/lib/masterview/directive_registry.rb +259 -69
  31. data/lib/masterview/directives/.metadata +16 -0
  32. data/lib/masterview/directives/attr.rb +9 -8
  33. data/lib/masterview/directives/block.rb +11 -14
  34. data/lib/masterview/directives/check_box.rb +13 -18
  35. data/lib/masterview/directives/collection_select.rb +15 -29
  36. data/lib/masterview/directives/content.rb +9 -3
  37. data/lib/masterview/directives/else.rb +15 -13
  38. data/lib/masterview/directives/elsif.rb +14 -13
  39. data/lib/masterview/directives/eval.rb +20 -0
  40. data/lib/masterview/directives/form.rb +56 -9
  41. data/lib/masterview/directives/form_remote.rb +26 -0
  42. data/lib/masterview/directives/global_inline_erb.rb +10 -14
  43. data/lib/masterview/directives/hidden_field.rb +11 -20
  44. data/lib/masterview/directives/if.rb +13 -12
  45. data/lib/masterview/directives/image_tag.rb +20 -28
  46. data/lib/masterview/directives/import.rb +5 -12
  47. data/lib/masterview/directives/import_render.rb +7 -19
  48. data/lib/masterview/directives/insert_generated_comment.rb +8 -11
  49. data/lib/masterview/directives/javascript_include.rb +21 -12
  50. data/lib/masterview/directives/link_to.rb +14 -8
  51. data/lib/masterview/directives/link_to_function.rb +22 -0
  52. data/lib/masterview/directives/link_to_if.rb +15 -13
  53. data/lib/masterview/directives/link_to_remote.rb +13 -8
  54. data/lib/masterview/directives/omit_tag.rb +32 -16
  55. data/lib/masterview/directives/password_field.rb +10 -22
  56. data/lib/masterview/directives/radio_button.rb +11 -22
  57. data/lib/masterview/directives/replace.rb +7 -8
  58. data/lib/masterview/directives/select.rb +11 -24
  59. data/lib/masterview/directives/stylesheet_link.rb +20 -12
  60. data/lib/masterview/directives/submit.rb +11 -5
  61. data/lib/masterview/directives/text_area.rb +10 -23
  62. data/lib/masterview/directives/text_field.rb +10 -22
  63. data/lib/masterview/exceptions.rb +21 -0
  64. data/lib/masterview/extras/app/controllers/masterview_controller.rb +102 -75
  65. data/lib/masterview/extras/app/views/layouts/masterview_admin.rhtml +24 -23
  66. data/lib/masterview/extras/app/views/layouts/masterview_admin_config.rhtml +81 -0
  67. data/lib/masterview/extras/app/views/masterview/admin/configuration.rhtml +5 -1
  68. data/lib/masterview/extras/app/views/masterview/admin/create.rhtml +2 -2
  69. data/lib/masterview/extras/app/views/masterview/admin/directives.rhtml +5 -0
  70. data/lib/masterview/extras/app/views/masterview/admin/features.rhtml +5 -79
  71. data/lib/masterview/extras/app/views/masterview/admin/interact.rhtml +5 -0
  72. data/lib/masterview/extras/app/views/masterview/admin/list.rhtml +3 -71
  73. data/lib/masterview/extras/init_mv_admin_pages.rb +42 -23
  74. data/lib/masterview/filter_helpers.rb +26 -0
  75. data/lib/masterview/initializer.rb +99 -53
  76. data/lib/masterview/io.rb +19 -15
  77. data/lib/masterview/keyword_expander.rb +7 -2
  78. data/lib/masterview/masterview_info.rb +229 -23
  79. data/lib/masterview/masterview_version.rb +2 -2
  80. data/lib/masterview/parser.rb +275 -105
  81. data/lib/masterview/parser_helpers.rb +54 -0
  82. data/lib/masterview/rails_ext/action_controller_erb_direct.rb +29 -0
  83. data/lib/masterview/rails_ext/action_controller_reparse_checking.rb +27 -0
  84. data/lib/masterview/{extras/init_rails_erb_mv_direct.rb → rails_ext/action_view_erb_direct.rb} +12 -59
  85. data/lib/masterview/template_spec.rb +3 -2
  86. data/lib/masterview.rb +21 -12
  87. data/lib/rexml/parsers/baseparser_with_doctype_fix.rb +473 -0
  88. data/lib/rexml/parsers/sax2parser_with_doctype_fix.rb +243 -0
  89. data/test/directive_test_helper.rb +135 -0
  90. data/test/fixtures/directives/id_check.rb +18 -0
  91. data/test/fixtures/directives/test_directive_events.rb +70 -0
  92. data/test/test_helper.rb +18 -5
  93. data/test/tmp/views/layouts/product.rhtml +10 -10
  94. data/test/tmp/views/product/_form.rhtml +4 -4
  95. data/test/tmp/views/product/_product.rhtml +3 -3
  96. data/test/tmp/views/product/destroy.rhtml +5 -5
  97. data/test/tmp/views/product/edit.rhtml +4 -4
  98. data/test/tmp/views/product/list.rhtml +3 -3
  99. data/test/tmp/views/product/new.rhtml +4 -4
  100. data/test/tmp/views/product/show.rhtml +2 -2
  101. data/test/unit/attr_string_parser_test.rb +105 -0
  102. data/test/unit/case_insensitive_hash_mod_test.rb +104 -0
  103. data/test/unit/config_settings_test.rb +13 -1
  104. data/test/unit/default_generate_mio_filter_test.rb +3 -3
  105. data/test/unit/deprecated_directive_base_test.rb +30 -0
  106. data/test/unit/directive_attr_test.rb +111 -35
  107. data/test/unit/directive_base_test.rb +520 -1
  108. data/test/unit/directive_block_test.rb +30 -22
  109. data/test/unit/directive_content_test.rb +24 -11
  110. data/test/unit/directive_else_test.rb +18 -15
  111. data/test/unit/directive_elsif_test.rb +17 -15
  112. data/test/unit/directive_form_remote_test.rb +59 -0
  113. data/test/unit/directive_form_test.rb +31 -39
  114. data/test/unit/directive_global_inline_erb_test.rb +28 -17
  115. data/test/unit/directive_grid_test_notready.rb +38 -0
  116. data/test/unit/directive_helpers_test.rb +39 -0
  117. data/test/unit/directive_hidden_field_test.rb +44 -29
  118. data/test/unit/directive_if_test.rb +10 -7
  119. data/test/unit/directive_image_tag_test.rb +69 -61
  120. data/test/unit/directive_import_render_test.rb +28 -38
  121. data/test/unit/directive_import_test.rb +16 -14
  122. data/test/unit/directive_insert_generated_comment_test.rb +32 -0
  123. data/test/unit/directive_javascript_include_test.rb +40 -43
  124. data/test/unit/directive_link_to_function_test.rb +40 -0
  125. data/test/unit/directive_link_to_if_test.rb +52 -12
  126. data/test/unit/directive_link_to_remote_test.rb +58 -0
  127. data/test/unit/directive_link_to_test.rb +46 -31
  128. data/test/unit/directive_load_path_test.rb +257 -0
  129. data/test/unit/directive_metadata_test.rb +313 -0
  130. data/test/unit/directive_omit_tag_test.rb +73 -21
  131. data/test/unit/directive_password_field_test.rb +44 -38
  132. data/test/unit/directive_registry_test.rb +44 -0
  133. data/test/unit/directive_replace_test.rb +28 -12
  134. data/test/unit/directive_stylesheet_link_test.rb +43 -36
  135. data/test/unit/directive_submit_test.rb +29 -30
  136. data/test/unit/directive_text_area_test.rb +40 -36
  137. data/test/unit/directive_text_field_test.rb +44 -38
  138. data/test/unit/example_directive_child_events_test.rb +41 -0
  139. data/test/unit/example_test.rb +31 -4
  140. data/test/unit/file_mio_test.rb +18 -13
  141. data/test/unit/filter_helpers_test.rb +10 -8
  142. data/test/unit/find_directive_parent_test.rb +174 -0
  143. data/test/unit/keyword_expander_test.rb +4 -2
  144. data/test/unit/mio_test.rb +18 -11
  145. data/test/unit/mtime_string_hash_mio_tree_test.rb +5 -1
  146. data/test/unit/parser_test.rb +41 -29
  147. data/test/unit/pathname_extensions_test.rb +1 -1
  148. data/test/unit/run_parser_test.rb +2 -2
  149. data/test/unit/simplified_directive_base_test.rb +256 -0
  150. data/test/unit/string_hash_mio_test.rb +5 -1
  151. data/test/unit/template_file_watcher_test.rb +2 -2
  152. data/test/unit/template_test.rb +221 -46
  153. metadata +86 -45
  154. data/lib/masterview/directives/testfilter.rb +0 -55
  155. data/lib/masterview/extras/init_rails_reparse_checking.rb +0 -62
@@ -0,0 +1,54 @@
1
+ module MasterView
2
+ module ParserHelpers
3
+ #returns an array of args by parsing and evaling the str value passed in
4
+ #uses evaling, so can't have any variables only simple strings, numbers, booleans
5
+ def parse_eval_into_array(value)
6
+ return [] if value.nil? || value.empty?
7
+ val = value.strip
8
+ args = []
9
+ until val.empty?
10
+ if val =~ /^[:'"%\[{&*]/ #starts with quote or ruby lang char
11
+ v = nil
12
+ val = '{'+val+'}' if val =~ /^:/ #starts with colon, assume hash so wrap with brackets
13
+ eval 'v = '+ val #rest is all evaled
14
+ if v.is_a? Array
15
+ args += v
16
+ else
17
+ args << v
18
+ end
19
+ break
20
+ else
21
+ unquoted_string = val.slice!( /^[^,]+/ ) #pull off everything up to a comma
22
+ unquoted_string.strip!
23
+ args.push unquoted_string
24
+ val.slice!( /^,/ ) #strip off comma if exists
25
+ val.strip!
26
+ end
27
+ end
28
+ args
29
+ end
30
+
31
+ #returns a hash, for values that are not already part of hash it adds them using default_key
32
+ #uses evaling so it cannot have any variables or non-simple types
33
+ def parse_eval_into_hash(value, default_key)
34
+ h = {}
35
+ a = parse_eval_into_array(value)
36
+ a.each do |v|
37
+ if v.is_a?(Hash)
38
+ h.merge!(v)
39
+ else #it adds any additional non-hash args using default key, if key,val exists, it changes to array and appends
40
+ prev = h[default_key]
41
+ if prev.nil? #nil just add it
42
+ h[default_key] = v
43
+ elsif prev.is_a?(Array) #was array, concat
44
+ h[default_key] = prev+v
45
+ else #anything else, make it into array
46
+ h[default_key] = [prev, v]
47
+ end
48
+ end
49
+ end
50
+ h
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,29 @@
1
+ #
2
+ # Installs hooks in ActionController::Layout to add layouts defined in MasterView templates
3
+ # to the list of layout template paths.
4
+ #
5
+ # Rails assumes everything is file-based and that there will be a file for each layout.
6
+ # MasterView template compilation of .html directly into the .rhtml erb cache
7
+ # introduces a separation betweeen the file name and the cache entry
8
+ # that does not fit the Rails viewpoint.
9
+ #
10
+
11
+ module ActionController #:nodoc:
12
+ module Layout #:nodoc:
13
+ module ClassMethods #:nodoc:
14
+
15
+ # get list of layout template paths, original rails implementation assumes everything is file based
16
+ # so this method is enhanced to pull layouts out of MasterView and concatenate them to the list
17
+ # from rails
18
+ alias :layout_list_pre_mv :layout_list #:nodoc:
19
+ def layout_list #:nodoc:
20
+ mv_layouts = []
21
+ MasterView::IOMgr.erb.find do |mio|
22
+ mv_layouts << "#{template_root}/"+mio.pathname.to_s if mio.pathname.to_s.starts_with?('layouts/')
23
+ end
24
+ layout_list_pre_mv.concat( mv_layouts )
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,27 @@
1
+ #
2
+ # Installs hooks to insert MasterView changed-template reparsing
3
+ # into the Rails request dispatching handler in ActionController::Base.
4
+ #
5
+ # Ensures that MasterView output files are always current while running a
6
+ # Rails application. The <code>:rails_reparse_checking</code> option in the
7
+ # MasterView configuration should generally be enabled/disabled in conjunction
8
+ # with Rails class load caching, which is normally off in a development environment
9
+ # configuration.
10
+ #
11
+ # Requires that MasterView templates be parsed at application startup to properly
12
+ # initialize the mechanism for detecting template changes after application startup.
13
+ #
14
+
15
+ module ActionController #:nodoc:
16
+ class Base #:nodoc
17
+ # Install hook to enable MasterView to detect and automatically reparse
18
+ # changed templates during Rails request dispatching.
19
+ alias :process_pre_mv :process #:nodoc:
20
+ def process(request, response, method = :perform_action, *arguments) #:nodoc:
21
+ MasterView::TemplateWatcher.check_updated(MasterView::IOMgr.template, MasterView::TemplateFilenamePattern ) do |mio|
22
+ MasterView::Parser.parse_mio( mio, MasterView::IOMgr.erb )
23
+ end
24
+ process_pre_mv(request, response, method, *arguments)
25
+ end
26
+ end
27
+ end
@@ -1,40 +1,19 @@
1
- #!/usr/bin/env ruby
2
-
3
- #--
4
- # Copyright (c) 2006 Jeff Barczewski
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining
7
- # a copy of this software and associated documentation files (the
8
- # "Software"), to deal in the Software without restriction, including
9
- # without limitation the rights to use, copy, modify, merge, publish,
10
- # distribute, sublicense, and/or sell copies of the Software, and to
11
- # permit persons to whom the Software is furnished to do so, subject to
12
- # the following conditions:
13
1
  #
14
- # The above copyright notice and this permission notice shall be
15
- # included in all copies or substantial portions of the Software.
2
+ # Installs hooks in ActionView::Base to intercept template_exist? calls
3
+ # and read_template_file so that Rails can find MasterView templates.
16
4
  #
17
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
- #++
5
+ # MasterView cannot use the provided hooks because Rails always assumes
6
+ # everything is file based and that there will be a file for each thing to render.
7
+ # MasterView template compilation of .html directly into the .rhtml erb cache
8
+ # introduces a separation betweeen the file name and the cache entry
9
+ # that does not fit this viewpoint.
25
10
  #
26
- # Setup hook to intercept template_exist? calls and read_template_file
27
- # so that rails can find masterview templates. MasterView cannot use the
28
- # provided hooks because rails always assumes everything is file based
29
- # and that there will be a file for each thing to render. If the
30
- # template dispatching code is enriched in the future we may be able
31
- # to rewrite this code to use the provided hooks
11
+ # If the template dispatching code is enriched in the future we may be able
12
+ # to rewrite this code to use the provided hooks.
32
13
  #
33
- #
34
-
35
- MasterView::Log.info { 'Adding hooks to enable Rails to read erb directly from MasterView' }
36
14
 
37
15
  module ActionView #:nodoc:
16
+
38
17
  class Base #:nodoc:
39
18
 
40
19
  # checks for template existence, uses standard rails file based check first and if not found
@@ -58,7 +37,7 @@ module ActionView #:nodoc:
58
37
  end
59
38
 
60
39
  # Check whether compilation is necessary.
61
- # Since rails compile_templat? is file based there was no easy way to hook into
40
+ # Since rails compile_template? is file based there was no easy way to hook into
62
41
  # this, so much of this method had to be duplicated.
63
42
  # If file_name exists in MasterView then check mtime from it otherwise defer to
64
43
  # original code.
@@ -92,7 +71,6 @@ module ActionView #:nodoc:
92
71
 
93
72
  end
94
73
 
95
-
96
74
  # The TemplateError exception is raised when the compilation of the template fails. This exception then gathers a
97
75
  # bunch of intimate details and uses it to report a very precise exception message.
98
76
  # Extend source_extract to be able to pull from MasterView if exists and fallback to file system
@@ -118,29 +96,4 @@ module ActionView #:nodoc:
118
96
  end
119
97
  end
120
98
 
121
- end
122
-
123
-
124
-
125
-
126
- module ActionController #:nodoc:
127
- module Layout #:nodoc:
128
- module ClassMethods
129
-
130
- # get list of layout template paths, original rails implementation assumes everything is file based
131
- # so this method is enhanced to pull layouts out of MasterView and concatenate them to the list
132
- # from rails
133
- alias :layout_list_pre_mv :layout_list
134
- def layout_list
135
- mv_layouts = []
136
- MasterView::IOMgr.erb.find do |mio|
137
- mv_layouts << "#{template_root}/"+mio.pathname.to_s if mio.pathname.to_s.starts_with?('layouts/')
138
- end
139
- layout_list_pre_mv.concat( mv_layouts )
140
- end
141
-
142
- end
143
- end
144
- end
145
-
146
- MasterView::LoadedFeatures[:rails_erb_mv_direct] = true
99
+ end
@@ -117,8 +117,9 @@ module MasterView
117
117
  #Log.debug { li.inspect }
118
118
  con = builder.data(li.name, li.index)
119
119
  if li.import
120
- con = con.gsub NamespacePrefix+'generate', NamespacePrefix+'import'
121
- con.gsub! NamespacePrefix+'gen_partial', NamespacePrefix+'import_render'
120
+ mv_ns = DirectiveRegistry.current.mv_namespace_prefix
121
+ con = con.gsub mv_ns+'generate', mv_ns+'import'
122
+ con.gsub! mv_ns+'gen_partial', mv_ns+'import_render'
122
123
  end
123
124
  out << con
124
125
  end
data/lib/masterview.rb CHANGED
@@ -23,18 +23,18 @@
23
23
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
24
  #++
25
25
  #
26
- # = MasterView - Rails-optimized (x)html friendly template engine
27
- #
28
- # MasterView is a ruby/rails optimized HTML/XHTML friendly template engine.
29
- # It is designed to use the full power and productivity of rails including
30
- # layouts, partials, and rails html helpers while still being editable/styleable
26
+ # = MasterView - Rails-optimized (x)html friendly template engine
27
+ #
28
+ # MasterView is a ruby/rails optimized HTML/XHTML friendly template engine.
29
+ # It is designed to use the full power and productivity of rails including
30
+ # layouts, partials, and rails html helpers while still being editable/styleable
31
31
  # in a WYSIWYG HTML editor.
32
- #
32
+ #
33
33
  # The MasterView template engine supports a number of configuration settings
34
34
  # which allow a client to easily customize its operation.
35
35
  # See MasterView::Configuration for a complete description of the
36
36
  # supported configuration options.
37
- #
37
+ #
38
38
  #--
39
39
  #TODO: add some documentation in MasterView::DirectiveBase for directive developers:
40
40
  # Reference the MV logger using <code>MasterView::Log</code>
@@ -59,12 +59,12 @@ end
59
59
  # is loaded below and then to perform final installation configuration.
60
60
  should_run_initializer = defined?(MasterView::ConfigSettings).nil?
61
61
  if should_run_initializer
62
- require 'masterview/initializer'
62
+ require 'masterview/initializer' # pulls in masterview/directive_load_path, directive_metadata
63
63
  MasterView::Initializer.run(:initialize_configuration) # bail out at load_plugin to continue below
64
64
  end
65
65
 
66
66
  #external requires
67
- require 'rexml/parsers/sax2parser'
67
+ require 'rexml/parsers/sax2parser_with_doctype_fix'
68
68
  require 'rexml/sax2listener'
69
69
  require 'cgi'
70
70
  require 'fileutils'
@@ -75,6 +75,7 @@ require 'stringio'
75
75
  require 'set'
76
76
  require 'pathname'
77
77
  require 'ostruct'
78
+ require 'yaml'
78
79
 
79
80
  #external gem requires
80
81
  require 'facets/core/string/blank'
@@ -89,20 +90,28 @@ rescue LoadError
89
90
  # Tidy was not available to load
90
91
  end
91
92
 
93
+ #internal requires - ruby and rails extensions
94
+ require 'masterview/core_ext/pathname'
95
+ require 'masterview/core_ext/string'
96
+
92
97
  #internal requires
93
98
  require 'masterview/masterview_version'
94
99
  require 'masterview/masterview_info'
95
- require 'masterview/pathname_extensions'
100
+ require 'masterview/case_insensitive_hash'
96
101
  require 'masterview/filter_helpers'
97
102
  require 'masterview/mtime_tracking_hash'
103
+ require 'masterview/exceptions'
98
104
  require 'masterview/io'
99
105
  require 'masterview/keyword_expander'
100
- require 'masterview/string_extensions'
101
- require 'masterview/directive_registry'
102
106
  require 'masterview/plugin_load_tracking'
103
107
  require 'masterview/attr_string_parser'
108
+ #require 'masterview/directive_metadata' # already loaded by initializer
109
+ require 'masterview/directive_dsl'
104
110
  require 'masterview/directive_helpers'
105
111
  require 'masterview/directive_base'
112
+ #require 'masterview/directive_load_path' # already loaded by initializer
113
+ require 'masterview/directive_registry'
114
+ require 'masterview/parser_helpers'
106
115
  require 'masterview/parser'
107
116
  require 'masterview/analyzer'
108
117
  require 'masterview/template_spec'