glib-web 0.4.1 → 0.4.2
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/concerns/glib/json/dynamic_text.rb +14 -13
- data/app/helpers/glib/dynamic_texts_helper.rb +23 -1
- data/app/models/glib/text.rb +7 -3
- data/app/views/json_ui/garage/dynamic_texts/basic.json.jbuilder +1 -0
- data/lib/generators/glib/install_generator.rb +8 -3
- data/lib/generators/templates/20191126071051_create_active_storage_tables.active_storage.rb +27 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '00370028bd3cdc3097c1b40e128c34ec08271d2858b5a83d2c54ebceb5f18c6e'
|
|
4
|
+
data.tar.gz: 5021c723ca5ef541455c0497fc0a25f86945b7d99383698fb76d587d034f2f9b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f7cc0a4fa5a08a8673e3306dfb91ca07e341c395b4a3f1e4cce985b7da72e394844ff5596087e657b15a1c610366aa34f5958446b40ba27c7a3ce3fc9afbd253
|
|
7
|
+
data.tar.gz: 9c4b027e7025dcb06a7734839fde49dc8138ae5865e442faebe0f0e715dc9d3077747f1e52b6f5198337d36635de9af89f52970abcf82a24929dc23ee5877948
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
module Glib::Json::DynamicText
|
|
2
2
|
def __json_dynamic_text_perform
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
crawl hash['footer']&.[]('childViews')
|
|
3
|
+
if (hash = json_transformation_start).is_a?(Hash)
|
|
4
|
+
@__specs = {}
|
|
5
|
+
|
|
6
|
+
crawl hash['header']&.[]('childViews')
|
|
7
|
+
crawl hash['body']&.[]('childViews')
|
|
8
|
+
crawl hash['footer']&.[]('childViews')
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
# TODO: retrieve texts from dynamictextreader
|
|
11
|
+
# translated_texts = retrieve_remote_texts(@__specs.keys)
|
|
12
|
+
|
|
13
|
+
translated_texts = retrieve_example_texts(@__specs.keys)
|
|
14
|
+
translated_texts.each do |key, value|
|
|
15
|
+
@__specs[key].each do |spec|
|
|
16
|
+
spec.substitute_with(value)
|
|
16
17
|
end
|
|
17
18
|
end
|
|
18
|
-
|
|
19
|
+
end
|
|
19
20
|
end
|
|
20
21
|
|
|
21
22
|
def retrieve_example_texts(keys)
|
|
@@ -11,8 +11,18 @@ module Glib
|
|
|
11
11
|
new_key = "#{controller_name}.#{action_name}#{key}"
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
content = Glib::Text.get_content(new_key, default_value, options: options)
|
|
14
|
+
content, text_object = Glib::Text.get_content(new_key, default_value, options: options)
|
|
15
15
|
content.gsub(/\{\{(\w+)\}\}/) { args.fetch($1.to_sym, "{{#{$1}}}") }
|
|
16
|
+
|
|
17
|
+
if text_object.images.attached?
|
|
18
|
+
content.gsub(/\{\{image(\d)\}\}/) {
|
|
19
|
+
if image = text_object.images[$1.to_i - 1]
|
|
20
|
+
image_server_url(image.blob.key)
|
|
21
|
+
else
|
|
22
|
+
"{{image#{$1}}}"
|
|
23
|
+
end
|
|
24
|
+
}
|
|
25
|
+
end
|
|
16
26
|
end
|
|
17
27
|
|
|
18
28
|
def dt_json(key, default_value = '', **args)
|
|
@@ -26,5 +36,17 @@ module Glib
|
|
|
26
36
|
dt_key: new_key
|
|
27
37
|
}.merge(args)
|
|
28
38
|
end
|
|
39
|
+
|
|
40
|
+
def image_server_url(blob_key, w: 100, h: 100)
|
|
41
|
+
return unless blob_key.present?
|
|
42
|
+
|
|
43
|
+
uri = URI::HTTPS.build(
|
|
44
|
+
host: 'imageserver-demo.herokuapp.com',
|
|
45
|
+
path: "/image/#{ENV['AWS_S3_BUCKET']}/#{blob_key}",
|
|
46
|
+
query: { w: w, h: h }.to_param
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
uri.to_s
|
|
50
|
+
end
|
|
29
51
|
end
|
|
30
52
|
end
|
data/app/models/glib/text.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
module Glib
|
|
2
2
|
class Text < Glib::DynamicTextRecord
|
|
3
|
+
has_many_attached :images
|
|
4
|
+
|
|
3
5
|
validates :scope, presence: true
|
|
4
6
|
validates :lang, presence: true
|
|
5
7
|
validates :key, presence: true, uniqueness: { scope: [:scope, :lang] }
|
|
@@ -10,18 +12,20 @@ module Glib
|
|
|
10
12
|
def self.get_content(key, default_value, options:)
|
|
11
13
|
scope_key = "#{options[:scope]}.#{options[:lang]}.#{key}"
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
if content = $dt_redis.get(scope_key)
|
|
16
|
+
text = find_by(scope: options[:scope], lang: options[:lang], key: key)
|
|
17
|
+
else
|
|
14
18
|
if text = find_by(scope: options[:scope], lang: options[:lang], key: key)
|
|
15
19
|
update_content(scope_key, text.content)
|
|
16
20
|
content = text.content
|
|
17
21
|
else
|
|
18
|
-
create(scope: options[:scope], lang: options[:lang], key: key, content: default_value)
|
|
22
|
+
text = create(scope: options[:scope], lang: options[:lang], key: key, content: default_value)
|
|
19
23
|
update_content(scope_key, default_value)
|
|
20
24
|
content = default_value
|
|
21
25
|
end
|
|
22
26
|
end
|
|
23
27
|
|
|
24
|
-
content
|
|
28
|
+
[content, text]
|
|
25
29
|
end
|
|
26
30
|
|
|
27
31
|
private
|
|
@@ -8,9 +8,14 @@ module Glib
|
|
|
8
8
|
class_option :app_name, type: :string, default: Rails.application.class.parent_name
|
|
9
9
|
|
|
10
10
|
def copy_initializer
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
[
|
|
12
|
+
'20191017062519_create_texts.rb',
|
|
13
|
+
'20191024063257_add_scope_to_texts.rb',
|
|
14
|
+
'20191112095018_add_lang_to_texts.rb',
|
|
15
|
+
'20191126071051_create_active_storage_tables.active_storage.rb'
|
|
16
|
+
].each do |migration_file|
|
|
17
|
+
template migration_file, "db/dynamic_text_migrate/#{migration_file}"
|
|
18
|
+
end
|
|
14
19
|
template 'dynamic_text.rb', 'config/initializers/dynamic_text.rb'
|
|
15
20
|
template 'database.yml', 'config/database.yml'
|
|
16
21
|
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# This migration comes from active_storage (originally 20170806125915)
|
|
2
|
+
class CreateActiveStorageTables < ActiveRecord::Migration[5.2]
|
|
3
|
+
def change
|
|
4
|
+
create_table :active_storage_blobs do |t|
|
|
5
|
+
t.string :key, null: false
|
|
6
|
+
t.string :filename, null: false
|
|
7
|
+
t.string :content_type
|
|
8
|
+
t.text :metadata
|
|
9
|
+
t.bigint :byte_size, null: false
|
|
10
|
+
t.string :checksum, null: false
|
|
11
|
+
t.datetime :created_at, null: false
|
|
12
|
+
|
|
13
|
+
t.index [ :key ], unique: true
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
create_table :active_storage_attachments do |t|
|
|
17
|
+
t.string :name, null: false
|
|
18
|
+
t.references :record, null: false, polymorphic: true, index: false
|
|
19
|
+
t.references :blob, null: false
|
|
20
|
+
|
|
21
|
+
t.datetime :created_at, null: false
|
|
22
|
+
|
|
23
|
+
t.index [ :record_type, :record_id, :name, :blob_id ], name: "index_active_storage_attachments_uniqueness", unique: true
|
|
24
|
+
t.foreign_key :active_storage_blobs, column: :blob_id
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: glib-web
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.
|
|
4
|
+
version: 0.4.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- ''
|
|
@@ -133,6 +133,7 @@ files:
|
|
|
133
133
|
- lib/generators/templates/20191017062519_create_texts.rb
|
|
134
134
|
- lib/generators/templates/20191024063257_add_scope_to_texts.rb
|
|
135
135
|
- lib/generators/templates/20191112095018_add_lang_to_texts.rb
|
|
136
|
+
- lib/generators/templates/20191126071051_create_active_storage_tables.active_storage.rb
|
|
136
137
|
- lib/generators/templates/database.yml
|
|
137
138
|
- lib/generators/templates/dynamic_text.rb
|
|
138
139
|
- lib/glib-web.rb
|