Class: Sal::U

Inherits:
Object
  • Object
show all
Defined in:
lib/sal/u.rb

Class Method Summary collapse

Class Method Details

.parse_for_attributes(result = nil, attrs = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/sal/u.rb', line 6

def parse_for_attributes(result = nil, attrs = {})
  result = result.value if result.kind_of?(Sal::Wrapper)

  return unless result.kind_of?(Hash)

  result = stringify_keys(result)

  # concat values on class attribute
  if attrs['class'] && result['class']
    result['class'] = attrs['class'] + ' ' + result['class']
  end

  " #{result.collect{ |k,v| "#{k}='#{v}'" unless k.to_s == 'html' }.compact.join(' ')}"
end

.parse_for_html(result, text = '') ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/sal/u.rb', line 21

def parse_for_html(result, text = '')
  result = result.value if result.kind_of?(Sal::Wrapper)
  if result.kind_of?(String)
    result
  elsif result.kind_of?(Hash)
    result.delete(:html)
  else
    text unless text.strip.empty?
  end
end