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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3d1149ca462352763a72cb6e58287a4de0769c92fd2ffda66bf7e2b63569890
4
- data.tar.gz: 8e0abe7b68f2e8a43c7b43bf792e288453978f77549415f6854ecf516e7e8ade
3
+ metadata.gz: '00370028bd3cdc3097c1b40e128c34ec08271d2858b5a83d2c54ebceb5f18c6e'
4
+ data.tar.gz: 5021c723ca5ef541455c0497fc0a25f86945b7d99383698fb76d587d034f2f9b
5
5
  SHA512:
6
- metadata.gz: ad4d63d5f450b027d2648d1fa5af30935e98174e01974a6a7c2db1f674bc441361fcde1d843cb821667659e71605696606950432944c74a3253b09326740c5e9
7
- data.tar.gz: a1d88def9320774a923f6805b259d3faaaf08e39407133c078e6ac1a2def4d4f100477bfec4c70c305f61adfae695f0b03cf7b7b064100b1f087e67873587c16
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
- # if Rails.env.development? && params[:_validate] == 'true'
4
- if (hash = json_transformation_start).is_a?(Hash)
5
- @__specs = {}
6
-
7
- crawl hash['header']&.[]('childViews')
8
- crawl hash['body']&.[]('childViews')
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
- translated_texts = retrieve_example_texts(@__specs.keys)
12
- translated_texts.each do |key, value|
13
- @__specs[key].each do |spec|
14
- spec.substitute_with(value)
15
- end
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
- # end
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
@@ -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
- unless content = $dt_redis.get(scope_key)
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
@@ -5,6 +5,7 @@ json_ui_page json do |page|
5
5
 
6
6
  page.scroll padding: glib_json_padding_body, childViews: ->(scroll) do
7
7
  scroll.h3 text: dt_json('.hello', name: 'John')
8
+ scroll.spacer height: 6
8
9
  scroll.label text: dt_json('.greeting')
9
10
  end
10
11
 
@@ -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
- template '20191017062519_create_texts.rb', 'db/dynamic_text_migrate/20191017062519_create_texts.rb'
12
- template '20191024063257_add_scope_to_texts.rb', 'db/dynamic_text_migrate/20191024063257_add_scope_to_texts.rb'
13
- template '20191112095018_add_lang_to_texts.rb', 'db/dynamic_text_migrate/20191112095018_add_lang_to_texts.rb'
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.1
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