Class: Sal::View

Inherits:
Object
  • Object
show all
Defined in:
lib/sal/view.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
20
21
22
23
# File 'lib/sal/view.rb', line 6

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

  if result.kind_of?(Hash) 
    result = stringify_keys(result)
    if result['html']
      result.delete('html')
      # concat values on class attribute
      if attrs['class'] && result['class']
        attrs['class'] << " #{result['class']}"
        result.delete('class')
      end
      attrs.merge!(result)
    end
  end

  attrs.empty? ?  '' : " #{attrs.collect{ |k,v| "#{k}='#{v}'"}.compact.join(' ')}"
end

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



25
26
27
28
29
30
31
32
33
34
# File 'lib/sal/view.rb', line 25

def parse_for_html(result, code, text = '')
  result = result.value if result.kind_of?(Sal::Wrapper)
  if result.kind_of?(String) || result.kind_of?(Numeric)
    result
  elsif result.kind_of?(Hash)
    result[:html] || result[code.to_sym]
  else
    text unless text.strip.empty?
  end
end