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
@@ -1,24 +1,25 @@
1
1
  module MasterView
2
2
  module Directives
3
3
 
4
- #outputs an elsif/end block around the text tags and remove previous end (from if)
4
+ # outputs an elsif/end block around the text tags and remove previous end (from if)
5
+ #
5
6
  class Elsif < MasterView::DirectiveBase
6
- def priority
7
- DirectivePriorities::High
8
- end
9
7
 
10
- def stag(directive_call_stack)
8
+ metadata :priority => 'High',
9
+ :category => 'erb',
10
+ :description => 'Used in conjunction with the mv:if directive to allow you to create if... elsif... end blocks'
11
+
12
+ # remove the last <% end -%> from the parent tag's content and add a <% else -%> instead.
13
+ # This is a continuation of previous if or elsif statement.
14
+ event :before_stag do
11
15
  tag = @directive_call_stack.context[:tag]
12
- delete_last_in_parent(tag, erb('end') )
13
- ret = []
14
- ret << erb('elsif '+attr_value)
15
- ret << directive_call_stack.render
16
+ delete_last_in_parent(tag, erb_eval('end') )
17
+ render erb_eval( 'elsif', attr_value )
16
18
  end
17
19
 
18
- def etag(directive_call_stack)
19
- ret = []
20
- ret << directive_call_stack.render
21
- ret << erb('end')
20
+ # output <% end -%> after everything
21
+ event :after_etag do
22
+ render erb_eval( 'end' )
22
23
  end
23
24
 
24
25
  end
@@ -0,0 +1,20 @@
1
+ module MasterView
2
+ module Directives
3
+
4
+ # outputs a <% attr_value %> before the element
5
+ # example: <foo><bar mv:eval="i = 1">baz</bar></foo>
6
+ # becomes: <foo><% i = 1 %><bar>baz</bar></foo>
7
+ # Inspired by Sergey Shalatskly's silent tag
8
+ class Eval < MasterView::DirectiveBase
9
+
10
+ metadata :priority => 'MediumHigh',
11
+ :category => 'erb',
12
+ :description => 'Inserts an rhtml evaluation expression for the attribute value prior to the element'
13
+
14
+ event :before_stag do
15
+ render erb_eval( attr_value )
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -1,19 +1,66 @@
1
1
  module MasterView
2
2
  module Directives
3
3
 
4
- # creates start_form_tag and end_form_tag from values in form
4
+ # creates form_tag block and ending form tag from values in form
5
+ #
5
6
  class Form < MasterView::DirectiveBase
6
- def stag(directive_call_stack)
7
- options = {}
8
- options[:multipart] = true if attr_lckv_matches('enctype', 'multipart/form-data')
9
- options[:method] = 'get' if attr_lckv_matches('method', 'get')
10
- merge_hash_attr_value!(1, options)
11
- erb_content('form_tag ' + attr_value)
7
+
8
+ metadata :priority => :default,
9
+ :category => 'form',
10
+ :description => 'Replaces the start and end tags of the element using the Rails form_tag helper and an ending form tag',
11
+ :element_usage => 'form'
12
+
13
+ attr_arg :url_for_options
14
+ attr_arg :options, :append_element_attrs => [:common_html, :method]
15
+ attr_arg :parameters_for_url, :varargs => true
16
+
17
+ event :stag do
18
+ merge_hash_into_str( {:multipart => true}, @options ) if element_attrs.get_lowercase_str_value('enctype') == 'multipart/form-data'
19
+ render erb_content( 'form_tag', :url_for_options, :options, :parameters_for_url )
12
20
  end
13
21
 
14
- def etag(directive_call_stack)
15
- erb_content('end_form_tag')
22
+ event :etag do
23
+ render '</form>'
16
24
  end
25
+
17
26
  end
27
+
18
28
  end
19
29
  end
