Class: Kitchen::Oven
Overview
A class for baking documents according to the instructions in recipes
Defined Under Namespace
Classes: BakeProfile
Class Method Summary collapse
-
.bake(input_file:, recipes:, output_file:, config_file: nil) ⇒ Object
Bakes an input file using a recipe to produce an output file.
Class Method Details
.bake(input_file:, recipes:, output_file:, config_file: nil) ⇒ Object
Bakes an input file using a recipe to produce an output file
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/kitchen/oven.rb', line 15 def self.bake(input_file:, recipes:, output_file:, config_file: nil) profile = BakeProfile.new profile.started! nokogiri_doc = File.open(input_file) do |f| profile.opened! Nokogiri::XML(f).tap { profile.parsed! } end config = config_file.nil? ? nil : Config.new_from_file(File.open(config_file)) doc = Kitchen::Document.new( nokogiri_document: nokogiri_doc, config: config ) I18n.locale = doc.locale [recipes].flatten.each do |recipe| recipe.document = doc recipe.bake end profile.baked! File.open(output_file, 'w') do |f| f.write doc.to_xhtml(indent: 2, encoding: doc.encoding || 'utf-8') end profile.written! Nokogiri::XML.print_profile_data if ENV['PROFILE'] && !ENV['TESTING'] profile end |