card-mod-script 0.15.0 → 0.15.1

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
  SHA256:
3
- metadata.gz: 61c8af991310acf4700552ba0690bfa466b62bc171f047fae46c598fc346258a
4
- data.tar.gz: eea339f41ec56f46f34094e36b89cc2f70542300d77c0cbaf142df6fb0ea4ed8
3
+ metadata.gz: 58d0754417a42220666a3045f952b7373d83ef060646f38036342be53ad84703
4
+ data.tar.gz: 1307b8c30a1e75c4809e691e07d342bb494ba8563a0cc7299ed0e48a0e44e5ed
5
5
  SHA512:
6
- metadata.gz: 0d145ddc1bc27fa6b91025223e69c40bc9350bda85318563375f8f4fce3d61ceb13ca521f04df3288b32d1e2ed6300b5c35e780f9e5ec173d21ab75db6cde82c
7
- data.tar.gz: '0387d3dd3646425e2f2c3cd62220e07716e7615d63273ee7482d6f9642e2e93c4151a360dc4c173f6bbeea4e49666d5057624e43d935408509599bf3d3e4ba18'
6
+ metadata.gz: e81cbbc65c3c6aa06254d2f51d044fddc7254e68e0d631155ca9732387ea1c3237a45040f6f18c6b817259db4f3d16ee3ce1134c7416f58e32a2a74caa5e14ee
7
+ data.tar.gz: 1dbcb912512fce25920d43072e7bfd14fc71f8831420b0a98999b3e12450645fea682e87a5360f8136ff9986232ecda50198a5631682701e3f18c8865b3dfeca
@@ -0,0 +1 @@
1
+ Cardio::Utils.extend Cardio::Utils::Ansi2Html
@@ -0,0 +1,72 @@
1
+ # Converts ansi formatting codes to html
2
+ module Cardio
3
+ module Utils
4
+ # convert ANSI to html
5
+ module Ansi2Html
6
+ def ansi2html data
7
+ data.gsub(/\033\[(?<code>[\d\;]{2,})m(?<content>.*?)\033\[0m/) do
8
+ to_span_tag Regexp.last_match(:code), Regexp.last_match(:content)
9
+ end
10
+ end
11
+
12
+ private
13
+
14
+ ANSI_COLOR_CODE = {
15
+ 0 => "black",
16
+ 1 => "red",
17
+ 2 => "green",
18
+ 3 => "gold",
19
+ 4 => "blue",
20
+ 5 => "magenta",
21
+ 6 => "darkcyan",
22
+ 7 => "white"
23
+ }.freeze
24
+
25
+ ANSI_BRIGHT_COLOR_CODE = {
26
+ 0 => "gray",
27
+ 1 => "lightcoral",
28
+ 2 => "lightgreen",
29
+ 3 => "lightyellow",
30
+ 4 => "lightblue",
31
+ 5 => "mediumpurple",
32
+ 6 => "lightcyan",
33
+ 7 => "lightgray"
34
+ }.freeze
35
+
36
+ STYLE_MAPPINGS = {
37
+ 1 => "font-weight:bold",
38
+ 2 => "opacity:0.5",
39
+ 3 => "font-style:italic",
40
+ 4 => "text-decoration:underline",
41
+ 5 => "text-decoration:blink",
42
+ 6 => "text-decoration:blink",
43
+ 9 => "text-decoration:line-through"
44
+ }.freeze
45
+
46
+ def to_span_tag codes, content
47
+ style = codes.split(";")
48
+ .map(&method(:translate_style_code))
49
+ .join
50
+ "<span style='#{style}'>#{content}</span>"
51
+ end
52
+
53
+ def translate_style_code code
54
+ return STYLE_MAPPINGS[code.to_i] if code.size == 1
55
+
56
+ color_code = code[-1].to_i
57
+ property, mapping =
58
+ case code[0..-2]
59
+ when "3"
60
+ ["color", ANSI_COLOR_CODE]
61
+ when "4"
62
+ ["background-color", ANSI_COLOR_CODE]
63
+ when "9"
64
+ ["color", ANSI_BRIGHT_COLOR_CODE]
65
+ when "10"
66
+ ["background-color", ANSI_BRIGHT_COLOR_CODE]
67
+ end
68
+ "#{property}: #{mapping[color_code]}; "
69
+ end
70
+ end
71
+ end
72
+ end
@@ -5,5 +5,5 @@ include_set Abstract::JavaScript
5
5
  event :validate_javascript_syntax, :validate, on: :save, changed: %i[type_id content] do
6
6
  Uglifier.compile content, harmony: true
7
7
  rescue Uglifier::Error => e
8
- errors.add :content, "<pre>#{Ansi2html.ansi2html(e.message)}</pre>".html_safe
8
+ errors.add :content, "<pre>#{Cardio::Utils.ansi2html(e.message)}</pre>".html_safe
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: card-mod-script
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.15.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan McCutchen
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-01-04 00:00:00.000000000 Z
13
+ date: 2023-03-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: card
@@ -18,42 +18,42 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 1.105.0
21
+ version: 1.105.1
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - '='
27
27
  - !ruby/object:Gem::Version
28
- version: 1.105.0
28
+ version: 1.105.1
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: card-mod-assets
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - '='
34
34
  - !ruby/object:Gem::Version
35
- version: 0.15.0
35
+ version: 0.15.1
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - '='
41
41
  - !ruby/object:Gem::Version
42
- version: 0.15.0
42
+ version: 0.15.1
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: card-mod-list
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - '='
48
48
  - !ruby/object:Gem::Version
49
- version: 0.15.0
49
+ version: 0.15.1
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - '='
55
55
  - !ruby/object:Gem::Version
56
- version: 0.15.0
56
+ version: 0.15.1
57
57
  description: ''
58
58
  email:
59
59
  - info@decko.org
@@ -62,10 +62,11 @@ extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
64
  - README.md
65
+ - config/early/init_execjs.rb
66
+ - config/late/extend_ansi.rb
65
67
  - data/real.yml
66
- - init/early/init_execjs.rb
67
- - lib/ansi2html.rb
68
68
  - lib/card/mod/script.rb
69
+ - lib/cardio/utils/ansi2_html.rb
69
70
  - lib/javascript/jquery.iframe-transport.js
70
71
  - lib/javascript/theme-textmate.js
71
72
  - set/abstract/00_script.rb
data/lib/ansi2html.rb DELETED
@@ -1,69 +0,0 @@
1
- # Converts ansi formatting codes to html
2
- module Ansi2html
3
- class << self
4
- def ansi2html data
5
- data.gsub(/\033\[(?<code>[\d\;]{2,})m(?<content>.*?)\033\[0m/) do
6
- to_span_tag Regexp.last_match(:code), Regexp.last_match(:content)
7
- end
8
- end
9
-
10
- private
11
-
12
- ANSI_COLOR_CODE = {
13
- 0 => "black",
14
- 1 => "red",
15
- 2 => "green",
16
- 3 => "gold",
17
- 4 => "blue",
18
- 5 => "magenta",
19
- 6 => "darkcyan",
20
- 7 => "white"
21
- }.freeze
22
-
23
- ANSI_BRIGHT_COLOR_CODE = {
24
- 0 => "gray",
25
- 1 => "lightcoral",
26
- 2 => "lightgreen",
27
- 3 => "lightyellow",
28
- 4 => "lightblue",
29
- 5 => "mediumpurple",
30
- 6 => "lightcyan",
31
- 7 => "lightgray"
32
- }.freeze
33
-
34
- STYLE_MAPPINGS = {
35
- 1 => "font-weight:bold",
36
- 2 => "opacity:0.5",
37
- 3 => "font-style:italic",
38
- 4 => "text-decoration:underline",
39
- 5 => "text-decoration:blink",
40
- 6 => "text-decoration:blink",
41
- 9 => "text-decoration:line-through"
42
- }.freeze
43
-
44
- def to_span_tag codes, content
45
- style = codes.split(";")
46
- .map(&method(:translate_style_code))
47
- .join
48
- "<span style='#{style}'>#{content}</span>"
49
- end
50
-
51
- def translate_style_code code
52
- return STYLE_MAPPINGS[code.to_i] if code.size == 1
53
-
54
- color_code = code[-1].to_i
55
- property, mapping =
56
- case code[0..-2]
57
- when "3"
58
- ["color", ANSI_COLOR_CODE]
59
- when "4"
60
- ["background-color", ANSI_COLOR_CODE]
61
- when "9"
62
- ["color", ANSI_BRIGHT_COLOR_CODE]
63
- when "10"
64
- ["background-color", ANSI_BRIGHT_COLOR_CODE]
65
- end
66
- "#{property}: #{mapping[color_code]}; "
67
- end
68
- end
69
- end
File without changes