Method: Erector::Erect#initialize

Defined in:
lib/erector/erect/erect.rb

#initialize(args) ⇒ Erect

Returns a new instance of Erect.



11
12
13
14
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/erector/erect/erect.rb', line 11

def initialize(args)
  @verbose = true
  @mode = :to_erector
  @output_dir = nil
  @superklass = 'Erector::Widget'
  @method_name = 'content'

  opts = OptionParser.new do |opts|
    opts.banner = "Usage: erector [options] [file|dir]*"

    opts.separator "Converts from html/rhtml files to erector widgets, or from erector widgets to html files"
    opts.separator ""
    opts.separator "Options:"

    opts.on("-q", "--quiet",
            "Operate silently except in case of error") do |quiet|
      @verbose = !quiet
    end

    opts.on("--to-erector", "(default) Convert from html/rhtml to erector classes") do
      @mode = :to_erector
    end

    opts.on("--to-html", "Convert from erector to html") do
      @mode = :to_html
    end

    opts.on("--superclass SUPERCLASS", "Superclass for new widget (default Erector::Widget)") do |superklass|
      @superklass = superklass
    end

    opts.on("--method METHOD", "Method containing content for widget (default 'content')") do |method_name|
      @method_name = method_name
    end

    opts.on("-o", "--output-dir DIRECTORY", "Output files to DIRECTORY (default: output files go next to input files)") do |dir|
      @output_dir = dir
    end

    opts.on_tail("-h", "--help", "Show this message") do
      @mode = :help
      puts opts
      exit
    end

    opts.on_tail("-v", "--version", "Show version") do
      puts Erector::VERSION
      exit
    end

  end
  opts.parse!(args)
  @files = args
  explode_dirs
end