tmux-erb-parser 0.2.0 → 0.3.0

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: b21b6279300cff2863e40a40358e778886c3edcf47a7de559847aa48d7007fae
4
- data.tar.gz: 354e717ab451bb2ea70bfbf121fdb12048c2250e6db18c4c2eb1d42561579315
3
+ metadata.gz: fa36f112f4bf7d15b5cbf20d8d19343cab7299dfdac7b2ed81918731ef97ef57
4
+ data.tar.gz: 45543c76a828931350e9e1bf86cef902576201748b50eae34bf6150542a04a8a
5
5
  SHA512:
6
- metadata.gz: 69945ff6ac0d8a61860ea885b93c9a6edb86a5bb09e312678c94936502d19e708663cc57d93a6542ffa44e974bddddb1d14b039164888f0cfa39f581ebe6f06f
7
- data.tar.gz: 5ac5c80541ef86f2c87c2cdc5de3b478bcdbe96b77509eb547ec2af83cebeb9fe4553f7ef4f1a248a78f0f6c9f601120f1328763f6a36c5f1530318ec38b8e49
6
+ metadata.gz: '083f5f3dc8d93410fcf156dbe34ce415f6108ea2d1641763b7ca0893262fc843a3235bcea87f54c0f0786ff8dfffcaa645071c81e8b04799fbbac2ea3f68b41a'
7
+ data.tar.gz: 77eeefd48f4a0f795e02b6d866c3008dc9c1236fa520b93f3ed377b1045a88789d172ccade6bf3f2134ccba25d397b53bf18073b6eb7fedd03943cb94a104089
data/README.md CHANGED
@@ -13,7 +13,7 @@ A Tmux plugin for loading tmux.conf written in Ruby (eRuby) notation.
13
13
  * You can use whatever you like as the default shell.
14
14
  * git
15
15
  * ruby:
16
- * 2.5 or higher is required.
16
+ * 2.7 or higher is required.
17
17
  * tmux
18
18
 
19
19
  ## How to use
@@ -27,9 +27,7 @@ module TmuxERBParser
27
27
 
28
28
  def check_args
29
29
  msg = 'INPUT_ERB_FILES are required.' if @args.empty?
30
- unless @options[:inline] ^ @options[:output]
31
- msg = 'Please specify either --inline or --output option.'
32
- end
30
+ msg = 'Please specify either --inline or --output option.' unless @options[:inline] ^ @options[:output]
33
31
 
34
32
  raise ArgumentError, msg if msg
35
33
  end
@@ -37,17 +35,13 @@ module TmuxERBParser
37
35
  def command_opts(opts) # rubocop:disable Metrics/MethodLength
38
36
  opts.banner = "Usage: #{@command_name} INPUT_FILES [options]"
39
37
 
40
- opts.on('-i',
41
- '--inline',
42
- 'Exec tmux subcommands to the current tmux-server.') do
38
+ opts.on('-i', '--inline', 'Exec tmux subcommands to the current tmux-server.') do
43
39
  @options[:inline] = true
44
40
  end
45
41
 
46
- opts.on('-o',
47
- '--output [OUTPUT_FILE_NAME]',
48
- String,
49
- 'Output the configuration to a file with the specified name.'\
50
- ' If the file name is omitted, output to stdout') do |fname|
42
+ opts.on('-o', '--output [OUTPUT_FILE_NAME]', String, <<~DESC) do |fname|
43
+ Output the configuration to a file with the specified name. If the file name is omitted, output to stdout
44
+ DESC
51
45
  @options[:output] = File.open(fname, 'w') if fname
52
46
  @options[:output] ||= $stdout
53
47
  end
@@ -89,8 +83,8 @@ module TmuxERBParser
89
83
  @args.each do |arg|
90
84
  @logger.info "open #{arg}."
91
85
  File.open(arg, 'r') do |input|
92
- p = Parser.new(input, File.extname(arg.downcase)[1..-1].to_sym)
93
- commands = p.parse(@options[:output].nil?)
86
+ p = Parser.new(input, File.extname(arg.downcase)[1..].to_sym)
87
+ commands = p.parse(strip_comments: @options[:output].nil?)
94
88
  exec(commands, @options[:output])
95
89
  end
96
90
  end
@@ -6,18 +6,20 @@ module TmuxERBParser
6
6
  def convert(structured)
7
7
  structured = [structured] if structured.is_a?(Hash)
8
8
 
9
- structured.inject([]) do |result, hash|
10
- result << '' unless result.empty?
11
-
12
- comment = hash.is_a?(Hash) && hash.delete('comment')
13
- result << "# #{comment}" if comment
14
-
15
- result.concat([*convert_structured(hash)])
16
- end
9
+ structured.inject([], &method(:convert_line))
17
10
  end
18
11
 
19
12
  private
20
13
 
14
+ def convert_line(result, line)
15
+ result << '' unless result.empty?
16
+
17
+ comment = line.is_a?(Hash) && line.delete('comment')
18
+ result << "# #{comment}" if comment
19
+
20
+ result.push(*convert_structured(line))
21
+ end
22
+
21
23
  def convert_hash(hash, prefix = [])
22
24
  converted = hash.map do |key, value|
23
25
  case key
@@ -3,6 +3,8 @@
3
3
  module TmuxERBParser
4
4
  module Helpers
5
5
  module EnvironmentHelper
6
+ module_function
7
+
6
8
  def prefix_key
7
9
  `tmux show-option -g prefix`.split[1]
8
10
  end
