fmt 0.1.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +167 -93
  3. data/lib/fmt/boot.rb +50 -0
  4. data/lib/fmt/lru_cache.rb +181 -0
  5. data/lib/fmt/mixins/matchable.rb +26 -0
  6. data/lib/fmt/models/arguments.rb +194 -0
  7. data/lib/fmt/models/embed.rb +48 -0
  8. data/lib/fmt/models/macro.rb +58 -0
  9. data/lib/fmt/models/model.rb +66 -0
  10. data/lib/fmt/models/pipeline.rb +47 -0
  11. data/lib/fmt/models/template.rb +55 -0
  12. data/lib/fmt/node.rb +128 -0
  13. data/lib/fmt/parsers/arguments_parser.rb +43 -0
  14. data/lib/fmt/parsers/embed_parser.rb +54 -0
  15. data/lib/fmt/parsers/macro_parser.rb +113 -0
  16. data/lib/fmt/parsers/parser.rb +56 -0
  17. data/lib/fmt/parsers/pipeline_parser.rb +41 -0
  18. data/lib/fmt/parsers/template_parser.rb +125 -0
  19. data/lib/fmt/refinements/kernel_refinement.rb +38 -0
  20. data/lib/fmt/registries/native_registry.rb +66 -0
  21. data/lib/fmt/registries/rainbow_registry.rb +36 -0
  22. data/lib/fmt/registries/registry.rb +127 -0
  23. data/lib/fmt/renderer.rb +132 -0
  24. data/lib/fmt/sigils.rb +23 -0
  25. data/lib/fmt/token.rb +126 -0
  26. data/lib/fmt/tokenizer.rb +96 -0
  27. data/lib/fmt/version.rb +3 -1
  28. data/lib/fmt.rb +50 -12
  29. data/sig/generated/fmt/boot.rbs +2 -0
  30. data/sig/generated/fmt/lru_cache.rbs +122 -0
  31. data/sig/generated/fmt/mixins/matchable.rbs +18 -0
  32. data/sig/generated/fmt/models/arguments.rbs +115 -0
  33. data/sig/generated/fmt/models/embed.rbs +34 -0
  34. data/sig/generated/fmt/models/macro.rbs +37 -0
  35. data/sig/generated/fmt/models/model.rbs +45 -0
  36. data/sig/generated/fmt/models/pipeline.rbs +31 -0
  37. data/sig/generated/fmt/models/template.rbs +33 -0
  38. data/sig/generated/fmt/node.rbs +64 -0
  39. data/sig/generated/fmt/parsers/arguments_parser.rbs +25 -0
  40. data/sig/generated/fmt/parsers/embed_parser.rbs +36 -0
  41. data/sig/generated/fmt/parsers/macro_parser.rbs +60 -0
  42. data/sig/generated/fmt/parsers/parser.rbs +44 -0
  43. data/sig/generated/fmt/parsers/pipeline_parser.rbs +25 -0
  44. data/sig/generated/fmt/parsers/template_parser.rbs +50 -0
  45. data/sig/generated/fmt/refinements/kernel_refinement.rbs +23 -0
  46. data/sig/generated/fmt/registries/native_registry.rbs +19 -0
  47. data/sig/generated/fmt/registries/rainbow_registry.rbs +11 -0
  48. data/sig/generated/fmt/registries/registry.rbs +69 -0
  49. data/sig/generated/fmt/renderer.rbs +70 -0
  50. data/sig/generated/fmt/sigils.rbs +30 -0
  51. data/sig/generated/fmt/token.rbs +77 -0
  52. data/sig/generated/fmt/tokenizer.rbs +51 -0
  53. data/sig/generated/fmt/version.rbs +5 -0
  54. data/sig/generated/fmt.rbs +41 -0
  55. metadata +126 -18
  56. data/lib/fmt/embed.rb +0 -19
  57. data/lib/fmt/filter.rb +0 -32
  58. data/lib/fmt/filter_groups/filter_group.rb +0 -56
  59. data/lib/fmt/filter_groups/rainbow_filter_group.rb +0 -27
  60. data/lib/fmt/filter_groups/string_filter_group.rb +0 -28
  61. data/lib/fmt/formatter.rb +0 -60
  62. data/lib/fmt/scanners/base_scanner.rb +0 -41
  63. data/lib/fmt/scanners/embed_scanner.rb +0 -56
  64. data/lib/fmt/scanners/filter_scanner.rb +0 -31
  65. data/lib/fmt/scanners/key_scanner.rb +0 -15
  66. data/lib/fmt/scanners.rb +0 -3
  67. data/lib/fmt/transformer.rb +0 -57
