run_tasks 1.4.0 → 1.4.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
  SHA1:
3
- metadata.gz: 0de82fa9c8781db30c68460761abbef5daf589b7
4
- data.tar.gz: 78d78c13f4dd1c98806e228eeb7187e1b32e2a04
3
+ metadata.gz: 3f8a01e9cf83e14af770fdf07028b7eeef28e5a2
4
+ data.tar.gz: 6298e13d2b841b1e66f3c095538fd99ea486346c
5
5
  SHA512:
6
- metadata.gz: dfbe8b48bd113e771749f9821a8844fccfe84eedf9a512bbfe52c11c13b1d19636fbf0d0008af8fd13edfcd2f507f87e27e736a71fb8046d84350bb82b766b47
7
- data.tar.gz: 152e3afd479a9bdea597a9560ef93c710b27b65724e08272b7199666a220416713aaa893fa4dd4c089a5c92e53fc4e353760e17c79dc21de97a9fa0834cdf5fe
6
+ metadata.gz: 840a4dea8f6978e7a4b48d48afe7148707a127a8d619698ffc7ffe11854996422b1aefe1c52be023728e9f8faf4e2fd61f0034b9821a03c43cecef7d20dec637
7
+ data.tar.gz: 0d3d3b5d42de907bf85acd67f14698231756af2c08c5c767aa6bd762aa2085cf83b770bdbc60f58ad8e9790710a4e9f167d8837c63ecd8f10b8fa6add574ff27
@@ -0,0 +1,44 @@
1
+ module Markdown
2
+ module AbstractTag
3
+ def initialize(value)
4
+ case value
5
+ when String
6
+ @string = value
7
+ when AbstractTag
8
+ @tag = value
9
+ else
10
+ raise "Invalid value of '#{value.class.name}' class"
11
+ end
12
+ end
13
+
14
+ def to_ansi
15
+ string = @string || @tag.to_ansi
16
+ pattern = Regexp.new(
17
+ "(^|.+?)" \
18
+ "(?:#{tokens.map{ |token| "\\" + token.chars.join("\\") }.join('|')})" \
19
+ "(.+?)" \
20
+ "(?:#{tokens.map{ |token| "\\" + token.chars.join("\\") }.join('|')})" \
21
+ "($|.+)"
22
+ )
23
+
24
+ loop do
25
+ string = string.sub(pattern) do
26
+ Regexp.last_match[1] + replace_by(Regexp.last_match[2]) + Regexp.last_match[3]
27
+ end
28
+ break if !Regexp.last_match
29
+ end
30
+
31
+ string
32
+ end
33
+
34
+ protected
35
+
36
+ def tokens
37
+ raise "Not implemented"
38
+ end
39
+
40
+ def replace_by(string)
41
+ raise "Not implemented"
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,18 @@
1
+ require_relative "./abstract_tag"
2
+ require_relative "../string"
3
+
4
+ module Markdown
5
+ class Bold
6
+ include AbstractTag
7
+
8
+ protected
9
+
10
+ def tokens
11
+ ['**', '__']
12
+ end
13
+
14
+ def replace_by(string)
15
+ string.bold
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ require_relative "./abstract_tag"
2
+ require_relative "../string"
3
+
4
+ module Markdown
5
+ class Code
6
+ include AbstractTag
7
+
8
+ protected
9
+
10
+ def tokens
11
+ ['`']
12
+ end
13
+
14
+ def replace_by(string)
15
+ string.cyan
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ require_relative "./bold_tag"
2
+ require_relative "./code_tag"
3
+ require_relative "./italic_tag"
4
+
5
+ module Markdown
6
+ class Engine
7
+ def initialize(string)
8
+ @string = string
9
+ end
10
+
11
+ def to_ansi
12
+ # The tags are ordered by priority.
13
+ # E.g. `Bold` should run before `Italic`.
14
+ tag = Code.new(
15
+ Italic.new(
16
+ Bold.new(@string)
17
+ )
18
+ )
19
+ tag.to_ansi
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ require_relative "./abstract_tag"
2
+ require_relative "../string"
3
+
4
+ module Markdown
5
+ class Italic
6
+ include AbstractTag
7
+
8
+ protected
9
+
10
+ def tokens
11
+ ['*', '_']
12
+ end
13
+
14
+ def replace_by(string)
15
+ string.italic
16
+ end
17
+ end
18
+ end
data/src/run.rb CHANGED
@@ -9,8 +9,8 @@ require "securerandom"
9
9
 
10
10
  ##########################################################################################
11
11
 
12
- require_relative "#{__dir__}/run/markdown"
13
12
  require_relative "#{__dir__}/run/string"
13
+ require_relative "#{__dir__}/run/markdown/engine"
14
14
 
15
15
  ##########################################################################################
16
16
 
@@ -44,7 +44,7 @@ def task(name, help = "", &block)
44
44
  @tasks.store(
45
45
  name,
46
46
  {
47
- :help => Markdown.new(help).to_ansi,
47
+ :help => Markdown::Engine.new(help).to_ansi,
48
48
  :block => block
49
49
  }
50
50
  )
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: run_tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aurélien Delogu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-20 00:00:00.000000000 Z
11
+ date: 2023-02-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: aurelien.delogu@gmail.com
@@ -19,7 +19,11 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - bin/run
21
21
  - src/run.rb
22
- - src/run/markdown.rb
22
+ - src/run/markdown/abstract_tag.rb
23
+ - src/run/markdown/bold_tag.rb
24
+ - src/run/markdown/code_tag.rb
25
+ - src/run/markdown/engine.rb
26
+ - src/run/markdown/italic_tag.rb
23
27
  - src/run/string.rb
24
28
  homepage: https://github.com/pyrsmk/run
25
29
  licenses:
data/src/run/markdown.rb DELETED
@@ -1,35 +0,0 @@
1
- require_relative "./string"
2
-
3
- class Markdown
4
- def initialize(string)
5
- @string = string
6
- end
7
-
8
- def to_ansi
9
- # Apply private methods onto string.
10
- private_methods(false).reject{ |name| name == :initialize }
11
- .reduce(@string) do |string, method|
12
- send(method, string)
13
- end
14
- end
15
-
16
- private
17
-
18
- def bold(string)
19
- string.gsub(/([^*_]|^)[*_]{2}([^*_]+)[*_]{2}([^*_]|$)/) do
20
- Regexp.last_match[1] + Regexp.last_match[2].bold + Regexp.last_match[3]
21
- end
22
- end
23
-
24
- def code(string)
25
- string.gsub(/([^`]|^)`([^*_]+)`([^`]|$)/) do
26
- Regexp.last_match[1] + Regexp.last_match[2].cyan + Regexp.last_match[3]
27
- end
28
- end
29
-
30
- def italic(string)
31
- string.gsub(/([^*_]|^)[*_]{1}([^*_]+)[*_]{1}([^*_]|$)/) do
32
- Regexp.last_match[1] + Regexp.last_match[2].italic + Regexp.last_match[3]
33
- end
34
- end
35
- end