Class: Aspen::CLI::Commands::BuildSteps::CompileMainAspen

Inherits:
BuildStep
  • Object
show all
Defined in:
lib/aspen/cli/commands/build_steps.rb

Instance Method Summary collapse

Methods inherited from BuildStep

#config, #manifest

Instance Method Details

#call(main_aspen_file, options) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/aspen/cli/commands/build_steps.rb', line 175

def call(main_aspen_file, options)
  super
  puts "----> Compiling main Aspen file (#{main_aspen_file.path})"
  # Compile the main Aspen file, according to manifest.yml
  unless manifest["output"]
    puts "      Defaulting to Cypher output. To customize, set up a manifest.yml."
  end

  outputs = manifest["output"] ? Array(manifest["output"]) : ["Cypher"]

  outputs.each do |format|
    adapter = Aspen::Adapters::Registry.get(format.downcase.to_sym)
    out_path = main_aspen_file.path.gsub(/\.aspen$/, '') + adapter.ext

    File.open(out_path, 'w') do |file|
      file << Aspen.compile_text(
        File.read(main_aspen_file),
        adapter: adapter.id,
        batch: options[:batch]
      )
    end
    puts "----> Compiled main #{adapter.name} file"
  end
end