30
+
31
+
32
+
33
+ =begin
34
+
35
+ module MasterView
36
+ module Directives
37
+
38
+ # once rails 1.2 is released we can use the form_tag block method of the helper but this does not work prior to rails 1.2
39
+ # creates form_tag block from values in form
40
+ #
41
+ class Form < MasterView::DirectiveBase
42
+
43
+ metadata :priority => :default,
44
+ :category => 'form',
45
+ :description => 'Replaces the start and end tags of the element using the Rails form_tag block helper',
46
+ :element_usage => 'form'
47
+
48
+ attr_arg :url_for_options
49
+ attr_arg :options, :append_element_attrs => [:common_html, :method]
50
+ attr_arg :parameters_for_url, :varargs => true
51
+
52
+ event :stag do
53
+ merge_hash_into_str( {:multipart => true}, @options ) if element_attrs.get_lowercase_str_value('enctype') == 'multipart/form-data'
54
+ render erb_eval( prepare_output('form_tag', :url_for_options, :options, :parameters_for_url)+' do' ) # call prepare_output directly so do won't be embedded in method call
55
+ end
56
+
57
+ event :etag do
58
+ render erb_eval( 'end' )
59
+ end
60
+
61
+ end
62
+ end
63
+ end
64
+
65
+ =end
66
+
@@ -0,0 +1,26 @@
1
+ module MasterView
2
+ module Directives
3
+
4
+ # creates form_remote_tag and closing form tag from values in form
5
+ #
6
+ class FormRemote < MasterView::DirectiveBase
7
+
8
+ metadata :priority => :default,
9
+ :category => 'form',
10
+ :description => 'Replaces the start and end tags of the element using the Rails form_remote_tag helper and </form> for Ajax-enabled form submission using the Prototype library',
11
+ :element_usage => 'form'
12
+
13
+ attr_arg :options, :append_element_attrs => [:common_html, :method]
14
+
15
+ event :stag do
16
+ merge_hash_into_str( {:multipart => true}, @options ) if element_attrs.get_lowercase_str_value('enctype') == 'multipart/form-data'
17
+ render erb_content( 'form_remote_tag', :options )
18
+ end
19
+
20
+ event :etag do
21
+ render '</form>'
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -3,24 +3,21 @@ module MasterView
3
3
 
4
4
  #outputs a block around the text tags, if left bracket count is higher than right
5
5
  #assume that the end is a right bracket otherwise use end
6
- class Global_inline_erb < MasterView::DirectiveBase
6
+ class GlobalInlineErb < MasterView::DirectiveBase
7
+
8
+ metadata :priority => 'Low',
9
+ :global_directive? => true,
10
+ :category => 'erb',
11
+ :description => 'Inline substitution notation for Erb expressions'
12
+
7
13
  def initialize(attribute_value = nil)
8
14
  super(attribute_value)
9
15
  end
10
16
 
11
- def priority
12
- DirectivePriorities::Low
13
- end
14
-
15
- def global_directive?
16
- true
17
- end
18
-
19
- def stag(dcs)
20
- attrs.each do |key, value|
17
+ event :before_stag do
18
+ element_attrs.each do |key, value|
21
19
  replace_with_erb!( value )
22
20
  end
23
- dcs.render
24
21
  end
25
22
 
26
23
  def characters(dcs)
@@ -28,12 +25,11 @@ module MasterView
28
25
  dcs.render
29
26
  end
30
27
 
31
- private
32
-
33
28
  def replace_with_erb!(value)
34
29
  subs = value.gsub!( MasterView::InlineErbSubstitutionRegex, '<%\1%>' )
35
30
  end
36
31
 
32
+
37
33
  end
38
34
  end
39
35
  end
@@ -1,29 +1,20 @@
1
1
  module MasterView
2
2
  module Directives
3
3
 
4
- class Hidden_field < MasterView::DirectiveBase
5
- def stag(dcs)
6
- #eat
7
- end
8
-
9
- def etag(dcs)
10
- args = parse_attr_value
11
- obj = args[0]
12
- method = args[1]
4
+ class HiddenField < MasterView::DirectiveBase
13
5
 
14
- obj = quote_if(obj)
15
- method = quote_if(method)
6
+ metadata :priority => :default,
7
+ :category => 'form',
8
+ :description => 'Replaces the element with a hidden input element using the Rails hidden_tag helper',
9
+ :element_usage => 'input'
16
10
 
17
- options = {}
18
- options.merge! common_html_options(attrs_lck)
19
- remove_strings_from_attr_value!
20
- merge_hash_attr_value!(0, options)
11
+ attr_arg :obj, :quote => true
12
+ attr_arg :method, :quote => true
13
+ attr_arg :value, :default => nil
14
+ attr_arg :options, :append_element_attrs => [:common_html]
21
15
 
22
- a = []
23
- a << 'hidden_field '+ obj
24
- a << method
25
- a << attr_value unless attr_value.strip.empty?
26
- erb_content(a.join(', '))
16
+ event :element do
17
+ render erb_content( 'hidden_field', :obj, :method, :value, :options )
27
18
  end
28
19
 
29
20
  end
@@ -1,22 +1,23 @@
1
1
  module MasterView
2
2
  module Directives
3
3
 
