Class: Sitepress::Compiler::Abstract

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/sitepress/compiler.rb

Direct Known Subclasses

Files

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site:, stdout: $stdout, fail_on_error: false) ⇒ Abstract

Returns a new instance of Abstract.



17
18
19
20
21
22
23
# File 'lib/sitepress/compiler.rb', line 17

def initialize(site:, stdout: $stdout, fail_on_error: false)
  @site = site
  @stdout = stdout
  @fail_on_error = fail_on_error
  @failed = []
  @succeeded = []
end

Instance Attribute Details

#fail_on_errorObject

If a resource can’t render, it will raise an exception and stop the compiler. Sometimes its useful to turn off errors so you can get through a full compilation and see how many errors you encounter along the way. To do that, you’d set ‘fail_on_error` to `false` and the compile will get through all the resources.



15
16
17
# File 'lib/sitepress/compiler.rb', line 15

def fail_on_error
  @fail_on_error
end

#failedObject (readonly)

Returns the value of attribute failed.



9
10
11
# File 'lib/sitepress/compiler.rb', line 9

def failed
  @failed
end

#siteObject (readonly)

Returns the value of attribute site.



9
10
11
# File 'lib/sitepress/compiler.rb', line 9

def site
  @site
end

#succeededObject (readonly)

Returns the value of attribute succeeded.



9
10
11
# File 'lib/sitepress/compiler.rb', line 9

def succeeded
  @succeeded
end

Instance Method Details

#compileObject

Iterates through all pages and writes them to disk



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sitepress/compiler.rb', line 26

def compile
  before_compile
  each do |resource, *args, **kwargs|
    if resource.renderable?
      render_resource(resource, *args, **kwargs)
    else
      copy_resource(resource, *args, **kwargs)
    end
    @succeeded << resource
  rescue
    status "Error building #{resource.inspect}"
    @failed << resource
    raise if fail_on_error
  end
  after_compile
end

#each(&block) ⇒ Object



43
44
45
# File 'lib/sitepress/compiler.rb', line 43

def each(&block)
  site.resources.each(&block)
end