nvim_conf 0.1.0 → 0.1.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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +63 -7
  3. data/lib/nvim_conf/commenter.rb +23 -0
  4. data/lib/nvim_conf/configuration_builder.rb +2 -2
  5. data/lib/nvim_conf/core.rb +37 -18
  6. data/lib/nvim_conf/generators/code/commands/lua.rb +37 -0
  7. data/lib/nvim_conf/generators/code/globals/lua.rb +47 -0
  8. data/lib/nvim_conf/generators/code/mappings/lua.rb +43 -11
  9. data/lib/nvim_conf/generators/code/plugins/packer.rb +4 -16
  10. data/lib/nvim_conf/generators/code/plugins/paq.rb +57 -0
  11. data/lib/nvim_conf/generators/code/requires/lua.rb +23 -0
  12. data/lib/nvim_conf/generators/code/settings/lua.rb +34 -12
  13. data/lib/nvim_conf/managers/commands.rb +38 -0
  14. data/lib/nvim_conf/{compiler_configurations/manager.rb → managers/compiler_configurations.rb} +4 -4
  15. data/lib/nvim_conf/managers/globals.rb +46 -0
  16. data/lib/nvim_conf/{mappings/manager.rb → managers/mappings.rb} +23 -8
  17. data/lib/nvim_conf/{plugins/manager.rb → managers/plugins.rb} +13 -6
  18. data/lib/nvim_conf/managers/requires.rb +34 -0
  19. data/lib/nvim_conf/{settings/manager.rb → managers/settings.rb} +22 -6
  20. data/lib/nvim_conf/models/command.rb +15 -0
  21. data/lib/nvim_conf/{compiler_configurations → models}/compiler_configuration.rb +1 -1
  22. data/lib/nvim_conf/models/global.rb +12 -0
  23. data/lib/nvim_conf/{mappings → models}/mapping.rb +2 -1
  24. data/lib/nvim_conf/{plugins → models}/plugin.rb +6 -1
  25. data/lib/nvim_conf/models/require.rb +11 -0
  26. data/lib/nvim_conf/{settings → models}/setting.rb +1 -1
  27. data/lib/nvim_conf/utils/io_operator.rb +21 -0
  28. data/lib/nvim_conf/utils/markdown_formatter.rb +35 -0
  29. data/lib/nvim_conf/version.rb +1 -1
  30. data/lib/nvim_conf/writer.rb +1 -1
  31. data/lib/nvim_conf/writers/code/commands.rb +36 -0
  32. data/lib/nvim_conf/writers/code/globals.rb +36 -0
  33. data/lib/nvim_conf/writers/code/mappings.rb +0 -1
  34. data/lib/nvim_conf/writers/code/orchestrator.rb +31 -6
  35. data/lib/nvim_conf/writers/code/plugins/configuration.rb +25 -0
  36. data/lib/nvim_conf/writers/code/plugins/handler.rb +25 -0
  37. data/lib/nvim_conf/writers/code/plugins/packer.rb +94 -0
  38. data/lib/nvim_conf/writers/code/plugins/paq.rb +49 -0
  39. data/lib/nvim_conf/writers/code/requires.rb +36 -0
  40. data/lib/nvim_conf/writers/documentation/globals.rb +45 -0
  41. data/lib/nvim_conf/writers/documentation/mappings.rb +5 -18
  42. data/lib/nvim_conf/writers/documentation/orchestrator.rb +26 -7
  43. data/lib/nvim_conf/writers/documentation/plugins.rb +54 -0
  44. data/lib/nvim_conf/writers/documentation/settings.rb +11 -18
  45. data/lib/nvim_conf.rb +11 -6
  46. metadata +32 -13
  47. data/lib/nvim_conf/generators/generator.rb +0 -6
  48. data/lib/nvim_conf/manager.rb +0 -6
  49. data/lib/nvim_conf/writers/code/plugins.rb +0 -86