4
- #outputs an if/end block around the text tags
4
+ # outputs an if/end block around the text tags
5
+ #
5
6
  class If < MasterView::DirectiveBase
6
- def priority
7
- DirectivePriorities::High
8
- end
9
7
 
10
- def stag(directive_call_stack)
11
- ret = []
12
- ret << erb('if '+attr_value)
13
- ret << directive_call_stack.render
8
+ metadata :priority => 'High',
9
+ :category => 'erb',
10
+ :description => 'Wraps the element with an if... end block using the attribute value for the condition'
11
+
12
+ #TODO: omit element entirely if attr_value == 'false'
13
+ #TODO: don't need to generate conditional block wrapping if attr_value == 'true'
14
+
15
+ event :before_stag do
16
+ render erb_eval( 'if', attr_value )
14
17
  end
15
18
 
16
- def etag(directive_call_stack)
17
- ret = []
18
- ret << directive_call_stack.render
19
- ret << erb('end')
19
+ event :after_etag do
20
+ render erb_eval( 'end' )
20
21
  end
21
22
 
22
23
  end
@@ -4,42 +4,34 @@ module MasterView
4
4
  # creates a image_tag.
5
5
  # if path is specified in attr_value then it will be used exactly as listed, otherwise if attr_value is empty
6
6
  # then masterview will attempt to find the public/images in the string and infer the path from what follows.
7
- # otherwise it will simply use the src path.
7
+ # otherwise it will simply use the src path.
8
8
  # If both width and height attr values are specified then it will build the :size option from them.
9
9
  # Other html attributes will be passed into image_tag options.
10
- class Image_tag < MasterView::DirectiveBase
10
+ class ImageTag < MasterView::DirectiveBase
11
11
 
12
12
  # /public\/images\/(.*)/
13
13
  IMAGE_SRC_EXTRACT_REGEX = MasterView::ConfigSettings.template_asset_base_ref_pattern[:images]
14
14
 
15
- def stag(dcs)
16
- end
17
-
18
- def etag(dcs)
19
- src = attrs_lck['src']
20
- if attr_value.empty? && src
21
- match = IMAGE_SRC_EXTRACT_REGEX.match(src)
22
- image_loc = (match) ? match[1] : src
23
- else
24
- image_loc = attr_value
15
+ metadata :priority => :default,
16
+ :category => 'asset',
17
+ :description => 'Replaces the element using the Rails image_tag helper.',
18
+ :element_usage => 'img'
19
+
20
+ attr_arg :src
21
+ attr_arg :options, :append_element_attrs => [:common_html]
22
+
23
+ event :element do
24
+ if (@src.nil? or @src.empty?) and src_attr = element_attrs[:src]
25
+ if match = IMAGE_SRC_EXTRACT_REGEX.match(src_attr)
26
+ @src = match[1]
27
+ else
28
+ @src = src_attr
29
+ end
25
30
  end
26
-
27
- image_tag_params = quote(image_loc)
28
- attrs.delete('src') # delete this if exists, path has already been specified
29
-
30
- width = attrs_lck['width']
31
- height = attrs_lck['height']
32
- if width && height
33
- attrs.delete('width') #delete these since being used in size
34
- attrs.delete('height')
35
- attrs[:size] = "#{width}x#{height}"
36
- end
37
-
38
- options = symbolize_sort_and_serialize_hash_to_str(attrs)
39
- image_tag_params += (', '+options) unless options.empty?
40
-
41
- erb_content('image_tag ' + image_tag_params)
31
+ @src = quote(@src) unless @src.nil?
32
+ render erb_content('image_tag', :src, :options)
42
33
  end
34
+
43
35
  end
44
36
 
45
37
  end
@@ -3,20 +3,13 @@ module MasterView
3
3
 
4
4
  # just eat this output since it is only used for design time
5
5
  class Import < MasterView::DirectiveBase
6
- def priority
7
- DirectivePriorities::VeryHigh
8
- end
9
6
 
10
- def stag(dcs)
11
- #output nothing
12
- end
13
-
14
- def etag(dcs)
15
- tag = dcs.context[:tag]
16
- tag.content = [] # clear out any content including from children
17
- nil
18
- end
7
+ metadata :priority => 'VeryHigh',
8
+ :category => 'processing',
9
+ :description => 'Design-time directive to mark a snapshot of generated code'
19
10
 
11
+ event :element, :render => :nothing
12
+
20
13
  end
21
14
  end
22
15
  end
@@ -1,27 +1,15 @@
1
1
  module MasterView
2
2
  module Directives
3
3
 
