Module: UlePage::SitePrismExtender

Includes:
SitePrism, SitePrism::ElementContainer
Included in:
Page
Defined in:
lib/ule_page/site_prism_extender.rb

Instance Method Summary collapse

Instance Method Details

#class_name(my_class) ⇒ Object



60
61
62
# File 'lib/ule_page/site_prism_extender.rb', line 60

def class_name(my_class)
  my_class.name.underscore.downcase
end

#define_elements(model_class, props = []) ⇒ Object

can define fields based on the model class usage:

define_elements Brand


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ule_page/site_prism_extender.rb', line 25

def define_elements(model_class, props = [])
  attributes = model_class.new.attributes.keys

  props = attributes if props.empty?
  props.map! { |x| x.to_s } unless props.empty?

  attributes.each do |attri|
    if props.include? attri
      selector = "#"+"#{class_name(model_class)}_#{attri.to_s}"

      element attri, selector
    end

  end
end

#define_elements_js(model_class, excluded_props = []) ⇒ Object

instead of the rails traditional form in js mode, there is no prefix before the element name



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/ule_page/site_prism_extender.rb', line 66

def define_elements_js(model_class, excluded_props = [])
  attributes = model_class.new.attributes.keys

  attributes.each do |attri|
    unless excluded_props.include? attri
      selector = "#"+attri
      # self.class.send "element", attri.to_sym, selector
      element attri, selector
    end

  end
end

#define_sub_elements(model_class, submodel_class, props = []) ⇒ Object

if you want to define the element as model1[name] whose id is “model1_model2_name” useage

define Brand User
define Brand, User, [:description]


45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ule_page/site_prism_extender.rb', line 45

def define_sub_elements(model_class, submodel_class, props = [])
  attributes = submodel_class.new.attributes.keys

  props = attributes if props.empty?
  props.map! { |x| x.to_s } unless props.empty?

  attributes.each do |attri|
    if props.include?(attri)
      selector = '#' + "#{class_name(model_class)}_#{class_name(submodel_class)}_attributes_#{attri.to_s}"

      element attri, selector
    end
  end
end

#element_collection(collection_name, *find_args) ⇒ Object

why define this method? if we use the elements method directly, it will be conflicted with RSpec.Mather.BuiltIn.All.elements. I have not found one good method to solve the confliction.



11
12
13
14
15
16
17
18
# File 'lib/ule_page/site_prism_extender.rb', line 11

def element_collection(collection_name, *find_args)
  build collection_name, *find_args do
    define_method collection_name.to_s do |*runtime_args, &element_block|
      self.class.raise_if_block(self, collection_name.to_s, !element_block.nil?)
      page.all(*find_args)
    end
  end
end