Class: Sitepress::Compiler
- Inherits:
-
Object
- Object
- Sitepress::Compiler
- Includes:
- FileUtils
- Defined in:
- lib/sitepress/compiler.rb
Overview
Compile all resources from a Sitepress site into static pages.
Instance Method Summary collapse
-
#compile(target_path:) ⇒ Object
Iterates through all pages and writes them to disk.
-
#initialize(site:, stdout: $stdout) ⇒ Compiler
constructor
A new instance of Compiler.
Constructor Details
#initialize(site:, stdout: $stdout) ⇒ Compiler
Returns a new instance of Compiler.
9 10 11 12 |
# File 'lib/sitepress/compiler.rb', line 9 def initialize(site:, stdout: $stdout) @site = site @stdout = stdout end |
Instance Method Details
#compile(target_path:) ⇒ Object
Iterates through all pages and writes them to disk
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sitepress/compiler.rb', line 15 def compile(target_path:) target_path = Pathname.new(target_path) mkdir_p target_path root = Pathname.new("/") cache_resources = @site.cache_resources @stdout.puts "Compiling #{@site.root_path.expand_path}" begin @site.cache_resources = true @site.resources.each do |resource| derooted = Pathname.new(resource.request_path).relative_path_from(root) path = target_path.join(derooted) mkdir_p path.dirname @stdout.puts " #{path}" File.open(path., "w"){ |f| f.write render(resource) } end @stdout.puts "Successful compilation to #{target_path.expand_path}" ensure @site.cache_resources = cache_resources end end |