@@ -0,0 +1,69 @@
1
+ # Generated from lib/fmt/registries/registry.rb with RBS::Inline
2
+
3
+ module Fmt
4
+ # Registry for storing and retrieving String formatters i.e. Procs
5
+ class Registry
6
+ extend Forwardable
7
+
8
+ INSTANCE_VAR: ::Symbol
9
+
10
+ # Constructor
11
+ def initialize: () -> untyped
12
+
13
+ # Indicates if a method name is registered for any Class
14
+ # @rbs method_name: Symbol -- method name to check
15
+ # @rbs return: bool
16
+ def any?: (Symbol method_name) -> bool
17
+
18
+ # Indicates if a method name is unregistered
19
+ # @rbs method_name: Symbol -- method name to check
20
+ # @rbs return: bool
21
+ def none?: (Symbol method_name) -> bool
22
+
23
+ # Adds a keypair to the registry
24
+ # @rbs key: Array[Class | Module, Symbol] -- key to use
25
+ # @rbs overwrite: bool -- overwrite the existing keypair (default: false)
26
+ # @rbs block: Proc -- Proc to add (optional, if proc is provided)
27
+ # @rbs return: Proc
28
+ def add: (Array[Class | Module, Symbol] key, ?overwrite: bool) ?{ (?) -> untyped } -> Proc
29
+
30
+ # Deletes a keypair from the registry
31
+ # @rbs key: Array[Class | Module, Symbol] -- key to delete
32
+ # @rbs return: Proc?
33
+ def delete: (Array[Class | Module, Symbol] key) -> Proc?
34
+
35
+ # Fetches a Proc from the registry
36
+ # @rbs key: Array[Class | Module, Symbol] -- key to retrieve
37
+ # @rbs callable: Proc -- Proc to use if the key is not found (optional, if block is provided)
38
+ # @rbs block: Proc -- block to use if the key is not found (optional, if proc is provided)
39
+ # @rbs return: Proc
40
+ def fetch: (Array[Class | Module, Symbol] key, ?callable: Proc) ?{ (?) -> untyped } -> Proc
41
+
42
+ # Retrieves the registered key for a Proc
43
+ # @rbs callable: Proc -- Proc to retrieve the key for
44
+ # @rbs return: Symbol?
45
+ def key_for: (Proc callable) -> Symbol?
46
+
47
+ # Merges another registry into this one
48
+ # @rbs other: Fmt::Registry -- other registry to merge
49
+ # @rbs return: Fmt::Registry
50
+ def merge!: (Fmt::Registry other) -> Fmt::Registry
51
+
52
+ # Executes a block with registry overrides
53
+ #
54
+ # @note Overrides will temporarily be added to the registry
55
+ # and will overwrite existing entries for the duration of the block
56
+ # Non overriden entries remain unchanged
57
+ #
58
+ # @rbs overrides: Hash[Array[Class | Module, Symbol], Proc] -- overrides to apply
59
+ # @rbs block: Proc -- block to execute with overrides
60
+ # @rbs return: void
61
+ def with_overrides: (Hash[Array[Class | Module, Symbol], Proc] overrides) ?{ (?) -> untyped } -> void
62
+
63
+ attr_reader store: untyped
64
+
65
+ # Hash of registered method names
66
+ # @rbs return: Hash[Symbol, TrueClass]
67
+ def method_names: () -> Hash[Symbol, TrueClass]
68
+ end
69
+ end
@@ -0,0 +1,70 @@
1
+ # Generated from lib/fmt/renderer.rb with RBS::Inline
2
+
3
+ module Fmt
4
+ # Renders templates to a formatted string
5
+ class Renderer
6
+ PIPELINE_START: untyped
7
+
8
+ # Constructor
9
+ # @rbs template: Template
10
+ def initialize: (Template template) -> untyped
11
+
12
+ attr_reader template: untyped
13
+
14
+ # Renders the template to a string
15
+ # @note Positional and Keyword arguments are mutually exclusive
16
+ # @rbs args: Array[Object] -- positional arguments (user provided)
17
+ # @rbs kwargs: Hash[Symbol, Object] -- keyword arguments (user provided)
18
+ # @rbs return: String -- rendered template
19
+ def render: (*untyped args, **untyped kwargs) -> String
20
+
21
+ private
22
+
23
+ # Escapes a string for use in a regular expression
24
+ # @rbs value: String -- string to escape
25
+ # @rbs return: String -- escaped string
26
+ def esc: (String value) -> String
27
+
28
+ # Renders all template embeds
29
+ # @rbs context: String -- starting context
30
+ # @rbs args: Array[Object] -- positional arguments (user provided)
31
+ # @rbs kwargs: Hash[Symbol, Object] -- keyword arguments (user provided)
32
+ # @rbs &block: Proc -- block to execute after rendering embeds (signature: Proc(String, *args, **kwargs))
33
+ def render_embeds: (String context, *untyped args, **untyped kwargs) -> untyped
34
+
35
+ # Renders all template pipelines
36
+ # @rbs context: String -- starting context
37
+ # @rbs args: Array[Object] -- positional arguments (user provided)
38
+ # @rbs kwargs: Hash[Symbol, Object] -- keyword arguments (user provided)
39
+ # @rbs return: String
40
+ def render_pipelines: (String context, *untyped args, **untyped kwargs) -> String
41
+
42
+ # Renders a single pipeline
43
+ # @rbs pipeline: Pipeline -- pipeline to render
44
+ # @rbs args: Array[Object] -- positional arguments (user provided)
45
+ # @rbs kwargs: Hash[Symbol, Object] -- keyword arguments (user provided)
46
+ # @rbs return: String
47
+ def render_pipeline: (Pipeline pipeline, *untyped args, **untyped kwargs) -> String
48
+
49
+ # Invokes native Ruby string formatting
50
+ # @rbs macro: Macro -- macro to use (source, arguments, etc.)
51
+ # @rbs args: Array[Object] -- positional arguments (user provided)
52
+ # @rbs kwargs: Hash[Symbol, Object] -- keyword arguments (user provided)
53
+ # @rbs return: String
54
+ def invoke_formatter: (Macro macro, *untyped args, **untyped kwargs) -> String
55
+
56
+ # Invokes a macro
57
+ # @rbs context: Object -- self in callable (Proc)
58
+ # @rbs macro: Macro -- macro to use (source, arguments, etc.)
59
+ # @rbs return: Object -- result
60
+ def invoke_macro: (Object context, Macro macro) -> Object
61
+
62
+ # Raises an invocation error if/when Proc invocations fail
63
+ # @rbs macro: Macro -- macro that failed
64
+ # @rbs args: Array[Object] -- positional arguments (user provided)
65
+ # @rbs cause: Exception -- exception that caused the error
66
+ # @rbs kwargs: Hash[Symbol, Object] -- keyword arguments (user provided)
67
+ # @rbs return: void
68
+ def raise_format_error: (Macro macro, *untyped args, cause: Exception, **untyped kwargs) -> void
69
+ end
70
+ end
@@ -0,0 +1,30 @@
1
+ # Generated from lib/fmt/sigils.rb with RBS::Inline
2
+
3
+ module Fmt
4
+ # Common Fmt sigils (used in String templates)
5
+ class Sigils
6
+ # Native Ruby format specifiers
7
+ # @see https://docs.ruby-lang.org/en/master/format_specifications_rdoc.html
8
+ FORMAT_PREFIX: ::String
9
+
10
+ FORMAT_SPECIFIERS: untyped
11
+
12
+ FORMAT_FLAGS: untyped
13
+
14
+ FORMAT_METHOD: ::Symbol
15
+
16
+ KEY_PREFIXES: untyped
17
+
18
+ KEY_SUFFIXES: untyped
19
+
20
+ ARGS_PREFIX: ::String
21
+
22
+ ARGS_SUFFIX: ::String
23
+
24
+ PIPE_OPERATOR: ::String
25
+
26
+ EMBED_PREFIX: ::String
27
+
28
+ EMBED_SUFFIX: ::String
29
+ end
30
+ end
@@ -0,0 +1,77 @@
1
+ # Generated from lib/fmt/token.rb with RBS::Inline
2
+
3
+ module Fmt
4
+ # Convenience wrapper for Ripper tokens
5
+ #
6
+ # @see https://rubyapi.org/3.4/o/ripper
7
+ # @see doc/RIPPER.md (cheetsheet)
8
+ #
9
+ # @example Ripper Token
10
+ # [[lineno, column], type, token, state]
11
+ # [[Integer, Integer], Symbol, String, Object]
12
+ class Token
13
+ include Matchable
14
+
15
+ # Constructor
16
+ # @rbs ripper_token: Array[[Integer, Integer], Symbol, String, Object] -- Ripper token
17
+ def initialize: (Array[[ Integer, Integer ], Symbol, String, Object] ripper_token) -> untyped
18
+
19
+ attr_reader ripper_token: untyped
20
+
21
+ attr_reader lineno: untyped
22
+
23
+ attr_reader column: untyped
24
+
25
+ attr_reader type: untyped
26
+
27
+ attr_reader token: untyped
28
+
29
+ attr_reader state: untyped
30
+
31
+ # Returns a Hash representation of the token
32
+ # @rbs return: Hash[Symbol, Object]
33
+ def to_h: () -> Hash[Symbol, Object]
34
+
35
+ # Returns a Hash representation of the token limited to the given keys
36
+ # @rbs keys: Array[Symbol] -- keys to include
37
+ # @rbs return: Hash[Symbol, Object]
38
+ def deconstruct_keys: (?Array[Symbol] keys) -> Hash[Symbol, Object]
39
+
40
+ # Indicates if the token is a left paren (i.e. start of arguments)
41
+ # @rbs return: bool
42
+ def arguments_start?: () -> bool
43
+
44
+ # Indicates if the token is a right paren (i.e. end of arguments)
45
+ # @rbs return: bool
46
+ def arguments_finish?: () -> bool
47
+
48
+ # Indicates if the token starts a key (string formatting named parameter)
49
+ # @rbs return: bool
50
+ def key_start?: () -> bool
51
+
52
+ # Indicates if the token finishes a key (string formatting named parameter)
53
+ # @rbs return: bool
54
+ def key_finish?: () -> bool
55
+
56
+ # Indicates if the token is an identifier (e.g. method name, format specifier, variable name, etc.)
57
+ # @rbs return: bool
58
+ def identifier?: () -> bool
59
+
60
+ # Indicates if the token is a method name (i.e. method name or operator)
61
+ # @rbs return: bool
62
+ def method_name?: () -> bool
63
+
64
+ # Indicates if the token is an operator
65
+ # @rbs return: bool
66
+ def operator?: () -> bool
67
+
68
+ # Indicates if the token is a whitespace
69
+ # @rbs return: bool
70
+ def whitespace?: () -> bool
71
+
72
+ # Indicates if the token is a native String format specifier
73
+ # @see Sigils::FORMAT_SPECIFIERS
74
+ # @rbs return: bool
75
+ def specifier?: () -> bool
76
+ end
77
+ end
@@ -0,0 +1,51 @@
1
+ # Generated from lib/fmt/tokenizer.rb with RBS::Inline
2
+
3
+ module Fmt
4
+ # Ruby source code token extractor
5
+ #
6
+ # Uses Ripper from Ruby's standard library
7
+ # @see https://rubyapi.org/3.4/o/ripper
8
+ # @see doc/RIPPER.md (cheetsheet)
9
+ #
10
+ # @example Ripper token
11
+ # [[lineno, column], type, token, state]
12
+ # [[Integer, Integer], Symbol, String, Object]
13
+ class Tokenizer
14
+ # Constructor
15
+ # @rbs urtext: String -- original source code
16
+ def initialize: (String urtext) -> untyped
17
+
18
+ attr_reader urtext: untyped
19
+
20
+ attr_reader tokens: untyped
21
+
22
+ # Tokenizes the urtext (original source code)
23
+ # @rbs return: Array[Token] -- wrapped ripper tokens
24
+ def tokenize: () -> Array[Token]
25
+
26
+ # Returns identifier tokens (typically method names)
27
+ # @rbs start: Integer -- start index
28
+ # @rbs return: Array[Token]
29
+ def identifier_tokens: (?start: Integer) -> Array[Token]
30
+
31
+ # Returns method tokens (identifiers and operators)
32
+ # @rbs start: Integer -- start index
33
+ # @rbs return: Array[Token]
34
+ def method_name_tokens: (?start: Integer) -> Array[Token]
35
+
36
+ # Returns key (named parameter) tokens
37
+ # @rbs start: Integer -- start index
38
+ # @rbs return: Array[Token]?
39
+ def key_tokens: (?start: Integer) -> Array[Token]?
40
+
41
+ # Returns operator tokens
42
+ # @rbs start: Integer -- start index
43
+ # @rbs return: Array[Token]
44
+ def operator_tokens: (?start: Integer) -> Array[Token]
45
+
46
+ # Returns the argument tokens
47
+ # @rbs start: Integer -- start index
48
+ # @rbs return: Array[Token]
49
+ def argument_tokens: (?start: Integer) -> Array[Token]
50
+ end
51
+ end
@@ -0,0 +1,5 @@
1
+ # Generated from lib/fmt/version.rb with RBS::Inline
2
+
3
+ module Fmt
4
+ VERSION: ::String
5
+ end
@@ -0,0 +1,41 @@
1
+ # Generated from lib/fmt.rb with RBS::Inline
2
+
3
+ # Extends native Ruby String format specifications
4
+ # @see https://ruby-doc.org/3.3.4/format_specifications_rdoc.html
5
+ module Fmt
6
+ LOCK: untyped
7
+
8
+ # Standard error class for Fmt
9
+ class Error < StandardError
10
+ end
11
+
12
+ # Error for formatting failures
13
+ class FormatError < Error
14
+ end
15
+
16
+ # Global registry for storing and retrieving String formatters i.e. Procs
17
+ def self.registry: () -> untyped
18
+
19
+ # Adds a keypair to the registry
20
+ # @rbs key: Array[Class | Module, Symbol] -- key to use
21
+ # @rbs overwrite: bool -- overwrite the existing keypair (default: false)
22
+ # @rbs block: Proc -- Proc to add (optional, if proc is provided)
23
+ # @rbs return: Proc
24
+ def self.register: () -> Proc
25
+
26
+ # Deletes a keypair from the registry
27
+ # @rbs key: Array[Class | Module, Symbol] -- key to delete
28
+ # @rbs return: Proc?
29
+ def self.unregister: () -> Proc?
30
+
31
+ # Executes a block with registry overrides
32
+ #
33
+ # @note Overrides will temporarily be added to the registry
34
+ # and will overwrite existing entries for the duration of the block
35
+ # Non overriden entries remain unchanged
36
+ #
37
+ # @rbs overrides: Hash[Array[Class | Module, Symbol], Proc] -- overrides to apply
38
+ # @rbs block: Proc -- block to execute with overrides
39
+ # @rbs return: void
40
+ def self.with_overrides: () -> void
41
+ end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fmt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nate Hopkins (hopsoft)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-29 00:00:00.000000000 Z
11
+ date: 2024-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ast
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
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: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 7.1.4
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 7.1.4
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: amazing_print
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -25,7 +53,7 @@ dependencies:
25
53
  - !ruby/object:Gem::Version
