masterview 0.0.2 → 0.0.3

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 (76) hide show
  1. data/CHANGELOG +3 -1
  2. data/Rakefile +201 -37
  3. metadata +23 -85
  4. data/generators/masterview/USAGE +0 -32
  5. data/generators/masterview/masterview_generator.rb +0 -277
  6. data/generators/masterview/templates/controller.rb +0 -50
  7. data/generators/masterview/templates/fields_scaffold.rhtml +0 -1
  8. data/generators/masterview/templates/form_scaffold.rhtml +0 -3
  9. data/generators/masterview/templates/functional_test.rb +0 -83
  10. data/generators/masterview/templates/helper.rb +0 -2
  11. data/generators/masterview/templates/layout.rhtml +0 -11
  12. data/generators/masterview/templates/list_head_scaffold.rhtml +0 -4
  13. data/generators/masterview/templates/list_line_scaffold.rhtml +0 -6
  14. data/generators/masterview/templates/masterview.rhtml +0 -182
  15. data/generators/masterview/templates/mvpreview.js +0 -31
  16. data/generators/masterview/templates/semantic.cache +0 -84
  17. data/generators/masterview/templates/show_scaffold.rhtml +0 -3
  18. data/generators/masterview/templates/style.css +0 -61
  19. data/generators/masterview_gem_plugin/masterview_gem_plugin_generator.rb +0 -21
  20. data/generators/masterview_gem_plugin/templates/init.rb +0 -43
  21. data/init.rb +0 -43
  22. data/lib/masterview/directive_base.rb +0 -163
  23. data/lib/masterview/directive_helpers.rb +0 -176
  24. data/lib/masterview/directives/block.rb +0 -30
  25. data/lib/masterview/directives/content.rb +0 -10
  26. data/lib/masterview/directives/else.rb +0 -25
  27. data/lib/masterview/directives/elsif.rb +0 -26
  28. data/lib/masterview/directives/form.rb +0 -19
  29. data/lib/masterview/directives/global_inline_erb.rb +0 -39
  30. data/lib/masterview/directives/hidden_field.rb +0 -31
  31. data/lib/masterview/directives/if.rb +0 -24
  32. data/lib/masterview/directives/insert_generated_comment.rb +0 -30
  33. data/lib/masterview/directives/javascript_include.rb +0 -15
  34. data/lib/masterview/directives/link_to.rb +0 -17
  35. data/lib/masterview/directives/link_to_if.rb +0 -21
  36. data/lib/masterview/directives/link_to_remote.rb +0 -17
  37. data/lib/masterview/directives/password_field.rb +0 -33
  38. data/lib/masterview/directives/preview.rb +0 -10
  39. data/lib/masterview/directives/replace.rb +0 -18
  40. data/lib/masterview/directives/stylesheet_link.rb +0 -14
  41. data/lib/masterview/directives/submit.rb +0 -14
  42. data/lib/masterview/directives/testfilter.rb +0 -55
  43. data/lib/masterview/directives/text_area.rb +0 -34
  44. data/lib/masterview/directives/text_field.rb +0 -33
  45. data/lib/masterview/extras/rails_init.rb +0 -67
  46. data/lib/masterview/extras/watcher.rb +0 -30
  47. data/lib/masterview/masterview_version.rb +0 -9
  48. data/lib/masterview/parser.rb +0 -585
  49. data/lib/masterview/plugin_load_tracking.rb +0 -41
  50. data/lib/masterview/runtime_helpers.rb +0 -9
  51. data/lib/masterview/string_extensions.rb +0 -15
  52. data/lib/masterview.rb +0 -130
  53. data/test/block_test.rb +0 -47
  54. data/test/content_test.rb +0 -26
  55. data/test/else_test.rb +0 -31
  56. data/test/elsif_test.rb +0 -31
  57. data/test/example_test.rb +0 -11
  58. data/test/filter_helpers_test.rb +0 -142
  59. data/test/form_test.rb +0 -66
  60. data/test/global_inline_erb_test.rb +0 -30
  61. data/test/hidden_field_test.rb +0 -62
  62. data/test/if_test.rb +0 -23
  63. data/test/javascript_include_test.rb +0 -26
  64. data/test/link_to_if_test.rb +0 -27
  65. data/test/link_to_test.rb +0 -52
  66. data/test/parser_test.rb +0 -166
  67. data/test/password_field_test.rb +0 -89
  68. data/test/replace_test.rb +0 -27
  69. data/test/run_parser_test.rb +0 -27
  70. data/test/stylesheet_link_test.rb +0 -26
  71. data/test/submit_test.rb +0 -54
  72. data/test/template_file_watcher_test.rb +0 -50
  73. data/test/template_test.rb +0 -181
  74. data/test/test_helper.rb +0 -24
  75. data/test/text_area_test.rb +0 -81
  76. data/test/text_field_test.rb +0 -89
