class Aspen::CLI::Commands::BuildSteps::CollectMainAspen

Public Instance Methods

call(*) click to toggle source
# File lib/aspen/cli/commands/build_steps.rb, line 113
def call(*)
  super
  # Grab all the grammars and Aspen source files, make into one main Aspen file.
  puts "----> Collecting main.aspen from src/ and src/grammars"

  # Clear the build/ folder
  Dir["build/main-*"].each { |path| @files.delete(path)}

  @grammars   = "" # Main grammars IO
  @discourses = "" # Main discourses IO
  @aspens     = "" # Main Aspen IO

  collect_discourses
  collect_grammars
  collect_aspen

  main_aspen = File.open("build/main-#{Time.now.to_i}.aspen", 'w') do |file|
    file << @discourses
    file << @grammars
    file << Aspen::SEPARATOR + "\n"
    file << @aspens
  end
  return main_aspen
end
collect_aspen() click to toggle source
# File lib/aspen/cli/commands/build_steps.rb, line 154
def collect_aspen
  Dir['src/*.aspen'].map do |path|
    next if manifest.dig("ignore", "src") && manifest.dig("ignore", "src").any? do |ignore_path|
      Regexp.new(ignore_path) =~ path
    end
    File.read(path)
  end.compact.each do |file|
    if file.include?(SEPARATOR)
      env, _sep, code = file.partition(SEPARATOR)
      @discourses << env
      @aspens << code
    else
      @aspens << file
    end
  end
end
collect_discourses() click to toggle source
# File lib/aspen/cli/commands/build_steps.rb, line 138
def collect_discourses
  Dir['src/discourses/*.aspen'].map do |path|
    # Skip if there's an ignore: src: in the manifest, and if it matches the file path
    next if manifest.dig("ignore", "discourses") && manifest.dig("ignore", "discourses").any? { |ignore_path| Regexp.new(ignore_path) =~ path }
    @discourses << File.read(path)
  end
end
collect_grammars() click to toggle source
# File lib/aspen/cli/commands/build_steps.rb, line 146
def collect_grammars
  Dir['src/grammars/*.aspen'].map do |path|
    # Skip if there's an ignore: src: in the manifest, and if it matches the file path
    next if manifest.dig("ignore", "grammars") && manifest.dig("ignore", "grammars").any? { |ignore_path| Regexp.new(ignore_path) =~ path }
    @grammars << File.read(path)
  end
end