26
54
  version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
- name: magic_frozen_string_literal
56
+ name: fiddle
29
57
  requirement: !ruby/object:Gem::Requirement
30
58
  requirements:
31
59
  - - ">="
@@ -52,6 +80,20 @@ dependencies:
52
80
  - - ">="
53
81
  - !ruby/object:Gem::Version
54
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest-cc
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'
55
97
  - !ruby/object:Gem::Dependency
56
98
  name: minitest-reporters
57
99
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +108,20 @@ dependencies:
66
108
  - - ">="
67
109
  - !ruby/object:Gem::Version
68
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: ostruct
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
69
125
  - !ruby/object:Gem::Dependency
70
126
  name: pry-byebug
71
127
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +178,20 @@ dependencies:
122
178
  - - ">="
123
179
  - !ruby/object:Gem::Version
124
180
  version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: rbs-inline
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
125
195
  - !ruby/object:Gem::Dependency
126
196
  name: tocer
127
197
  requirement: !ruby/object:Gem::Requirement
@@ -150,7 +220,7 @@ dependencies:
150
220
  - - ">="
151
221
  - !ruby/object:Gem::Version
152
222
  version: '0'
153
- description: A simple template engine based on native Ruby String formatting mechanics
223
+ description: Pipeline driven template engine based on native Ruby String formatting
154
224
  email:
