Sha256: fbd281373d3107baa360041fb09b759f2461355f81be8c6854eec8cacb9318b3

Contents?: true

Size: 1.96 KB

Versions: 2

Compression:

Stored size: 1.96 KB

Contents

#!/usr/bin/env ruby
# encoding: utf-8

if RUBY_VERSION < "1.9.1"
  abort "Ace requires Ruby 1.9"
end

base   = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
libdir = File.expand_path(File.join(File.dirname(base), "..", "lib"))

# because of system installation, there is bin/../lib, but not bin/../lib/ace
if File.directory?(File.join(libdir, "ace"))
  $:.unshift(libdir) unless $:.include?(libdir)
end

require "ace"
require "ace/dsl"

if File.join(Dir.pwd, "boot.rb")
  require File.join(Dir.pwd, "boot.rb")
else
  abort "No boot.rb!"
end

if File.join(Dir.pwd, "rules.rb")
  path  = File.join(Dir.pwd, "rules.rb")
  code  = File.read(path)
  rules = Ace::DSL.new
  begin
    rules.instance_eval(code)
  rescue Exception => exception
    puts "Error in DSL: #{exception.message}"
    puts exception.backtrace
    exit 1
  end
else
  abort "No rules.rb!"
end

rules.rules.each do |klass, files|
  # puts "#{klass} #{files.inspect}"
  files.each do |file|
    if File.binread(file).match(/^-{3,5}\s*$/) # TODO: this should be a filter or lazy-loaded
      puts "~ Read #{file} with parse"
      raw_item = Ace::RawItem.new(file).tap(&:parse)
      raw_item.check_metadata_created_at(file)
      item = klass.create(raw_item.metadata, raw_item.content)
    else
      puts "~ Read #{file} without parse"
      item = klass.create(Hash.new, File.read(file))
    end
    item.original_path = file
  end
end

puts

# Generator is anything what provides #generate method.
rules.generators.each do |generator|
  puts "~ Running generator #{generator}"
  begin
    if generator.respond_to?(:generate)
      generator.generate
    else
      abort "Generator #{generator.inspect} doesn't respond to the #generate method!"
    end
  rescue Exception => exception
    puts "Error in generator #{generator.inspect}: #{exception.message}"
    puts exception.backtrace
    exit 1
  end
end

unless ARGV.include?("--no-generate")
  puts
  Ace::Item.all_instances.each do |item|
    item.save!
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ace-0.4.4 bin/ace
ace-0.4.3 bin/ace