@@ -1,84 +0,0 @@
1
- ;; Object templates/
2
- ;; SEMANTICDB Tags save file
3
- (semanticdb-project-database-file "templates/"
4
- :tables (list
5
- (semanticdb-table "masterview.rhtml"
6
- :major-mode 'html-mode
7
- :tags '((": {{{= controller.action_name }}}" section nil nil [74 282]) ("messages" section nil nil [282 411]) ("messages" section nil nil [411 540]) ("messages" section nil nil [540 667]) ("messages" section nil nil [667 808]) ("messages" section (:members (("Tasks:" section (:members (("Back to overview" section nil nil [1175 1403]))) nil [1143 1403]) ("Creating <%= singular_name %>" section (:members (("Creating <%= singular_name %>" section nil nil [1511 2406]))) nil [1403 2406]) ("Tasks:" section (:members (("Back to overview" section nil nil [2438 2667]))) nil [2406 2667]) ("Editing <%= singular_name %>" section (:members (("Editing <%= singular_name %>" section nil nil [2807 3579]))) nil [2667 3579]) ("Tasks:" section (:members (("Create new <%= singular_name %>" section nil nil [3611 3853]))) nil [3579 3853]) ("Previous page" section nil nil [3853 4650]) ("Tasks:" section (:members (("Back to overview" section nil nil [4682 4833]) ("Edit this <%= singular_name %>" section nil nil [4833 5108]))) nil [4650 5108]) ("Tasks:" section nil nil [5108 5495]) ("Tasks:" section (:members (("Back to overview" section nil nil [5530 5686]) ("Show this <%= singular_name %>" section nil nil [5686 5957]))) nil [5495 5957]) ("error messages" section nil nil [5957 6847]))) nil [808 6847]) ("mvpreview.copySections();
8
- mvpreview.showOneSection('product_list');" section nil nil [6847 6953]) ("mvpreview.copySections();
9
- mvpreview.showOneSection('product_list');" section nil nil [6953 6961]))
10
- :file "masterview.rhtml"
11
- :pointmax 7120
12
- :unmatched-syntax 'nil
13
- )
14
- (semanticdb-table "fields_scaffold.rhtml"
15
- :major-mode 'html-mode
16
- :tags 'nil
17
- :file "fields_scaffold.rhtml"
18
- :pointmax 60
19
- )
20
- (semanticdb-table "form.rhtml"
21
- :major-mode 'html-mode
22
- :tags 'nil
23
- :file "form.rhtml"
24
- :pointmax 81
25
- )
26
- (semanticdb-table "show_line_scaffolding.rhtml"
27
- :major-mode 'html-mode
28
- :tags 'nil
29
- :file "show_line_scaffolding.rhtml"
30
- :pointmax 284
31
- )
32
- (semanticdb-table "show_scaffold.rhtml"
33
- :major-mode 'html-mode
34
- :tags 'nil
35
- :file "show_scaffold.rhtml"
36
- :pointmax 132
37
- )
38
- (semanticdb-table "list_line_scaffold.rhtml"
39
- :major-mode 'html-mode
40
- :tags '(("Show" section nil nil [87 274]) ("Edit" section nil nil [274 461]) ("Destroy" section nil nil [461 464]))
41
- :file "list_line_scaffold.rhtml"
42
- :pointmax 621
43
- )
44
- (semanticdb-table "form_scaffold.rhtml"
45
- :major-mode 'html-mode
46
- :tags 'nil
47
- :file "form_scaffold.rhtml"
48
- :pointmax 132
49
- )
50
- (semanticdb-table "layout.rhtml"
51
- :major-mode 'html-mode
52
- :tags '((": <%%= controller.action_name %>" section nil nil [17 142]) ("" section nil nil [142 147]))
53
- :file "layout.rhtml"
54
- :pointmax 195
55
- )
56
- (semanticdb-table "view_destroy.rhtml"
57
- :major-mode 'html-mode
58
- :tags '(("Tasks:" section nil nil [22 290]) ("Are you sure you want to delete this item?" section nil nil [290 293]))
59
- :file "view_destroy.rhtml"
60
- :pointmax 516
61
- )
62
- (semanticdb-table "view_edit.rhtml"
63
- :major-mode 'html-mode
64
- :tags '(("Tasks:" section nil nil [22 163]) ("\"edit\", :id => @<%=singular_name%>.id %>
65
-
66
- <div class=\"form\">
67
- <h2>Editing <%= singular_name %>" section (:members (("Editing <%= singular_name %>" section nil nil [302 305]))) nil [163 166]))
68
- :file "view_edit.rhtml"
69
- :pointmax 482
70
- )
71
- (semanticdb-table "view_new.rhtml"
72
- :major-mode 'html-mode
73
- :tags '(("Tasks:" section nil nil [22 163]) ("\"new\" %>
74
-
75
- <div class=\"form\">
76
- <h2>Creating <%= singular_name %>" section (:members (("Creating <%= singular_name %>" section nil nil [270 273]))) nil [163 166]))
77
- :file "view_new.rhtml"
78
- :pointmax 451
79
- )
80
- )
81
- :file "semantic.cache"
82
- :semantic-tag-version "2.0pre3"
83
- :semanticdb-version "2.0pre3"
84
- )
@@ -1,3 +0,0 @@
1
- <table class="<%= singular_name %>_show_table" cellpadding="5">
2
- <%= all_input_tags(@model_instance, @singular_name, {}) %>
3
- </table>
@@ -1,61 +0,0 @@
1
- body { background-color: #fff; color: #333; }
2
-
3
- body, p, ol, ul, td {
4
- font-family: verdana, arial, helvetica, sans-serif;
5
- font-size: 13px;
6
- line-height: 18px;
7
- }
8
-
9
- pre {
10
- background-color: #eee;
11
- padding: 10px;
12
- font-size: 11px;
13
- }
14
-
15
- a { color: #000; }
16
- a:visited { color: #666; }
17
- a:hover { color: #fff; background-color:#000; }
18
-
19
- .fieldWithErrors {
20
- padding: 2px;
21
- background-color: red;
22
- display: table;
23
- }
24
-
25
- .messages {
26
- color: green;
27
- }
28
-
29
- .label {
30
- text-align: right;
31
- }
32
-
33
- #ErrorExplanation {
34
- width: 400px;
35
- border: 2px solid #red;
36
- padding: 7px;
37
- padding-bottom: 12px;
38
- margin-bottom: 20px;
39
- background-color: #f0f0f0;
40
- }
41
-
42
- #ErrorExplanation h2 {
43
- text-align: left;
44
- font-weight: bold;
45
- padding: 5px 5px 5px 15px;
46
- font-size: 12px;
47
- margin: -7px;
48
- background-color: #c00;
49
- color: #fff;
50
- }
51
-
52
- #ErrorExplanation p {
53
- color: #333;
54
- margin-bottom: 0;
55
- padding: 5px;
56
- }
57
-
58
- #ErrorExplanation ul li {
59
- font-size: 12px;
60
- list-style: square;
61
- }
@@ -1,21 +0,0 @@
1
- # Generator to generate small init.rb plugin which is used in
2
- # conjunction with the masterview gem
3
- class MasterviewGemPluginGenerator < Rails::Generator::Base
4
- def initialize(runtime_args, runtime_options = {})
5
- super
6
- end
7
-
8
- def manifest
9
- record do |m|
10
- m.directory 'vendor/plugins/masterview'
11
- m.directory 'vendor/plugins/masterview/directives'
12
- m.template 'init.rb', 'vendor/plugins/masterview/init.rb'
13
- end
14
- end
15
-
16
- protected
17
- def banner
18
- "Usage: #{$0} masterview_gem_plugin"
19
- end
20
-
21
- end
@@ -1,43 +0,0 @@
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
- #
14
- # The above copyright notice and this permission notice shall be
15
- # included in all copies or substantial portions of the Software.
16
- #
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
- #++
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
31
- # in a WYSIWYG HTML editor.
32
-
33
- require 'masterview'
34
-
35
- module ::MasterView
36
- #override any constants here, see masterview.rb for more
37
- #DefaultDirectiveLoadPaths.push File.join( File.dirname(__FILE__), 'directives') #uncomment if you want to add a local directives dir
38
- #DefaultParserOptions = { :tidy => false, :escape_erb => true }
39
- #TidyPath = '/usr/lib/libtidy.so'
40
- end
41
-
42
- require 'masterview/extras/rails_init.rb'
43
-
data/init.rb DELETED
@@ -1,43 +0,0 @@
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
- #
14
- # The above copyright notice and this permission notice shall be
15
- # included in all copies or substantial portions of the Software.
16
- #
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
- #++
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
31
- # in a WYSIWYG HTML editor.
32
-
33
- require 'masterview'
34
-
35
- module ::MasterView
36
- #override any constants here, see masterview.rb for more
37
- #DefaultDirectiveLoadPaths.push File.join( File.dirname(__FILE__), 'directives') #uncomment if you want to add a local directives dir
38
- #DefaultParserOptions = { :tidy => false, :escape_erb => true }
39
- #TidyPath = '/usr/lib/libtidy.so'
40
- end
41
-
42
- require 'masterview/extras/rails_init.rb'
43
-
@@ -1,163 +0,0 @@
1
- module MasterView
2
-
3
- class DirectiveBase
4
- include PluginLoadTracking
5
- include DirectiveHelpers
6
-
7
- # Register a class manually without regard to whether it inherits from DirectiveBase.
8
- # Classes which derive from DirectiveBase will automatically be registered as they are
9
- # loaded.
10
- def self.register_directive(directive_class)
11
- self.register_class(directive_class)
12
- end
13
-
14
- def initialize(attribute_value)
15
- @attribute_value = attribute_value
16
- end
17
-
18
- #if this method exists, it will be called by renderer to save directive_call_stack before each method call
19
- def save_directive_call_stack(directive_call_stack)
20
- @directive_call_stack = directive_call_stack
21
- end
22
-
23
- # returns the full attribute name which is the mv_ns prefix + attr_name if that method has been provided, otherwise
24
- # it default to the class name (without any module prefix) and it downcases the first letter
25
- def self.full_attr_name(namespace_prefix)
26
- namespace_prefix + (self.respond_to?(:attr_name) ? self.attr_name : self.name.split(':').last.downcase_first_letter)
27
- end
28
-
29
- #get the directives attribute value string
30
- def attr_value
31
- @attribute_value
32
- end
33
-
34
- #set the directives attribute value string
35
- def attr_value=(attribute_value)
36
- @attribute_value = attribute_value
37
- end
38
-
39
- #get attribute hash from tag
40
- def attrs
41
- @directive_call_stack.context[:tag].attributes
42
- end
43
-
44
- #set attribute hash for tag
45
- def attrs=(attributes)
46
- @directive_call_stack.context[:tag].attributes = attributes
47
- end
48
-
49
- #get attribute hash with lowercased keys and values, and cache it
50
- def attrs_lckv
51
- @attrs_lckv ||= lowercase_attribute_keys_and_values(attrs)
52
- end
53
-
54
- #get attribute hash with lowercased keys (and original values) and cache it
55
- def attrs_lck
56
- @attrs_lck ||= lowercase_attribute_keys(attrs)
57
- end
58
-
59
- #returns true if the value for lckey of the attribute hash with lowercased keys and values
60
- #matches (lowercase) lcmatch string
61
- def attr_lckv_matches(lckey, lcmatch)
62
- (attrs_lckv[lckey] && attrs_lckv[lckey] == lcmatch.downcase) ? true : false
63
- end
64
-
65
- #output '<% '+str+' %>'
66
- def erb(str)
67
- ERB_START + str + ERB_END
68
- end
69
-
70
- #output '<%= '+str+' %>
71
- def erb_content(str)
72
- ERB_EVAL + str + ERB_END
73
- end
74
-
75
- #get tag_name
76
- def tag_name
77
- @directive_call_stack.context[:tag].tag_name
78
- end
79
-
80
- #set tag_name
81
- def tag_name=(tag_name)
82
- @directive_call_stack.context[:tag].tag_name = tag_name
83
- end
84
-
85
- #inside characters, cdata, or comment you can call this to get the characters passed
86
- def data
87
- @directive_call_stack.context[:content_part]
88
- end
89
-
90
- #set the data that will be passed to characters, cdata, or comment directives
91
- def data=(data)
92
- @directive_call_stack.context[:content_part]=data
93
- end
94
-
95
- # rolled up content from all children of the tag, note this will not be complete until hitting the end tag method :etag
96
- def content
97
- @directive_call_stack.context[:tag].content
98
- end
99
-
100
- #return rolled up content from all children as string, note this will not be complete until hitting the end tag method :etag
101
- def content_str
102
- content = @directive_call_stack.context[:tag].content
103
- content = content.join if content.respond_to? :join
104
- content
105
- end
106
-
107
- # replace the content from all children with a new value
108
- def content=(content)
109
- @directive_call_stack.context[:tag].content = content
110
- end
111
-
112
- #add single quotes around string
113
- def quote(str)
114
- '\''+str+'\''
115
- end
116
-
117
- def remove_strings_from_attr_value!
118
- self.attr_value = remove_prepended_strings(attr_value)
119
- end
120
-
121
- #prepend string to attribute value adding a comma if attribute value was not empty
122
- def prepend_to_attr_value!(str)
123
- return attr_value if str.nil? || str.strip.empty?
124
- av = str
125
- av << ', ' << attr_value unless attr_value.strip.empty?
126
- self.attr_value = av
127
- end
128
-
129
- #append string to attribute value adding a comma if attribute value was not empty
130
- def append_to_attr_value!(str)
131
- return attr_value if str.nil? || str.strip.empty?
132
- av = attr_value
133
- av << ', ' unless av.strip.empty?
134
- av << str
135
- self.attr_value = av
136
- end
137
-
138
- #merge merge_hash into hashes stored in attribute_value string
139
- #hash_index is the zero based index of the hash you want to add to
140
- def merge_hash_attr_value!(hash_index, merge_hash)
141
- self.attr_value = merge_into_embedded_hash(attr_value, hash_index, merge_hash)
142
- end
143
-
144
- #calls non-evaling parse to split into string arguments
145
- def parse_attr_value
146
- parse(attr_value)
147
- end
148
-
149
- # check for common html options and return the hash
150
- def common_html_options(attrs_lck)
151
- options = {}
152
- options[:class] = attrs_lck['class'] if attrs_lck['class']
153
- options[:style] = attrs_lck['style'] if attrs_lck['style']
154
- options[:tabindex] = attrs_lck['tabindex'] if attrs_lck['tabindex']
155
- options[:accesskey] = attrs_lck['accesskey'] if attrs_lck['accesskey']
156
- options[:disabled] = true if attrs_lck['disabled']
157
- options[:readonly] = true if attrs_lck['readonly']
158
- options
159
- end
160
-
161
- end
162
-
163
- end
@@ -1,176 +0,0 @@
1
- module MasterView
2
-
3
- module DirectiveHelpers
4
- CRLF = "\r\n"
5
- ERB_START = '<% '
6
- ERB_EVAL = '<%= '
7
- ERB_END = ' %>'
8
-
9
- #convenience constants defined to allow priority to directives
10
- #higher priority (lower value) will be executed first in chain
11
- module DirectivePriorities
12
- Highest = 0
13
- High = 0x3FFFFFFF/4
14
- MediumHigh = 0x3FFFFFFF/3
15
- Medium = 0x3FFFFFFF/2
16
- MediumLow = (0x3FFFFFFF/3)*2
17
- Low = (0x3FFFFFFF/4)*3
18
- Lowest = 0x3FFFFFFF
19
- end
20
-
21
-
22
- # find the last string that fully matches exactly the
23
- # parent tags content string array
24
- # It looks for something that has been output as a unit in
25
- # the array not a substring
26
- # returns the ref to the string which you can operate on
27
- # using replace
28
- def find_last_in_parent(tag, full_string)
29
- ret = nil
30
- parent = tag.parent
31
- unless parent.nil?
32
- parent.content.reverse.each do |str|
33
- if str == full_string
34
- ret = str
35
- break
36
- end
37
- end
38
- end
39
- ret
40
- end
41
-
42
- # set the last occurence to empty string
43
- # returns true if found and set to empty string
44
- def delete_last_in_parent(tag, full_string)
45
- str = find_last_in_parent(tag, full_string)
46
- found = !str.nil?
47
- str.replace('') if found
48
- found
49
- end
50
-
51
- # find a hash value from inside a simple str containing a hash
52
- # non-evaling, looks for a :key => 'foo/bar' returning foo/bar string
53
- def find_string_val_in_string_hash(str, key_or_sym)
54
- key = key_or_sym.to_s
55
- m = str.match( Regexp.new( Regexp.escape(key)+"\s*=>\s*'([^']*)'" ) ) #try single quote
56
- m = str.match( Regexp.new( Regexp.escape(key)+"\s*=>\s*\"([^\"]*)\"" ) ) if m.nil? #try double quote
57
- return nil if m.nil?
58
- m[1]
59
- end
60
-
61
- #returns an array of args by parsing and evaling the str value passed in
62
- #uses evaling, so can't have any variables only simple strings, numbers, booleans
63
- def parse_eval_into_array(value)
64
- return [] if value.nil? || value.empty?
65
- val = value.strip
66
- args = []
67
- until val.empty?
68
- if val =~ /^[:'"%\[{&*]/ #starts with quote or ruby lang char
69
- v = nil
70
- val = '{'+val+'}' if val =~ /^:/ #starts with colon, assume hash so wrap with brackets
71
- eval 'v = '+ val #rest is all evaled
72
- if v.is_a? Array
73
- args += v
74
- else
75
- args << v
76
- end
77
- break
78
- else
79
- unquoted_string = val.slice!( /^[^,]+/ ) #pull off everything up to a comma
80
- unquoted_string.strip!
81
- args.push unquoted_string
82
- val.slice!( /^,/ ) #strip off comma if exists
83
- val.strip!
84
- end
85
- end
86
- args
87
- end
88
-
89
- #returns a hash, for values that are not already part of hash it adds them using default_key
90
- #uses evaling so it cannot have any variables or non-simple types
91
- def parse_eval_into_hash(value, default_key)
92
- h = {}
93
- a = parse_eval_into_array(value)
94
- a.each do |v|
95
- if v.is_a?(Hash)
96
- h.merge!(v)
97
- else #it adds any additional non-hash args using default key, if key,val exists, it changes to array and appends
98
- prev = h[default_key]
99
- if prev.nil? #nil just add it
100
- h[default_key] = v
101
- elsif prev.is_a?(Array) #was array, concat
102
- h[default_key] = prev+v
103
- else #anything else, make it into array
104
- h[default_key] = [prev, v]
105
- end
106
- end
107
- end
108
- h
109
- end
110
-
111
- #parse into array of strings, containing the various arguments without evaling
112
- #looks for %q{}, %q[], hash, array, function call using (), values deliminated by commas,
113
- #it does not handle embedded quotes yet
114
- def parse(str)
115
- return [] if str.nil? || str.strip.empty?
116
- s = str.strip
117
- args = []
118
- s.scan( /(%q"[^"]*"|%q\{[^}]*\}|%q\[[^\]]*\]|\{?\s*\S+\s*=>[^{}]+\}?|\[[^\]]*\]|[\w\.@]+\s*\([^\)]*\)|'[^']*'|[^,]+)\s*,?\s*/ ).flatten
119
- end
120
-
121
- #remove any strings that were prepended to the hashes, typically these are overridden by other values, so
122
- # we need to strip them off leaving only the hashes, returns a string with only hashes
123
- def remove_prepended_strings(full_string)
124
- return full_string if full_string.nil? || full_string.strip.empty?
125
- hashes = full_string.scan( /(\{?)\s*(\S+\s*=>.*)/ ).flatten
126
- hashes.join.strip
127
- end
128
-
129
- #merge hash_to_merge values into the hash contained in the full_string, hash_arg is zero based index of which
130
- #hash this needes to be merged to if there are multiple ones.
131
- def merge_into_embedded_hash(full_string, hash_arg, hash_to_merge)
132
- return full_string if hash_to_merge.empty?
133
- full_string ||= ""
134
- sorted_hash_to_merge = hash_to_merge.sort { |a,b| a.to_s <=> b.to_s } #sort, remember the keys might be symbols so use to_s
135
- str_to_merge = sorted_hash_to_merge.collect{ |h,v| "#{h.inspect} => #{v.inspect}" }.join(', ')
136
-
137
- hashes = full_string.scan( /(\{?[^{}]+=>[^{}]+\}?)\s*,?\s*/ ).flatten
138
- hash_str = hashes[hash_arg] #be careful to use methods to update string in place or else put back in hash
139
-
140
- if hash_str.nil?
141
- hashes.each do |v| #make sure each prior hash has brackets, since we are adding a hash
142
- unless v.index '}'
143
- v.insert(0, '{')
144
- v.insert(-1, '}')
145
- end
146
- end
147
- hashes[hash_arg] = hash_str = ""
148
- end
149
-
150
- closing_brack = hash_str.index '}'
151
- if closing_brack
152
- hash_str.insert(closing_brack, ', '+str_to_merge)
153
- else
154
- hash_str << ', ' unless hash_str.empty?
155
- hash_str << str_to_merge
156
- end
157
-
158
- hashes.join(', ')
159
- end
160
-
161
- #return attributes with lowercase keys
162
- def lowercase_attribute_keys(attributes)
163
- lcattrs = {}
164
- attributes.each { |k,v| lcattrs[k.downcase] = v }
165
- lcattrs
166
- end
167
-
168
- #return attributes with lowercase keys and values
169
- def lowercase_attribute_keys_and_values(attributes)
170
- lcattrs = {}
171
- attributes.each { |k,v| lcattrs[k.downcase] = v.downcase }
172
- lcattrs
173
- end
174
- end
175
-
176
- end
@@ -1,30 +0,0 @@
1
- module MasterView
2
- module Directives
3
-
4
- #outputs a block around the text tags, if left bracket count is higher than right
5
- #assume that the end is a right bracket otherwise use end
6
- class Block < MasterView::DirectiveBase
7
- def priority
8
- DirectivePriorities::MediumHigh
9
- end
10
-
11
- def stag(directive_call_stack)
12
- count_left_brackets = attr_value.scan( /\{/ ).size
13
- count_right_brackets = attr_value.scan( /\}/ ).size
14
- @end_block = (count_left_brackets > count_right_brackets) ? '}' : 'end'
15
-
16
- ret = []
17
- ret << erb(attr_value)
18
- ret << directive_call_stack.render
19
- end
20
-
21
- def etag(directive_call_stack)
22
- ret = []
23
- ret << directive_call_stack.render
24
- ret << erb(@end_block)
25
- end
26
-
27
- end
28
- end
29
- end
30
-
@@ -1,10 +0,0 @@
1
- module MasterView
2
- module Directives
3
- class Content < MasterView::DirectiveBase
4
- def etag(dcs)
5
- self.content = erb_content(attr_value)
6
- dcs.render
7
- end
8
- end
9
- end
10
- end
@@ -1,25 +0,0 @@
1
- module MasterView
2
- module Directives
3
- #outputs an else/end block around the text tags removing previous end tag (from if/elsif)
4
- class Else < MasterView::DirectiveBase
5
- def priority
6
- DirectivePriorities::High
7
- end
8
-
9
- def stag(directive_call_stack)
10
- tag = @directive_call_stack.context[:tag]
11
- delete_last_in_parent(tag, erb('end') )
12
- ret = []
13
- ret << erb('else')
14
- ret << directive_call_stack.render
15
- end
16
-
17
- def etag(directive_call_stack)
18
- ret = []
19
- ret << directive_call_stack.render
20
- ret << erb('end')
21
- end
22
-
23
- end
24
- end
25
- end