pnote_client 2.4.5 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/pnote_to_json +56 -19
- data/lib/pnote_client/display/console_display.rb +0 -4
- data/lib/pnote_client/documents/hml/equation.rb +2 -0
- data/lib/pnote_client/documents/hml/paragraph.rb +1 -1
- data/lib/pnote_client/validators/hml_validator.rb +110 -0
- data/lib/pnote_client/validators/pnote_validator.rb +1 -7
- data/lib/pnote_client/version.rb +1 -1
- data/pnote_client.gemspec +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3ba1826c4b23e1951591e2b88f0b835ea3c5ffa2c3501f58afd971d8a0b52c2
|
4
|
+
data.tar.gz: b18197526f4a93f7910310b885479c55d8f32f4c4b3b7cb3165afa54ef13cfb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c3edfc027d91c5738e144885f03d495f87f401cbdd0c5cc31d2be566479c241520c73a3d410b1269ec62b9b3f31710d202dd26ad9f39287761a3fd5fefe3c5d
|
7
|
+
data.tar.gz: 9feceda15a01f1fe44c87875057b2c85625a52bdd67bb1cd588cbfcaaf94656d10501714f5fae5a490d09a90a73ca1b152750929f5a136701edfab2782ac04a9
|
data/exe/pnote_to_json
CHANGED
@@ -9,6 +9,7 @@ require 'pnote_client/converters/pnote_to_json_converter'
|
|
9
9
|
require 'pnote_client/documents/hml'
|
10
10
|
require 'pnote_client/display/console_display'
|
11
11
|
require 'pnote_client/validators/pnote_validator'
|
12
|
+
require 'pnote_client/validators/hml_validator'
|
12
13
|
|
13
14
|
def read_file(filepath)
|
14
15
|
f = File.open(filepath, 'r')
|
@@ -25,22 +26,21 @@ def write_file(content, filepath)
|
|
25
26
|
f.close
|
26
27
|
end
|
27
28
|
|
28
|
-
def save_validation_log_file(
|
29
|
+
def save_validation_log_file(hml_validate_result, pnote_validate_result, log_filepath)
|
29
30
|
log_content = ""
|
30
31
|
log_content += "==========[Warnings]=========="
|
31
32
|
log_content += "\n"
|
32
|
-
|
33
|
+
(hml_validate_result[:warnings] + pnote_validate_result[:warnings]).each_with_index do |warning, index|
|
33
34
|
log_content += "#{index + 1}.\n[경고 메시지]\n#{warning[:message]}\n[상세내용]\n#{warning[:detail]}\n\n\n"
|
34
35
|
end
|
35
36
|
log_content += "\n\n"
|
36
37
|
log_content += "==========[Errors]=========="
|
37
38
|
log_content += "\n"
|
38
|
-
|
39
|
+
(hml_validate_result[:errors] + pnote_validate_result[:errors]).each_with_index do |error, index|
|
39
40
|
log_content += "#{index + 1}.\n[에러 메시지]\n#{error[:message]}\n[상세내용]\n#{error[:detail]}\n\n\n"
|
40
41
|
end
|
41
42
|
|
42
43
|
write_file(log_content, log_filepath)
|
43
|
-
puts "로그 파일이 저장되었습니다. (#{log_filepath})"
|
44
44
|
end
|
45
45
|
|
46
46
|
# 커맨드라인 argument로 옵션 입력받기
|
@@ -104,28 +104,65 @@ input_filename, input_dir_path, hml_content = read_file(options[:input_filepath]
|
|
104
104
|
output_filepath = File.join(input_dir_path, input_filename + ".json")
|
105
105
|
log_filepath = File.join(input_dir_path, input_filename + ".log")
|
106
106
|
|
107
|
-
#
|
107
|
+
# 변환 전 HmlDocument 검증
|
108
|
+
puts ""
|
109
|
+
puts "=============================================="
|
110
|
+
puts "hml 파일을 검사하는 중입니다..."
|
111
|
+
puts "=============================================="
|
112
|
+
puts ""
|
113
|
+
sleep(1)
|
108
114
|
hml_document = PnoteClient::Documents::Hml.parse(hml_content)
|
115
|
+
hml_validator = PnoteClient::Validators::HmlValidator.new(hml_document)
|
116
|
+
hml_validate_result = hml_validator.validate
|
117
|
+
|
118
|
+
# HmlDocument를 PnoteDocument로 변환
|
119
|
+
puts ""
|
120
|
+
puts "=============================================="
|
121
|
+
puts "hml 파일을 pnote 파일로 변환하는 중입니다..."
|
109
122
|
hml_to_pnote_converter = PnoteClient::Converters::HmlToPnoteConverter.new(hml_document, show_time: options[:show_time], type_style_mapper: type_style_mapper, include_image_data: options[:include_image_data])
|
110
123
|
hml_to_pnote_converter.delegate = display
|
111
124
|
pnote_document = hml_to_pnote_converter.convert
|
125
|
+
puts "=============================================="
|
126
|
+
puts ""
|
112
127
|
|
113
128
|
# PnoteDocument 상태 검증
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
response = gets.chomp.downcase
|
124
|
-
if response != 'y'
|
125
|
-
abort
|
126
|
-
end
|
127
|
-
end
|
129
|
+
puts ""
|
130
|
+
puts "=============================================="
|
131
|
+
puts "pnote 파일을 검사하는 중입니다..."
|
132
|
+
puts "=============================================="
|
133
|
+
puts ""
|
134
|
+
sleep(1)
|
135
|
+
pnote_validator = PnoteClient::Validators::PnoteValidator.new(pnote_document)
|
136
|
+
pnote_validate_result = pnote_validator.validate
|
137
|
+
|
128
138
|
|
129
139
|
# PnoteDocument를 JSON 파일로 저장
|
140
|
+
puts ""
|
141
|
+
puts "=============================================="
|
142
|
+
puts "pnote 파일을 json 파일로 저장하는 중입니다..."
|
143
|
+
puts "=============================================="
|
144
|
+
puts ""
|
145
|
+
sleep(1)
|
130
146
|
json = PnoteClient::Converters::PnoteToJsonConverter.new(pnote_document).convert
|
131
147
|
write_file(json, output_filepath)
|
148
|
+
|
149
|
+
|
150
|
+
#로그 파일 저장
|
151
|
+
puts ""
|
152
|
+
puts "=============================================="
|
153
|
+
puts "로그 파일을 저장하는 중입니다..."
|
154
|
+
puts "파일 경로: #{log_filepath}"
|
155
|
+
puts "=============================================="
|
156
|
+
puts ""
|
157
|
+
sleep(1)
|
158
|
+
save_validation_log_file(hml_validate_result, pnote_validate_result, log_filepath)
|
159
|
+
|
160
|
+
puts ""
|
161
|
+
puts "=============================================="
|
162
|
+
puts "변환이 완료되었습니다. (파일 경로: #{output_filepath})"
|
163
|
+
puts "hml 파일 검사 결과: 경고 #{hml_validate_result[:warnings].length}개, 에러 #{hml_validate_result[:errors].length}개"
|
164
|
+
puts "pnote 파일 검사 결과: 경고 #{pnote_validate_result[:warnings].length}개, 에러 #{pnote_validate_result[:errors].length}개"
|
165
|
+
puts ""
|
166
|
+
puts "에러가 있을 경우 json 파일 업로드나 LaTeX 렌더링에 문제가 발생할 수 있습니다."
|
167
|
+
puts "=============================================="
|
168
|
+
puts ""
|
@@ -0,0 +1,110 @@
|
|
1
|
+
#
|
2
|
+
# Author: osh
|
3
|
+
# Created: 2019-05-23
|
4
|
+
# Last modified: 2019-05-23
|
5
|
+
|
6
|
+
require 'pnote_client/documents/hml/equation'
|
7
|
+
|
8
|
+
module PnoteClient
|
9
|
+
module Validators
|
10
|
+
class HmlValidator
|
11
|
+
def initialize(hml_document)
|
12
|
+
@hml_document = hml_document
|
13
|
+
@result = {
|
14
|
+
errors: [],
|
15
|
+
warnings: []
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def validate
|
20
|
+
reset_result
|
21
|
+
validate_document
|
22
|
+
return @result
|
23
|
+
end
|
24
|
+
|
25
|
+
def has_error?
|
26
|
+
return error_count > 0
|
27
|
+
end
|
28
|
+
|
29
|
+
def has_warning?
|
30
|
+
return warning_count > 0
|
31
|
+
end
|
32
|
+
|
33
|
+
def error_count
|
34
|
+
return @result[:errors].length
|
35
|
+
end
|
36
|
+
|
37
|
+
def warning_count
|
38
|
+
return @result[:warnings].length
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def reset_result
|
44
|
+
@result = {
|
45
|
+
errors: [],
|
46
|
+
warnings: []
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def validate_document
|
51
|
+
@hml_document.paragraphs.each do |paragraph|
|
52
|
+
validate_paragraph(paragraph)
|
53
|
+
|
54
|
+
paragraph.footnote_paragraphs.each do |paragraph|
|
55
|
+
validate_paragraph(paragraph)
|
56
|
+
end
|
57
|
+
|
58
|
+
paragraph.endnote_paragraphs.each do |paragraph|
|
59
|
+
validate_paragraph(paragraph)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def validate_paragraph(paragraph)
|
65
|
+
paragraph.elements.each do |element|
|
66
|
+
if element.class == Documents::Hml::Equation
|
67
|
+
invalids = validate_equation(element)
|
68
|
+
invalids.each do |invalid|
|
69
|
+
if invalid[:type] == :error
|
70
|
+
@result[:errors] << {
|
71
|
+
message: invalid[:message],
|
72
|
+
detail: paragraph.content
|
73
|
+
}
|
74
|
+
elsif invalid[:type] == :warning
|
75
|
+
@result[:warnings] << {
|
76
|
+
message: invalid[:message],
|
77
|
+
detail: paragraph.content
|
78
|
+
}
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def validate_equation(equation)
|
86
|
+
open_bracket_regex = /(?<![\\])\s*{/
|
87
|
+
close_bracket_regex = /(?<![\\])\s*}/
|
88
|
+
open_bracket_count = equation.script.scan(open_bracket_regex).length
|
89
|
+
close_bracket_count = equation.script.scan(close_bracket_regex).length
|
90
|
+
invalids = []
|
91
|
+
|
92
|
+
if open_bracket_count > close_bracket_count
|
93
|
+
invalids << {
|
94
|
+
type: :error,
|
95
|
+
message: "닫는 중괄호(`}`)가 부족합니다."
|
96
|
+
}
|
97
|
+
end
|
98
|
+
|
99
|
+
if open_bracket_count < close_bracket_count
|
100
|
+
invalids << {
|
101
|
+
type: :error,
|
102
|
+
message: "여는 중괄호(`}`)가 부족합니다."
|
103
|
+
}
|
104
|
+
end
|
105
|
+
|
106
|
+
return invalids
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -6,9 +6,8 @@
|
|
6
6
|
module PnoteClient
|
7
7
|
module Validators
|
8
8
|
class PnoteValidator
|
9
|
-
def initialize(pnote_document
|
9
|
+
def initialize(pnote_document)
|
10
10
|
@pnote_document = pnote_document
|
11
|
-
@display = display
|
12
11
|
@result = {
|
13
12
|
errors: [],
|
14
13
|
warnings: []
|
@@ -18,7 +17,6 @@ module PnoteClient
|
|
18
17
|
def validate
|
19
18
|
reset_result
|
20
19
|
validate_pnote_document
|
21
|
-
print_validation_result
|
22
20
|
return @result
|
23
21
|
end
|
24
22
|
|
@@ -110,10 +108,6 @@ module PnoteClient
|
|
110
108
|
}
|
111
109
|
end
|
112
110
|
end
|
113
|
-
|
114
|
-
def print_validation_result
|
115
|
-
@display&.print_validation(@result)
|
116
|
-
end
|
117
111
|
end
|
118
112
|
end
|
119
113
|
end
|
data/lib/pnote_client/version.rb
CHANGED
data/pnote_client.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pnote_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bluesh55
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 1.
|
75
|
+
version: 1.4.0
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 1.
|
82
|
+
version: 1.4.0
|
83
83
|
description:
|
84
84
|
email:
|
85
85
|
- bluesh55@naver.com
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- lib/pnote_client/documents/pnote/sub_chapter.rb
|
127
127
|
- lib/pnote_client/documents/pnote/teacher_comment.rb
|
128
128
|
- lib/pnote_client/utils/string_util.rb
|
129
|
+
- lib/pnote_client/validators/hml_validator.rb
|
129
130
|
- lib/pnote_client/validators/pnote_validator.rb
|
130
131
|
- lib/pnote_client/version.rb
|
131
132
|
- pnote_client.gemspec
|