i18n_on_steroids 0.1.0 → 0.2.0

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: 6f2aa815dd1dd225a377d1e33ea973c20fa779ee11ebbf8faf3c64138a2cb449
4
- data.tar.gz: '0942cb04b9e24f1717cd88f532ed44814898d2088922779a08f5aa72e476dfe5'
3
+ metadata.gz: 5482b9d52b60ea2d856bcc1a26aab2d3805978a1445c27de768b985f58faa02c
4
+ data.tar.gz: ca5a1565ac889dbbf335ff9541e6a46787aefaec98321cd4aff72524dd0cd755
5
5
  SHA512:
6
- metadata.gz: 34920fb6f7e9e2c9badc793c08334a497328daff4a1737ba8df1eb289a130e5256ffc87d4839d5a99b6ebb202f4dc6f8c9a648a12c505687770ffb476f721071
7
- data.tar.gz: 84d87d3de4dbfce25f7293f67ba457033ff9af7dea82663608ff2ecafa04e3eeeb6a799cd2d0672732e6c9e7eb94968813c67bc0d370d077f735d915ce4ff9da
6
+ metadata.gz: 01e7f5bb75dcf4167f1f0fdad5f7da3a2203ea76aa4e525fcc8f20a37f04eccc25ae5781d48dafd8187b91fff8db2b282d398c229ce479426ec1533691e12f6c
7
+ data.tar.gz: 71755126e980b49d907441ee660b5a1ac32266299eb44c859410a3c215b0530da1e464fa2cf566d6cd6810bda4448fc20572274a93d26281fd8bf73f02736fbf
data/.rubocop.yml CHANGED
@@ -1,3 +1,9 @@
1
+ require:
2
+ - rubocop-minitest
3
+ - rubocop-packaging
4
+ - rubocop-performance
5
+ - rubocop-rake
6
+
1
7
  AllCops:
2
8
  TargetRubyVersion: 3.0
3
9
  NewCops: disable
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.1] - 2024-08-21
4
+
5
+ - Added ability to pipe regular strings. Because, why not?
6
+ `${ 'Hello, World!' | upcase } => HELLO, WORLD!`
7
+ Note: This needs to be done via `${}` instead of `%{}` otherwise Psych will throw an error.
8
+ - Started listening to `rubocop-performance` and apparently improved some performance.
9
+ - Enabled more `rubocop` cops.
10
+ - Lowered 'ActiveSupport' and 'ActionView' version requirements to allow more Ruby versions to be supported.
11
+
3
12
  ## [0.1.0] - 2024-08-22
4
13
 
5
- - Initial release
14
+ - Initial release
@@ -20,33 +20,44 @@ module I18nOnSteroids
20
20
  private
21
21
 
22
22
  def process_mixed_translation(translation, options)
23
- parts = translation.split(/(%\{[^}]+\}|\$\{[^}]+\})/)
23
+ parts = translation.split(/(\$\{[^}]+\}|%\{[^}]+\})/)
24
24
  processed_parts = parts.map do |part|
25
- if part.start_with?("%{") || part.start_with?("${")
25
+ if part.start_with?("${", "%{")
26
26
  process_interpolation(part, options)
27
27
  else
28
28
  part
29
29
  end
30
30
  end
31
31
 
32
- processed_parts.join.html_safe
32
+ processed_parts.join
33
33
  end
34
34
 
35
35
  def process_interpolation(interpolation, options)
36
- match_data = interpolation.match(/^(%\{|\$\{)([^}]+)\}$/)
36
+ match_data = interpolation.match(/^(\$\{|%\{)([^}]+)}$/)
37
37
 
38
38
  return interpolation unless match_data
39
39
 
40
- key, *pipes = match_data[2].split("|").map(&:strip)
41
- value = options[key.to_sym]
42
-
43
- if value.nil?
44
- interpolation
40
+ if (content = match_data[2].strip).start_with?("'", '"')
41
+ # This is a regular string with pipes: ${'Hello' | upcase}
42
+ process_string_with_pipes(content)
45
43
  else
44
+ # This is a variable interpolation with pipes: ${name | upcase}
45
+ key, *pipes = content.split("|").map(&:strip)
46
+ value = options[key.to_sym]
47
+
48
+ return interpolation if value.nil?
49
+
46
50
  apply_pipes(value, pipes, options)
47
51
  end
48
52
  end
49
53
 
54
+ def process_string_with_pipes(content)
55
+ string, *pipes = content.split("|").map(&:strip)
56
+ string = string[1...-1] if string.start_with?('"', "'")
57
+
58
+ apply_pipes(string, pipes, {})
59
+ end
60
+
50
61
  # rubocop:disable Metrics/MethodLength
51
62
  # rubocop:disable Metrics/AbcSize
52
63
  # rubocop:disable Metrics/CyclomaticComplexity
@@ -1,5 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Reminder to self with how Semantic Versioning works:
4
+ #
5
+ # MAJOR version when you make incompatible API changes
6
+ # MINOR version when you add functionality in a backward compatible manner
7
+ # PATCH version when you make backward compatible bug fixes
8
+ #
9
+ # Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.
10
+
3
11
  module I18nOnSteroids
4
- VERSION = "0.1.0"
12
+ VERSION = "0.2.0"
5
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n_on_steroids
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pacMakaveli