155
225
  - natehop@gmail.com
156
226
  executables: []
@@ -159,19 +229,57 @@ extra_rdoc_files: []
159
229
  files:
160
230
  - README.md
161
231
  - lib/fmt.rb
162
- - lib/fmt/embed.rb
163
- - lib/fmt/filter.rb
164
- - lib/fmt/filter_groups/filter_group.rb
165
- - lib/fmt/filter_groups/rainbow_filter_group.rb
166
- - lib/fmt/filter_groups/string_filter_group.rb
167
- - lib/fmt/formatter.rb
168
- - lib/fmt/scanners.rb
169
- - lib/fmt/scanners/base_scanner.rb
170
- - lib/fmt/scanners/embed_scanner.rb
171
- - lib/fmt/scanners/filter_scanner.rb
172
- - lib/fmt/scanners/key_scanner.rb
173
- - lib/fmt/transformer.rb
232
+ - lib/fmt/boot.rb
233
+ - lib/fmt/lru_cache.rb
234
+ - lib/fmt/mixins/matchable.rb
235
+ - lib/fmt/models/arguments.rb
236
+ - lib/fmt/models/embed.rb
237
+ - lib/fmt/models/macro.rb
238
+ - lib/fmt/models/model.rb
239
+ - lib/fmt/models/pipeline.rb
240
+ - lib/fmt/models/template.rb
241
+ - lib/fmt/node.rb
242
+ - lib/fmt/parsers/arguments_parser.rb
243
+ - lib/fmt/parsers/embed_parser.rb
244
+ - lib/fmt/parsers/macro_parser.rb
245
+ - lib/fmt/parsers/parser.rb
246
+ - lib/fmt/parsers/pipeline_parser.rb
247
+ - lib/fmt/parsers/template_parser.rb
248
+ - lib/fmt/refinements/kernel_refinement.rb
249
+ - lib/fmt/registries/native_registry.rb
250
+ - lib/fmt/registries/rainbow_registry.rb
251
+ - lib/fmt/registries/registry.rb
252
+ - lib/fmt/renderer.rb
253
+ - lib/fmt/sigils.rb
254
+ - lib/fmt/token.rb
255
+ - lib/fmt/tokenizer.rb
174
256
  - lib/fmt/version.rb
