Class: MasterView::DirectiveBase
- Inherits:
-
Object
- Object
- MasterView::DirectiveBase
- Includes:
- DirectiveHelpers, PluginLoadTracking
- Defined in:
- lib/masterview/directive_base.rb
Direct Known Subclasses
MasterView::Directives::Block, MasterView::Directives::Content, MasterView::Directives::Else, MasterView::Directives::Elsif, MasterView::Directives::Form, MasterView::Directives::Global_inline_erb, MasterView::Directives::Hidden_field, MasterView::Directives::If, MasterView::Directives::Insert_generated_comment, MasterView::Directives::Javascript_include, MasterView::Directives::Link_to, MasterView::Directives::Link_to_if, MasterView::Directives::Link_to_remote, MasterView::Directives::Password_field, MasterView::Directives::Replace, MasterView::Directives::Stylesheet_link, MasterView::Directives::Submit, MasterView::Directives::TestDirective, MasterView::Directives::Text_area, MasterView::Directives::Text_field
Constant Summary
Constants included from DirectiveHelpers
MasterView::DirectiveHelpers::CRLF, MasterView::DirectiveHelpers::ERB_END, MasterView::DirectiveHelpers::ERB_EVAL, MasterView::DirectiveHelpers::ERB_START
Class Method Summary collapse
-
.full_attr_name(namespace_prefix) ⇒ Object
returns the full attribute name which is the mv_ns prefix + attr_name if that method has been provided, otherwise it default to the class name (without any module prefix) and it downcases the first letter.
-
.register_directive(directive_class) ⇒ Object
Register a class manually without regard to whether it inherits from DirectiveBase.
Instance Method Summary collapse
-
#append_to_attr_value!(str) ⇒ Object
append string to attribute value adding a comma if attribute value was not empty.
-
#attr_lckv_matches(lckey, lcmatch) ⇒ Object
returns true if the value for lckey of the attribute hash with lowercased keys and values matches (lowercase) lcmatch string.
-
#attr_value ⇒ Object
get the directives attribute value string.
-
#attr_value=(attribute_value) ⇒ Object
set the directives attribute value string.
-
#attrs ⇒ Object
get attribute hash from tag.
-
#attrs=(attributes) ⇒ Object
set attribute hash for tag.
-
#attrs_lck ⇒ Object
get attribute hash with lowercased keys (and original values) and cache it.
-
#attrs_lckv ⇒ Object
get attribute hash with lowercased keys and values, and cache it.
-
#common_html_options(attrs_lck) ⇒ Object
check for common html options and return the hash.
-
#content ⇒ Object
rolled up content from all children of the tag, note this will not be complete until hitting the end tag method :etag.
-
#content=(content) ⇒ Object
replace the content from all children with a new value.
-
#content_str ⇒ Object
return rolled up content from all children as string, note this will not be complete until hitting the end tag method :etag.
-
#data ⇒ Object
inside characters, cdata, or comment you can call this to get the characters passed.
-
#data=(data) ⇒ Object
set the data that will be passed to characters, cdata, or comment directives.
-
#erb(str) ⇒ Object
output ‘<% ’
str‘ %>’. -
#erb_content(str) ⇒ Object
output ‘<%= ’
str‘ %>. -
#initialize(attribute_value) ⇒ DirectiveBase
constructor
A new instance of DirectiveBase.
-
#merge_hash_attr_value!(hash_index, merge_hash) ⇒ Object
merge merge_hash into hashes stored in attribute_value string hash_index is the zero based index of the hash you want to add to.
-
#parse_attr_value ⇒ Object
calls non-evaling parse to split into string arguments.
-
#prepend_to_attr_value!(str) ⇒ Object
prepend string to attribute value adding a comma if attribute value was not empty.
-
#quote(str) ⇒ Object
add single quotes around string.
- #remove_strings_from_attr_value! ⇒ Object
-
#save_directive_call_stack(directive_call_stack) ⇒ Object
if this method exists, it will be called by renderer to save directive_call_stack before each method call.
-
#tag_name ⇒ Object
get tag_name.
-
#tag_name=(tag_name) ⇒ Object
set tag_name.
Methods included from DirectiveHelpers
#delete_last_in_parent, #find_last_in_parent, #find_string_val_in_string_hash, #lowercase_attribute_keys, #lowercase_attribute_keys_and_values, #merge_into_embedded_hash, #parse, #parse_eval_into_array, #parse_eval_into_hash, #remove_prepended_strings
Methods included from PluginLoadTracking
Constructor Details
#initialize(attribute_value) ⇒ DirectiveBase
Returns a new instance of DirectiveBase.
14 15 16 |
# File 'lib/masterview/directive_base.rb', line 14 def initialize(attribute_value) @attribute_value = attribute_value end |
Class Method Details
.full_attr_name(namespace_prefix) ⇒ Object
returns the full attribute name which is the mv_ns prefix + attr_name if that method has been provided, otherwise it default to the class name (without any module prefix) and it downcases the first letter
25 26 27 |
# File 'lib/masterview/directive_base.rb', line 25 def self.full_attr_name(namespace_prefix) namespace_prefix + (self.respond_to?(:attr_name) ? self.attr_name : self.name.split(':').last.downcase_first_letter) end |
.register_directive(directive_class) ⇒ Object
Register a class manually without regard to whether it inherits from DirectiveBase. Classes which derive from DirectiveBase will automatically be registered as they are loaded.
10 11 12 |
# File 'lib/masterview/directive_base.rb', line 10 def self.register_directive(directive_class) self.register_class(directive_class) end |
Instance Method Details
#append_to_attr_value!(str) ⇒ Object
append string to attribute value adding a comma if attribute value was not empty
130 131 132 133 134 135 136 |
# File 'lib/masterview/directive_base.rb', line 130 def append_to_attr_value!(str) return attr_value if str.nil? || str.strip.empty? av = attr_value av << ', ' unless av.strip.empty? av << str self.attr_value = av end |
#attr_lckv_matches(lckey, lcmatch) ⇒ Object
returns true if the value for lckey of the attribute hash with lowercased keys and values matches (lowercase) lcmatch string
61 62 63 |
# File 'lib/masterview/directive_base.rb', line 61 def attr_lckv_matches(lckey, lcmatch) (attrs_lckv[lckey] && attrs_lckv[lckey] == lcmatch.downcase) ? true : false end |
#attr_value ⇒ Object
get the directives attribute value string
30 31 32 |
# File 'lib/masterview/directive_base.rb', line 30 def attr_value @attribute_value end |
#attr_value=(attribute_value) ⇒ Object
set the directives attribute value string
35 36 37 |
# File 'lib/masterview/directive_base.rb', line 35 def attr_value=(attribute_value) @attribute_value = attribute_value end |
#attrs ⇒ Object
get attribute hash from tag
40 41 42 |
# File 'lib/masterview/directive_base.rb', line 40 def attrs @directive_call_stack.context[:tag].attributes end |
#attrs=(attributes) ⇒ Object
set attribute hash for tag
45 46 47 |
# File 'lib/masterview/directive_base.rb', line 45 def attrs=(attributes) @directive_call_stack.context[:tag].attributes = attributes end |
#attrs_lck ⇒ Object
get attribute hash with lowercased keys (and original values) and cache it
55 56 57 |
# File 'lib/masterview/directive_base.rb', line 55 def attrs_lck @attrs_lck ||= lowercase_attribute_keys(attrs) end |
#attrs_lckv ⇒ Object
get attribute hash with lowercased keys and values, and cache it
50 51 52 |
# File 'lib/masterview/directive_base.rb', line 50 def attrs_lckv @attrs_lckv ||= lowercase_attribute_keys_and_values(attrs) end |
#common_html_options(attrs_lck) ⇒ Object
check for common html options and return the hash
150 151 152 153 154 155 156 157 158 159 |
# File 'lib/masterview/directive_base.rb', line 150 def (attrs_lck) = {} [:class] = attrs_lck['class'] if attrs_lck['class'] [:style] = attrs_lck['style'] if attrs_lck['style'] [:tabindex] = attrs_lck['tabindex'] if attrs_lck['tabindex'] [:accesskey] = attrs_lck['accesskey'] if attrs_lck['accesskey'] [:disabled] = true if attrs_lck['disabled'] [:readonly] = true if attrs_lck['readonly'] end |
#content ⇒ Object
rolled up content from all children of the tag, note this will not be complete until hitting the end tag method :etag
96 97 98 |
# File 'lib/masterview/directive_base.rb', line 96 def content @directive_call_stack.context[:tag].content end |
#content=(content) ⇒ Object
replace the content from all children with a new value
108 109 110 |
# File 'lib/masterview/directive_base.rb', line 108 def content=(content) @directive_call_stack.context[:tag].content = content end |
#content_str ⇒ Object
return rolled up content from all children as string, note this will not be complete until hitting the end tag method :etag
101 102 103 104 105 |
# File 'lib/masterview/directive_base.rb', line 101 def content_str content = @directive_call_stack.context[:tag].content content = content.join if content.respond_to? :join content end |
#data ⇒ Object
inside characters, cdata, or comment you can call this to get the characters passed
86 87 88 |
# File 'lib/masterview/directive_base.rb', line 86 def data @directive_call_stack.context[:content_part] end |
#data=(data) ⇒ Object
set the data that will be passed to characters, cdata, or comment directives
91 92 93 |
# File 'lib/masterview/directive_base.rb', line 91 def data=(data) @directive_call_stack.context[:content_part]=data end |
#erb(str) ⇒ Object
output ‘<% ’str‘ %>’
66 67 68 |
# File 'lib/masterview/directive_base.rb', line 66 def erb(str) ERB_START + str + ERB_END end |
#erb_content(str) ⇒ Object
output ‘<%= ’str‘ %>
71 72 73 |
# File 'lib/masterview/directive_base.rb', line 71 def erb_content(str) ERB_EVAL + str + ERB_END end |
#merge_hash_attr_value!(hash_index, merge_hash) ⇒ Object
merge merge_hash into hashes stored in attribute_value string hash_index is the zero based index of the hash you want to add to
140 141 142 |
# File 'lib/masterview/directive_base.rb', line 140 def merge_hash_attr_value!(hash_index, merge_hash) self.attr_value = (attr_value, hash_index, merge_hash) end |
#parse_attr_value ⇒ Object
calls non-evaling parse to split into string arguments
145 146 147 |
# File 'lib/masterview/directive_base.rb', line 145 def parse_attr_value parse(attr_value) end |
#prepend_to_attr_value!(str) ⇒ Object
prepend string to attribute value adding a comma if attribute value was not empty
122 123 124 125 126 127 |
# File 'lib/masterview/directive_base.rb', line 122 def prepend_to_attr_value!(str) return attr_value if str.nil? || str.strip.empty? av = str av << ', ' << attr_value unless attr_value.strip.empty? self.attr_value = av end |
#quote(str) ⇒ Object
add single quotes around string
113 114 115 |
# File 'lib/masterview/directive_base.rb', line 113 def quote(str) '\''+str+'\'' end |
#remove_strings_from_attr_value! ⇒ Object
117 118 119 |
# File 'lib/masterview/directive_base.rb', line 117 def remove_strings_from_attr_value! self.attr_value = remove_prepended_strings(attr_value) end |
#save_directive_call_stack(directive_call_stack) ⇒ Object
if this method exists, it will be called by renderer to save directive_call_stack before each method call
19 20 21 |
# File 'lib/masterview/directive_base.rb', line 19 def save_directive_call_stack(directive_call_stack) @directive_call_stack = directive_call_stack end |
#tag_name ⇒ Object
get tag_name
76 77 78 |
# File 'lib/masterview/directive_base.rb', line 76 def tag_name @directive_call_stack.context[:tag].tag_name end |
#tag_name=(tag_name) ⇒ Object
set tag_name
81 82 83 |
# File 'lib/masterview/directive_base.rb', line 81 def tag_name=(tag_name) @directive_call_stack.context[:tag].tag_name = tag_name end |