Class: Curly::ComponentCompiler

Inherits:
Object
  • Object
show all
Defined in:
lib/curly/component_compiler.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(presenter_class, component, type: nil) ⇒ ComponentCompiler



9
10
11
# File 'lib/curly/component_compiler.rb', line 9

def initialize(presenter_class, component, type: nil)
  @presenter_class, @component, @type = presenter_class, component, type
end

Instance Attribute Details

#componentObject (readonly)

Returns the value of attribute component



3
4
5
# File 'lib/curly/component_compiler.rb', line 3

def component
  @component
end

#presenter_classObject (readonly)

Returns the value of attribute presenter_class



3
4
5
# File 'lib/curly/component_compiler.rb', line 3

def presenter_class
  @presenter_class
end

#typeObject (readonly)

Returns the value of attribute type



3
4
5
# File 'lib/curly/component_compiler.rb', line 3

def type
  @type
end

Class Method Details

.compile(presenter_class, component, type: nil) ⇒ Object



5
6
7
# File 'lib/curly/component_compiler.rb', line 5

def self.compile(presenter_class, component, type: nil)
  new(presenter_class, component, type: type).compile
end

Instance Method Details

#compileObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/curly/component_compiler.rb', line 13

def compile
  unless presenter_class.component_available?(method)
    raise Curly::InvalidComponent.new(method)
  end

  validate_block_argument!
  validate_attributes!

  code = "presenter.#{method}("

  append_positional_argument(code)
  append_keyword_arguments(code)

  code << ")"
end