257
+ - sig/generated/fmt.rbs
258
+ - sig/generated/fmt/boot.rbs
259
+ - sig/generated/fmt/lru_cache.rbs
260
+ - sig/generated/fmt/mixins/matchable.rbs
261
+ - sig/generated/fmt/models/arguments.rbs
262
+ - sig/generated/fmt/models/embed.rbs
263
+ - sig/generated/fmt/models/macro.rbs
264
+ - sig/generated/fmt/models/model.rbs
265
+ - sig/generated/fmt/models/pipeline.rbs
266
+ - sig/generated/fmt/models/template.rbs
267
+ - sig/generated/fmt/node.rbs
268
+ - sig/generated/fmt/parsers/arguments_parser.rbs
269
+ - sig/generated/fmt/parsers/embed_parser.rbs
270
+ - sig/generated/fmt/parsers/macro_parser.rbs
271
+ - sig/generated/fmt/parsers/parser.rbs
272
+ - sig/generated/fmt/parsers/pipeline_parser.rbs
273
+ - sig/generated/fmt/parsers/template_parser.rbs
274
+ - sig/generated/fmt/refinements/kernel_refinement.rbs
275
+ - sig/generated/fmt/registries/native_registry.rbs
276
+ - sig/generated/fmt/registries/rainbow_registry.rbs
277
+ - sig/generated/fmt/registries/registry.rbs
278
+ - sig/generated/fmt/renderer.rbs
279
+ - sig/generated/fmt/sigils.rbs
280
+ - sig/generated/fmt/token.rbs
281
+ - sig/generated/fmt/tokenizer.rbs
282
+ - sig/generated/fmt/version.rbs
175
283
  homepage: https://github.com/hopsoft/fmt
