Module: Glib::Json::DynamicText
- Defined in:
- app/controllers/concerns/glib/json/dynamic_text.rb
Defined Under Namespace
Classes: TextSpec
Class Method Summary collapse
- .crawl_multiple(views, block) ⇒ Object
- .crawl_single(view, block) ⇒ Object
- .crawl_vertical_content(view, block) ⇒ Object
Instance Method Summary collapse
- #__json_dynamic_text_perform ⇒ Object
- #crawl(views) ⇒ Object
- #extract_spec(view, prop) ⇒ Object
- #retrieve_example_texts(keys) ⇒ Object
- #retrieve_remote_texts(keys) ⇒ Object
Class Method Details
.crawl_multiple(views, block) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/controllers/concerns/glib/json/dynamic_text.rb', line 60 def self.crawl_multiple views, block if views.is_a? Array views.each do |view| crawl_single view, block end # views.each do |view| # case view['view'] # when 'panels/form-v1' # @@forms << view # crawl_single view, block # @@forms.pop # else # crawl_single view, block # end # end end end |
.crawl_single(view, block) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/controllers/concerns/glib/json/dynamic_text.rb', line 83 def self.crawl_single view, block block.call view # Generic view children crawl_multiple view['childViews'], block # panels/split # crawl_multiple view['leftViews'], block # crawl_multiple view['rightViews'], block # Split panel crawl_vertical_content view['left'], block crawl_vertical_content view['center'], block crawl_vertical_content view['right'], block # TODO: crawl header and footer # Table/List if (sections = view['sections']).is_a? Array sections.each do |section| # Table crawl_multiple section['rows'], block end end end |
.crawl_vertical_content(view, block) ⇒ Object
79 80 81 |
# File 'app/controllers/concerns/glib/json/dynamic_text.rb', line 79 def self.crawl_vertical_content view, block crawl_multiple view['childViews'], block if view end |
Instance Method Details
#__json_dynamic_text_perform ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/concerns/glib/json/dynamic_text.rb', line 2 def __json_dynamic_text_perform if (hash = json_transformation_start).is_a?(Hash) @__specs = {} crawl hash['header']&.[]('childViews') crawl hash['body']&.[]('childViews') crawl hash['footer']&.[]('childViews') translated_texts = retrieve_remote_texts(@__specs.keys) # translated_texts = retrieve_example_texts(@__specs.keys) translated_texts.each do |key, value| @__specs[key].each do |spec| spec.substitute_with(value) end end end end |
#crawl(views) ⇒ Object
39 40 41 42 43 |
# File 'app/controllers/concerns/glib/json/dynamic_text.rb', line 39 def crawl views Glib::Json::DynamicText::crawl_multiple views, ->(view) do extract_spec(view, 'text') end end |
#extract_spec(view, prop) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'app/controllers/concerns/glib/json/dynamic_text.rb', line 45 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_example_texts(keys) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/concerns/glib/json/dynamic_text.rb', line 21 def retrieve_example_texts(keys) examples_translations = { 'home.json_ui_garage.hello' => 'Hello {{name}}', 'home.json_ui_garage.greeting' => 'Good day!', } translated_texts = {} keys.each do |key| translated_texts[key] = examples_translations[key] end translated_texts end |
#retrieve_remote_texts(keys) ⇒ Object
34 35 36 37 |
# File 'app/controllers/concerns/glib/json/dynamic_text.rb', line 34 def retrieve_remote_texts(keys) response = RestClient.get(ENV['DTR_URL'], { params: { keys: keys } }) JSON.parse(response) end |