ovec 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf233d8093609535f86f06d12e54d8d53ea44da0
4
- data.tar.gz: 61af216b5f2b5bda2dafe0affd86d3991ac9b957
3
+ metadata.gz: 3e5e4d58f8170a737c81c93d9ee01a5749a4c700
4
+ data.tar.gz: d6f4e332980e2f449cced3995ce6af5fd7039142
5
5
  SHA512:
6
- metadata.gz: ae3384bf00f9d20dd2ab7cc398a70959a44454ed953c1f0ec9cbddb485fc06adeace43e1313baf8fdcea80f1bb7b45fa2459d7ec3437b65f7f981dc384858ddf
7
- data.tar.gz: 11ffb6b266c098c33047a48962f461de4c602b77e5c9737739157f59816dc00632e12ac81b1a184016ea8b52876ce2e40893e8e809df9ac75455c51acab6643a
6
+ metadata.gz: 0bdc65af08ee00e49957231e1c810b60c1593ccf48aec384b4926074a574d4c8cae00885e9a2d4fe98d2825a1644e26f518405ce782dfd1a38770900e8134115
7
+ data.tar.gz: e5e61c00f0603d7ec7cb1bc2c872f76db56f139212915ee5c6974a273e27545239d3d14032a9bc0cfbda1451a3b6baf0aa6adf99e9770f1fb43a2dab34bf849f
data/bin/ovec CHANGED
@@ -1,10 +1,61 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'ovec'
4
+ require 'optparse'
4
5
 
5
- content = ARGF.read
6
+ options = {}
6
7
 
7
- parser = Ovec::Parser.new
8
+ opts_parser = OptionParser.new do |opts|
9
+ opts.banner = "Usage: ovec [options]"
10
+
11
+ opts.on("-i", "--input FILENAME", "Input filename or - for stdin (required)") do |filename|
12
+ options[:input] = filename
13
+ end
14
+
15
+ opts.on("-o", "--output FILENAME", "Output filename or - for stdout (required)") do |filename|
16
+ options[:output] = filename
17
+ end
18
+
19
+ opts.on("-d", "--[no-]debug", "Show debugging messages (on STDERR)") do |v|
20
+ options[:debug] = v
21
+ end
22
+
23
+ opts.on_tail("-h", "--help", "Show this message") do
24
+ puts opts
25
+ exit
26
+ end
27
+
28
+ opts.on_tail("-v", "--version", "Show version") do
29
+ puts Ovec::NAME_WITH_VERSION
30
+ exit
31
+ end
32
+ end
33
+
34
+ input_file = nil
35
+ output_file = nil
36
+
37
+ begin
38
+ opts_parser.parse!
39
+ unless options.key?(:input) && options.key?(:output)
40
+ $stderr.puts "You must specify both an input file and an output file."
41
+ $stderr.puts opts_parser.help
42
+ exit 1
43
+ end
44
+
45
+ input_file = (options[:input] == '-') ? STDIN : File.open(options[:input], "r")
46
+ output_file = (options[:output] == '-') ? STDOUT : File.open(options[:output], "w")
47
+ rescue OptionParser::ParseError => ex
48
+ $stderr.puts "Invalid options: #{ex.message}"
49
+ $stderr.puts opts_parser.help
50
+ exit 1
51
+ rescue StandardError => ex
52
+ $stderr.puts ex.message
53
+ exit 1
54
+ end
55
+
56
+ content = input_file.read
57
+
58
+ parser = Ovec::Parser.new(debug: options[:debug])
8
59
  tree = parser.parse(content)
9
60
 
10
61
  tm = Ovec::TexManipulator.new
@@ -14,4 +65,7 @@ tier = Ovec::Tier.new
14
65
 
15
66
  tm.run_text_manipulator(tier)
16
67
 
17
- puts tree.to_tex
68
+ output_file.puts tree.to_tex
69
+
70
+ input_file.close
71
+ output_file.close
data/lib/ovec/parser.rb CHANGED
@@ -7,7 +7,7 @@ module Ovec
7
7
  class Parser
8
8
  NORMAL_REGEX = /\A([^\\$%])+/
9
9
  # TODO: more escapes: there are probably 10x more...
10
- COMMAND_REGEX = /\A\\([a-zA-Z0-9]+|[%:,\\])/
10
+ COMMAND_REGEX = /\A\\([a-zA-Z0-9]+|[~%:,^$&\\ ])/
11
11
  COMMENT_REGEX = /\A%.*$/
12
12
 
13
13
  TEXT_COMMANDS = %w(textit textbf textsc title author)
@@ -19,7 +19,9 @@ module Ovec
19
19
 
20
20
  private
21
21
  def debug(*args)
22
- $stderr.puts(*args)
22
+ if @debug
23
+ $stderr.puts(*args)
24
+ end
23
25
  end
24
26
 
25
27
  def find_other_side(string, start, left = '{', right = '}')
@@ -38,6 +40,10 @@ module Ovec
38
40
  end
39
41
 
40
42
  public
43
+ def initialize(debug: false)
44
+ @debug = debug
45
+ end
46
+
41
47
  def self.delimiter_right_side(left)
42
48
  {
43
49
  '{' => '}', '[' => ']', '(' => ')', '<' => '>'
data/lib/ovec/version.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  module Ovec
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
+ NAME_WITH_VERSION = "Ovec #{VERSION}"
3
4
  end
@@ -73,5 +73,11 @@ module Ovec
73
73
  result = @parser.parse(text)
74
74
  assert_equal text, result.to_tex
75
75
  end
76
+
77
+ def test_weird_commands_parsed
78
+ text = '\%\ \\\ \ahoj\~\^\,\:\$\&'
79
+ result = @parser.parse(text)
80
+ assert_equal text, result.to_tex
81
+ end
76
82
  end
77
83
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ovec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michal Pokorný
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-30 00:00:00.000000000 Z
11
+ date: 2013-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  version: '0'
86
86
  requirements: []
87
87
  rubyforge_project:
88
- rubygems_version: 2.0.0
88
+ rubygems_version: 2.0.2
89
89
  signing_key:
90
90
  specification_version: 4
91
91
  summary: Ovec inserts nonbreakable spaces into your Czech language TeX files.