176
284
  licenses:
177
285
  - MIT
@@ -193,8 +301,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
301
  - !ruby/object:Gem::Version
194
302
  version: '0'
195
303
  requirements: []
196
- rubygems_version: 3.5.11
304
+ rubygems_version: 3.5.16
197
305
  signing_key:
198
306
  specification_version: 4
199
- summary: A simple template engine based on native Ruby String formatting mechanics
307
+ summary: Pipeline driven template engine based on native Ruby String formatting
200
308
  test_files: []
data/lib/fmt/embed.rb DELETED
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Fmt
4
- class Embed
5
- def initialize(string)
6
- @string = string
7
- end
8
-
9
- attr_reader :string
10
-
11
- def placeholder
12
- "{{#{string}}}"
13
- end
14
-
15
- def format(**locals)
16
- Fmt(string, **locals)
17
- end
18
- end
19
- end
data/lib/fmt/filter.rb DELETED
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Fmt
4
- class Filter
5
- def initialize(name, value)
6
- raise ArgumentError, "value must be a String or Proc" unless value.is_a?(String) || value.is_a?(Proc)
7
- @name = name
8
- @value = value
9
- end
10
-
11
- attr_reader :name, :value
12
-
13
- def apply(string)
14
- case value
15
- when String then sprintf("%#{filter.value}", string)
16
- when Proc then filter.value.call(string)
17
- end
18
- end
19
-
20
- def string?
21
- value.is_a? String
22
- end
23
-
24
- def proc?
25
- value.is_a? Proc
26
- end
27
-
28
- def inspect
29
- "#<#{self.class.name} name=#{name.inspect} value=#{value.inspect}>"
30
- end
31
- end
32
- end
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "monitor"
4
- require_relative "../filter"
5
-
6
- module Fmt
7
- class FilterGroup
8
- include Enumerable
9
- include MonitorMixin
10
-
11
- def initialize
12
- super
13
- @data = {}
14
- end
15
-
16
- def [](name)
17
- synchronize { data[name.to_sym] }
18
- end
19
-
20
- def add(name, filter_proc = nil, &block)
21
- raise ArgumentError, "filter_proc and block are mutually exclusive" if filter_proc && block
22
- raise ArgumentError, "filter_proc must be a Proc" unless block || filter_proc.is_a?(Proc)
23
- synchronize do
24
- data[name.to_sym] = Fmt::Filter.new(name.to_sym, filter_proc || block)
25
- end
26
- end
27
-
28
- def each(&block)
29
- synchronize { data.each(&block) }
30
- end
31
-
32
- def fetch(name, default = nil)
33
- synchronize { data.fetch name.to_sym, default }
34
- end
35
-
36
- def key?(name)
37
- synchronize { data.key? name.to_sym }
38
- end
39
-
40
- alias_method :added?, :key?
41
- alias_method :include?, :key?
42
-
43
- def merge!(other)
44
- synchronize { data.merge! other.to_h }
45
- self
46
- end
47
-
48
- def to_h
49
- data.dup
50
- end
51
-
52
- protected
53
-
54
- attr_reader :data
55
- end
56
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "filter_group"
4
-
5
- module Fmt
6
- class RainbowFilterGroup < FilterGroup
7
- def initialize
8
- super
9
-
10
- if defined? Rainbow
11
- methods = Rainbow::Presenter.public_instance_methods(false).select do |method|
12
- Rainbow::Presenter.public_instance_method(method).arity == 0
13
- end
14
-
15
- method_names = methods
16
- .map { |m| m.name.to_sym }
17
- .concat(Rainbow::X11ColorNames::NAMES.keys)
18
-
19
- method_names.each do |name|
20
- add(name) { |string| Rainbow(string).public_send name }
21
- end
22
- end
23
- rescue => error
24
- puts "Error adding Rainbow filters! #{error.inspect}"
25
- end
26
- end
27
- end