pirka 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -1
- data/app/highlight.rb +36 -27
- data/app.rb +1 -1
- data/lib/pirka/library.rb +5 -3
- data/lib/pirka/version.rb +2 -2
- data/pirka.gemspec +1 -1
- data/test/test_library.rb +5 -5
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8efc7a4fc80d21165bc3028ce64eaec7da9ad6a0
|
4
|
+
data.tar.gz: cc83f7eda83e32e524382b68d0e38945ae37ad35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51263f69726fc459254de1fe5d466cf3fe46a54a4ae69610c5b605b0794e742aa06ce8f86362fb75819a06ff1c883454bd82481ea9116b90b544116918d7c875
|
7
|
+
data.tar.gz: f59125cb2a8383bb709680c10308fac044ebedcfa42ce414434ec6bb7da5fcf9005d6dbc206c04ab621110106852332691279579e076967768f98545ca17a08e
|
data/.yardopts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
--markup markdown --title "
|
1
|
+
--markup markdown --markup-provider kramdown --title "Pirka Documentation" --protected
|
data/app/highlight.rb
CHANGED
@@ -34,17 +34,9 @@ module Pirka
|
|
34
34
|
parse_options! argv
|
35
35
|
|
36
36
|
epub_path = argv.shift
|
37
|
-
|
37
|
+
epub = prepare_epub(epub_path)
|
38
38
|
|
39
|
-
|
40
|
-
# @todo Make this optional
|
41
|
-
require 'epub/maker/ocf/physical_container/zipruby'
|
42
|
-
EPUB::OCF::PhysicalContainer.adapter = :Zipruby
|
43
|
-
rescue LoadError
|
44
|
-
end
|
45
|
-
epub = EPUB::Parser.parse(epub_path)
|
46
|
-
library = find_library(epub.unique_identifier, epub.modified)
|
47
|
-
raise RuntimeError, "Cannot find code list #{Library.filename(epub.release_identifier)} for #{epub.release_identifier}(#{epub_path}) in any directory of #{Library.directories.join(", ")}" unless library
|
39
|
+
library = find_library(epub)
|
48
40
|
|
49
41
|
css_item = add_css_file(epub)
|
50
42
|
need_save = highlight_contents(epub, css_item, library)
|
@@ -70,10 +62,23 @@ module Pirka
|
|
70
62
|
}
|
71
63
|
end
|
72
64
|
|
65
|
+
# @todo Make this optional
|
66
|
+
def prepare_epub(path)
|
67
|
+
raise ArgumentError, 'Specify EPUB file' unless path
|
68
|
+
begin
|
69
|
+
require 'epub/maker/ocf/physical_container/zipruby'
|
70
|
+
EPUB::OCF::PhysicalContainer.adapter = :Zipruby
|
71
|
+
rescue LoadError
|
72
|
+
end
|
73
|
+
EPUB::Parser.parse(path)
|
74
|
+
end
|
75
|
+
|
73
76
|
# @todo Do the best when file for release identifier is not find but for unique identifier found
|
74
|
-
def find_library(
|
75
|
-
@library_path ? Library.load_file(@library_path) :
|
76
|
-
Library.find_by_release_identifier(
|
77
|
+
def find_library(epub)
|
78
|
+
library = @library_path ? Library.load_file(@library_path) :
|
79
|
+
Library.find_by_release_identifier(epub.release_identifier)
|
80
|
+
raise RuntimeError, "Cannot find code list #{Library.filename(epub.release_identifier)} for #{epub.release_identifier}(#{epub_path}) in any directory of #{Library.directories.join(", ")}" unless library
|
81
|
+
library
|
77
82
|
end
|
78
83
|
|
79
84
|
# @todo Consider descendant elements of code
|
@@ -92,7 +97,7 @@ module Pirka
|
|
92
97
|
}
|
93
98
|
end
|
94
99
|
|
95
|
-
library.
|
100
|
+
library.reverse_each do |(cfi, data)|
|
96
101
|
lang = data["language"]
|
97
102
|
unless lang
|
98
103
|
warn "Language for #{cfi} is not detected"
|
@@ -112,19 +117,7 @@ module Pirka
|
|
112
117
|
highlighter.markup elem, lang
|
113
118
|
end
|
114
119
|
|
115
|
-
|
116
|
-
unless link
|
117
|
-
item_entry_name = DUMMY_ORIGIN + item.entry_name
|
118
|
-
entry_name = DUMMY_ORIGIN + css_item.entry_name
|
119
|
-
href = entry_name.route_from(item_entry_name)
|
120
|
-
link = Nokogiri::XML::Node.new('link', doc)
|
121
|
-
link['href'] = href
|
122
|
-
link['type'] = 'text/css'
|
123
|
-
link['rel'] = 'stylesheet'
|
124
|
-
link['id'] = 'pirka'
|
125
|
-
head = (doc/'head').first
|
126
|
-
head << link
|
127
|
-
end
|
120
|
+
embed_stylesheet_link doc, item, css_item
|
128
121
|
item.content = doc.to_xml
|
129
122
|
need_save << item
|
130
123
|
end
|
@@ -152,6 +145,22 @@ module Pirka
|
|
152
145
|
epub.package.edit
|
153
146
|
end
|
154
147
|
|
148
|
+
def embed_stylesheet_link(doc, item, css_item)
|
149
|
+
link = doc.at('#pirka') # @todo Avoid conflict with existing link
|
150
|
+
unless link
|
151
|
+
item_entry_name = DUMMY_ORIGIN + item.entry_name
|
152
|
+
entry_name = DUMMY_ORIGIN + css_item.entry_name
|
153
|
+
href = entry_name.route_from(item_entry_name)
|
154
|
+
link = Nokogiri::XML::Node.new('link', doc)
|
155
|
+
link['href'] = href
|
156
|
+
link['type'] = 'text/css'
|
157
|
+
link['rel'] = 'stylesheet'
|
158
|
+
link['id'] = 'pirka'
|
159
|
+
head = (doc/'head').first
|
160
|
+
head << link
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
155
164
|
private
|
156
165
|
|
157
166
|
# @todo theme
|
data/app.rb
CHANGED
data/lib/pirka/library.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "pathname"
|
2
2
|
require "base64"
|
3
3
|
require "yaml"
|
4
|
-
require "epub/
|
4
|
+
require "epub/cfi"
|
5
5
|
|
6
6
|
module Pirka
|
7
7
|
# Environment variables affect this class:
|
@@ -10,6 +10,8 @@ module Pirka
|
|
10
10
|
#
|
11
11
|
# @see https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
12
12
|
class Library
|
13
|
+
include Enumerable
|
14
|
+
|
13
15
|
DIR_NAME = "pirka/local"
|
14
16
|
EXT = ".yaml"
|
15
17
|
SUBDIR_LENGTH = 4
|
@@ -79,7 +81,7 @@ module Pirka
|
|
79
81
|
h.each_pair do |key, value|
|
80
82
|
if key == "codelist"
|
81
83
|
value.each_pair do |cfi, data|
|
82
|
-
library.codelist[EPUB::
|
84
|
+
library.codelist[EPUB::CFI.parse(cfi)] = data
|
83
85
|
end
|
84
86
|
else
|
85
87
|
library.metadata[key] = value
|
@@ -139,7 +141,7 @@ module Pirka
|
|
139
141
|
def to_h
|
140
142
|
metadata.merge({
|
141
143
|
"codelist" => each.with_object({}) {|(cfi, value), list|
|
142
|
-
list[cfi.
|
144
|
+
list[cfi.to_s] = value
|
143
145
|
}
|
144
146
|
})
|
145
147
|
end
|
data/lib/pirka/version.rb
CHANGED
data/pirka.gemspec
CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |gem|
|
|
29
29
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
30
30
|
gem.require_paths = ['lib']
|
31
31
|
|
32
|
-
gem.add_runtime_dependency 'epub-parser', Pirka::EPUB_PARSER_VERSION
|
32
|
+
gem.add_runtime_dependency 'epub-parser', ">= #{Pirka::EPUB_PARSER_VERSION}"
|
33
33
|
gem.add_runtime_dependency 'epub-maker'
|
34
34
|
gem.add_runtime_dependency 'rouge'
|
35
35
|
gem.add_runtime_dependency 'rouge-lexers-fluentd'
|
data/test/test_library.rb
CHANGED
@@ -2,7 +2,7 @@ require "helper"
|
|
2
2
|
require "yaml"
|
3
3
|
require "tmpdir"
|
4
4
|
require "pirka/library"
|
5
|
-
require "epub/
|
5
|
+
require "epub/cfi"
|
6
6
|
|
7
7
|
class TestLibrary < Test::Unit::TestCase
|
8
8
|
def setup
|
@@ -47,7 +47,7 @@ EOY
|
|
47
47
|
/6/31!/4/2/56/2]
|
48
48
|
i = 0
|
49
49
|
@library.each do |(cfi, _)|
|
50
|
-
assert_equal cfi.
|
50
|
+
assert_equal cfi.path_string, cfis[i]
|
51
51
|
i += 1
|
52
52
|
end
|
53
53
|
end
|
@@ -56,7 +56,7 @@ EOY
|
|
56
56
|
assert_equal %w[/6/30!/4/2/56/2
|
57
57
|
/6/30!/4/2/58/2
|
58
58
|
/6/31!/4/2/56/2],
|
59
|
-
@library.each.collect {|(cfi, _)| cfi.
|
59
|
+
@library.each.collect {|(cfi, _)| cfi.path_string}
|
60
60
|
end
|
61
61
|
|
62
62
|
def test_to_yaml
|
@@ -74,7 +74,7 @@ EOY
|
|
74
74
|
assert_equal @library.metadata, data
|
75
75
|
|
76
76
|
expected_codelist = @library.each.with_object({}) {|(cfi, value), list|
|
77
|
-
list[cfi.
|
77
|
+
list[cfi.to_s] = value
|
78
78
|
}
|
79
79
|
assert_equal expected_codelist, codelist
|
80
80
|
end
|
@@ -97,7 +97,7 @@ EOY
|
|
97
97
|
assert_equal @library.metadata, data
|
98
98
|
|
99
99
|
expected_codelist = @library.each.with_object({}) {|(cfi, value), list|
|
100
|
-
list[cfi.
|
100
|
+
list[cfi.to_s] = value
|
101
101
|
}
|
102
102
|
assert_equal expected_codelist, codelist
|
103
103
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pirka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- KITAITI Makoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: epub-parser
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.3.
|
19
|
+
version: 0.3.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.3.
|
26
|
+
version: 0.3.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: epub-maker
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -286,7 +286,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
286
286
|
version: '0'
|
287
287
|
requirements: []
|
288
288
|
rubyforge_project:
|
289
|
-
rubygems_version: 2.6.
|
289
|
+
rubygems_version: 2.6.11
|
290
290
|
signing_key:
|
291
291
|
specification_version: 4
|
292
292
|
summary: Syntax highlighting tool for EPUB books
|