Class: Staticz::Compilable::React

Inherits:
Object
  • Object
show all
Includes:
Staticz::Compilable
Defined in:
lib/manifest/compilable/react.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Staticz::Compilable

#build_path, #create_link_function, #errors, #exists?, included, #path, #path_method_name, #print, #source_path, #valid?, #warnings

Constructor Details

#initialize(name) ⇒ React

Returns a new instance of React.



13
14
15
# File 'lib/manifest/compilable/react.rb', line 13

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/manifest/compilable/react.rb', line 9

def name
  @name
end

Instance Method Details

#build(listener_class: nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/manifest/compilable/react.rb', line 17

def build(listener_class: nil)
  listener = listener_class&.new(self)

  if exists?
    File.write build_path, render

    listener&.finish
  else
    listener&.error
  end
end

#renderObject



29
30
31
# File 'lib/manifest/compilable/react.rb', line 29

def render
  Babel::Transpiler.transform(File.read(source_path))["code"]
end