class Syaso::Base
Constants
- BLOCK_BUFFER
Attributes
content[RW]
context[RW]
tag[RW]
Public Class Methods
new(context)
click to toggle source
initialize method
@param [ActionView] context
Calls superclass method
# File lib/syaso/base.rb, line 23 def initialize(context) super() self.context = context end
Public Instance Methods
render(content = nil, options = {}, &block)
click to toggle source
render content.
@parma [Object] content @param [Hash] options
# File lib/syaso/base.rb, line 32 def render(content = nil, options = {}, &block) self._render(content, options, &block) end
Protected Instance Methods
_render(content = nil, options = {}) { |self| ... }
click to toggle source
render method
@parma [Object] content @param [Hash] options
# File lib/syaso/base.rb, line 45 def _render(content = nil, options = {}, &block) ops = filter_args(content, options) ops = filter_options(ops) self.buffer do self.context.content_tag(self.tag, ops) do if block_given? yield(self) else self.buffer do self.content end end end # context.content_tag end # buffer end
block_buffer() { || ... }
click to toggle source
block unexpected buffer
# File lib/syaso/base.rb, line 62 def block_buffer(&block) yield if block_given? BLOCK_BUFFER end
buffer() { || ... }
click to toggle source
buffer contents
# File lib/syaso/base.rb, line 68 def buffer(&block) block_buffer do self.context.concat(yield) end end
default_data_options()
click to toggle source
default html data-* attibutes
@param [Hash]
# File lib/syaso/base.rb, line 77 def default_data_options {} end
default_html_class()
click to toggle source
default html classes
@return [Array<String>]
# File lib/syaso/base.rb, line 91 def default_html_class [] end
default_html_tag()
click to toggle source
default tag
@return [Symbol]
# File lib/syaso/base.rb, line 84 def default_html_tag :div end
Private Instance Methods
filter_args(content = nil, options = {})
click to toggle source
filter render arguments
@param [Object] content @param [Hash] options
# File lib/syaso/base.rb, line 102 def filter_args(content = nil, options = {}) if (content.is_a?(Hash)) && (options.empty?) ops = content else self.content = ((content.nil?) || (content.empty?)) ? self.content : content ops = options end ops end
filter_data_options(options = {})
click to toggle source
filter data options
@param [Hash] options
# File lib/syaso/base.rb, line 132 def filter_data_options(options = {}) ops = self.default_data_options.merge(options) options.each do |k, v| if k.to_s.match(/^_/) key = "data-#{k.to_s.sub(/^_/, "").gsub(/_/, "-")}" ops[key] = v ops.delete(k) end end ops end
filter_html_class_options(options = {})
click to toggle source
filter html classes
@param [Hash] options @return [Hash]
# File lib/syaso/base.rb, line 149 def filter_html_class_options(options = {}) options[:class] ||= [] options[:class] = options[:class].to_s.split(" ") unless options[:class].is_a?(Array) options[:class] += self.default_html_class options.delete(:class) if options[:class].blank? options end
filter_options(options = {})
click to toggle source
filter html options
@param [Hash] options @return [Hash]
# File lib/syaso/base.rb, line 116 def filter_options(options = {}) ops = options.dup options.each do |k, v| ops[k] = v.is_a?(Proc) ? v.call(self) : v end self.tag = ops.delete(:tag)||self.default_html_tag ops = filter_html_class_options(ops) ops = filter_data_options(ops) ops end
method_missing(name, *args, &block)
click to toggle source
method missing
@param [Symbol] name @param [Array] args
Calls superclass method
# File lib/syaso/base.rb, line 161 def method_missing(name, *args, &block) begin self.content.__send__(name, *args, &block) rescue => e super end end