Sha256: 47a503462c1f210ce5f5c0ff2d566423b1871f81edb84b0e09c8f6f9a02e4765

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

require 'brite/site'

module Brite

  # Webrite command line interface.

  class Command

    def self.start
      new.start
    end

    def initialize(argv=nil)
      @argv ||= ARGV.dup

      @noharm = @argv.delete('--dryrun') || @argv.delete('--noharm')
      @debug  = @argv.delete('--debug')

      @argv.reject!{ |e| e =~ /^-/ }

      @location = @argv.shift || '.'
      #@output = @argv.shift
    end

    #
    def start
      begin
        site.build
      rescue => e
        @debug ? raise(e) : puts(e.message)
      end
    end

    def site
      Site.new(
        :location => @location,
        :output   => @output,
        :noharm   => @noharm,
        :trace    => @trace
      )
    end
  end

  #
  # Command to generate a single part to standard out.
  #

  class PartCommand

    def self.start
      new.start
    end

    def initialize(argv=nil)
      @argv ||= ARGV.dup
    end

    def start
      render(parts)
    end

    # render a single part to stdout.

    def render(parts)
      $stdout << Page.new(parts).to_html
    end

  private

    def parts
      parts = []
      @argv.each do |x|
        if /^-/ =~ x
          parts << [x.sub(/-{1,2}/,'')]
        else
          parts.last < x
        end
      end
      Hash[*parts]
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
brite-0.5 lib/brite/command.rb