Class: Staticz::Compilable::Slim

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Staticz::Compilable

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

Constructor Details

#initialize(name) ⇒ Slim

Returns a new instance of Slim.



13
14
15
# File 'lib/manifest/compilable/slim.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/slim.rb', line 9

def name
  @name
end

Instance Method Details

#build(listener_class: nil) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/manifest/compilable/slim.rb', line 32

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

  if valid?
    template = ::Slim::Template.new(source_path)
    File.write build_path, template.render

    listener&.finish
  else
    listener&.error
  end
end

#errorsObject



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

def errors
  errors = super

  if exists?
    begin
      template = ::Slim::Template.new(source_path)
      template.render
    rescue => e
      errors << e.message
    end
  end

  errors
end