twine-flutter 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 586677a3df54ba426027489178ca89aaf7afb56237e679c85a9ca22685d5a08c
4
+ data.tar.gz: 8fc4f010b07820cd403f27a716e54f83c134178e10fd8ed3e99090bb2fb9278f
5
+ SHA512:
6
+ metadata.gz: 346c7568b35680f03335f050a9618d569d1e0b1a2705b333ce2778be9374ad6ffc46800bed4df08fef8bb1167463d83206016736be1780da8edbdae83b423803
7
+ data.tar.gz: 502b267c3bc039c7435504efa81ef6c0f2d6ad444295e69b6691253dc24f911046c028eb034709426ba6d298135bb2db3ce87c900de21e5db0d47496050f0f70
data/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2022, Tiknil
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # Twine Flutter formatter plugin
2
+ This [twine](https://github.com/scelis/twine) plugin provide a formatter for `.arb` files, used by Flutter projects.
3
+
4
+ ## Installation
5
+ Install this gem:
6
+
7
+ ```gem install twine-flutter```
8
+
9
+ Then setup twine to use it as described [here](https://github.com/scelis/twine/blob/main/documentation/formatters.md#plugins).
10
+
11
+ ```gems: twine-flutter```
data/lib/formatter.rb ADDED
@@ -0,0 +1,90 @@
1
+ module Twine
2
+ module Formatters
3
+ class Flutter < Abstract
4
+ def format_name
5
+ 'flutter'
6
+ end
7
+
8
+ def extension
9
+ '.arb'
10
+ end
11
+
12
+ def default_file_name
13
+ 'app.arb'
14
+ end
15
+
16
+ def determine_language_given_path(path)
17
+ match = /^.+_([^-]{2})\.arb$/.match File.basename(path)
18
+ return match[1] if match
19
+
20
+ return super
21
+ end
22
+
23
+ def read(io, lang)
24
+ begin
25
+ require "json"
26
+ rescue LoadError
27
+ raise Twine::Error.new "You must run `gem install json` in order to read or write flutter files."
28
+ end
29
+
30
+ json = JSON.load(io)
31
+ json.each do |key, value|
32
+ if key == "@@locale"
33
+ # Ignore because it represents the file lang
34
+ elsif key[0,1] == "@"
35
+ description_value = "{\n \"description\":\"#{value}\"\n }"
36
+ if value["description"]
37
+ set_comment_for_key(key[1..-1], value["description"])
38
+ end
39
+ else
40
+ set_translation_for_key(key, lang, value)
41
+ end
42
+ end
43
+ end
44
+
45
+ def format_file(lang)
46
+ result = super
47
+ return result unless result
48
+ "{\n \"@@locale\": \"#{lang}\",\n\n#{super}\n}"
49
+ end
50
+
51
+ def format_sections(twine_file, lang)
52
+ sections = twine_file.sections.map { |section| format_section(section, lang) }
53
+ sections.delete_if(&:empty?)
54
+ sections.join(",\n\n")
55
+ end
56
+
57
+ def format_section_header(section)
58
+ "\n"
59
+ end
60
+
61
+ def format_section(section, lang)
62
+ definitions = section.definitions.dup
63
+
64
+ definitions.map! { |definition| format_definition(definition, lang) }
65
+ definitions.compact! # remove nil definitions
66
+ definitions.join(",\n")
67
+ end
68
+
69
+ def format_definition(definition, lang)
70
+ [format_key_value(definition, lang), format_comment(definition, lang)].compact.join(",\n")
71
+ end
72
+
73
+ def key_value_pattern
74
+ " \"%{key}\": \"%{value}\""
75
+ end
76
+
77
+ def format_comment(definition, lang)
78
+ " \"@#{definition.key}\": {\n \"description\": \"#{definition.comment}\"\n }" if definition.comment
79
+ end
80
+
81
+ def format_key(key)
82
+ escape_quotes(key)
83
+ end
84
+
85
+ def format_value(value)
86
+ escape_quotes(value)
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'twine'
3
+
4
+ require_relative 'formatter'
5
+
6
+ Twine::Formatters.formatters << Twine::Formatters::Flutter.new
@@ -0,0 +1,15 @@
1
+ {
2
+ "@@locale": "en",
3
+
4
+ "key1": "value1-english",
5
+ "@key1": {
6
+ "description": "comment key1"
7
+ },
8
+ "key2": "value2-english",
9
+
10
+ "key3": "value3-english",
11
+ "key4": "value4-english",
12
+ "@key4": {
13
+ "description": "comment key4"
14
+ }
15
+ }
@@ -0,0 +1,13 @@
1
+ [[Section A]]
2
+ [key1]
3
+ en = value1-english
4
+ comment = comment key1
5
+ [key2]
6
+ en = value2-english
7
+
8
+ [[Section B]]
9
+ [key3]
10
+ en = value3-english
11
+ [key4]
12
+ en = value4-english
13
+ comment = comment key4
@@ -0,0 +1,18 @@
1
+ require 'minitest/autorun'
2
+ require 'twine-flutter'
3
+
4
+ class TestFlutterFormatter < Minitest::Test
5
+ def setup
6
+ formatter = Twine::Formatters::Flutter.new
7
+ formatter.twine_file = Twine::TwineFile.new
8
+ formatter.options = { consume_all: true, consume_comments: true }
9
+ end
10
+
11
+ def test_twine_to_arb
12
+ assert true #TODO
13
+ end
14
+
15
+ def test_arb_to_twine
16
+ assert true #TODO
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: twine-flutter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Fabio Butti
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-08-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: twine
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.0
27
+ description: Plugin for twine that enables .arb generation for use with Flutter.
28
+ email:
29
+ - butti.fabio@tiknil.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENSE
35
+ - README.md
36
+ - lib/formatter.rb
37
+ - lib/twine-flutter.rb
38
+ - test/fixtures/flutter_format.arb
39
+ - test/fixtures/twine.txt
40
+ - test/test_flutter_formatter.rb
41
+ homepage: https://github.com/tiknil/twine-flutter
42
+ licenses:
43
+ - BSD-3-Clause
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '2.4'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubygems_version: 3.0.3
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Plugin for twine that enables .arb generation for use with Flutter
64
+ test_files:
65
+ - test/test_flutter_formatter.rb