Module: Glib::Json::DynamicText

Defined in:
app/controllers/concerns/glib/json/dynamic_text.rb

Defined Under Namespace

Classes: TextSpec

Instance Method Summary collapse

Instance Method Details

#__json_traversal_register_dynamic_textObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/concerns/glib/json/dynamic_text.rb', line 2

def __json_traversal_register_dynamic_text
  @__specs = {}
  @__specs_db = {}

  __json_traversal_on_traverse do |view|
    extract_spec(view, 'text')
  end

  __json_traversal_on_complete do |view|
    if @__specs.keys.size > 0
      translated_texts = retrieve_texts(@__specs.keys)
      # translated_texts = retrieve_local_texts(@__specs.keys).merge(retrieve_remote_texts(@__specs.keys))
      translated_texts.each do |key, value|
        @__specs[key].each do |spec|
          spec.substitute_with(value)
        end

        if @__specs_db[key] && @__specs_db[key].images.attached?
          @__specs[key].each do |spec|
            spec.substitute_image_with(@__specs_db[key].images)
          end
        end
      end
    end
  end
end

#extract_spec(view, prop) ⇒ Object

translated_texts end



89
90
91
92
93
94
95
96
# File 'app/controllers/concerns/glib/json/dynamic_text.rb', line 89

def extract_spec(view, prop)
  if (spec = view[prop])
    if spec.is_a?(Hash) && (key = spec['dt_key'])
      @__specs[key] ||= []
      @__specs[key] << TextSpec.new(view, prop, spec)
    end
  end
end

#retrieve_textsObject



29
30
31
32
# File 'app/controllers/concerns/glib/json/dynamic_text.rb', line 29

def retrieve_texts
  # TODO: Check local memory
  # TODO: Then check DTR
end