Module: Xass::ViewHelpers

Defined in:
lib/xass/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#namespace(*names, reset: false, &block) ⇒ Object Also known as: dns



3
4
5
6
7
8
9
10
11
# File 'lib/xass/view_helpers.rb', line 3

def namespace(*names, reset: false, &block)
  n = reset ? names : namespace_stack.last + names
  namespace_stack.push(n)
  res = capture(&block)
  namespace_stack.pop
  node = Nokogiri::HTML.fragment(res)
  process_namespace_classes(node, n)
  node.to_html.html_safe
end

#namespace!(*names, &block) ⇒ Object Also known as: dns!



13
14
15
# File 'lib/xass/view_helpers.rb', line 13

def namespace!(*names, &block)
  namespace(*names, reset: true, &block)
end

#namespace_with_root(*names, tag: :div, attrs: {}, reset: false, &block) ⇒ Object Also known as: dnsr



17
18
19
20
# File 'lib/xass/view_helpers.rb', line 17

def namespace_with_root(*names, tag: :div, attrs: {}, reset: false, &block)
  nss = reset ? [] : namespace_stack.last
  (tag, block ? namespace(*names, reset: reset, &block) : '', attrs_with_additional_class(attrs, ns_root!(*(nss + names))))
end

#namespace_with_root!(*names, tag: :div, attrs: {}, &block) ⇒ Object Also known as: dnsr!



22
23
24
# File 'lib/xass/view_helpers.rb', line 22

def namespace_with_root!(*names, tag: :div, attrs: {}, &block)
  namespace_with_root(*names, tag: tag, attrs: attrs, reset: true, &(block || Proc.new {}))
end

#ns(*names) ⇒ Object



46
47
48
# File 'lib/xass/view_helpers.rb', line 46

def ns(*names)
  ns!(*(namespace_stack.last + names))
end

#ns!(*names) ⇒ Object



50
51
52
# File 'lib/xass/view_helpers.rb', line 50

def ns!(*names)
  "#{ns_root!(*names[0...-1])}___#{names[-1]}"
end

#ns_content(name = :content, _tag = nil, _attrs = nil, tag: :div, attrs: {}, &block) ⇒ Object Also known as: nsc



32
33
34
35
36
# File 'lib/xass/view_helpers.rb', line 32

def ns_content(name = :content, _tag = nil, _attrs = nil, tag: :div, attrs: {}, &block)
  _tag ||= tag
  _attrs ||= attrs
  ns_wrap(name, tag: _tag, attrs: _attrs, &block)
end


54
55
56
57
58
59
60
61
62
# File 'lib/xass/view_helpers.rb', line 54

def ns_link_to(name, _name = nil, options = nil, html_options = nil, &block)
  if block
    options ||= {}
    link_to(_name, attrs_with_additional_name(options, name), &block)
  else
    html_options ||= {}
    link_to(_name, options, attrs_with_additional_name(html_options, name), &block)
  end
end

#ns_root(*names) ⇒ Object Also known as: nsr



38
39
40
# File 'lib/xass/view_helpers.rb', line 38

def ns_root(*names)
  ns_root!(*(namespace_stack.last + names))
end

#ns_root!(*names) ⇒ Object Also known as: nsr!



42
43
44
# File 'lib/xass/view_helpers.rb', line 42

def ns_root!(*names)
  names.map(&:to_s).join('__')
end

#ns_wrap(name = :wrap, _tag = nil, _attrs = nil, tag: :div, attrs: {}, &block) ⇒ Object



26
27
28
29
30
# File 'lib/xass/view_helpers.rb', line 26

def ns_wrap(name = :wrap, _tag = nil, _attrs = nil, tag: :div, attrs: {}, &block)
  _tag ||= tag
  _attrs ||= attrs
  (_tag, block ? capture(&block) : '', attrs_with_additional_name(_attrs, name))
end