ruby_native 0.10.4 → 0.10.8
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 +4 -4
- data/app/controllers/ruby_native/config_controller.rb +1 -1
- data/lib/ruby_native/version.rb +1 -1
- data/lib/ruby_native.rb +81 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a84e26b885c93151197f1ae505a45b9cb99d8f3049df4b89dce036c431411a51
|
|
4
|
+
data.tar.gz: cba347806df4afc1f3e21c1b0201e616148633632c712eb44c432166b43f1115
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7add53e3f05dc87ff5688b0b5714cb627c0a60facc70dde3322cf898d7d5128ffef60b64eca922fefee35441775e1b0ee18108499a795603081cd841ff4e0d70
|
|
7
|
+
data.tar.gz: 91bc86d031b25887d4c321ce50dbc10227ecc89f84c9fc2b695091289c1d128a10cecd398e19d5f0928ac40a03c6fac4884d815a21319b370ebe670684dfe561
|
data/lib/ruby_native/version.rb
CHANGED
data/lib/ruby_native.rb
CHANGED
|
@@ -43,6 +43,7 @@ module RubyNative
|
|
|
43
43
|
self.config[:auth] ||= {}
|
|
44
44
|
normalize_oauth_paths
|
|
45
45
|
backfill_tab_icons
|
|
46
|
+
backfill_error_icons
|
|
46
47
|
end
|
|
47
48
|
|
|
48
49
|
# Mirrors per-platform `icons:` into the legacy flat `icon:` field so native
|
|
@@ -59,6 +60,86 @@ module RubyNative
|
|
|
59
60
|
end
|
|
60
61
|
end
|
|
61
62
|
|
|
63
|
+
# Mirrors `backfill_tab_icons` for the error screen: fills a state's flat
|
|
64
|
+
# `icon` from its per-platform `icons` (ios first, then android), so the iOS
|
|
65
|
+
# app, which reads only the flat `icon`, still renders one. An explicit
|
|
66
|
+
# `icon:` wins.
|
|
67
|
+
def self.backfill_error_icons
|
|
68
|
+
errors = self.config[:errors]
|
|
69
|
+
return unless errors.is_a?(Hash)
|
|
70
|
+
|
|
71
|
+
ERROR_SCREEN_STATES.each do |state|
|
|
72
|
+
state_config = errors[state]
|
|
73
|
+
next unless state_config.is_a?(Hash)
|
|
74
|
+
|
|
75
|
+
icons = state_config[:icons]
|
|
76
|
+
next unless icons.is_a?(Hash)
|
|
77
|
+
|
|
78
|
+
state_config[:icon] ||= icons[:ios] || icons[:android]
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# The native fallback screen has two states: `offline` (no connectivity) and
|
|
83
|
+
# `generic` (any other load failure). Each can carry a per-platform icon and
|
|
84
|
+
# localized copy.
|
|
85
|
+
ERROR_SCREEN_STATES = %i[offline generic].freeze
|
|
86
|
+
ERROR_SCREEN_COPY_KEYS = %i[title message].freeze
|
|
87
|
+
|
|
88
|
+
# The JSON served at GET /native/config. Identical to `config`, except the
|
|
89
|
+
# `errors` block is enriched: per-state icons from config/ruby_native.yml are
|
|
90
|
+
# merged with localized title/message pulled from the host app's I18n
|
|
91
|
+
# (`ruby_native.errors.<state>.<key>`), one entry per available locale. Only
|
|
92
|
+
# values the developer actually provided are emitted; the native apps fall
|
|
93
|
+
# back to bundled English copy for anything missing. Built on a deep copy so
|
|
94
|
+
# the in-memory `config` the server reads for view helpers is never mutated.
|
|
95
|
+
def self.config_as_json
|
|
96
|
+
return config if config.nil?
|
|
97
|
+
|
|
98
|
+
payload = config.deep_dup
|
|
99
|
+
errors = error_screen_config(payload[:errors])
|
|
100
|
+
if errors.empty?
|
|
101
|
+
payload.delete(:errors)
|
|
102
|
+
else
|
|
103
|
+
payload[:errors] = errors
|
|
104
|
+
end
|
|
105
|
+
payload
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Merges per-state error-screen icons (from YAML) with localized copy (from
|
|
109
|
+
# I18n) into the shape the native apps decode. Omits any state with neither an
|
|
110
|
+
# icon nor copy, so an untouched app sends no `errors` block at all.
|
|
111
|
+
def self.error_screen_config(yaml_errors)
|
|
112
|
+
config = ERROR_SCREEN_STATES.each_with_object({}) do |state, result|
|
|
113
|
+
entry = {}
|
|
114
|
+
state_config = yaml_errors[state] if yaml_errors.is_a?(Hash)
|
|
115
|
+
if state_config.is_a?(Hash)
|
|
116
|
+
entry[:icon] = state_config[:icon] if state_config[:icon]
|
|
117
|
+
entry[:icons] = state_config[:icons] if state_config[:icons]
|
|
118
|
+
end
|
|
119
|
+
ERROR_SCREEN_COPY_KEYS.each do |key|
|
|
120
|
+
translations = error_screen_translations("#{state}.#{key}")
|
|
121
|
+
entry[key] = translations unless translations.empty?
|
|
122
|
+
end
|
|
123
|
+
result[state] = entry unless entry.empty?
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# The Retry button label is shared by both states, so it sits at the top of
|
|
127
|
+
# the block rather than under a state.
|
|
128
|
+
retry_label = error_screen_translations("retry")
|
|
129
|
+
config[:retry] = retry_label unless retry_label.empty?
|
|
130
|
+
config
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# Reads `ruby_native.errors.<subkey>` for every available locale, keeping only
|
|
134
|
+
# the locales the developer actually translated. Copy lives in the host app's
|
|
135
|
+
# own locale files; the gem ships none.
|
|
136
|
+
def self.error_screen_translations(subkey)
|
|
137
|
+
I18n.available_locales.each_with_object({}) do |locale, result|
|
|
138
|
+
value = I18n.t("ruby_native.errors.#{subkey}", locale: locale, default: nil)
|
|
139
|
+
result[locale] = value unless value.nil?
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
62
143
|
# `auth.oauth_paths` must list only OAuth authorize paths, never their
|
|
63
144
|
# callbacks. The native app treats every listed path as a sign-in trigger and
|
|
64
145
|
# derives the provider from the last path segment, so a callback entry like
|