pirka 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2738af9c92c8ea4e733d3a5b13af7655c02a35b6
4
- data.tar.gz: d2f785e5256f7a46c73b6b6e916cb165eda4a333
3
+ metadata.gz: 8efc7a4fc80d21165bc3028ce64eaec7da9ad6a0
4
+ data.tar.gz: cc83f7eda83e32e524382b68d0e38945ae37ad35
5
5
  SHA512:
6
- metadata.gz: e14c7cb017f012c9e7f7c159072eba66767aa5501626dc241fa4e434d412fe35628ac6c0f16eca8a49cf6c5d7d69cfde7416e89506e08737c57704a3beea86c9
7
- data.tar.gz: 801534cf03b1be044a8b828f5e37aed3a4f5eec67926e7cb2a7e12e73284b9b4a2261dc2bc33966487fd2bc8a4ed77ae89e65078705a1f0f06c6ae5b45eac7ff
6
+ metadata.gz: 51263f69726fc459254de1fe5d466cf3fe46a54a4ae69610c5b605b0794e742aa06ce8f86362fb75819a06ff1c883454bd82481ea9116b90b544116918d7c875
7
+ data.tar.gz: f59125cb2a8383bb709680c10308fac044ebedcfa42ce414434ec6bb7da5fcf9005d6dbc206c04ab621110106852332691279579e076967768f98545ca17a08e
data/.yardopts CHANGED
@@ -1 +1 @@
1
- --markup markdown --title "pirka Documentation" --protected
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
- raise ArgumentError, 'Specify EPUB file' unless epub_path
37
+ epub = prepare_epub(epub_path)
38
38
 
39
- begin
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(unique_identifier, modified)
75
- @library_path ? Library.load_file(@library_path) :
76
- Library.find_by_release_identifier("#{unique_identifier}@#{modified}")
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.each.reverse_each do |(cfi, data)|
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
- link = doc.at('#pirka') # @todo Avoid conflict with existing link
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
@@ -2,7 +2,7 @@ require "optparse"
2
2
  require "pirka/version"
3
3
  require "pirka/config"
4
4
 
5
- gem "epub-parser", Pirka::EPUB_PARSER_VERSION
5
+ gem "epub-parser", ">= #{Pirka::EPUB_PARSER_VERSION}"
6
6
 
7
7
  module Pirka
8
8
  class App
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/parser/cfi"
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::Parser::CFI.parse(cfi)] = data
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.to_fragment] = value
144
+ list[cfi.to_s] = value
143
145
  }
144
146
  })
145
147
  end
data/lib/pirka/version.rb CHANGED
@@ -17,6 +17,6 @@
17
17
 
18
18
  module Pirka
19
19
  # pirka version
20
- VERSION = "0.1.2"
21
- EPUB_PARSER_VERSION = "0.3.1"
20
+ VERSION = "0.1.3"
21
+ EPUB_PARSER_VERSION = "0.3.2"
22
22
  end
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/parser/cfi"
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.to_s, cfis[i]
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.to_s}
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.to_fragment] = value
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.to_fragment] = value
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.2
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-03-05 00:00:00.000000000 Z
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.1
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.1
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.8
289
+ rubygems_version: 2.6.11
290
290
  signing_key:
291
291
  specification_version: 4
292
292
  summary: Syntax highlighting tool for EPUB books