Class: WrapIt::Base
- Inherits:
-
Object
- Object
- WrapIt::Base
- Defined in:
- lib/wrap_it/base.rb
Overview
Base class for all HTML helper classes
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Instance Method Summary collapse
-
#initialize(template, *args, &block) ⇒ Base
constructor
A new instance of Base.
- #omit_content? ⇒ Boolean
-
#render(*args) {|element| ... } ⇒ String
Renders element to template.
- #unwrap ⇒ Object
-
#wrap(*args, &block) ⇒ void
Wraps element with another.
Methods included from Renderer
Methods included from Enums
Methods included from DerivedAttributes
Methods included from Switches
Methods included from HTMLData
included, #remove_html_data, #set_html_data
Methods included from HTMLClass
#add_html_class, #html_class, #html_class=, #html_class?, #html_class_prefix, included, #no_html_class?, #remove_html_class, sanitize
Methods included from Sections
Methods included from Callbacks
Constructor Details
#initialize(template, *args, &block) ⇒ Base
Returns a new instance of Base.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/wrap_it/base.rb', line 44 def initialize(template, *args, &block) @template, @arguments, @block = template, args, block self. = @arguments. @helper_name = @options.delete(:helper_name) @helper_name.is_a?(String) && @helper_name = @helper_name.to_sym @arguments.extend ArgumentsArray add_default_classes run_callbacks :initialize do @tag = @options.delete(:tag) || self.class.get_derived(:@default_tag) || 'div' @tag = @tag.to_s end end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
37 38 39 |
# File 'lib/wrap_it/base.rb', line 37 def @options end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
36 37 38 |
# File 'lib/wrap_it/base.rb', line 36 def tag @tag end |
Instance Method Details
#omit_content? ⇒ Boolean
61 62 63 |
# File 'lib/wrap_it/base.rb', line 61 def omit_content? self.class.get_derived(:@omit_content) end |
#render(*args) {|element| ... } ⇒ String
Renders element to template
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/wrap_it/base.rb', line 77 def render(*args, &render_block) # return cached copy if it available return @rendered unless @rendered.nil? capture_sections # add to content string args and block result if its present args.flatten.each { |a| self[:render_arguments] << a if a.is_a? String } if block_given? result = instance_exec(self, &render_block) || empty_html result.is_a?(String) && self[:render_block] << result end do_render do_wrap if @template.output_buffer.nil? # when render called from code, just return content as a String @rendered else # in template context, write content to templates buffer concat(@rendered) empty_html end end |
#unwrap ⇒ Object
135 136 137 |
# File 'lib/wrap_it/base.rb', line 135 def unwrap @wrapper = nil end |
#wrap(*args, &block) ⇒ void
This method returns an undefined value.
Wraps element with another.
You can provide wrapper directly or specify wrapper class as first argument. In this case wrapper will created with specified set of arguments and options. If wrapper class ommited, WrapIt::Base will be used.
If block present, it will be called when wrapper will rendered.
126 127 128 129 130 131 132 133 |
# File 'lib/wrap_it/base.rb', line 126 def wrap(*args, &block) if args.first.is_a?(Base) @wrapper = args.shift else wrapper_class = args.first.is_a?(Class) ? args.shift : Base @wrapper = wrapper_class.new(@template, *args, &block) end end |