Class: Rtlize::Exec

Inherits:
Object
  • Object
show all
Defined in:
lib/rtlize/exec.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Exec

Returns a new instance of Exec.



5
6
7
8
9
# File 'lib/rtlize/exec.rb', line 5

def initialize(args)
  @args   = args
  @input  = $stdin
  @output = $stdout
end

Instance Method Details

#parse!Object



51
52
53
54
55
# File 'lib/rtlize/exec.rb', line 51

def parse!
  parse_options
  rtlize_input
  exit 0
end

#parse_optionsObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rtlize/exec.rb', line 38

def parse_options
  setup_option_parser
  @option_parser.parse!(@args)

  if @args.length > 2
    puts @option_parser
    exit 1
  end

  @input  = File.open(@args[0], 'r') if @args.length > 0
  @output = File.open(@args[1], 'w') if @args.length > 1
end

#rtlize_inputObject



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rtlize/exec.rb', line 57

def rtlize_input
  if @input.tty?
    puts "Warning: Reading from standard input. Use Ctrl-D to indicate EOF."
  end
  input = @input.read
  @input.close

  output = Rtlize::RTLizer.transform(input)

  @output.write(output)
  @output.close
end

#setup_option_parserObject



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
# File 'lib/rtlize/exec.rb', line 11

def setup_option_parser
  @option_parser = OptionParser.new do |opts|
    opts.banner = <<-END
Usage: rtlize [options | source_file [target_file]]

Description:

The rtlize utility reads CSS from the source_file, or the standard input (stdin) if no source_file is specified,
and transforms it to target right-to-left (RTL) layouts instead of left-to-right (LTR) layouts, or vice versa.

The transformed CSS will then be written to the target_file, or the standard output (stdout) if no target_file is specified.

Options:
END

    opts.on_tail("-h", "-?", "--help", "Show this message") do
      puts opts
      exit
    end

    opts.on_tail("-v", "--version", "Print version") do
      puts("RTLize #{Rtlize::VERSION}")
      exit
    end
  end
end