4
- # just eat this output since it is only used for design time
5
- class Import_render < MasterView::DirectiveBase
6
- def priority
7
- DirectivePriorities::VeryHigh
8
- end
4
+ # output the render partial after expanding keywords
5
+ class ImportRender < MasterView::DirectiveBase
9
6
 
10
- # need to expand keywords
11
- def initialize(attribute_value)
12
- super(attribute_value)
13
- @attribute_value = Renderer.last_renderer.keyword_expander.expand_keywords(attribute_value)
14
- end
7
+ metadata :priority => 'VeryHigh',
8
+ :category => 'processing',
9
+ :description => 'Design-time directive to mark a snapshot of generated partial code, outputs render partial after expanding keywords'
15
10
 
16
- def stag(dcs)
17
- #output nothing
18
- end
19
-
20
- def etag(dcs)
21
- tag = dcs.context[:tag]
22
- tag.content = [] # clear out any content including from children
23
- ret = []
24
- ret << erb_content('render( '+attr_value+' )')
11
+ event :element do
12
+ render erb_content( 'render', self.renderer.keyword_expander.expand_keywords(attr_value) )
25
13
  end
26
14
 
27
15
  end
@@ -5,25 +5,22 @@ module MasterView
5
5
  # and should not be edited, else changes could be lost. The standard generated-file
6
6
  # comment includes the path to the original file that should be edited.
7
7
  #
8
- class Insert_generated_comment < MasterView::DirectiveBase
8
+ class InsertGeneratedComment < MasterView::DirectiveBase
9
9
 
10
10
  # Configured value for generated comment text is eval'd to support #{template_path} field substitution
11
11
  Comment_eval_template = 'comment_text = "' + MasterView::GeneratedCommentText + '"'
12
12
 
13
- def priority
14
- DirectivePriorities::VeryLow
15
- end
13
+ metadata :priority => 'VeryLow',
14
+ :category => 'internal'
15
+
16
+ attr_arg :comment_template_path
16
17
 
17
- def stag(directive_call_stack)
18
- # do variable substitution to fill in any slots in the template
19
- template_path = attr_value
18
+ event :after_stag do
19
+ template_path = @comment_template_path
20
20
  comment_text = ''
21
21
  eval(Comment_eval_template, binding)
22
22
  comment = "\n<%\n#{comment_text}\n-%>" # "\n#{ERB_EVAL_START.strip()}\n#{comment_text}\n#{ERB_EVAL_END.strip()}"
23
-
24
- ret = []
25
- ret << directive_call_stack.render
26
- ret << comment
23
+ render comment
27
24
  end
28
25
 
29
26
  end
@@ -1,25 +1,34 @@
1
1
  module MasterView
2
2
  module Directives
3
3
 
4
- #creates a link_to
5
- class Javascript_include < MasterView::DirectiveBase
4
+ #creates a javascript_include asset helper
5
+ #
6
+ class JavascriptInclude < MasterView::DirectiveBase
6
7
 
7
8
  # /public\/javascripts\/(.*)/
8
9
  JAVASCRIPT_SRC_EXTRACT_REGEX = MasterView::ConfigSettings.template_asset_base_ref_pattern[:javascripts]
9
10
 
10
- def stag(dcs)
11
- end
11
+ metadata :priority => :default,
12
+ :category => 'asset',
13
+ :description => 'Replaces the element with the Rails javascript_include_tag helper',
14
+ :element_usage => 'script'
15
+
16
+ attr_arg :src, :varargs => true
12
17
 
13
- def etag(dcs)
14
- src = attrs_lck['src']
15
- if attr_value.empty? && src
16
- match = JAVASCRIPT_SRC_EXTRACT_REGEX.match(src)
17
- js_loc = quote( (match) ? match[1] : src )
18
- else
19
- js_loc = attr_value.starts_with?(':') ? attr_value : quote(attr_value)
18
+ event :element do
19
+ if @src.nil? or @src.empty?
20
+ if src_attr = element_attrs[:src]
21
+ if match = JAVASCRIPT_SRC_EXTRACT_REGEX.match(src_attr)
22
+ @src = [match[1]]
23
+ else
24
+ @src = [src_attr]
25
+ end
26
+ end
20
27
  end
21
- erb_content('javascript_include_tag ' + js_loc)
28
+ @src.collect! { |x| x.starts_with?(':') ? x : quote(x) }
29
+ render erb_content('javascript_include_tag', :src)
22
30
  end
31
+
23
32
  end
24
33
 
25
34
  end
@@ -2,16 +2,22 @@ module MasterView
2
2
  module Directives
