Class: CompEx::ComponentDescriptor

Inherits:
Object
  • Object
show all
Defined in:
lib/compex/component_descriptor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ ComponentDescriptor

Returns a new instance of ComponentDescriptor.



12
13
14
15
16
17
# File 'lib/compex/component_descriptor.rb', line 12

def initialize(parent)
  @parent = parent
  @args = Set.new
  @exposed = Set.new
  @css_prefix = "cx_#{@parent.component_id}"
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



9
10
11
# File 'lib/compex/component_descriptor.rb', line 9

def args
  @args
end

#cssObject (readonly)

Returns the value of attribute css.



9
10
11
# File 'lib/compex/component_descriptor.rb', line 9

def css
  @css
end

#css_hashObject (readonly)

Returns the value of attribute css_hash.



9
10
11
# File 'lib/compex/component_descriptor.rb', line 9

def css_hash
  @css_hash
end

#css_prefixObject (readonly)

Returns the value of attribute css_prefix.



9
10
11
# File 'lib/compex/component_descriptor.rb', line 9

def css_prefix
  @css_prefix
end

#exposedObject (readonly)

Returns the value of attribute exposed.



9
10
11
# File 'lib/compex/component_descriptor.rb', line 9

def exposed
  @exposed
end

#raw_html=(value) ⇒ Object (writeonly)

Sets the attribute raw_html

Parameters:

  • value

    the value to set the attribute raw_html to.



10
11
12
# File 'lib/compex/component_descriptor.rb', line 10

def raw_html=(value)
  @raw_html = value
end

#raw_js=(value) ⇒ Object (writeonly)

Sets the attribute raw_js

Parameters:

  • value

    the value to set the attribute raw_js to.



10
11
12
# File 'lib/compex/component_descriptor.rb', line 10

def raw_js=(value)
  @raw_js = value
end

#raw_styleObject

Returns the value of attribute raw_style.



8
9
10
# File 'lib/compex/component_descriptor.rb', line 8

def raw_style
  @raw_style
end

Instance Method Details

#dynamically_defined?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/compex/component_descriptor.rb', line 55

def dynamically_defined?
  @dynamically_defined ||= @parent.name.include?("#")
end

#has_js?Boolean

Returns:

  • (Boolean)


24
# File 'lib/compex/component_descriptor.rb', line 24

def has_js? = !@js.nil?

#has_style?Boolean

Returns:

  • (Boolean)


25
# File 'lib/compex/component_descriptor.rb', line 25

def has_style? = !@css.nil?

#htmlObject



19
20
21
22
# File 'lib/compex/component_descriptor.rb', line 19

def html
  prepare!
  @html
end

#js_class_idObject



46
47
48
49
50
51
52
53
# File 'lib/compex/component_descriptor.rb', line 46

def js_class_id
  return @js_class_id if @js_class_id

  id = @parent.name.split("::")
    .reject { it.start_with?("#") }
    .map(&:hashed).join
  @js_class_id = "CompEx_#{id}_#{@parent.component_id.upcase}"
end

#prepare!Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/compex/component_descriptor.rb', line 27

def prepare!
  return if @prepared

  # prime cached templates
  js_template
  css_template

  prepare_html
  prepare_js
  prepare_css
  update_html_attrs

  @prepared = true
end

#required_hashesObject



42
43
44
# File 'lib/compex/component_descriptor.rb', line 42

def required_hashes
  [@css_hash, @js_hash].compact
end