mdhost 0.3 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dbad6d4cf0eee94afaf0fb0d3b4b4de4daaefce726b93d6286f7d53b078c4d23
4
- data.tar.gz: 2b2c6e7f473c8dc01e786ef247d44ab49b73e9bfc0d17d6ad420c5e5735ad8b9
3
+ metadata.gz: 62280fb528dd0907b39a1031ff4f42d63d18502897c22df0a95702d9a09760df
4
+ data.tar.gz: 53793a87bdca36b8aec9680b5bf4365072d3d291641de33452881cd37ab513ac
5
5
  SHA512:
6
- metadata.gz: d8db2ff43540427438950d1b1b3a1977b1774f86e44a9bad1cd1336d742dd44dd7c02de0d560a267e06e436ff9e5b02aaa4764467c9b71634d740f4b71cc15ec
7
- data.tar.gz: 2a98c530ee577254a2e9c59f67e64e898fbbd258e3478a4519c19584ba2d77eb98e828c3037769063bee90a8a07b204bfdb0b85eb5771628ae0d21fca3e28c27
6
+ metadata.gz: d047182f45d558bf47f6c91ae9214ebf3a9780390889fc6feefa4bc03afbeb9aec286154c6cdde1297de282fe1c20574498470bd1cefcf0360809e0e3fca0d0d
7
+ data.tar.gz: 38a81dc6b74c659ba06eb11a9d512dee04e7d8b9327b6d913505031cb985af207f0a34eb176f972c79188aba05b83602d7253dedfa8b87591854a8b9f75ff331
data/.rubocop.yml CHANGED
@@ -1,3 +1,6 @@
1
+ require:
2
+ - rubocop-rspec
3
+
1
4
  AllCops:
2
5
  NewCops: enable
3
6
  TargetRubyVersion: 3.2
data/README.md CHANGED
@@ -3,3 +3,88 @@
3
3
  Runs `eshost`, displays the table output in the terminal, and generates a
4
4
  Markdown table of a few of the results (JavaScriptCore, SpiderMonkey, and V8),
5
5
  copying it to your clipboard.