@@ -0,0 +1,46 @@
1
+ require "nvim_conf/models/global"
2
+
3
+ module NvimConf
4
+ module Managers
5
+ class Globals
6
+ attr_reader :globals
7
+
8
+ def initialize
9
+ @globals = []
10
+ end
11
+
12
+ def set(name, value = true)
13
+ store_global(
14
+ name,
15
+ value
16
+ )
17
+ end
18
+
19
+ class << self
20
+ def section_name
21
+ "Globals"
22
+ end
23
+ end
24
+
25
+ def store?
26
+ @globals.any?
27
+ end
28
+
29
+ def unset(name)
30
+ store_global(
31
+ name,
32
+ false
33
+ )
34
+ end
35
+
36
+ private
37
+
38
+ def store_global(name, value)
39
+ @globals << Models::Global.new(
40
+ name,
41
+ value
42
+ )
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,9 +1,10 @@
1
- require "nvim_conf/mappings/mapping"
1
+ require "nvim_conf/models/mapping"
2
+
2
3
  # TODO: Refactor error messages
3
4
  module NvimConf
4
- module Mappings
5
- class Manager < NvimConf::Manager
6
- AVAILABLE_METHODS = %w[map map! nmap vmap imap cmap smap xmap omap lmap]
5
+ module Managers
6
+ class Mappings
7
+ AVAILABLE_METHODS = %w[map map! nmap vmap imap cmap smap xmap omap lmap tmap]
7
8
  attr_reader :mappings
8
9
 
9
10
  def initialize(namespace)
@@ -13,6 +14,12 @@ module NvimConf
13
14
  validate!
14
15
  end
15
16
 
17
+ class << self
18
+ def section_name
19
+ "Mappings"
20
+ end
21
+ end
22
+
16
23
  def validate!
17
24
  return if @namespace.nil? || @namespace.empty?
18
25
 
@@ -31,6 +38,14 @@ module NvimConf
31
38
  end
32
39
  end
33
40
 
41
+ AVAILABLE_METHODS.each do |operator|
42
+ define_method("r#{operator}") do |binding|
43
+ store_mapping(
44
+ operator, binding, nil, remove: true
45
+ )
46
+ end
47
+ end
48
+
34
49
  def new(binding, action)
35
50
  raise "No namespace was given for <mappings>" unless @namespace
36
51
  raise "No namespace was given for <mappings>" if @namespace.empty?
@@ -44,14 +59,14 @@ module NvimConf
44
59
 
45
60
  private
46
61
 
47
- def store_mapping(operator, binding, action)
62
+ def store_mapping(operator, binding, action, **params)
48
63
  @mappings << build_mapping(
49
- operator, binding, action
64
+ operator, binding, action, params
50
65
  )
51
66
  end
52
67
 
53
- def build_mapping(operator, binding, action)
54
- Mapping.new(operator, binding, action)
68
+ def build_mapping(operator, binding, action, params)
69
+ Models::Mapping.new(operator, binding, action, **params)
55
70
  end
56
71
  end
57
72
  end
@@ -1,16 +1,23 @@
1
- require "nvim_conf/plugins/plugin"
1
+ require "nvim_conf/models/plugin"
2
2
 
3
3
  module NvimConf
4
- module Plugins
5
- class Manager < NvimConf::Manager
6
- attr_reader :plugins, :name, :bootstraped
4
+ module Managers
5
+ class Plugins
6
+ attr_reader :plugins, :name, :title, :bootstraped
7
7
 
8
- def initialize(name, bootstraped: false)
8
+ def initialize(name, title, bootstraped: false)
9
9
  @name = name
10
+ @title = title
10
11
  @bootstraped = bootstraped
11
12
  @plugins = []
12
13
  end
13
14
 
15
+ class << self
16
+ def section_name
17
+ "Plugins"
18
+ end
19
+ end
20
+
14
21
  def store?
15
22
  @plugins.any?
16
23
  end
@@ -31,7 +38,7 @@ module NvimConf
31
38
  end
32
39
 
33
40
  def build_plugin(name, params)
