Module: Elpong::Rails::Helper

Defined in:
lib/elpong/rails/helper.rb

Instance Method Summary collapse

Instance Method Details

#elpong_collection(name, options = {}) ⇒ Object

Raises:

  • (StandardError)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/elpong/rails/helper.rb', line 9

def elpong_collection(name, options = {})
  scheme = get_scheme_from_name_or_scheme(options[:scheme])
  # options[:locals] ||=
  raise StandardError, 'No path or data' unless options[:path] || options[:data]

  content =
    options[:data] || h( render(formats: [:json], template: options[:path], locals: options[:locals] || {}) )

  attributes = {
    name: 'elpong-collection',
    content: content,
    scheme: scheme.name,
    collection: name
  }
  (:meta, nil, attributes)
end

#elpong_element(singular_name, options = {}) ⇒ Object

Raises:

  • (StandardError)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/elpong/rails/helper.rb', line 26

def elpong_element(singular_name, options = {})
  scheme = get_scheme_from_name_or_scheme(options[:scheme])
  raise StandardError, 'No path or data' unless options[:path] || options[:data]

  content =
    options[:data] || h( render(formats: [:json], template: options[:path], locals: options[:locals] || {}) )

  attributes = {
    name: 'elpong-element',
    content: content,
    scheme: scheme.name,
    collection: singular_name.pluralize
  }
  options[:attributes].each do |name, value|
    attributes[name] = value
  end
  (:meta, nil, attributes)
end

#elpong_scheme(name_or_scheme = nil) ⇒ Object



4
5
6
7
# File 'lib/elpong/rails/helper.rb', line 4

def elpong_scheme(name_or_scheme = nil)
  scheme = get_scheme_from_name_or_scheme(name_or_scheme)
  (:meta, nil, name: 'elpong-scheme', content: scheme.to_json, scheme: scheme.name)
end