6
+
7
+ ## Installation
8
+
9
+ Install via [RubyGems](https://rubygems.org/gems/mdhost):
10
+
11
+ ```sh
12
+ gem install mdhost
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### Single input
18
+
19
+ Given a single input, `mdhost` will output the table from `eshost -t` to your
20
+ terminal, and will copy to your clipboard a markdown code block containing the
21
+ relevant `eshost` command, followed by a markdown table of the results. For
22
+ example, running this:
23
+
24
+ ```sh
25
+ mdhost 'Date.parse("0")'
26
+ ```
27
+
28
+ Will output the following markdown to your clipboard:
29
+
30
+ ```
31
+ > eshost -te 'Date.parse("0")'
32
+ ```
33
+ |Engine |Result |
34
+ |--------------|---------------|
35
+ |JavaScriptCore|-62167219200000|
36
+ |SpiderMonkey |NaN |
37
+ |V8 |946710000000 |
38
+
39
+ ### Multiple inputs
40
+
41
+ You can have multiple unrelated inputs at once, and a more complex table will
42
+ be generated. For example, running this:
43
+
44
+ ```sh
45
+ mdhost '"hello"' "42"
46
+ ```
47
+
48
+ Will output the following markdown to your clipboard:
49
+
50
+ |Input|JavaScriptCore|SpiderMonkey|V8
51
+ |---|---|---|---
52
+ |`"hello"`|hello|hello|hello
53
+ |`42`|42|42|42
54
+
55
+ ### Format inputs
56
+
57
+ If you have multiple similar inputs, for example arguments to a function, you
58
+ can format them into a string passed into the `--format` or `-f` parameter. The
59
+ substring `#{}` in the format string will be replaced by each of the multiple
60
+ arguments that follow and arranged into a table. For example, running this:
61
+
62
+ ```sh
63
+ mdhost -f 'Date.parse("#{}")' "1970-01-01" "Thu 1970-01-01" "Thu Jan.01.1970"
64
+ ```
65
+
66
+ Will output the following markdown to your clipboard:
67
+
68
+ |Input|JavaScriptCore|SpiderMonkey|V8
69
+ |---|---|---|---
70
+ |`Date.parse("1970-01-01")`|0|0|0
71
+ |`Date.parse("Thu 1970-01-01")`|NaN|25200000|25200000
72
+ |`Date.parse("Thu Jan.01.1970")`|NaN|25200000|25200000
73
+
74
+ You can also use the `--table-format` or `-t` parameter to specify a different
75
+ format string for the "Input" column of the table. For example, if you wanted
76
+ the inputs to the function in the previous example to simply be displayed
77
+ surrounded by quotation marks, you could run:
78
+
79
+ ```sh
80
+ mdhost -f 'Date.parse("#{}")' -t '"#{}"' "1970-01-01" "Thu 1970-01-01" "Thu Jan.01.1970"
81
+ Date.parse("1970-01-01")
82
+ ```
83
+
84
+ And the following markdown would be output to your clipboard:
85
+
86
+ |Input|JavaScriptCore|SpiderMonkey|V8
87
+ |---|---|---|---
88
+ |`"1970-01-01"`|0|0|0
89
+ |`"Thu 1970-01-01"`|NaN|25200000|25200000
90
+ |`"Thu Jan.01.1970"`|NaN|25200000|25200000
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3
1
+ 0.4.1
data/lib/mdhost.rb CHANGED
@@ -27,6 +27,8 @@ module MDHost
27
27
  opt :format, "Format string to compose multiple inputs into", type: :string
28
28
  opt :table_format, 'Format string to use for the table "Input" column', type: :string
29
29
 
30
+ opt :browser_names, "Use browser names in output table"
31
+
30
32
  educate_on_error
31
33
  end
32
34
 
@@ -64,11 +66,11 @@ module MDHost
64
66
  end
65
67
 
66
68
  def display_table(input)
67
- system("eshost", "-h", "JavaScriptCore,SpiderMonkey,V8", "-te", input)
69
+ system("eshost", "-g", "jsc,jsshell,d8", "-te", input)
68
70
  end
69
71
 
70
72
  def results_for(escaped_input)
71
- result = `eshost -e #{escaped_input}`.split(/\n+/)
73
+ result = `eshost -g jsc,jsshell,d8 -e #{escaped_input}`.split(/\n+/)
72
74
 
73
75
  # We can't just #each_slice by 2, because sometimes an engine acts up and
74
76
  # produces no output, which would mess up the grouping. So, we need to
@@ -76,8 +78,12 @@ module MDHost
76
78
  # line as the result.
77
79
  table = {}
78
80
  result.each_with_index do |line, i|
79
- if %w[JavaScriptCore SpiderMonkey V8].any? { |e| line.end_with? e }
80
- table[line.match(/\w+/).to_s.to_sym] = result[i + 1]
81
+ engine_name = %w[JavaScriptCore SpiderMonkey V8].find do |engine|
82
+ line.downcase.end_with?(engine.downcase)
83
+ end
84
+
85
+ if engine_name
86
+ table[engine_name.to_sym] = result[i + 1]
81
87
  end
82
88
  end
83
89
 
@@ -117,10 +123,10 @@ module MDHost
117
123
  end
118
124
 
119
125
  def run_format
120
- output = +<<~TABLE
121
- |Input|JavaScriptCore|SpiderMonkey|V8
122
- |-----|--------------|------------|--
123
- TABLE
126
+ output = +"|Input|"
127
+ output += @options.browser_names ? "Safari|Firefox|Chrome"
128
+ : "JavaScriptCore|SpiderMonkey|V8"
129
+ output += "\n|---|---|---|---\n"
124
130
 
125
131
  ARGV.each do |input|
126
132
  formatted_input = format(@format_string, input)
data/mdhost.gemspec CHANGED
@@ -22,5 +22,8 @@ Gem::Specification.new do |gem|
22
22
  gem.add_dependency "clipboard", "~> 1.1"
23
23
  gem.add_dependency "optimist", "~> 3.1"
24
24
 
25
+ gem.add_development_dependency "fuubar", "~> 2.0"
26
+ gem.add_development_dependency "rspec", "~> 3.12"
25
27
  gem.add_development_dependency "rubocop", "~> 1.54"
28
+ gem.add_development_dependency "rubocop-rspec", "~> 2.22"
26
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mdhost
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vinny Diehl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-25 00:00:00.000000000 Z
11
+ date: 2023-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clipboard
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: fuubar
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.12'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: rubocop
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +80,20 @@ dependencies:
52
80
  - - "~>"
53
81
  - !ruby/object:Gem::Version
54
82
  version: '1.54'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.22'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.22'
55
97
  description: Runs eshost in table mode, copying a Markdown version of the table to
56
98
  your clipboard.
57
99
  email: vinny.diehl@gmail.com
@@ -90,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
132
  - !ruby/object:Gem::Version
91
133
  version: '0'
92
134
  requirements: []
93
- rubygems_version: 3.4.20
135
+ rubygems_version: 3.4.22
94
136
  signing_key:
95
137
  specification_version: 4
96
138
  summary: Generate Markdown eshost tables