34
- Plugin.new(
41
+ Models::Plugin.new(
35
42
  name,
36
43
  **params
37
44
  )
@@ -0,0 +1,34 @@
1
+ require "nvim_conf/models/require"
2
+
3
+ # TODO: Refactor error messages
4
+ module NvimConf
5
+ module Managers
6
+ class Requires
7
+ attr_reader :requires
8
+
9
+ def initialize
10
+ @requires = []
11
+ end
12
+
13
+ class << self
14
+ def section_name
15
+ "Requires"
16
+ end
17
+ end
18
+
19
+ def setup(file)
20
+ store_require(file)
21
+ end
22
+
23
+ private
24
+
25
+ def store?
26
+ @requires.any?
27
+ end
28
+
29
+ def store_require(file)
30
+ @requires << Models::Require.new(file)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,11 +1,12 @@
1
- require "nvim_conf/settings/setting"
1
+ require "nvim_conf/models/setting"
2
2
 
3
3
  module NvimConf
4
- module Settings
5
- class Manager < NvimConf::Manager
6
- attr_reader :settings
4
+ module Managers
5
+ class Settings
6
+ attr_reader :settings, :title
7
7
 
8
- def initialize
8
+ def initialize(title)
9
+ @title = title
9
10
  @settings = []
10
11
  end
11
12
 
@@ -13,6 +14,12 @@ module NvimConf
13
14
  @settings.any?
14
15
  end
15
16
 
17
+ class << self
18
+ def section_name
19
+ "Settings"
20
+ end
21
+ end
22
+
16
23
  def set(key, value = nil, **params)
17
24
  store_setting(
18
25
  :set,
@@ -29,6 +36,15 @@ module NvimConf
29
36
  )
30
37
  end
31
38
 
39
+ def add(key, value, **params)
40
+ store_setting(
41
+ :add,
42
+ key: key,
43
+ value: value,
44
+ **params
45
+ )
46
+ end
47
+
32
48
  private
33
49
 
34
50
  def store_setting(operation, key:, value: nil, scope: :global)
@@ -36,7 +52,7 @@ module NvimConf
36
52
  end
37
53
 
38
54
  def build_setting(operation, key, value, scope)
39
- Setting.new(operation, key, value, scope)
55
+ Models::Setting.new(operation, key, value, scope)
40
56
  end
41
57
  end
42
58
  end
@@ -0,0 +1,15 @@
1
+ require "dry-initializer"
2
+
3
+ module NvimConf
4
+ module Models
5
+ class Command
6
+ extend Dry::Initializer
7
+
8
+ param :name
9
+ param :description
10
+ param :body
11
+
12
+ option :vim_exec, default: -> { false }
13
+ end
14
+ end
15
+ end
@@ -1,7 +1,7 @@
1
1
  require "dry-initializer"
2
2
 
3
3
  module NvimConf
4
- module CompilerConfigurations
4
+ module Models
5
5
  class CompilerConfiguration
6
6
  extend Dry::Initializer
7
7
 
@@ -0,0 +1,12 @@
1
+ require "dry-initializer"
2
+
3
+ module NvimConf
4
+ module Models
5
+ class Global
6
+ extend Dry::Initializer
7
+
8
+ param :name
9
+ param :value, default: -> { true }
10
+ end
11
+ end
12
+ end
@@ -1,13 +1,14 @@
1
1
  require "dry-initializer"
2
2
 
3
3
  module NvimConf
4
- module Mappings
4
+ module Models
5
5
  class Mapping
6
6
  extend Dry::Initializer
7
7
 
8
8
  param :operator
9
9
  param :binding
10
10
  param :action
11
+ option :remove, default: -> { false }
11
12
  end
12
13
  end
13
14
  end
@@ -1,7 +1,7 @@
1
1
  require "dry-initializer"
2
2
 
3
3
  module NvimConf
4
- module Plugins
4
+ module Models
5
5
  class Plugin
6
6
  extend Dry::Initializer
7
7
 
@@ -14,6 +14,11 @@ module NvimConf
14
14
  option :file_types, optional: true
15
15
  option :cmd, optional: true
16
16
  option :run, optional: true
17
+ option :requires, optional: true
18
+
19
+ def self.optional_arguments
20
+ %i[as opt file_types branch run cmd requires]
21
+ end
17
22
  end
18
23
  end
19
24
  end
@@ -0,0 +1,11 @@
1
+ require "dry-initializer"
2
+
3
+ module NvimConf
4
+ module Models
5
+ class Require
6
+ extend Dry::Initializer
7
+
8
+ param :file
9
+ end
10
+ end
11
+ end
@@ -1,7 +1,7 @@
1
1
  require "dry-initializer"
2
2
 
3
3
  module NvimConf
4
- module Settings
4
+ module Models
5
5
  class Setting
6
6
  extend Dry::Initializer
7
7
 
@@ -0,0 +1,21 @@
1
+ require "forwardable"
2
+
3
+ module NvimConf
4
+ module Utils
5
+ class IoOperator
6
+ extend Forwardable
7
+
8
+ def_delegators :@io, :write
9
+
10
+ def initialize(io)
11
+ @io = io
12
+ end
13
+
14
+ def write_separator
15
+ @io.write(
16
+ Utils::MarkdownFormatter.separator
17
+ )
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,35 @@
1
+ module NvimConf
2
+ module Utils
3
+ class MarkdownFormatter
4
+ class << self
5
+ def collapisible(summary, content)
6
+ <<~FORMAT
7
+ <details>
8
+ <summary>
9
+ #{summary}
10
+ </summary>
11
+
12
+ #{content}
13
+ </details>
14
+ FORMAT
15
+ end
16
+
17
+ def separator(count: 2)
18
+ "\n" * count
19
+ end
20
+
21
+ def format_title(title, level: 0, indent: 0)
22
+ prefix = [
23
+ indent.positive? ? " " * indent : nil,
24
+ level != 0 ? "#" * level : nil
25
+ ].compact.join
26
+
27
+ [
28
+ prefix,
29
+ "#{title}\n\n"
30
+ ].compact.join(" ")
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NvimConf
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
@@ -27,7 +27,7 @@ module NvimConf
27
27
  File.open(documentation_file_path, "w+") do |file|
28
28
  NvimConf::Writers::Documentation::Orchestrator.new(
29
29
  @managers,
30
- file,
30
+ Utils::IoOperator.new(file),
31
31
  @configuration
32
32
  ).aggregate_writes
33
33
  end
@@ -0,0 +1,36 @@
1
+ require "nvim_conf/generators/code/commands/lua"
2
+
3
+ module NvimConf
4
+ module Writers
5
+ module Code
6
+ class CommandsWriter
7
+ COMMANDS_GENERATOR_MAPPING = {
8
+ lua: Generators::Commands::Code::Lua
9
+ }
10
+
11
+ def initialize(manager, io, format: :lua, commented: false)
12
+ @manager = manager
13
+ @io = io
14
+ @format = format
15
+ end
16
+
17
+ def write
18
+ @manager.commands.each do |command|
19
+ @io.write(
20
+ [
21
+ generator_class.new(command).generate,
22
+ "\n"
23
+ ].join
24
+ )
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def generator_class
31
+ COMMANDS_GENERATOR_MAPPING[@format]
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ require "nvim_conf/generators/code/globals/lua"
2
+
3
+ module NvimConf
4
+ module Writers
5
+ module Code
6
+ class GlobalsWriter
7
+ GLOBAL_GENERATOR_MAPPING = {
8
+ lua: Generators::Globals::Code::Lua
9
+ }
10
+
11
+ def initialize(manager, io, format: :lua, commented: false)
12
+ @manager = manager
13
+ @io = io
14
+ @format = format
15
+ end
16
+
17
+ def write
18
+ @manager.globals.each do |global|
19
+ @io.write(
20
+ [
21
+ generator_class.new(global).generate,
22
+ "\n"
23
+ ].join
24
+ )
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def generator_class
31
+ GLOBAL_GENERATOR_MAPPING[@format]
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -14,7 +14,6 @@ module NvimConf
14
14
  @manager = manager
15
15
  @io = io
16
16
  @format = format
17
- @commented = commented
18
17
  end
19
18
 
20
19
  def write
@@ -1,17 +1,23 @@
1
1
  require "nvim_conf/writers/code/settings"
2
+ require "nvim_conf/writers/code/requires"
3
+ require "nvim_conf/writers/code/globals"
4
+ require "nvim_conf/writers/code/commands"
2
5
  require "nvim_conf/writers/code/mappings"
3
- require "nvim_conf/writers/code/plugins"
6
+ require "nvim_conf/writers/code/plugins/handler"
4
7
 
5
8
  module NvimConf
6
9
  module Writers
7
10
  module Code
8
11
  class Orchestrator
9
- NON_WRITABLE_MANAGER = NvimConf::CompilerConfigurations::Manager
12
+ NON_WRITABLE_MANAGER = NvimConf::Managers::CompilerConfigurations
10
13
 
11
14
  WRITER_CONFIGURATION = {
12
- NvimConf::Settings::Manager => SettingsWriter,
13
- NvimConf::Mappings::Manager => MappingsWriter,
14
- NvimConf::Plugins::Manager => PluginsWriter
15
+ NvimConf::Managers::Settings => SettingsWriter,
16
+ NvimConf::Managers::Mappings => MappingsWriter,
17
+ NvimConf::Managers::Plugins => Code::Plugins::Handler,
18
+ NvimConf::Managers::Globals => GlobalsWriter,
19
+ NvimConf::Managers::Requires => RequiresWriter,
20
+ NvimConf::Managers::Commands => CommandsWriter
15
21
  }
16
22
 
17
23
  def initialize(managers, io, configuration = nil)
@@ -22,17 +28,36 @@ module NvimConf
22
28
 
23
29
  def aggregate_writes
24
30
  @managers.select { |manager| manager.class != NON_WRITABLE_MANAGER }.each_with_index do |manager, index|
25
- if index.positive?
31
+ @io.write(
32
+ NvimConf::Commenter.comment_block(
33
+ @configuration,
34
+ manager_section_name(manager),
35
+ spacer: index.positive?
36
+ )
37
+ )
38
+
39
+ if index.positive? || @configuration[:commented]
26
40
  @io.write(
27
41
  separator
28
42
  )
29
43
  end
44
+
30
45
  aggregate_writes_for_manager(manager)
31
46
  end
32
47
  end
33
48
 
34
49
  private
35
50
 
51
+ def manager_section_name(manager)
52
+ return manager.class.section_name unless manager.respond_to?(:title)
53
+ return manager.class.section_name if manager.title.nil?
54
+
55
+ [
56
+ manager.class.section_name,
57
+ manager.title
58
+ ].join(" - ")
59
+ end
60
+
36
61
  def separator
37
62
  "\n\n"
38
63
  end
@@ -0,0 +1,25 @@
1
+ require_relative "./packer"
2
+ require_relative "./paq"
3
+
4
+ module NvimConf
5
+ module Writers
6
+ module Code
7
+ module Plugins
8
+ class Configuration
9
+ PLUGIN_CONFIGURATION = {
10
+ packer: {
11
+ generator: NvimConf::Generators::Plugins::Code::Packer,
12
+ writer: NvimConf::Writers::Code::Plugins::Packer,
13
+ indent: 2
14
+ },
15
+ paq: {
16
+ generator: NvimConf::Generators::Plugins::Code::Paq,
17
+ writer: NvimConf::Writers::Code::Plugins::Paq,
18
+ indent: 2
19
+ }
20
+ }
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require_relative "./configuration"
2
+
3
+ module NvimConf
4
+ module Writers
5
+ module Code
6
+ module Plugins
7
+ class Handler
8
+ def initialize(manager, io, _params)
9
+ @manager = manager
10
+ @io = io
11
+ @configuration = Configuration::PLUGIN_CONFIGURATION[manager.name.to_sym]
12
+ end
13
+
14
+ def write
15
+ @configuration[:writer].new(
16
+ @manager,
17
+ @io,
18
+ @configuration
19
+ ).write
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end