agate 0.3.4 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +8 -0
- data/bin/agate +3 -1
- data/lib/agate/cli.rb +51 -0
- data/lib/agate/version.rb +1 -1
- data/spec/lib/parser_spec.rb +22 -0
- metadata +3 -1
data/CHANGELOG.md
CHANGED
data/bin/agate
CHANGED
data/lib/agate/cli.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'agate'
|
3
|
+
require 'singleton'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
module Agate
|
7
|
+
class CLI
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@options = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def start
|
15
|
+
parse_opts
|
16
|
+
|
17
|
+
agate = Agate::Parser.new(@options)
|
18
|
+
puts agate.parse(ARGV.join)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def parse_opts
|
23
|
+
opts = OptionParser.new do |opts|
|
24
|
+
opts.banner = "Usage: agate [options] text-to-convert"
|
25
|
+
|
26
|
+
opts.separator ""
|
27
|
+
opts.separator "Options:"
|
28
|
+
|
29
|
+
opts.on("-d", "--delimiters DELIMITERS", "Specify custom delimiters for ruby text (default: 【】)") do |delims|
|
30
|
+
@options[:delimiters] = delims
|
31
|
+
end
|
32
|
+
|
33
|
+
opts.on("-f", "--formatter FORMAT", "Specify a formatter to use (default/fallback: HTML)") do |format|
|
34
|
+
@options[:formatter] = format.to_sym
|
35
|
+
end
|
36
|
+
|
37
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
38
|
+
puts opts
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
|
42
|
+
opts.on_tail("-v", "--version", "Show version") do
|
43
|
+
puts Agate::VERSION
|
44
|
+
exit
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
opts.parse!(ARGV)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/agate/version.rb
CHANGED
data/spec/lib/parser_spec.rb
CHANGED
@@ -33,4 +33,26 @@ describe Agate::Parser do
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
36
|
+
|
37
|
+
context "with formatter" do
|
38
|
+
context "HTML" do
|
39
|
+
let(:agate) { Agate::Parser.new(:formatter => :html) }
|
40
|
+
let(:text) { "勉【べん】強【きょう】します" }
|
41
|
+
let(:parsed_text) { "<ruby>勉<rp>【</rp><rt>べん</rt><rp>】</rp></ruby><ruby>強<rp>【</rp><rt>きょう</rt><rp>】</rp></ruby>します" }
|
42
|
+
|
43
|
+
it "parses delimited text and turns it into HTML" do
|
44
|
+
agate.parse(text).should eql(parsed_text)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "not matching an available formatter" do
|
49
|
+
let(:agate) { Agate::Parser.new(:formatter => :foobar) }
|
50
|
+
let(:text) { "勉【べん】強【きょう】します" }
|
51
|
+
let(:parsed_text) { "<ruby>勉<rp>【</rp><rt>べん</rt><rp>】</rp></ruby><ruby>強<rp>【</rp><rt>きょう</rt><rp>】</rp></ruby>します" }
|
52
|
+
|
53
|
+
it "parses delimited text and turns it into HTML" do
|
54
|
+
agate.parse(text).should eql(parsed_text)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
36
58
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: agate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.4.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jesse B. Hannah
|
@@ -107,6 +107,8 @@ files:
|
|
107
107
|
YmluL2FnYXRl
|
108
108
|
- !binary |-
|
109
109
|
bGliL2FnYXRlLnJi
|
110
|
+
- !binary |-
|
111
|
+
bGliL2FnYXRlL2NsaS5yYg==
|
110
112
|
- !binary |-
|
111
113
|
bGliL2FnYXRlL2Zvcm1hdHRlci9odG1sLnJi
|
112
114
|
- !binary |-
|