@@ -3,6 +3,8 @@
3
3
  module TmuxERBParser
4
4
  module Helpers
5
5
  module FormatHelper
6
+ module_function
7
+
6
8
  def format_and(*args)
7
9
  return args.first if args.length < 2
8
10
 
@@ -1,32 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module TmuxERBParser
4
- module Classifyable
5
- refine String do
6
- def classify
7
- snake_case = File.basename(self, '.rb')
8
- splitted = snake_case.split('_').map do |w|
9
- w[0] = w[0].upcase
10
- w
11
- end
12
- splitted.join
13
- end
14
- end
15
- end
3
+ require_relative 'helpers/environment_helper'
4
+ require_relative 'helpers/format_helper'
16
5
 
6
+ module TmuxERBParser
17
7
  module Helpers
18
- using Classifyable
8
+ extend EnvironmentHelper
9
+ extend FormatHelper
19
10
 
20
- Dir[File.expand_path('helpers/*.rb', __dir__)].sort.each do |h|
21
- require h
22
- klass = const_get(h.classify)
23
- self.class.class_eval do
24
- prepend klass
25
- end
26
- end
11
+ module_function
27
12
 
28
- def self.binding
29
- super # NOTE: Kernel.#binding is private
13
+ def binding # rubocop:disable Lint/UselessMethodDefinition: super(= Kernel.#binding) is private
14
+ super
30
15
  end
31
16
  end
32
17
  end
@@ -22,7 +22,7 @@ module TmuxERBParser
22
22
  @type = type
23
23
  end
24
24
 
25
- def parse(strip_comments = false)
25
+ def parse(strip_comments: false)
26
26
  parse_string(@input, @type).map do |line|
27
27
  line = replace_source_file(line)
28
28
  line = strip_comment(line) if strip_comments
@@ -35,6 +35,10 @@ module TmuxERBParser
35
35
  def parse_string(input, type)
36
36
  erb_result = ERB.new(input).result(TmuxERBParser::Helpers.binding)
37
37
 
38
+ parse_structure(erb_result, type)
39
+ end
40
+
41
+ def parse_structure(erb_result, type)
38
42
  case type
39
43
  when :json
40
44
  Converter.convert(JSON.parse(erb_result))
@@ -45,17 +49,15 @@ module TmuxERBParser
45
49
  Converter.convert(YAML.safe_load(erb_result, aliases: true))
46
50
  end
47
51
  else
48
- # rubocop:disable Layout/LineLength
49
52
  erb_result
50
53
  .gsub(/(\R){3,}/) { Regexp.last_match(1) * 2 } # reduce continuity blankline
51
54
  .each_line(chomp: true)
52
- # rubocop:enable Layout/LineLength
53
55
  end
54
56
  end
55
57
 
56
58
  def replace_source_file(line)
57
59
  # source file -> run-shell "parser --inline file"
58
- if line =~ /source/ && line !~ /run(-shell)?/
60
+ if line.include?('source') && line !~ /run(-shell)?/
59
61
  line = line.gsub(/"source(-file)?( -q)?\s([^\s\\;]+)"/) do
60
62
  %("run-shell \\"#{PARSER_CMD} --inline #{Regexp.last_match(3)}\\"")
61
63
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TmuxERBParser
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
@@ -1,3 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Dir[File.expand_path('tmux-erb-parser/*.rb', __dir__)].each(&method(:require))
3
+ require_relative 'tmux-erb-parser/command'
4
+ require_relative 'tmux-erb-parser/converter'
5
+ require_relative 'tmux-erb-parser/helpers'
6
+ require_relative 'tmux-erb-parser/logger'
7
+ require_relative 'tmux-erb-parser/parser'
8
+ require_relative 'tmux-erb-parser/version'
metadata CHANGED
@@ -1,127 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tmux-erb-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - epaew
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-05 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: pry
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rubocop
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: simplecov
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "<"
74
- - !ruby/object:Gem::Version
75
- version: '0.18'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "<"
81
- - !ruby/object:Gem::Version
82
- version: '0.18'
83
- - !ruby/object:Gem::Dependency
84
- name: simplecov-console
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: test-unit
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '3.2'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '3.2'
111
- - !ruby/object:Gem::Dependency
112
- name: test-unit-rr
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '1.0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '1.0'
11
+ date: 2023-04-29 00:00:00.000000000 Z
12
+ dependencies: []
125
13
  description: A Tmux plugin for loading tmux.conf written in Ruby (eRuby) notation.
126
14
  email:
127
15
  - epaew.333@gmail.com
@@ -148,6 +36,7 @@ licenses:
148
36
  - MIT
149
37
  metadata:
150
38
  allowed_push_host: https://rubygems.org
39
+ rubygems_mfa_required: 'true'
151
40
  post_install_message:
152
41
  rdoc_options: []
153
42
  require_paths:
@@ -156,7 +45,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
156
45
  requirements:
157
46
  - - ">="
158
47
  - !ruby/object:Gem::Version
159
- version: 2.5.0
48
+ version: 2.7.0
160
49
  required_rubygems_version: !ruby/object:Gem::Requirement
161
50
  requirements:
162
51
  - - ">="
@@ -165,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
54
  requirements:
166
55
  - bash
167
56
  - tmux
168
- rubygems_version: 3.1.2
57
+ rubygems_version: 3.1.6
169
58
  signing_key:
170
59
  specification_version: 4
171
60
  summary: A Tmux plugin for loading tmux.conf written in Ruby (eRuby) notation.