3
3
 
4
4
  #creates a link_to
5
- class Link_to < MasterView::DirectiveBase
6
- def stag(dcs)
7
- end
5
+ class LinkTo < MasterView::DirectiveBase
6
+
7
+ metadata :priority => :default,
8
+ :category => 'link',
9
+ :description => 'Replaces the element using the Rails link_to helper',
10
+ :element_usage => 'a'
8
11
 
9
- def etag(dcs)
10
- remove_strings_from_attr_value!
11
- prepend_to_attr_value! quote( content_str ) #prepend quoted link name
12
- self.content=''
13
- erb_content('link_to ' + attr_value)
12
+ attr_arg :name do |value, args| if value.include?('=>') : args.unshift(value); end; nil; end # if hash push back on, discard name
13
+ attr_arg :options, :default => {}
14
+ attr_arg :html_options, :default => {}, :append_element_attrs => [:common_html]
15
+ attr_arg :params, :varargs => true
16
+
17
+ event :element do
18
+ render erb_content('link_to', quote(content_string), :options, :html_options, :params)
14
19
  end
20
+
15
21
  end
16
22
  end
17
23
  end
@@ -0,0 +1,22 @@
1
+ module MasterView
2
+ module Directives
3
+
4
+ #creates a link_to_function
5
+ class LinkToFunction < MasterView::DirectiveBase
6
+
7
+ metadata :priority => :default,
8
+ :category => 'link',
9
+ :description => 'Replaces the element with the Rails link_to_function helper which creates a link which calls a JavaScript function.',
10
+ :element_usage => 'a'
11
+
12
+ attr_arg :function
13
+ attr_arg :html_options, :append_element_attrs => [:common_html]
14
+
15
+ event :element do
16
+ @function = quote(@function, '"') unless @function.strip =~ /^('|")/ # quote unless already quoted, use double quote
17
+ render erb_content('link_to_function', quote(content_string), :function, :html_options)
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -1,21 +1,23 @@
1
1
  module MasterView
2
2
  module Directives
3
3
 
4
- class Link_to_if < MasterView::DirectiveBase
5
- def stag(dcs)
6
- end
4
+ class LinkToIf < MasterView::DirectiveBase
5
+
6
+ metadata :priority => :default,
7
+ :category => 'link',
8
+ :description => 'Replaces the element using the Rails link_to_if helper',
9
+ :element_usage => 'a'
7
10
 
8
- def etag(dcs)
9
- args = parse_attr_value
10
- condition = args[0]
11
- remove_strings_from_attr_value!
12
- a = []
13
- a << 'link_to_if '+condition
14
- a << quote(content_str)
15
- a << attr_value unless attr_value.strip.empty?
16
- self.content=''
17
- erb_content(a.join(', '))
11
+ attr_arg :condition
12
+ attr_arg :name do |value, args| if value.include?('=>') : args.unshift(value); end; nil; end # if hash push back on, discard name
13
+ attr_arg :options, :default => {}
14
+ attr_arg :html_options, :default => {}, :append_element_attrs => [:common_html]
15
+ attr_arg :params, :varargs => true #including the block
16
+
17
+ event :element do
18
+ render erb_content('link_to_if', :condition, quote(content_string), :options, :html_options, :params)
18
19
  end
20
+
19
21
  end
20
22
  end
21
23
  end
@@ -2,16 +2,21 @@ module MasterView
2
2
  module Directives
3
3
 
4
4
  #creates a link_to_remote
5
- class Link_to_remote < MasterView::DirectiveBase
6
- def stag(dcs)
7
- end
5
+ class LinkToRemote < MasterView::DirectiveBase
6
+
7
+ metadata :priority => :default,
8
+ :category => 'link',
9
+ :description => 'Replaces the element using the Rails link_to_remote helper',
10
+ :element_usage => 'a'
8
11
 
9
- def etag(dcs)
10
- remove_strings_from_attr_value!
11
- prepend_to_attr_value! quote( content_str ) #prepend quoted link name
12
- self.content=''
13
- erb_content('link_to_remote ' + attr_value)
12
+ attr_arg :name do |value, args| if value.include?('=>') : args.unshift(value); end; nil; end # if hash push back on, discard name
13
+ attr_arg :options, :default => {}
14
+ attr_arg :html_options, :default => {}, :append_element_attrs => [:common_html]
15
+
16
+ event :element do
17
+ render erb_content('link_to_remote', quote(content_string), :options, :html_options)
14
18
  end
19
+
15
20
  end
16
21
  end
17
22
  end