iro 0.0.2 → 0.0.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 +4 -4
- data/.travis.yml +8 -0
- data/LICENSE +1 -1
- data/iro.gemspec +2 -2
- data/lib/iro.rb +2 -0
- data/lib/iro/formatter/html_formatter.rb +77 -0
- data/lib/iro/formatter/sample.css +35 -0
- data/lib/iro/ruby/parser.rb +1 -0
- data/lib/iro/version.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70fd273da825be5057ee448d52262c1f55bfdcc39781368b07a156ceb5177a5b
|
4
|
+
data.tar.gz: c2089d3d515a192be77bc5d74d926b2101a399e1eefe712206a5c724f53688b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69d36181c3efd70f7e26235e18364e72eacd4399d64efb6b42bcb357da36965f1c5a010a8744580d0d70117690a6ee9c78e4380223c70349331d1b2e3e070614
|
7
|
+
data.tar.gz: 98459e81eb6e9b10173e1cafba4001245205c4fdd62e29fae8106db75a04bc5ee2faf8c5371ee2d4b2fdbeebdeea87e582345711f1926fa1f34117effec8f82e
|
data/.travis.yml
ADDED
data/LICENSE
CHANGED
@@ -186,7 +186,7 @@
|
|
186
186
|
same "printed page" as the copyright notice for easier
|
187
187
|
identification within third-party archives.
|
188
188
|
|
189
|
-
Copyright
|
189
|
+
Copyright 2017-2018 Masataka Pocke Kuwabara
|
190
190
|
|
191
191
|
Licensed under the Apache License, Version 2.0 (the "License");
|
192
192
|
you may not use this file except in compliance with the License.
|
data/iro.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ["Masataka Pocke Kuwabara"]
|
9
9
|
spec.email = ["kuwabara@pocke.me"]
|
10
10
|
|
11
|
-
spec.summary = %q{}
|
12
|
-
spec.description = %q{}
|
11
|
+
spec.summary = %q{A library for syntax highlighter}
|
12
|
+
spec.description = %q{A library for syntax highlighter}
|
13
13
|
spec.homepage = "https://github.com/pocke/iro"
|
14
14
|
spec.license = 'Apache-2.0'
|
15
15
|
|
data/lib/iro.rb
CHANGED
@@ -0,0 +1,77 @@
|
|
1
|
+
module Iro
|
2
|
+
module Formatter
|
3
|
+
class HTMLFormatter
|
4
|
+
module ConvertedHighlight
|
5
|
+
refine Array do
|
6
|
+
def group() self[0] end
|
7
|
+
def line() self[1]-1 end
|
8
|
+
def column() self[2]-1 end
|
9
|
+
def length() self[3] end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
using ConvertedHighlight
|
13
|
+
|
14
|
+
def self.format(source, highlight, prefix: '')
|
15
|
+
formatter = self.new(
|
16
|
+
source: source,
|
17
|
+
highlight: highlight,
|
18
|
+
prefix: prefix,
|
19
|
+
)
|
20
|
+
formatter.format
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.sample_stylesheet
|
24
|
+
File.join(__dir__, 'sample.css')
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize(source:, highlight:, prefix:)
|
28
|
+
@source = source.each_line.map(&:chomp)
|
29
|
+
@highlight = sort_highlight_by_position(highlight)
|
30
|
+
@prefix = prefix
|
31
|
+
end
|
32
|
+
|
33
|
+
def format
|
34
|
+
buf = []
|
35
|
+
|
36
|
+
@source.each.with_index do |line, lineno|
|
37
|
+
highlights = pop_highlight(lineno)
|
38
|
+
if highlights.empty?
|
39
|
+
buf << CGI.escapeHTML(line)
|
40
|
+
next
|
41
|
+
end
|
42
|
+
|
43
|
+
last_col = 0
|
44
|
+
highlighted_line = +''
|
45
|
+
highlights.each do |hi|
|
46
|
+
highlighted_line << CGI.escapeHTML(line[last_col...hi.column])
|
47
|
+
last_col = hi.column + hi.length
|
48
|
+
token = CGI.escapeHTML(line[(hi.column)...last_col])
|
49
|
+
highlighted_line << %Q!<span class="#{@prefix}#{hi.group}">#{token}</span>!
|
50
|
+
end
|
51
|
+
highlighted_line << line[last_col..-1]
|
52
|
+
buf << highlighted_line
|
53
|
+
end
|
54
|
+
|
55
|
+
buf.join("\n")
|
56
|
+
end
|
57
|
+
|
58
|
+
def sort_highlight_by_position(highlight)
|
59
|
+
highlight.flat_map do |group, positions|
|
60
|
+
positions.map do |pos|
|
61
|
+
[group, *pos]
|
62
|
+
end
|
63
|
+
end.sort_by do |pos|
|
64
|
+
[pos.line, pos.column]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def pop_highlight(lineno)
|
69
|
+
[].tap do |res|
|
70
|
+
while @highlight.first&.line == lineno
|
71
|
+
res << @highlight.shift
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
.ruby-String {
|
2
|
+
color: #ff6d6d;
|
3
|
+
}
|
4
|
+
|
5
|
+
.ruby-Number {
|
6
|
+
color: #ff6d6d;
|
7
|
+
}
|
8
|
+
|
9
|
+
.ruby-Float {
|
10
|
+
color: #ff6d6d;
|
11
|
+
}
|
12
|
+
|
13
|
+
.ruby-Comment {
|
14
|
+
color: #dddddd;
|
15
|
+
}
|
16
|
+
|
17
|
+
.ruby-Type {
|
18
|
+
color: #ffdb6b;
|
19
|
+
}
|
20
|
+
|
21
|
+
.ruby-Delimiter {
|
22
|
+
color: #c649ff;
|
23
|
+
}
|
24
|
+
|
25
|
+
.ruby-rubyDefine {
|
26
|
+
color: #48ffa7;
|
27
|
+
}
|
28
|
+
|
29
|
+
.ruby-Keyword {
|
30
|
+
color: #3dbfff;
|
31
|
+
}
|
32
|
+
|
33
|
+
.ruby-rubyLocalVariable {
|
34
|
+
color: #3dbfff;
|
35
|
+
}
|
data/lib/iro/ruby/parser.rb
CHANGED
data/lib/iro/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masataka Pocke Kuwabara
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.11'
|
55
|
-
description:
|
55
|
+
description: A library for syntax highlighter
|
56
56
|
email:
|
57
57
|
- kuwabara@pocke.me
|
58
58
|
executables: []
|
@@ -60,6 +60,7 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
63
64
|
- Gemfile
|
64
65
|
- LICENSE
|
65
66
|
- README.md
|
@@ -68,6 +69,8 @@ files:
|
|
68
69
|
- bin/setup
|
69
70
|
- iro.gemspec
|
70
71
|
- lib/iro.rb
|
72
|
+
- lib/iro/formatter/html_formatter.rb
|
73
|
+
- lib/iro/formatter/sample.css
|
71
74
|
- lib/iro/ripper_wrapper.rb
|
72
75
|
- lib/iro/ruby/parser.rb
|
73
76
|
- lib/iro/version.rb
|
@@ -94,5 +97,5 @@ rubyforge_project:
|
|
94
97
|
rubygems_version: 2.7.6
|
95
98
|
signing_key:
|
96
99
|
specification_version: 4
|
97
|
-
summary:
|
100
|
+
summary: A library for syntax highlighter
|
98
101
|
test_files: []
|