ad_hoc_template 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/README.md +3 -3
- data/ad_hoc_template.gemspec +1 -0
- data/lib/ad_hoc_template/command_line_interface.rb +27 -31
- data/lib/ad_hoc_template/default_tag_formatter.rb +36 -0
- data/lib/ad_hoc_template/parser.rb +4 -4
- data/lib/ad_hoc_template/pseudohiki_formatter.rb +25 -0
- data/lib/ad_hoc_template/record_reader.rb +3 -3
- data/lib/ad_hoc_template/version.rb +1 -1
- data/lib/ad_hoc_template.rb +2 -23
- data/spec/ad_hoc_template_spec.rb +9 -9
- data/spec/command_line_interface_spec.rb +2 -23
- data/spec/default_tag_formatter_spec.rb +47 -0
- data/spec/parser_spec.rb +25 -0
- data/spec/pseudohiki_formatter_spec.rb +69 -0
- data/spec/record_reader_spec.rb +12 -12
- metadata +23 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77dedc981af5ec62410d30504f9d41bb01fb78b3
|
4
|
+
data.tar.gz: 090b330043f0d60d385e613dc50a617d85fe6dba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e96dd5a5f56ded725d6fd1d5c8a02ec5855dbed793200da55e4594ac9f832a441383963eee8f2f46b61dcd21002295264f5f3ddbae891ee6f3ebba2ee41c0c0b
|
7
|
+
data.tar.gz: 46682a5ae8479d813c14b5019ba7150d4db4a1e5199f2a1252ed1a971faec73ed9ba832327761998ccc631925a95047ea4efdc22b30b26d53c06fc85792a23e9
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -6,7 +6,7 @@ I conceived this template as a workaroud for some tasks in a working environment
|
|
6
6
|
|
7
7
|
And I hope this tool saves you from meaningless tasks when you have to face such a situation.
|
8
8
|
|
9
|
-
## Installation
|
9
|
+
## Installation
|
10
10
|
|
11
11
|
Add this line to your application's Gemfile:
|
12
12
|
|
@@ -42,7 +42,7 @@ key1: value1
|
|
42
42
|
key2: value2
|
43
43
|
key3: value3
|
44
44
|
|
45
|
-
|
45
|
+
///@#iteration_block
|
46
46
|
|
47
47
|
sub_key1: value1-1
|
48
48
|
sub_key2: value1-2
|
@@ -50,7 +50,7 @@ sub_key2: value1-2
|
|
50
50
|
sub_key1: value2-1
|
51
51
|
sub_key2: value2-2
|
52
52
|
|
53
|
-
|
53
|
+
///@block
|
54
54
|
|
55
55
|
the first line of block
|
56
56
|
the second line of block
|
data/ad_hoc_template.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
spec.add_runtime_dependency "pseudohikiparser", "0.0.5.develop"
|
21
|
+
spec.add_runtime_dependency "optparse_plus"
|
21
22
|
|
22
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
23
24
|
spec.add_development_dependency "rake", "~> 10.1"
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'ad_hoc_template'
|
4
|
-
require '
|
4
|
+
require 'optparse_plus'
|
5
5
|
|
6
6
|
module AdHocTemplate
|
7
7
|
class CommandLineInterface
|
@@ -37,38 +37,16 @@ module AdHocTemplate
|
|
37
37
|
@data_format = nil
|
38
38
|
end
|
39
39
|
|
40
|
-
def set_encoding(given_opt)
|
41
|
-
external, internal = given_opt.split(/:/o, 2)
|
42
|
-
Encoding.default_external = external if external and not external.empty?
|
43
|
-
Encoding.default_internal = internal if internal and not internal.empty?
|
44
|
-
end
|
45
|
-
|
46
40
|
def parse_command_line_options
|
47
|
-
OptionParser.
|
48
|
-
opt.
|
49
|
-
|
50
|
-
self.set_encoding(given_opt)
|
51
|
-
end
|
41
|
+
OptionParser.new_with_yaml do |opt|
|
42
|
+
opt.banner = "USAGE: #{File.basename($0)} [OPTION]... TEMPLATE_FILE DATA_FILE"
|
43
|
+
opt.version = AdHocTemplate::VERSION
|
52
44
|
|
53
|
-
opt.
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
opt.on("-t [tag_type]", "--tag-type [=tag_type]",
|
59
|
-
"Choose a template tag type: default, curly_brackets or square_brackets") do |given_type|
|
60
|
-
choose_tag_type(given_type)
|
61
|
-
end
|
62
|
-
|
63
|
-
opt.on("-d [data_format]", "--data-format [=data_format]",
|
64
|
-
"Specify the format of input data: default, yaml, json, csv or tsv") do |data_format|
|
65
|
-
choose_data_format(data_format)
|
66
|
-
end
|
67
|
-
|
68
|
-
opt.on("-u [tag_config.yaml]","--user-defined-tag [=tag_config.yaml]",
|
69
|
-
"Configure a user-defined tag. The configuration file is in YAML format.") do |tag_config_yaml|
|
70
|
-
register_user_defined_tag_type(tag_config_yaml)
|
71
|
-
end
|
45
|
+
opt.inherit_ruby_options('E') # -E, --encoding
|
46
|
+
opt.on(:output_file) {|output_file| @output_filename = File.expand_path(output_file) }
|
47
|
+
opt.on(:tag_type) {|given_type| choose_tag_type(given_type) }
|
48
|
+
opt.on(:data_format) {|data_format| choose_data_format(data_format) }
|
49
|
+
opt.on(:tag_config) {|tag_config_yaml| register_user_defined_tag_type(tag_config_yaml) }
|
72
50
|
|
73
51
|
opt.parse!
|
74
52
|
end
|
@@ -155,3 +133,21 @@ module AdHocTemplate
|
|
155
133
|
end
|
156
134
|
end
|
157
135
|
end
|
136
|
+
|
137
|
+
__END__
|
138
|
+
output_file:
|
139
|
+
short: "-o [output_file]"
|
140
|
+
long: "--output [=output_file]"
|
141
|
+
description: "Save the result into the specified file."
|
142
|
+
tag_type:
|
143
|
+
short: "-t [tag_type]"
|
144
|
+
long: "--tag-type [=tag_type]"
|
145
|
+
description: "Choose a template tag type: default, curly_brackets or square_brackets"
|
146
|
+
data_format:
|
147
|
+
short: "-d [data_format]"
|
148
|
+
long: "--data-format [=data_format]"
|
149
|
+
description: "Specify the format of input data: default, yaml, json, csv or tsv"
|
150
|
+
tag_config:
|
151
|
+
short: "-u [tag_config.yaml]"
|
152
|
+
long: "--user-defined-tag [=tag_config.yaml]"
|
153
|
+
description: "Configure a user-defined tag. The configuration file is in YAML format."
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
module AdHocTemplate
|
4
|
+
class DefaultTagFormatter
|
5
|
+
FUNCTION_TABLE = {
|
6
|
+
"=" => :default,
|
7
|
+
"h" => :html_encode
|
8
|
+
}
|
9
|
+
|
10
|
+
def self.assign_format(format_label, &func)
|
11
|
+
FUNCTION_TABLE[format_label] = func
|
12
|
+
end
|
13
|
+
|
14
|
+
def find_function(format_label)
|
15
|
+
FUNCTION_TABLE[format_label]||:default
|
16
|
+
end
|
17
|
+
|
18
|
+
def format(format_label, var, record)
|
19
|
+
func = find_function(format_label)
|
20
|
+
case func
|
21
|
+
when Symbol, String
|
22
|
+
self.send(func, var, record)
|
23
|
+
else
|
24
|
+
func.call(var, record)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def default(var, record)
|
29
|
+
record[var]||"[#{var}]"
|
30
|
+
end
|
31
|
+
|
32
|
+
def html_encode(var, record)
|
33
|
+
HtmlElement.escape(record[var]||var)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -113,12 +113,12 @@ module AdHocTemplate
|
|
113
113
|
end
|
114
114
|
|
115
115
|
def self.remove_indent_before_iteration_tags(template_source, tag_type)
|
116
|
-
[
|
116
|
+
start_tag, end_tag = [
|
117
117
|
tag_type.iteration_start,
|
118
118
|
tag_type.iteration_end
|
119
|
-
].
|
120
|
-
|
121
|
-
|
119
|
+
].map {|tag| Regexp.escape(tag) }
|
120
|
+
template_source.gsub(/^([ \t]+#{start_tag}\S*(?:\r?\n|\r))/) {|s| s.lstrip }
|
121
|
+
.gsub(/^([ \t]+#{end_tag}(?:\r?\n|\r))/) {|s| s.lstrip }
|
122
122
|
end
|
123
123
|
|
124
124
|
def self.register_user_defined_tag_type(config_source)
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'pseudohikiparser'
|
4
|
+
|
5
|
+
module AdHocTemplate
|
6
|
+
class DefaultTagFormatter
|
7
|
+
module PseudoHikiFormatter
|
8
|
+
include PseudoHiki
|
9
|
+
|
10
|
+
def self.to_xhtml(var, record)
|
11
|
+
hiki_source = record[var] || var
|
12
|
+
parser = choose_parser(hiki_source)
|
13
|
+
PseudoHiki::XhtmlFormat.format(parser.parse(hiki_source)).to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.choose_parser(hiki_source)
|
17
|
+
hiki_source[/(?:\r?\n|\r)/] ? BlockParser : InlineParser
|
18
|
+
end
|
19
|
+
|
20
|
+
private_class_method :choose_parser
|
21
|
+
end
|
22
|
+
|
23
|
+
assign_format("ph") {|var, record| PseudoHikiFormatter.to_xhtml(var, record) }
|
24
|
+
end
|
25
|
+
end
|
@@ -64,12 +64,12 @@ module AdHocTemplate
|
|
64
64
|
return label, field_sep
|
65
65
|
end
|
66
66
|
|
67
|
-
private_class_method :convert_to_hash
|
67
|
+
private_class_method :convert_to_hash, :parse_config
|
68
68
|
end
|
69
69
|
|
70
70
|
SEPARATOR = /:\s*/o
|
71
|
-
BLOCK_HEAD = /\A
|
72
|
-
ITERATION_HEAD = /\A
|
71
|
+
BLOCK_HEAD = /\A\/\/\/@/o
|
72
|
+
ITERATION_HEAD = /\A\/\/\/@#/o
|
73
73
|
EMPTY_LINE = /\A(?:\r?\n|\r)\Z/o
|
74
74
|
ITERATION_MARK = /\A#/o
|
75
75
|
READERS_RE = {
|
data/lib/ad_hoc_template.rb
CHANGED
@@ -1,31 +1,10 @@
|
|
1
1
|
require "ad_hoc_template/version"
|
2
2
|
require "ad_hoc_template/parser"
|
3
3
|
require "ad_hoc_template/record_reader"
|
4
|
+
require "ad_hoc_template/default_tag_formatter"
|
5
|
+
require "ad_hoc_template/pseudohiki_formatter"
|
4
6
|
|
5
7
|
module AdHocTemplate
|
6
|
-
class DefaultTagFormatter
|
7
|
-
def find_function(tag_type)
|
8
|
-
FUNCTION_TABLE[tag_type]||:default
|
9
|
-
end
|
10
|
-
|
11
|
-
def format(tag_type, var, record)
|
12
|
-
self.send(find_function(tag_type), var, record)
|
13
|
-
end
|
14
|
-
|
15
|
-
def default(var, record)
|
16
|
-
record[var]||"[#{var}]"
|
17
|
-
end
|
18
|
-
|
19
|
-
def html_encode(var, record)
|
20
|
-
HtmlElement.escape(record[var]||var)
|
21
|
-
end
|
22
|
-
|
23
|
-
FUNCTION_TABLE = {
|
24
|
-
"=" => :default,
|
25
|
-
"h" => :html_encode
|
26
|
-
}
|
27
|
-
end
|
28
|
-
|
29
8
|
class DataLoader
|
30
9
|
def self.format(template, record, tag_formatter=DefaultTagFormatter.new)
|
31
10
|
if record.kind_of? Array
|
@@ -25,7 +25,7 @@ key1: value1
|
|
25
25
|
key2: value2
|
26
26
|
key3: value3
|
27
27
|
|
28
|
-
|
28
|
+
///@#iteration_block
|
29
29
|
|
30
30
|
sub_key1: value1-1
|
31
31
|
sub_key2: value1-2
|
@@ -33,7 +33,7 @@ sub_key2: value1-2
|
|
33
33
|
sub_key1: value2-1
|
34
34
|
sub_key2: value2-2
|
35
35
|
|
36
|
-
|
36
|
+
///@block
|
37
37
|
|
38
38
|
the first line of block
|
39
39
|
the second line of block
|
@@ -104,7 +104,7 @@ key2: value2
|
|
104
104
|
key3: value3
|
105
105
|
key-without-value:
|
106
106
|
|
107
|
-
|
107
|
+
///@block
|
108
108
|
|
109
109
|
the first line of block
|
110
110
|
the second line of block
|
@@ -156,14 +156,14 @@ the value of sub_key1 is <%= sub_key1 %>
|
|
156
156
|
TEMPLATE
|
157
157
|
|
158
158
|
config_data = <<CONFIG
|
159
|
-
|
159
|
+
///@#iteration_block
|
160
160
|
|
161
161
|
sub_key1: value1-1
|
162
162
|
sub_key2: value1-2
|
163
163
|
|
164
164
|
sub_key1: value2-1
|
165
165
|
|
166
|
-
|
166
|
+
///@block
|
167
167
|
|
168
168
|
the first line of block
|
169
169
|
CONFIG
|
@@ -247,7 +247,7 @@ RESULT
|
|
247
247
|
describe "with data in default format" do
|
248
248
|
it "should not ignore the content of an iteration block when some data are provided" do
|
249
249
|
config_data = <<CONFIG
|
250
|
-
|
250
|
+
///@#iteration_block
|
251
251
|
|
252
252
|
key1: value1
|
253
253
|
|
@@ -265,7 +265,7 @@ CONFIG
|
|
265
265
|
|
266
266
|
it "should ignore the content of an iteration block if no thing is provided" do
|
267
267
|
config_data = <<CONFIG
|
268
|
-
|
268
|
+
///@#iteration_block
|
269
269
|
|
270
270
|
CONFIG
|
271
271
|
|
@@ -286,7 +286,7 @@ RESULT
|
|
286
286
|
key: value
|
287
287
|
optional1: optinal value1
|
288
288
|
|
289
|
-
|
289
|
+
///@#iteration_block
|
290
290
|
|
291
291
|
key1: value1
|
292
292
|
|
@@ -308,7 +308,7 @@ CONFIG
|
|
308
308
|
key:
|
309
309
|
optional1:
|
310
310
|
|
311
|
-
|
311
|
+
///@#iteration_block
|
312
312
|
|
313
313
|
key1:
|
314
314
|
|
@@ -25,7 +25,7 @@ key1: value1
|
|
25
25
|
key2: value2
|
26
26
|
key3: value3
|
27
27
|
|
28
|
-
|
28
|
+
///@#iteration_block
|
29
29
|
|
30
30
|
sub_key1: value1-1
|
31
31
|
sub_key2: value1-2
|
@@ -33,7 +33,7 @@ sub_key2: value1-2
|
|
33
33
|
sub_key1: value2-1
|
34
34
|
sub_key2: value2-2
|
35
35
|
|
36
|
-
|
36
|
+
///@block
|
37
37
|
|
38
38
|
the first line of block
|
39
39
|
the second line of block
|
@@ -59,27 +59,6 @@ the second paragraph in block
|
|
59
59
|
RESULT
|
60
60
|
end
|
61
61
|
|
62
|
-
it "can set the input/output encoding" do
|
63
|
-
command_line_interface = AdHocTemplate::CommandLineInterface.new
|
64
|
-
command_line_interface.set_encoding("UTF-8:Shift_JIS")
|
65
|
-
expect(Encoding.default_external.names).to include("UTF-8")
|
66
|
-
expect(Encoding.default_internal.names).to include("Shift_JIS")
|
67
|
-
end
|
68
|
-
|
69
|
-
it "accepts an internal only argument" do
|
70
|
-
command_line_interface = AdHocTemplate::CommandLineInterface.new
|
71
|
-
command_line_interface.set_encoding(":UTF-8")
|
72
|
-
expect(Encoding.default_internal.names).to include("UTF-8")
|
73
|
-
end
|
74
|
-
|
75
|
-
it "accepts also an external only argument" do
|
76
|
-
command_line_interface = AdHocTemplate::CommandLineInterface.new
|
77
|
-
command_line_interface.set_encoding("Shift_JIS")
|
78
|
-
expect(Encoding.default_external.names).to include("Shift_JIS")
|
79
|
-
command_line_interface.set_encoding("UTF-8:")
|
80
|
-
expect(Encoding.default_external.names).to include("UTF-8")
|
81
|
-
end
|
82
|
-
|
83
62
|
it "can set the internal/external encoding from the command line" do
|
84
63
|
command_line_interface = AdHocTemplate::CommandLineInterface.new
|
85
64
|
set_argv("-E UTF-8:Shift_JIS")
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'ad_hoc_template'
|
5
|
+
|
6
|
+
describe AdHocTemplate do
|
7
|
+
describe AdHocTemplate::DefaultTagFormatter do
|
8
|
+
before do
|
9
|
+
@record = {
|
10
|
+
'var1' => '<value1>',
|
11
|
+
'var2' => 'value2'
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'has "=" format label for the default format' do
|
16
|
+
formatter = AdHocTemplate::DefaultTagFormatter.new
|
17
|
+
default = formatter.format('=', 'var1', @record)
|
18
|
+
expect(default).to eq('<value1>')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'has "h" format label for HTML encoding' do
|
22
|
+
formatter = AdHocTemplate::DefaultTagFormatter.new
|
23
|
+
default = formatter.format('h', 'var1', @record)
|
24
|
+
expect(default).to eq('<value1>')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'proc objects may be assigned in DefaultTagFormatter::FUNCTION_TABLE' do
|
28
|
+
proc_label = 'proc_label'
|
29
|
+
function_table = AdHocTemplate::DefaultTagFormatter::FUNCTION_TABLE
|
30
|
+
function_table[proc_label] = proc {|var, record| "test for proc assignment: #{record[var]}" }
|
31
|
+
formatter = AdHocTemplate::DefaultTagFormatter.new
|
32
|
+
proc_assigned = formatter.format(proc_label, 'var1', @record)
|
33
|
+
function_table.delete(proc_label)
|
34
|
+
expect(proc_assigned).to eq('test for proc assignment: <value1>')
|
35
|
+
end
|
36
|
+
|
37
|
+
it '.assign_format may be used to register a new format' do
|
38
|
+
proc_label = 'proc_label'
|
39
|
+
AdHocTemplate::DefaultTagFormatter.assign_format(proc_label) {|var, record| "test for proc assignment: #{record[var]}" }
|
40
|
+
formatter = AdHocTemplate::DefaultTagFormatter.new
|
41
|
+
proc_assigned = formatter.format(proc_label, 'var1', @record)
|
42
|
+
AdHocTemplate::DefaultTagFormatter::FUNCTION_TABLE.delete(proc_label)
|
43
|
+
expect(proc_assigned).to eq('test for proc assignment: <value1>')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
data/spec/parser_spec.rb
CHANGED
@@ -358,6 +358,31 @@ A template with an iteration tag
|
|
358
358
|
This part will be repeated with <!--% variable %-->
|
359
359
|
<!--%/iterate%-->
|
360
360
|
|
361
|
+
TEMPLATE
|
362
|
+
|
363
|
+
without_indent = AdHocTemplate::Parser.parse(template_without_indent, :xml_comment_like)
|
364
|
+
with_indent = AdHocTemplate::Parser.parse(template_with_indent, :xml_comment_like)
|
365
|
+
|
366
|
+
expect(with_indent).to eq(without_indent)
|
367
|
+
end
|
368
|
+
|
369
|
+
it "removes indents from the lines which contain only a labeled iteration tag" do
|
370
|
+
template_without_indent = <<TEMPLATE_WITHOUT_INDENT
|
371
|
+
A template with an iteration tag
|
372
|
+
|
373
|
+
<!--%iterate%-->label
|
374
|
+
This part will be repeated with <!--% variable %-->
|
375
|
+
<!--%/iterate%-->
|
376
|
+
|
377
|
+
TEMPLATE_WITHOUT_INDENT
|
378
|
+
|
379
|
+
template_with_indent = <<TEMPLATE
|
380
|
+
A template with an iteration tag
|
381
|
+
|
382
|
+
<!--%iterate%-->label
|
383
|
+
This part will be repeated with <!--% variable %-->
|
384
|
+
<!--%/iterate%-->
|
385
|
+
|
361
386
|
TEMPLATE
|
362
387
|
|
363
388
|
without_indent = AdHocTemplate::Parser.parse(template_without_indent, :xml_comment_like)
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
describe AdHocTemplate do
|
4
|
+
describe AdHocTemplate::DefaultTagFormatter::PseudoHikiFormatter do
|
5
|
+
it 'with "ph" format label, you can use Hiki notation' do
|
6
|
+
config_data = <<CONFIG
|
7
|
+
///@#iteration
|
8
|
+
|
9
|
+
key1: value1-1
|
10
|
+
key2: value2-1 with [[a link|http://www.example.org/]]
|
11
|
+
|
12
|
+
key1: value1-2
|
13
|
+
key2: value2-2
|
14
|
+
|
15
|
+
///@block
|
16
|
+
|
17
|
+
the ''first'' line of block
|
18
|
+
the second line of block
|
19
|
+
|
20
|
+
the second paragraph in block
|
21
|
+
|
22
|
+
CONFIG
|
23
|
+
|
24
|
+
template = <<TEMPLATE
|
25
|
+
<ul>
|
26
|
+
<%#iteration
|
27
|
+
<li>
|
28
|
+
<ul>
|
29
|
+
<li><%ph key1 %></li>
|
30
|
+
<li><%ph key2 %></li>
|
31
|
+
</ul>
|
32
|
+
</li>
|
33
|
+
#%>
|
34
|
+
</ul>
|
35
|
+
|
36
|
+
<%ph block %>
|
37
|
+
TEMPLATE
|
38
|
+
|
39
|
+
expected_result = <<RESULT
|
40
|
+
<ul>
|
41
|
+
<li>
|
42
|
+
<ul>
|
43
|
+
<li>value1-1</li>
|
44
|
+
<li>value2-1 with <a href="http://www.example.org/">a link</a></li>
|
45
|
+
</ul>
|
46
|
+
</li>
|
47
|
+
<li>
|
48
|
+
<ul>
|
49
|
+
<li>value1-2</li>
|
50
|
+
<li>value2-2</li>
|
51
|
+
</ul>
|
52
|
+
</li>
|
53
|
+
</ul>
|
54
|
+
|
55
|
+
<p>
|
56
|
+
the <em>first</em> line of block
|
57
|
+
the second line of block
|
58
|
+
</p>
|
59
|
+
<p>
|
60
|
+
the second paragraph in block
|
61
|
+
</p>
|
62
|
+
|
63
|
+
RESULT
|
64
|
+
|
65
|
+
result = AdHocTemplate.convert(config_data, template)
|
66
|
+
expect(result).to eq(expected_result)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/spec/record_reader_spec.rb
CHANGED
@@ -24,7 +24,7 @@ CONFIG
|
|
24
24
|
|
25
25
|
it "can read several header type configurations at once." do
|
26
26
|
data = <<CONFIGS
|
27
|
-
|
27
|
+
///@#configs
|
28
28
|
|
29
29
|
key1-1: value1-1
|
30
30
|
key1-2: value1-2
|
@@ -48,7 +48,7 @@ CONFIGS
|
|
48
48
|
|
49
49
|
it "can read sets of several header type configurations at once." do
|
50
50
|
data = <<CONFIGS
|
51
|
-
|
51
|
+
///@#configs
|
52
52
|
|
53
53
|
key1-1: value1-1
|
54
54
|
key1-2: value1-2
|
@@ -59,7 +59,7 @@ key2-2: value2-2
|
|
59
59
|
key3-1: value3-1
|
60
60
|
key3-2: value3-2
|
61
61
|
|
62
|
-
|
62
|
+
///@#configs2
|
63
63
|
|
64
64
|
key1-1: value1-1
|
65
65
|
key1-2: value1-2
|
@@ -93,14 +93,14 @@ key1: value1
|
|
93
93
|
key2: value2
|
94
94
|
key3: value3
|
95
95
|
|
96
|
-
|
96
|
+
///@block1
|
97
97
|
|
98
98
|
the first line of block1
|
99
99
|
the second line of block1
|
100
100
|
|
101
101
|
the second paragraph in block1
|
102
102
|
|
103
|
-
|
103
|
+
///@block2
|
104
104
|
the first line of block2
|
105
105
|
the second line of block2
|
106
106
|
|
@@ -123,7 +123,7 @@ key1: value1
|
|
123
123
|
key2: value2
|
124
124
|
key3: value3
|
125
125
|
|
126
|
-
|
126
|
+
///@#subconfigs
|
127
127
|
|
128
128
|
key1-1: value1-1
|
129
129
|
key1-2: value1-2
|
@@ -131,7 +131,7 @@ key1-2: value1-2
|
|
131
131
|
key2-1: value2-1
|
132
132
|
key2-2: value2-2
|
133
133
|
|
134
|
-
|
134
|
+
///@block
|
135
135
|
|
136
136
|
the first line of block
|
137
137
|
the second line of block
|
@@ -158,7 +158,7 @@ key1: value1
|
|
158
158
|
key2: value2
|
159
159
|
key3: value3
|
160
160
|
|
161
|
-
|
161
|
+
///@#subconfigs
|
162
162
|
|
163
163
|
key1-1: value1-1
|
164
164
|
key1-2: value1-2
|
@@ -166,7 +166,7 @@ key1-2: value1-2
|
|
166
166
|
key2-1: value2-1
|
167
167
|
key2-2: value2-2
|
168
168
|
|
169
|
-
|
169
|
+
///@block
|
170
170
|
|
171
171
|
the first line of block
|
172
172
|
the second line of block
|
@@ -237,7 +237,7 @@ key1: value1
|
|
237
237
|
key2: value2
|
238
238
|
key3: value3
|
239
239
|
|
240
|
-
|
240
|
+
///@#subconfigs
|
241
241
|
|
242
242
|
key1-1: value1-1
|
243
243
|
key1-2: value1-2
|
@@ -245,7 +245,7 @@ key1-2: value1-2
|
|
245
245
|
key2-1: value2-1
|
246
246
|
key2-2: value2-2
|
247
247
|
|
248
|
-
|
248
|
+
///@block
|
249
249
|
|
250
250
|
the first line of block
|
251
251
|
the second line of block
|
@@ -303,7 +303,7 @@ JSON
|
|
303
303
|
describe AdHocTemplate::RecordReader::CSVReader do
|
304
304
|
before do
|
305
305
|
@config_source = <<CONFIG
|
306
|
-
|
306
|
+
///@#subconfigs
|
307
307
|
|
308
308
|
key1: value1-1
|
309
309
|
key2: value1-2
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ad_hoc_template
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HASHIMOTO, Naoki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pseudohikiparser
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.0.5.develop
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: optparse_plus
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,12 +100,16 @@ files:
|
|
86
100
|
- bin/ad_hoc_template
|
87
101
|
- lib/ad_hoc_template.rb
|
88
102
|
- lib/ad_hoc_template/command_line_interface.rb
|
103
|
+
- lib/ad_hoc_template/default_tag_formatter.rb
|
89
104
|
- lib/ad_hoc_template/parser.rb
|
105
|
+
- lib/ad_hoc_template/pseudohiki_formatter.rb
|
90
106
|
- lib/ad_hoc_template/record_reader.rb
|
91
107
|
- lib/ad_hoc_template/version.rb
|
92
108
|
- spec/ad_hoc_template_spec.rb
|
93
109
|
- spec/command_line_interface_spec.rb
|
110
|
+
- spec/default_tag_formatter_spec.rb
|
94
111
|
- spec/parser_spec.rb
|
112
|
+
- spec/pseudohiki_formatter_spec.rb
|
95
113
|
- spec/record_reader_spec.rb
|
96
114
|
- spec/spec_helper.rb
|
97
115
|
homepage: https://github.com/nico-hn/AdHocTemplate
|
@@ -114,13 +132,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
132
|
version: '0'
|
115
133
|
requirements: []
|
116
134
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.
|
135
|
+
rubygems_version: 2.6.4
|
118
136
|
signing_key:
|
119
137
|
specification_version: 4
|
120
138
|
summary: A tiny template processor
|
121
139
|
test_files:
|
122
140
|
- spec/ad_hoc_template_spec.rb
|
123
141
|
- spec/command_line_interface_spec.rb
|
142
|
+
- spec/default_tag_formatter_spec.rb
|
124
143
|
- spec/parser_spec.rb
|
144
|
+
- spec/pseudohiki_formatter_spec.rb
|
125
145
|
- spec/record_reader_spec.rb
|
126
146
|
- spec/spec_helper.rb
|