pirka 0.1.1 → 0.1.2
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/ChangeLog.md +11 -1
- data/README.md +1 -1
- data/app/detect.rb +7 -1
- data/app/highlight.rb +11 -3
- data/app/subcommand.rb +2 -2
- data/lib/pirka/highlighter.rb +21 -0
- data/lib/pirka/library.rb +3 -3
- data/lib/pirka/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2738af9c92c8ea4e733d3a5b13af7655c02a35b6
|
4
|
+
data.tar.gz: d2f785e5256f7a46c73b6b6e916cb165eda4a333
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e14c7cb017f012c9e7f7c159072eba66767aa5501626dc241fa4e434d412fe35628ac6c0f16eca8a49cf6c5d7d69cfde7416e89506e08737c57704a3beea86c9
|
7
|
+
data.tar.gz: 801534cf03b1be044a8b828f5e37aed3a4f5eec67926e7cb2a7e12e73284b9b4a2261dc2bc33966487fd2bc8a4ed77ae89e65078705a1f0f06c6ae5b45eac7ff
|
data/ChangeLog.md
CHANGED
@@ -1,4 +1,14 @@
|
|
1
|
-
### 0.1.
|
1
|
+
### 0.1.2 / 2017-03-06
|
2
|
+
|
3
|
+
* Make it possible to specify CSS selector when detecting source code
|
4
|
+
* Make it possible to use location specific middleware
|
5
|
+
* Add `TextLineNum` middleware
|
6
|
+
|
7
|
+
### 0.1.1 / 2017-03-05
|
8
|
+
|
9
|
+
* Introduce middleware architecture
|
10
|
+
|
11
|
+
### 0.1.0 / 2017-03-05
|
2
12
|
|
3
13
|
* Initial release:
|
4
14
|
|
data/README.md
CHANGED
@@ -73,7 +73,7 @@ You also determine languages interactively. Set `-i`(`--interactive`) option:
|
|
73
73
|
|
74
74
|
$ pirka update
|
75
75
|
|
76
|
-
Pirka provides official library files for some EPUB books as Git repository([https://gitlab.com/KitaitiMakoto/pirka-library](https://gitlab.com/KitaitiMakoto/pirka-library)). `pirka update` command
|
76
|
+
Pirka provides official library files for some EPUB books as Git repository([https://gitlab.com/KitaitiMakoto/pirka-library](https://gitlab.com/KitaitiMakoto/pirka-library)). `pirka update` command fetches the files from the repository and you benefit from it.
|
77
77
|
|
78
78
|
Additionally, you can host library files by your own and make Pirka recognizes it by configuration file. See later section for that.
|
79
79
|
|
data/app/detect.rb
CHANGED
@@ -18,11 +18,14 @@ module Pirka
|
|
18
18
|
|
19
19
|
include Subcommand
|
20
20
|
|
21
|
+
SELECTOR = "code"
|
22
|
+
|
21
23
|
def initialize(config)
|
22
24
|
super
|
23
25
|
|
24
26
|
@library_path = nil
|
25
27
|
@interactive = false
|
28
|
+
@selector = SELECTOR
|
26
29
|
|
27
30
|
@available_lexers = Rouge::Lexer.all.sort_by(&:tag).each_with_object({}).with_index {|(lexer, lexers), index|
|
28
31
|
lexers[(index + 1).to_s] = lexer
|
@@ -71,7 +74,7 @@ module Pirka
|
|
71
74
|
library.metadata["Release Identifier"] = epub.release_identifier
|
72
75
|
library.metadata["title"] = epub.title
|
73
76
|
catch do |quit|
|
74
|
-
EPUB::Searcher.search_element(epub, css:
|
77
|
+
EPUB::Searcher.search_element(epub, css: @selector).each do |result|
|
75
78
|
item = result[:itemref].item
|
76
79
|
if @interactive
|
77
80
|
catch do |skip|
|
@@ -134,6 +137,9 @@ module Pirka
|
|
134
137
|
opt.on "-o", "--output=FILE", "File to save library data", Pathname do |path|
|
135
138
|
@library_path = path
|
136
139
|
end
|
140
|
+
opt.on "-s", "--selector=SELECTOR", "CSS selector to detect source code element. Defaults to #{SELECTOR.dump}." do |selector|
|
141
|
+
@selector = selector
|
142
|
+
end
|
137
143
|
end
|
138
144
|
end
|
139
145
|
|
data/app/highlight.rb
CHANGED
@@ -85,8 +85,8 @@ module Pirka
|
|
85
85
|
Highlighter.new),
|
86
86
|
class_name: CSS_CLASS_NAME)
|
87
87
|
middleware = library.metadata["middleware"]
|
88
|
-
if middleware && !
|
89
|
-
highlighter =
|
88
|
+
if middleware && !middleware.empty?
|
89
|
+
highlighter = middleware.reduce(highlighter) {|highlighter, desc|
|
90
90
|
params = desc["params"] || {}
|
91
91
|
Highlighter::Middleware.const_get(desc["name"]).new(highlighter, params)
|
92
92
|
}
|
@@ -102,7 +102,15 @@ module Pirka
|
|
102
102
|
item = itemref.item
|
103
103
|
doc = elem.document
|
104
104
|
|
105
|
-
|
105
|
+
if data["middleware"] && !data["middleware"].empty?
|
106
|
+
additional_highlighter = data["middleware"].reduce(highlighter) {|highlighter, desc|
|
107
|
+
params = desc["params"] || {}
|
108
|
+
Highlighter::Middleware.const_get(desc["name"]).new(highlighter, params)
|
109
|
+
}
|
110
|
+
additional_highlighter.markup elem, lang
|
111
|
+
else
|
112
|
+
highlighter.markup elem, lang
|
113
|
+
end
|
106
114
|
|
107
115
|
link = doc.at('#pirka') # @todo Avoid conflict with existing link
|
108
116
|
unless link
|
data/app/subcommand.rb
CHANGED
@@ -18,11 +18,11 @@ module Pirka
|
|
18
18
|
def parse_options!(argv)
|
19
19
|
parser = OptionParser.new {|opt|
|
20
20
|
usage = "Usage: #{opt.program_name} [options] #{self.class::PROGRAM_NAME}"
|
21
|
-
usage << " " << self.class::ARGS.join(" ") if self
|
21
|
+
usage << " " << self.class::ARGS.join(" ") if self.class.const_defined?(:ARGS)
|
22
22
|
|
23
23
|
opt.program_name = "#{opt.program_name} [global options] #{self.class::PROGRAM_NAME}"
|
24
24
|
opt.banner = <<EOB
|
25
|
-
#{self
|
25
|
+
#{self.class::DESCRIPTION}
|
26
26
|
|
27
27
|
#{usage}
|
28
28
|
EOB
|
data/lib/pirka/highlighter.rb
CHANGED
@@ -68,6 +68,27 @@ module Pirka
|
|
68
68
|
}.join
|
69
69
|
end
|
70
70
|
end
|
71
|
+
|
72
|
+
class TextLineNum
|
73
|
+
def initialize(highlighter, params = {})
|
74
|
+
@highlighter = highlighter
|
75
|
+
@width = params["width"]
|
76
|
+
end
|
77
|
+
|
78
|
+
def markup(element, lang)
|
79
|
+
lines = []
|
80
|
+
nums = []
|
81
|
+
element.content.each_line do |line|
|
82
|
+
nums << line[0, @width]
|
83
|
+
lines << line[@width..-1]
|
84
|
+
end
|
85
|
+
element.inner_html = lines.join
|
86
|
+
@highlighter.markup element, lang
|
87
|
+
element.inner_html = element.inner_html.lines.collect.with_index {|line, index|
|
88
|
+
nums[index] << line
|
89
|
+
}.join
|
90
|
+
end
|
91
|
+
end
|
71
92
|
end
|
72
93
|
end
|
73
94
|
end
|
data/lib/pirka/library.rb
CHANGED
@@ -125,10 +125,10 @@ module Pirka
|
|
125
125
|
# @overload each
|
126
126
|
# @return [Enumerator] Enumerator which iterates over cfi and lang
|
127
127
|
def each
|
128
|
-
sorted_list = @codelist.each_pair.sort_by {|(cfi,
|
128
|
+
sorted_list = @codelist.each_pair.sort_by {|(cfi, data)| cfi}
|
129
129
|
if block_given?
|
130
|
-
sorted_list.each do |(cfi,
|
131
|
-
yield cfi,
|
130
|
+
sorted_list.each do |(cfi, data)|
|
131
|
+
yield cfi, data
|
132
132
|
end
|
133
133
|
else
|
134
134
|
sorted_list.each
|
data/lib/pirka/version.rb
CHANGED