Class: Sitepress::Compiler::Abstract
- Inherits:
-
Object
- Object
- Sitepress::Compiler::Abstract
- Includes:
- Enumerable
- Defined in:
- lib/sitepress/compiler.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#fail_on_error ⇒ Object
If a resource can’t render, it will raise an exception and stop the compiler.
-
#failed ⇒ Object
readonly
Returns the value of attribute failed.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
-
#succeeded ⇒ Object
readonly
Returns the value of attribute succeeded.
Instance Method Summary collapse
-
#compile ⇒ Object
Iterates through all pages and writes them to disk.
- #each(&block) ⇒ Object
-
#initialize(site:, stdout: $stdout, fail_on_error: false) ⇒ Abstract
constructor
A new instance of Abstract.
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_error ⇒ Object
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 |
#failed ⇒ Object (readonly)
Returns the value of attribute failed.
9 10 11 |
# File 'lib/sitepress/compiler.rb', line 9 def failed @failed end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
9 10 11 |
# File 'lib/sitepress/compiler.rb', line 9 def site @site end |
#succeeded ⇒ Object (readonly)
Returns the value of attribute succeeded.
9 10 11 |
# File 'lib/sitepress/compiler.rb', line 9 def succeeded @succeeded end |
Instance Method Details
#compile ⇒ Object
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 |