pirka 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88fcda5b7f58df80108a0eba4386756ccd9ddbaf
4
- data.tar.gz: 428c8af5035de8b0da4a0fc63507f3b5f8d2f6fe
3
+ metadata.gz: 2738af9c92c8ea4e733d3a5b13af7655c02a35b6
4
+ data.tar.gz: d2f785e5256f7a46c73b6b6e916cb165eda4a333
5
5
  SHA512:
6
- metadata.gz: 55814a01738772bead120d50677462cc911d72df46621fb43b97747a603d8175d909652cc1e7a00d6b93f4c1398af654017b6b6282b658c17b7975939672515e
7
- data.tar.gz: 9037389b5d65fa6867a41901102f5e8b91f5cb270e74c57357276159a3aae17dca21107a17e13a5ff8eaa8d03cc1910479fdec54942227a18536878a8bd9f6f4
6
+ metadata.gz: e14c7cb017f012c9e7f7c159072eba66767aa5501626dc241fa4e434d412fe35628ac6c0f16eca8a49cf6c5d7d69cfde7416e89506e08737c57704a3beea86c9
7
+ data.tar.gz: 801534cf03b1be044a8b828f5e37aed3a4f5eec67926e7cb2a7e12e73284b9b4a2261dc2bc33966487fd2bc8a4ed77ae89e65078705a1f0f06c6ae5b45eac7ff
data/ChangeLog.md CHANGED
@@ -1,4 +1,14 @@
1
- ### 0.1.0 / 2017-02-07
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 fethes the files from the repository and you benefit from it.
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: 'code').each do |result|
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 && !library.metadata["middleware"].empty?
89
- highlighter = library.metadata["middleware"].reduce(highlighter) {|highlighter, desc|
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
- highlighter.markup elem, lang
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::class.const_defined?(:ARGS)
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::class::DESCRIPTION}
25
+ #{self.class::DESCRIPTION}
26
26
 
27
27
  #{usage}
28
28
  EOB
@@ -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, lang)| cfi}
128
+ sorted_list = @codelist.each_pair.sort_by {|(cfi, data)| cfi}
129
129
  if block_given?
130
- sorted_list.each do |(cfi, lang)|
131
- yield cfi, lang
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
@@ -17,6 +17,6 @@
17
17
 
18
18
  module Pirka
19
19
  # pirka version
20
- VERSION = "0.1.1"
20
+ VERSION = "0.1.2"
21
21
  EPUB_PARSER_VERSION = "0.3.1"
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pirka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - KITAITI Makoto